var url="";
var tmp_status = false;
var chkingval="";
var option="";
var amountval=0;

function chk_sponsordetail(sponid,optionval,amtval,email,uname,phone,amount) { 
	tmp_status = true;
	option=optionval;
	amountval=amount;
	url="chkvalid.php?sponid="+sponid+"&option="+optionval+"&amt="+amtval+"&email="+email+"&uname="+uname+"&phone="+phone+"&amount="+amount;
	//prompt('',url);
	res=loadXMLDoc(url,'handleRequest');
}
function chk_paypalcheckout(sponid,sponamt) { 
	tmp_status = true;
	option='checkout';
	amountval=sponamt;
	url="chkvalid.php?sponid="+sponid+"&sponamt="+sponamt+"&option=checkout";
	//prompt('',url);
	res=loadXMLDoc(url,'handleRequest');
}
function chk_LoginInfo(username,password,sponid,sponamt) {
	tmp_status = true;
	option='login';
	url="chkvalid.php?uname="+username+"&pass="+password+"&sponid="+sponid+"&sponamt="+sponamt;
	//prompt('',url);
	res=loadXMLDoc(url,'handleRequest');
}
function chk_NewRegister(email,password,name,city,state,country,phone,sponid,sponamt) {
	tmp_status = true;
	option='register';
	url="chkvalid.php?email="+email+"&pass="+password+"&name="+name+"&city="+city+"&state="+state+"&country="+country+"&phone="+phone+"&sponid="+sponid+"&sponamt="+sponamt+"&option=register";
	//prompt('',url);
	res=loadXMLDoc(url,'handleRequest');
}
function chk_captcha() {
	//document.getElementById('div_captcha').innerHTML='<img src="ajaxCaptcha.php?width=100&height=40&characters=6" />';
	tmp_status = true;
	option='captcha';
	url="chkvalid.php?captcha=yes";
	//prompt('',url);
	res=loadXMLDoc(url,'handleRequest');
}
function chk_Updateprofile(password,name,city,state,country,phone,sponid,sponamt) {
	tmp_status = true;
	option='updateprofile';
	url="chkvalid.php?pass="+password+"&name="+name+"&city="+city+"&state="+state+"&country="+country+"&phone="+phone+"&sponid="+sponid+"&sponamt="+sponamt+"&option=update";
	//prompt('',url);
	res=loadXMLDoc(url,'handleRequest');
}
function chequepayment(cheque,sponid,sponamt) {
	tmp_status = true;
	option='chequepayment';
	url="chkvalid.php?cheque="+cheque+"&sponid="+sponid+"&sponamt="+sponamt+"&option=chequepayment";
	//prompt('',url);
	res=loadXMLDoc(url,'handleRequest');
}

function showdivcontent(result) {
	//prompt('',result);
	if(option=="login") {
		if(result=="No") {
			document.getElementById('div_loginerr').innerHTML='<font color="#FF0000">Sorry, Invalid Email/Password.</font>';
		} else {
			document.getElementById('readmore_dialog').innerHTML=result;
		}
	}
	if(option=="register") {
		if(result=="No") {
			document.getElementById('div_regerr').innerHTML='<font color="#FF0000">Sorry, Email already exit. Enter another one.</font>';
		} else {
			document.getElementById('readmore_dialog').innerHTML=result;
		}
	}
	if(option=="updateprofile") {
		//alert(result);
		document.getElementById('div_updateprofile').innerHTML=result;
	}
	if(option=="chequepayment") {
		//alert(result);
		document.getElementById('readmore_dialog').innerHTML=result;
	}
	if(option=="captcha") {
		//alert(result);
		document.getElementById('hid_captcha').value=result;
		document.getElementById('div_captcha').innerHTML='<img src="ajaxCaptcha.php?width=100&height=40&characters=6&strval='+result+'" />';
	}
	if(option=="readmore") {
		//document.getElementById('donate_dialog').style.display='none';
		document.getElementById('readmore_dialog').innerHTML=result;
	}
	if(option=="donate") {
		//document.getElementById('readmore_dialog').style.display='none';
		document.getElementById('readmore_dialog').innerHTML=result;
	}
	if(option=="checkout") {
		document.frm_sendpaypal.action="https://www.paypal.com/cgi-bin/webscr";
		document.frm_sendpaypal.amount.value=amountval;
		document.frm_sendpaypal.item_number.value=result;
		document.frm_sendpaypal.submit();
	}
	tmp_status = false;
	window.popupflg = false; 
}

/* width return result */
function loadXMLDoc(url,callbackFunction) {
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
	  try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
	  catch(oc) { req = null; }
   }
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   if (req != null) {
	  req.onreadystatechange = eval(callbackFunction);
	  req.open("GET", url, true);
	  req.send(null);
   }
}
var handleRequest = function() {
	var returnresult="";
	if (req.readyState == 4 && req.status == 200) {
		if (req.responseText!="") {
			returnresult = req.responseText;
		} else {
			returnresult= "";
			tmp_status = false;
			return false;

		}
		showdivcontent(returnresult);
	} else {
			returnresult="";
	}
}