var xmlhttp;

function Local_login(username,password,errormsg,noreload,sourcefile){
	
	xmlhttp=GetXmlHttpObject();

	if (noreload == undefined) { noreload=0;}
	
    if (xmlhttp==null)
	  {
	  alert ("Please update your browser to use AviationResults ");
	  return;
	  }
    
    
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4){
		  if (xmlhttp.responseText=='NOUSER'){
			  document.getElementById('INFO_LoginResult').innerHTML=errormsg; }
		
		  if (xmlhttp.responseText=='NOACTIVE'){
			  document.getElementById('INFO_LoginResult').innerHTML="Account not Active. <br>Need Email Confirmation<br><a href='MainLoader.php?Page=AccountActivation'>Go to Activation Page</a>";
		  }
		  
		  if (xmlhttp.responseText!='NOUSER' && xmlhttp.responseText!='NOACTIVE' ){
			 
			  RespText=xmlhttp.responseText;
			  SessID=RespText.substring(0,RespText.indexOf("***"));
			  RespText=RespText.substring(RespText.indexOf("***")+3);
			  SessCT=RespText.substring(0,RespText.indexOf("***"));
			  SessName=RespText.substring(RespText.indexOf("***")+3);
			  
			  Set_Cookie('SessID',SessID,4,"/","");
			  Set_Cookie('SessCT',SessCT,4,"/","");
			  Set_Cookie('Name',SessName,4,"/","");
     		  if (noreload ==0) {window.location.reload(); }
     		
     		  if (noreload ==2) {window.location.assign(sourcefile); }
		  }
		}
	};
	xmlreq = "";
	Pass=SHA256(password);
	//alert(Pass);
	xmlreq = xmlreq.concat('LoginCheck.php?User=',username,'&Passw=',Pass);
	xmlhttp.open("GET",xmlreq,true);
	 
	xmlhttp.send(null);
	
}


function Local_logout(){
	
	
	xmlhttp=GetXmlHttpObject();

    if (xmlhttp==null)
	  {
	  alert ("Please update your browser to use Mail2Car");
	  return;
	  }
    
    xmlreq = "";
	xmlreq = xmlreq.concat('LogoutUser.php');
	xmlhttp.open("GET",xmlreq,false);
	xmlhttp.send(null);
      
    Del_Cookie('SessID',"/","");
	Del_Cookie('SessCT',"/","");
	Del_Cookie('Name',"/","");
		
	window.location.reload();
	
}


function reloadmodule(moduleref,sourcefile,nowait)
{

	if (nowait==null) { nowait=true; }

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
name=moduleref;
xmlhttp.onreadystatechange=function(){
	document.getElementById(name).innerHTML=xmlhttp.responseText;
};
xmlhttp.open("GET",sourcefile,nowait);
xmlhttp.send(null);
}

function reloadmodulew(moduleref,sourcefile,nowait)
{

	if (nowait==null) { nowait=true; }

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
name=moduleref;
xmlhttp.open("GET",sourcefile,false);
xmlhttp.send(null);
document.getElementById(name).innerHTML=xmlhttp.responseText;
}

function adv_reloadmodule(moduleref,sourcefile)
{

	
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
name=moduleref;

xmlhttp.open("GET",sourcefile,false);
xmlhttp.send(null);
document.getElementById(name).innerHTML=xmlhttp.responseText;
}






