// JavaScript Document
 //Valaditions//
function checkMandatory()
{
	var name = document.getElementById('txtName').value;
	var email = document.getElementById('txtEmail').value;
	var comments = document.getElementById('txtComments').value;
	var errorText = "";
 
 if((name=='') || (email=='') || (comments==''))
 {
	document.getElementById('messageBox').className = "show";
	return false;
 }
 else
 {
 	ValidateForm();
 }

}
//Email Validations//

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   document.getElementById('messageBox').className = "show";
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   document.getElementById('messageBox').className = "show";
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    document.getElementById('messageBox').className = "show";
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    document.getElementById('messageBox').className = "show";
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    document.getElementById('messageBox').className = "show";
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    document.getElementById('messageBox').className = "show";
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    document.getElementById('messageBox').className = "show";
		    return false
		 }

 		 			
	}

function ValidateForm(){
	var emailID=document.frmGenocideVote.txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		document.getElementById('messageBox').className = "show";
		return false
	}
	if (echeck(emailID.value)==false){
		document.getElementById('messageBox').className = "show";
		return false
	}
	addComments();
 }
////////////////////////////////////////////////////////////////////////////////////////////////////// 

function addComments()
{ 
	document.getElementById('messageBox').className = "hide";
	var name = document.getElementById('txtName').value;
	var email = document.getElementById('txtEmail').value;
	var countrySelIndex = document.getElementById('cmbCountry').selectedIndex;
	var country = document.getElementById('cmbCountry').options[countrySelIndex].text;
	var location = document.getElementById('txtLocation').value;
	var comments = document.getElementById('txtComments').value;
	
	if(document.getElementById('chkParti').checked == true)
	{
		var parti = 1;
	}else
	{
		var parti = 0;
	}
	
	if(document.getElementById('chkNewsletter').checked == true)
	{
		var newsletter = 1;
	}else
	{
		var newsletter = 0;
	}
	
	var operation = "Add";
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	} 
	var url="/php/userComments.php";
	url=url+"?Name="+name+"&Email="+email+"&Country="+country+"&Location="+location+"&Comments="+comments+"&Parti="+parti+"&Newsletter="+newsletter+"&Operation="+operation;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedAdd;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}
function stateChangedAdd() 
{
	if (xmlHttp.readyState==3)
	{
		
		
	}
	if (xmlHttp.readyState==4)
	{
		
		alert(xmlHttp.responseText);
		clearAll();
		/*document.getElementById("lblDispText").innerHTML=xmlHttp.responseText;*/	
	
	}
}

function clearAll(){
	document.getElementById('txtName').value = "";
	document.getElementById('txtEmail').value = "";
	document.getElementById('cmbCountry').selectedIndex = 0;
	document.getElementById('txtLocation').value = "";
	document.getElementById('txtComments').value = "";
	document.getElementById('chkParti').checked = true;
	document.getElementById('chkNewsletter').checked = true;
}