// add by zheng on 20100116
document.write('<script src="admin_site/js/lang.js"></'+'script>'); 

function epaperSubUnsub(){

	var radio1,radio2,elt,action;

	elt = document.getElementById("mailaddress");
	if(!emailcheck(elt.value)){
		//alert('Enter a valid email id !');  // org code before 20100116
		alert(langObj['Enter a valid email id !']); // add by zheng on 20100116
		return false;
	}

	radio1 = document.getElementById("epyes");
	radio2 = document.getElementById("epno");

	if(!radio1.checked && !radio2.checked){
		//alert('Choose a option between subscription and un-subscription !');  // org code before 20100116
		alert(langObj['Choose a option between subscription and un-subscription !']); // add by zheng on 20100116
		return false;
	}
	else if(radio1.checked){
		action="subscribe";
	}
	else{
		action="unsubscribe";
	}


	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		//alert ("Your browser does not support AJAX!");  // org code before 20100116
		alert (langObj["Your browser does not support AJAX!"]); // add by zheng on 20100116
		return;
	}

	var url="subscriberManager.php";
	var param = "";
	param += "email="+elt.value;
	param += "&action="+action;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	try
	{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	}

	return xmlHttp;
}

function stateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState==200)
	{
		var ss=xmlHttp.responseText;
		//alert(ss);  // org code before 20100116
		alert(langObj[ss]); // add by zheng on 20100116
		
		document.getElementById("mailaddress").value='';
	}
}


function emailcheck(str)
{
	if((str.lastIndexOf(".") > 2 && str.lastIndexOf(".") < (str.length - 1)) && (str.indexOf("@") > 0) && (str.lastIndexOf("@") == str.indexOf("@")))
	{
	return true;
	}
	else
	return false;
}

