function setFormAction(action){
	//alert(action);	//alert(document.form2);
	document.getElementById('form_action').value=action;	
	//alert(document.getElementById('form_action').value);
	document.form2.submit();
}
	
function showHideRow(value){
	//alert(value);	
	if (value==1){
		$('myRow').style.visibility='hidden';
		$('btmRow').style.visibility='hidden';		
		$('btnRow').style.visibility='visible';
	}else{
		$('myRow').style.visibility='visible';
		$('btmRow').style.visibility='visible';
		$('btnRow').style.visibility='hidden';		
	}	
}

function checkDraftfields(field,field1,field2){
	alert(field);
	alert(field1);
	alert(field2);
	
	var boolNull=true;	
	
	if ($F(field).length==0) {
		boolNull=false;
	}
	bool=checkSpecialChars(field);
	nBool=true;
	nBool=IsNumeric($F(field));
	
	nBool=IsNumeric($F(field1));
	nBool=IsNumeric($F(field2));
	
	
	if (	checkSpecialChars(field) && boolNull && !IsNumeric($F(field1)) && !IsNumeric($F(field2))) {
			$('err_div').style.visibility='hidden';
			document.form1.submit();
		}else{
			 $('err_div').style.visibility='visible';
	 }  
}


function checkMemberfields(field,field2){
	var boolNull=true;
	myBool=false;
	
	if ($F(field).length==0) {
		
		boolNull=false;
		//alert(boolNull);
	}	
	//bool=IsNumeric($F('SubSectionName'));
	bool=checkSpecialChars(field);
	nBool=true;
	nBool=IsNumeric($F(field));
	//alert('nBool- outside-----'+nBool);
	myBool=IsNumeric($F(field2));
	//alert(myBool);
	if (	(bool) && (boolNull) && (nBool) &&(!myBool) ) {
			$('err_div').style.visibility='hidden';
			document.form1.submit();
		}else{
			 $('err_div').style.visibility='visible';
	 }  
	 	
}
function getContentHTML(ID,action){
	//alert(ID);
	var url = 'ajax.php?action='+action;
	var pars = 'ID='+ID;
	//alert(url);
	var myAjax = new Ajax.Updater(
		{success: 'placeholder'}, 

		url, 
		{
			method: 'get', 
			parameters: pars,
			onFailure: reportError

		});	
}

function getHTML(ID,action){
	//alert(ID);
	var url = 'ajax.php?action='+action;
	var pars = 'ID='+ID;
	
	var myAjax = new Ajax.Updater(
		{success: 'placeholder'}, 

		url, 
		{
			method: 'get', 
			parameters: pars,
			onFailure: reportError

		});	
}

function getFrontHTML(ID,action){
	//alert(ID);
	var url = 'includes/ajax.php?action='+action;
	//alert(url);
	var pars = 'ID='+ID;
	
	var myAjax = new Ajax.Updater(
		{success: 'placeholder'}, 

		url, 
		{
			method: 'get', 
			parameters: pars,
			onFailure: reportError

		});	
}

function reportError(request){
	alert('Sorry. There was an error.');
}


function checkSectionBlankFields(field){
	var boolNull=true;
	
	if ($F(field).length==0) {
		
		boolNull=false;
		//alert(boolNull);
	}
	
	//bool=IsNumeric($F('SubSectionName'));
	bool=checkSpecialChars(field);
	nBool=true;
	nBool=IsNumeric($F(field));
	//alert('nBool- outside-----'+nBool);

	  if (	(bool) && (boolNull) && (nBool)	) {
			$('err_div').style.visibility='hidden';
			document.form1.submit();
		}else{
			 $('err_div').style.visibility='visible';
	 }  
	 
}

function checkSubSectionBlankFields(field){
	//alert('here');
	var boolNull=true;
	
	if ($F('ContentTitle').length==0) {
		boolNull=false;
		//alert(boolNull);
	}
	
	//bool=IsNumeric($F('SubSectionName'));
	bool=checkSpecialChars('ContentTitle');
	nBool=true;
	nBool=IsNumeric($F('ContentTitle'));
	//alert('nBool- outside-----'+nBool);

  if (	(bool) && (boolNull) && (nBool)	) {
	  	$('err_div').style.visibility='hidden';
		document.form1.submit();
	}else{
	 	 $('err_div').style.visibility='visible';
 }  
 
}

function showHideDiv(field){
	//alert(field);
	if ($F(field)==0){
		$('err_div').style.visibility='visible';
	}else{
		$('err_div').style.visibility='hidden';
		document.form1.submit();
	}
}

function IsNumeric(sText)
{
  
  //alert(sText);
  var ValidChars = "0123456789.";
  var sbool=false;
  var Char;

 
   for (i = 0; i < sText.length && sbool == false; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         sbool = true;
         }
      }
   //alert('sbool---'+sbool);
   return sbool;
   
   }