function reloadandfetch(moduleref,sourcefile,formname,tablename,funct,successmessage){
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	name=moduleref;
	xmlhttp.open("GET",sourcefile,false);
	xmlhttp.send(null);	
	response=xmlhttp.responseText;
	if (response.indexOf('**OK**')==0) {
		if (funct==1) {document.getElementById(name).innerHTML=successmessage; }
		FetchAndLoad(formname,tablename,response.slice(6))	
	}
	else {
		document.getElementById(name).innerHTML=xmlhttp.responseText;	
	}
	
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


function BuildPOST(FormName) {
    CurrentForm = document.forms[FormName];
    var qs = '';
    for (e=0;e<CurrentForm.elements.length;e++) {
        if (CurrentForm.elements[e].name!='') {
            var name = CurrentForm.elements[e].name;
            qs+=(qs=='')?'':'&'
            	if (CurrentForm.elements[e].type=="checkbox" || CurrentForm.elements[e].type=="radio" ) {
            		
            		
            		   if (CurrentForm.elements[e].checked){
            			   qs+= name+'='+CurrentForm.elements[e].value;
            		   }
            		
            		
            		
            	}                
                else {	
                	qs+= name+'='+CurrentForm.elements[e].value; }
        }
    }
    qs+="\n";
    return qs
} 

function BuildPOST2(FormName,FormName2) {
    CurrentForm = document.forms[FormName];
    var qs = '';
    for (e=0;e<CurrentForm.elements.length;e++) {
        if (CurrentForm.elements[e].name!='') {
            var name = CurrentForm.elements[e].name;
            
            qs+=(qs=='')?'':'&'
            	if (CurrentForm.elements[e].type=="checkbox" || CurrentForm.elements[e].type=="radio" ) {
            		   
            			
            		   if (CurrentForm.elements[e].checked){
            			   qs+= name+'='+CurrentForm.elements[e].value;
            		   }
            	
            		
            	}
                else {	
                	qs+= name+'='+CurrentForm.elements[e].value; }
            
        }
    }
    CurrentForm = document.forms[FormName2];
    
    for (e=0;e<CurrentForm.elements.length;e++) {
        if (CurrentForm.elements[e].name!='') {
            var name = CurrentForm.elements[e].name;
            qs+=(qs=='')?'':'&'
            	if (CurrentForm.elements[e].type=="checkbox" || CurrentForm.elements[e].type=="radio" ) {
            		
            		   if (CurrentForm.elements[e].checked){
            			   qs+= name+'='+CurrentForm.elements[e].value;
            		   }
            		
            		
            		
            	}
                else {	
                	qs+= name+'='+CurrentForm.elements[e].value; }
        }
    }
    
    
    qs+="\n";
    return qs
} 

function RemoveSpecialCharacters(str)
{

    sb="";
    for (i=0; i<str.Length; i++)
    {
        if ((str[i] >= '0' && str[i] <= '9') || (str[i] >= 'A' && str[i] <= 'z' || (str[i] == '.' || str[i] == '_')))
            sb.Append(str[i]);
    }

    return sb;
}


function FetchAndLoad(FormName,Tablename,Key) {
    
	// Test Mode - alert(key);
	CurrentForm = document.forms[FormName];
    
    NewxmlHTTP = GetXmlHttpObject();
 
    if (NewxmlHTTP==null)
    {
       alert ("Browser does not support HTTP Request");
       return;
    }
    
    sourcefile = 'FTI.php'+Key+'&TBN='+Tablename;
  
    NewxmlHTTP.open("GET",sourcefile,false);
    NewxmlHTTP.send(null);	
    
    xmlResult=NewxmlHTTP.responseXML;

    for (e=0;e<CurrentForm.elements.length;e++) {
    	
        if (CurrentForm.elements[e].name!='') {
        	
        	try{typeofcell=xmlResult.getElementsByTagName(CurrentForm.elements[e].name)[0].getAttribute('type');
        	    
        	    if(typeofcell=='text') {CurrentForm.elements[e].value = xmlResult.getElementsByTagName(CurrentForm.elements[e].name)[0].childNodes[0].nodeValue;}
        	    if(typeofcell=='date') { elementname=CurrentForm.elements[e].name;
        	                             DateValue=xmlResult.getElementsByTagName(CurrentForm.elements[e].name)[0].childNodes[0].nodeValue;
        	                             Ys=DateValue.substr(0,4);
        	                             Ms=DateValue.substr(5,2);
        	                             Ds=DateValue.substr(8,2);
        	                             Msa=String(parseInt(Ms,10)-1);
        	                             DateOfBirth_Object.setPicked(Ys,Msa,Ds);
        	                             document.getElementById(elementname+'_Day_ID').options[parseInt(Ds,10)-1].selected=true;
        	                             document.getElementById(elementname+'_Month_ID').options[parseInt(Ms,10)-1].selected=true;
        	                             document.getElementById(elementname+'_Year_ID').value=parseInt(Ys,10);
        	    	                     } 
        	    if (CurrentForm.elements[e].type=="select-one") {
        	                            valcheck=xmlResult.getElementsByTagName(CurrentForm.elements[e].name)[0].childNodes[0].nodeValue;
        	                            valcheck=valcheck.replace(/^\s*/, "").replace(/\s*$/, "");
        	                            //alert(valcheck.length);
        	                            for (ii=0;ii<=CurrentForm.elements[e].length;ii++) {
        	                                
        	                            	if (CurrentForm.elements[e].options[ii].value==valcheck){
        	                            		//alert(valcheck);
        	                            		CurrentForm.elements[e].options[ii].selected=true;
        	                            		
        	                            	} else { CurrentForm.elements[e].options[ii].selected=false; }
        	                            }
        	    
        	    }
        	    							
        	    } //try closing 
            catch(err){ ErrorCode=err;}
        }
    }
    
} 



function DBInteract(FormReference,sourcefile)
{

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return "";
  }

parameters=BuildPOST(FormReference);

xmlhttp.open("POST",sourcefile,false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(parameters);
return xmlhttp.responseText;
}

function DBQuery(sourcefile)
{

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return "";
  }

xmlhttp.open("GET",sourcefile,false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(sourcefile);
return xmlhttp.responseText;
}

function DBInteract2(FormReference,FormReference2,sourcefile)
{

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return "";
  }

parameters=BuildPOST2(FormReference,FormReference2);

xmlhttp.open("POST",sourcefile,false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(parameters);
return xmlhttp.responseText;
}


function DBAction(FormReference,sourcefile,errormodule,nexturl,login,username,password){


	response = DBInteract(FormReference,sourcefile); 
	// if the PHP interaction is positive it will return a **OK** string at the beginning of the return response
	// followed by the parameters to pass to the next URL 
	okresponse = response.indexOf("**OK**");
	
	if (login == undefined) {login=0;}
	
	if (okresponse == 0) {
		response = response.slice(6);
		nexturlrequest = nexturl.concat(response);
		if (login==1) {Local_login(username,password,errormodule,1);}
		window.location.assign(nexturlrequest);  	
	} else { 
		document.getElementById(errormodule).innerHTML=response;	
	}
}

function DBAction2(FormReference,FormReference2,sourcefile,errormodule,frameurl){


	response = DBInteract2(FormReference,FormReference2,sourcefile); 
	// if the PHP interaction is positive it will return a **OK** string at the beginning of the return response
	// followed by the parameters to pass to the next URL 
	okresponse = response.indexOf("**CHRT**");
	//alert(response);		
	if (okresponse==-1) { MissionPos=response.indexOf("**OK**");  
				          if (MissionPos!=-1){ 
				        	  return response.substr(6);
				        	  
				          } else {
		                           document.getElementById(errormodule).innerHTML=response; 
		                           }}
	else {
	document.getElementById(errormodule).innerHTML=response.substr(0,okresponse);	

    sourcefile="http://chart.apis.google.com/chart"+response.substr(okresponse+8);
	if (frameurl!="") {    
	    document.getElementById(frameurl).src=sourcefile;
	    fr=document.getElementById(frameurl);
	    fr.style.display="block"; }
	}
	
}


function DBAction3(FormReference,FormReference2,sourcefile,errormodule,frameurl,sourceurl){

    //alert('here');
	response = DBInteract2(FormReference,FormReference2,sourcefile); 
	// if the PHP interaction is positive it will return a **OK** string at the beginning of the return response
	// followed by the parameters to pass to the next URL 
	okresponse = response.indexOf("**OK**");
    	
	//alert(response);		
	if (okresponse==-1) {  document.getElementById(errormodule).innerHTML=response; }
	else {
	   if (frameurl=="") {
		 window.location.assign("Mainloader.php?Page="+sourceurl);  
	   } else {	reloadmodule(frameurl,sourceurl); }
	}
	
}




function hidegraph(Graphname) {
   fr=document.getElementById (Graphname);
   fr.style.display="none";
}

function ResetForm(Formname){
	
	CurrentForm=document.forms[Formname];
	CurrentForm.reset();
}


function SwitchButton(ButtonName,NewFace) {
	
	try {document.getElementById(ButtonName).value=NewFace;}
	catch(err) {alert(err);}
	
}

function DisableButton(ButtonName,Active) {
	
	try {document.getElementById(ButtonName).disabled=Active;}
	catch(err) {alert(err);}
	
}

function disablefield(FieldName,Active) {
	
	try {document.getElementById("INPUT_"+FieldName).disabled=Active; }
	catch (err) {alert(err);}
	
}


function ClearDropDown(id)
{
	document.getElementById(id).options.length = 0;
}


function AddOrEdit(CheckButton,FormName,ErrorModule,SourceAdd,SourceEdit,ReloadModule,ReloadSource){
	// Source Add - PHP in case of ADD
	// Source Edit - PHP in case of EDIT
 
	
    if (CheckButton.slice(0,2) == "**") {
    TagButton=CheckButton.slice(2);
    }
    else {
   	TagButton=document.getElementById(CheckButton).value;
    }
    
	if (TagButton==CONST_Edit){
	   response=DBInteract(FormName,SourceEdit); 	
	}
	
	if (TagButton==CONST_Add) {
		response=DBInteract(FormName,SourceAdd);	
	}
	
	if (TagButton==CONST_Delete){
	   
		DeleteConfirmation=GetDeleteConfirmation(FormName);
	   if (DeleteConfirmation) { response=DBInteract(FormName,SourceEdit); }
	   else {response="";}
	}
   
    
	okresponse = response.indexOf("**OK**");

	if (okresponse==0) {
	   reloadmodule(ReloadModule,ReloadSource+response.slice(6));	
	}
	else {
		document.getElementById(ErrorModule).innerHTML=response;
	}	
		
		
	
}



function GetDeleteConfirmation(FormName) {
	
    CurrentForm = document.forms[FormName];
    
    AlertText = 'Do You Really want to delete this record : \n';
    
    for (e=0;e<CurrentForm.elements.length;e++) {
    
        if (CurrentForm.elements[e].name!='') {
        	
            name = CurrentForm.elements[e].name;
            AlertText=AlertText+name+":"+CurrentForm.elements[e].value+"\n";
        }
    }
    
    return confirm(AlertText);
	
	
}


function ChangePage(NewPage,Parameters){
	
    i=0;
    qs="";
	for (var Cur in Parameters){
		
		try {qs=qs+"&"+Parameters[i]+"="+document.getElementById('INPUT_'+Parameters[i]).value;}
		catch(err) {alert(err);}
		i++;
	}
	
	url='MainLoader.php?Pgref='+NewPage+qs;
	location.assign(url);
	
}



function MessOut(MessageModule,MessageText,MessageClass){
	
	try { document.getElementById(MessageModule).innerHTML="<div id='Message_'"+MessageModule+" class='"+MessageClass+"'>"+MessageText+"</div>"; }
	catch(err) {alert(err);}
	
}


function Val(Field) {
	
   try { var output='';
         output = document.getElementById("INPUT_"+Field).value;
	     return output; }
   catch(err) {alert(err);}
	
}


function SetVal(Field,FieldValue) {
	
   try { document.getElementById("INPUT_"+Field).value = FieldValue;}
   catch(err) {alert(err);}
	
}

function SHA256(s){
	 
	var chrsz   = 8;
	var hexcase = 0;
 
	function safe_add (x, y) {
		var lsw = (x & 0xFFFF) + (y & 0xFFFF);
		var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
		return (msw << 16) | (lsw & 0xFFFF);
	}
 
	function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
	function R (X, n) { return ( X >>> n ); }
	function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
	function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
	function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
	function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
	function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
	function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }
 
	function core_sha256 (m, l) {
		var K = new Array(0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2);
		var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
		var W = new Array(64);
		var a, b, c, d, e, f, g, h, i, j;
		var T1, T2;
 
		m[l >> 5] |= 0x80 << (24 - l % 32);
		m[((l + 64 >> 9) << 4) + 15] = l;
 
		for ( var i = 0; i<m.length; i+=16 ) {
			a = HASH[0];
			b = HASH[1];
			c = HASH[2];
			d = HASH[3];
			e = HASH[4];
			f = HASH[5];
			g = HASH[6];
			h = HASH[7];
 
			for ( var j = 0; j<64; j++) {
				if (j < 16) W[j] = m[j + i];
				else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
 
				T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
				T2 = safe_add(Sigma0256(a), Maj(a, b, c));
 
				h = g;
				g = f;
				f = e;
				e = safe_add(d, T1);
				d = c;
				c = b;
				b = a;
				a = safe_add(T1, T2);
			}
 
			HASH[0] = safe_add(a, HASH[0]);
			HASH[1] = safe_add(b, HASH[1]);
			HASH[2] = safe_add(c, HASH[2]);
			HASH[3] = safe_add(d, HASH[3]);
			HASH[4] = safe_add(e, HASH[4]);
			HASH[5] = safe_add(f, HASH[5]);
			HASH[6] = safe_add(g, HASH[6]);
			HASH[7] = safe_add(h, HASH[7]);
		}
		return HASH;
	}
 
	function str2binb (str) {
		var bin = Array();
		var mask = (1 << chrsz) - 1;
		for(var i = 0; i < str.length * chrsz; i += chrsz) {
			bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
		}
		return bin;
	}
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	}
 
	function binb2hex (binarray) {
		var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
		var str = "";
		for(var i = 0; i < binarray.length * 4; i++) {
			str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
			hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
		}
		return str;
	}
 
	s = Utf8Encode(s);
	return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
 
}

