var xmlHttp;
var xmlHttp2;
var xmlHttp3;

function AddComments(lngTableId, lngId, strDescription, strName, strEmail) {
	if (strDescription == "") {
		alert("Comments Not Typed.");
		return false;
	} else if (strName == "") {
		alert("Name Not Specified.");
		return false;
	} else if (strEmail == "") {
		alert("Email Not Specified.");
		return false;
	} else {
		xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null) {
			alert ("Browser does not support HTTP Request");
			return false;
		}        
		var url="/phpajax_savecomments.php";
		url=url+"?txtName="+txtName;
		url=url+"&txtEmail="+txtEmail;
		url=url+"&txtComments="+txtComments;
		url=url+"&lngTableId="+lngTableId;
		url=url+"&lngId="+lngId;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=CommentSaved;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}
function CommentSaved() {
	if (xmlHttp.readyState==4 || xmlHttp3.readyState=="complete") {
		document.getElementById("Comments").innerHTML=xmlHttp3.responseText
	}
}

function FillPlotList() {
	xmlHttp3=GetXmlHttpObject();
	if (xmlHttp3==null) {
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url="/plotlist.php";
	url=url+"?sid="+Math.random();
	xmlHttp3.onreadystatechange=FillPlot;
	xmlHttp3.open("GET", url, true);
	xmlHttp3.send(null)
}
function FillPlot() {
	if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete") {
		document.getElementById("PlotList").innerHTML=xmlHttp3.responseText
	}
}


function FillMostRead() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url="/mostread.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=MostRead;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null)
}
function MostRead() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("mostread").innerHTML=xmlHttp.responseText
	}
}


function AddToCart(lngPlotId) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) 	{
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url="/phpajax_addtocart.php"
	url=url+"?lngPlotId="+lngPlotId
	url=url+"&sid="+Math.random()
	alert(url);
	xmlHttp.onreadystatechange=AddedToCart;
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}
function AddedToCart() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		alert(xmlHttp.responseText);
	}
} 

function PollResult(lngPollId,optVote) {
	xmlHttp2=GetXmlHttpObject()
	if (xmlHttp2==null) {
		alert ("Browser does not support HTTP Request");
		return false;
	}
	var url="/poll.php";
	url=url+"?lngPollId="+lngPollId;
	url=url+"&optVote="+optVote;
	url=url+"&sid="+Math.random();
	xmlHttp2.onreadystatechange=ShowResult;
	xmlHttp2.open("GET", url, true);
	xmlHttp2.send(null);
}

function ShowResult() {
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") {
		document.getElementById("divPollId").innerHTML=xmlHttp2.responseText
	}
} 

function subscription(str) {
	xmlHttp=GetXmlHttpObject()
	if (document.nls.txtEmail.value == "" ) {
		alert("Email Not Specified.");
		return false;
	}

	if (xmlHttp==null) 	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var inputs = str.split(",")
	if (inputs[0] == 1) {
	  	var url="/subscription.php"
		url=url+"?txtEmail="+inputs[1];
	} else {
	  	var url="/unsubscription.php"
		url=url+"?txtEmail="+inputs[1]
	}
	xmlHttp.onreadystatechange=subscribed
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}
function subscribed() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("divSubscriptionId").innerHTML=xmlHttp.responseText
	}
} 

function imposeMaxLength(Object, MaxLen) {
	if (Object.value.length > MaxLen) {
  		Object.value = Object.value.substring(0, MaxLen);
		alert("Max Permited Length is: " + MaxLen + " Characters. Truncated!!");
	}
	return (Object.value.length <= MaxLen);
}



/* End of Functions For Displaying the Caste When Religion is Selected in the Registrations Form */
function GetXmlHttpObject() {
	xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