function checkSpecialChars(varField){
	
	varBool=true;
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"; 
	var val=document.getElementById(varField).value.length;
	for (var i = 0; i < val; i++) {
		if (iChars.indexOf(document.getElementById(varField).value.charAt(i)) != -1) {
		  varBool=false;
		}
	  }
	return varBool;  
}
  

function checkBlankFields(){
	
	var bool=false;
	var section_bool=false;
	var usertype_bool=false;
	
	
	
	if ($F('UserTypeID').length==0)	usertype_bool=true;
	
	if ($F('LoginID').length==0)	bool=true;
	
	if ($F('Password').length==0)	bool=true;
	
	var sectionLength=document.form1.SectionID.length;
	//alert(sectionLength);
	for (var i=0; i < sectionLength; i++){
		//alert("i==="+i+"----"+document.frmAddAdmin.sectionid[i].checked);
		if (document.form1.SectionID[i].checked==true){
			section_bool=true;			
			break;
		}
	}
	
	
	
	//alert('usertype_bool----'+usertype_bool);
	if (section_bool)
		document.getElementById('section_div').style.visibility='hidden';
	else
		document.getElementById('section_div').style.visibility='visible';
		
	if (usertype_bool)
		document.getElementById('usertype_div').style.visibility='visible';
	else
		document.getElementById('usertype_div').style.visibility='hidden';
		
	if (bool)
		$('err_div').style.visibility='visible';
	else
		$('err_div').style.visibility='hidden';
	
	if ((bool==false) && (section_bool==true)	&& (usertype_bool==false))	{
		//alert('hello');
		document.form1.submit();
	}
	
}


function handleUserNameResponse(objXHR){
	
	var resp=objXHR.responseText;
	/*alert(resp);
	alert(resp.length);
	*/
	if (resp.length > 13){
		user_exists=false;
		//alert('NOW----'+user_exists);
		//$('userexists_div').style.visibility='visible';
	}	
}


function checkUserNameExists(url,param1Val){
	params="username="+param1Val;
	var myAjax = new Ajax.Request(
		url, 
			{
			method: 'get', 
			parameters: params, 
			onComplete: handleUserNameResponse
			}
		);
}

function showAlert(page,numrows) { 
	var b=parseInt(document.getElementById('myhidden').value);
	if (b!=0){	
		if (confirm('Are you sure you want to delete these selected record(s) ?')) {
			document.form1.action='?action=doDelete';
			document.form1.submit();			
		}
	}else{	
	alert('Please select atleast one record to delete');	
	}
}

function EnableDisable(chkbox) {
	var a=parseInt(document.getElementById('myhidden').value);
	//alert(chkbox);
	//alert(ref_id.value);
	if (chkbox.checked!=false) {
		a=a+1;
		document.getElementById('myhidden').value=a;
	}else{
		a=a-1;
		document.getElementById('myhidden').value=a;
	}
	//alert(a);
}

function checkLogin(url){
	//alert(url);
	var params=$('login_form').serialize();
	params=params+ "&sid="+Math.random();
	//alert(params);
	var myAjax = new Ajax.Request(
		url, 
			{
			method: 'get', 
			parameters: params, 
			onComplete: handleResponse
			}
		);
}

function handleResponse(objXHR){
	var resp=objXHR.responseText;
	/*
	alert('resp----'+resp);
	alert('length-----'+resp.length);
	*/
	if (resp.length=='5'){
		window.location="index.php";
	}else{
		$('login_div').innerHTML='Invalid username/password,try again';
	}	
}

function changePassword(url){
	//alert(url);
	var params=$('change_password').serialize();
	params=params+ "&sid="+Math.random();
	//alert(params);
	var myAjax = new Ajax.Request(
		url, 
			{
			method: 'get', 
			parameters: params, 
			onComplete: handleChangePasswordResponse
			}
		);
}

function handleChangePasswordResponse(objXHR){
	var resp=objXHR.responseText;
	
	
	//alert('length-----'+resp.length);
	
	/*if (resp=='userexists'){
		//alert('resp2222----'+resp);
		//alert($('userexist_div').style.visibility);
		$('userexist_div').style.visibility=true;
	}else{
		//alert('-----');
	}
	
	//alert('resp1111----'+resp);
	*/
}



function getProvince()
{
	var PartyID = $F('PartyID');
	var url = 'ajax.php?action=getProvince';
	var pars = 'ID=' + PartyID;
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: populateField
		});
	
}

function populateField(originalRequest)
{
	//alert(originalRequest.responseText);
	$('Province').value = originalRequest.responseText;
}