function ReloadTimer(Time,Module,ModuleFile){

	adv_reloadmodule(Module,ModuleFile);

	ReloadString="ReloadTimer(";
	ReloadString=ReloadString.concat(Time,",'",Module,"','",ModuleFile,"')");

    
	t=setTimeout(ReloadString,Time);
	
}

function param_reloadmodule(Module,ModuleFile,Param) {
	
	callmodule=ModuleFile+Param;
	adv_reloadmodule(Module,callmodule);
	
	
}


function ResetModule(Module) {
	
	document.getElementById(name).innerHTML="";	
		
}




function SearchUser(sourcefile,error,username,primaryemail,authfield){
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }

	xmlhttp.open("GET",sourcefile,false);
	xmlhttp.send(null);
	response=xmlhttp.responseText;
	
	if (response.indexOf("*OK**")>0) {
		document.getElementById('INPUT_UserEmail').value=primaryemail;
		document.getElementById(username).innerHTML=response.substr(6,response.indexOf("****")-6);
		Permission=response.substr(response.indexOf("****"));
	
		if (Permission.indexOf('P')>0) {document.getElementById(authfield+'P').checked=true; } else {document.getElementById(authfield+'P').checked=false; }
		if (Permission.indexOf('D')>0) {document.getElementById(authfield+'D').checked=true; } else {document.getElementById(authfield+'D').checked=false; }
		if (Permission.indexOf('U')>0) {document.getElementById(authfield+'U').checked=true; } else {document.getElementById(authfield+'U').checked=false; }
		if (Permission.indexOf('O')>0) {document.getElementById(authfield+'O').checked=true; } else {document.getElementById(authfield+'O').checked=false; }
		if (Permission.indexOf('M')>0) {document.getElementById(authfield+'M').checked=true; } else {document.getElementById(authfield+'M').checked=false; }
		document.getElementById(error).innerHTML="<span class='bold_head'>User Found</span>";
		DisableButton('ButtonSave',false);
		DisableButton('ButtonDel',false);
	} else {
		document.getElementById(error).innerHTML=response;	
		DisableButton('ButtonSave',true);
		DisableButton('ButtonDel',true);
	}	
	
	
}


