var request=null;
//function is using for send user type value in database and get plan details according to user type.
function changeuser(value,plan_id){

       // showHideBroker(value);
       //alert(value);
	createRequest();
	url	=	"changeuser.php?value="+escape(value)+"&plan_id="+escape(plan_id);
	//url = url + escape(value);
	//alert(url);	
	sendRequest(url);
}

//function is using for show hide broker fee. If user is standard user then show broker fee else hide broker fee.
	function showHideBroker(value){
		if(value == 'S'){
		  document.getElementById('broker_fee_show').style.display='inline';
		}else{
		  document.getElementById('broker_fee_show').style.display='none';
		}
	}

function check(){
       var conf;
	if(document.getElementById("chkRenewPlan").checked == true){	
        conf = confirm('Do you really want to renew plan automatically');
         if(!conf){           
           document.getElementById("chkRenewPlan").checked = false;
	  renewPlan = 'N';
          return false;
         }else {
document.getElementById("chkRenewPlan").checked = true;
renewPlan = 'Y';
}
	 
	}else{
       
          conf = confirm('Do you really want to cancel Automatic Renewal of Plan');
         if(!conf){
document.getElementById("chkRenewPlan").checked = true;
renewPlan = 'Y';
 return false;
           
         }else{
document.getElementById("chkRenewPlan").checked = false;
renewPlan = 'N';
}
	 
	}
	
	createRequest();
	url	=	"autoRenewPlan.php?renewPlan="+renewPlan;
	//url = url + escape();	
	sendRequest(url);
}

function check1(){
       var conf;
	if(document.getElementById("clear_setting").checked == true){	
        conf = confirm('Do you really want to clear setting');
         if(!conf){           
           document.getElementById("clear_setting").checked = false;
	  clearSetting = 'N';
          return false;
         }else {
document.getElementById("clear_setting").checked = true;
 clearSetting = 'Y';
}
	 
	}else{
       
          conf = confirm('Do you really want to cancel setting clearence');
         if(!conf){
document.getElementById("clear_setting").checked = true;
clearSetting = 'Y';
 return false;
           
         }else{
document.getElementById("clear_setting").checked = false;
clearSetting = 'N';
}
	 
	}
	
	createRequest();
	url	=	"clearSetting.php?clearSetting="+clearSetting;
	//url = url + escape();	
	sendRequest(url);
}





















function showResult()
{
	var response;
	if(request.readyState == 4)
	{
		response	=	request.responseText;
		var newtext=response;
		document.getElementById("div_change").style.display	=	"block";
		document.getElementById("div_change").innerHTML = response;
	}else{
		document.getElementById("div_change").innerHTML = "<img src='/img/loading.gif'>";
	}
}
function decodePassword($password)
{
	
	// ,"%5C" ,"%2F" ,"%22" ,"%3A","%3B" ,"%3F");
	$find=array("+", "," ,"`" ,"=" ,"@" ,"#" ,"$" ,"%" ,"^" ,"&" ,"{" ,"}" ,"|",":" ,";" ,"?",'"','/','[',']');
	$replace=array("%2B", "%2C" ,"%60" ,"%3D" ,"%40" ,"%23" ,"%24" ,"%25" ,"%5E" ,"%26" ,"%7B" ,"%7D" ,"%7C","%3A","%3B" ,"%3F","%22","%2F","%5B","%5D");
	//,"\" ,'/' ,""" ,":" ,";" ,"?");
	$resultPassword=str_replace($find,$replace,$password);
return $resultPassword;
}

function html_entity_decode(str) {
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return ta.value;
}
function encodeEntities()
{
	var strfun = new ActiveXObject("CkString.StrFun");
	document.form1.etx.value = strfun.HtmlEntityEncode(document.form1.etx.value);
}
function URLEncode(plaintext)
{
	
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	//var plaintext = document.getElementById(id).value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

//document.URLForm.F2.value = encoded;
 //document.URLForm.F2.select();
	return encoded;
};
function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   //document.URLForm.F1.value = plaintext;
   //document.URLForm.F1.select();
   return plaintext;
};

function white_space(field)
{
     field.value = (field.value).replace(/^\s*|\s*$/g,'');
}