function CheckMandatory(CurrentValue,ErrorField) {

	if (CurrentValue=="") {
	   document.getElementById(ErrorField).innerHTML="&nbsp; &nbsp; This Field is Mandatory";
	} else {
	  document.getElementById(ErrorField).innerHTML="";
		
	}
	
	
}

function CheckEqual(Field1, Field2, ErrorMessageField, ErrorMessage){

    Field1V=document.getElementById(Field1).value;
    Field2V=document.getElementById(Field2).value;

    if (Field1V!=Field2V) { document.getElementById(ErrorMessageField).innerHTML=ErrorMessage; }
    else { document.getElementById(ErrorMessageField).innerHTML="";}
	
}

function clearForms(){  
  // declare element type  
  var type = null;  
  // loop through forms on HTML page  
  for (var x=0; x<document.forms.length; x++){  
    // loop through each element on form  
    for (var y=0; y<document.forms[x].elements.length; y++){  
      // define element type  
      type = document.forms[x].elements[y].type  
      // alert before erasing form element  
      //alert('form='+x+' element='+y+' type='+type);  
      // switch on element type  
      switch(type){  
        case "text":  
        case "textarea":  
        case "password":  
        //case "hidden":  
          document.forms[x].elements[y].value = "";  
          break;  
        case "radio":  
        case "checkbox":  
          document.forms[x].elements[y].checked = "";  
          break;  
        case "select-one":  
          document.forms[x].elements[y].options[0].selected = true;  
          break;  
        case "select-multiple":  
          for (z=0; z<document.forms[x].elements[y].options.length; z++){  
            document.forms[x].elements[y].options[z].selected = false;  
          }  
        break;  
      }  
    }  
  }  
}  


function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

