var err;

function checkDate()
{
	 document.getElementById('error').innerHTML="";
	 var mnth = document.dateform.month.options[document.dateform.month.selectedIndex].value;
	 mnth = parseInt(mnth,10);
	var  dy = parseInt(document.dateform.day.options[document.dateform.day.selectedIndex].value,10);
	 dy = dy;
	var maxdy = 30;
	 //if the month 22 isn't February...
	 if (mnth !== 2)
	 {
	 // then see if it's a month that only has 30 days...

	 if (mnth === 4 || mnth === 6 || mnth === 9 || mnth === 11)
	 {
	 // if it is, and the day value is greater than 30, alert the user
	 if (dy > maxdy)
	 {
	 document.getElementById('error').innerHTML='<font color="#FF0000">'+"لا يمكن أن يكون هناك أكثر من" +maxdy+ "يوما"+' </font>';

	 // and select the 30 for them...
	 document.dateform.day.selectedIndex = 0;
	 err = true;
	 return;
	 }
	 }
	 }
	 else
	 {
	 //if it IS February , check if it's a leap year
	 var yr1 = parseInt(document.dateform.year.value,10);
	 // (this is the modulus operation which returns the remainder of the selected year divided by 4
	 var leapYrTest = yr1 % 4;
	 // if the year divides evenly by 4, it is a leap year and the remainder will be 0...
	 if (leapYrTest === 0)
	 {
	 // so our max day for february is 29
	 maxdy = 29;
	 }
	 else
	 {
	 maxdy = 28;
	 }
	 // if the user selected a value greater than the max day AND the month is February
	 if (dy > maxdy)
	 {
	 // Alert the user and set the day back to 1

		document.getElementById('error').innerHTML='<font color="#FF0000">'+"لا يمكن أن يكون هناك أكثر من" +maxdy+ "يوما"+' </font>';
	 document.dateform.day.selectedIndex = 0;
	  err = true;
	 return;
	 }
	 }
}
function changeType(index)
{
	document.dateform.type[index].checked = true;
}
function changeDateHandler(sText){
	document.getElementById('loading').style.display="none";
	document.getElementById('go').style.display="block";
	if(sText){
		document.getElementById('result').innerHTML=sText;
	}else{
		document.getElementById('error').innerHTML='<font color="#FF0000">نعتذر منك  لم نتمكن من الحصول على نتيجة </font>';
	}
}
function changeDate(DateLang)
{
	var rad_val;
	document.getElementById('loading').style.display="block";
	document.getElementById('go').style.display="none";
	for (var i=0; i < document.dateform.type.length; i++)
   {
	   if (document.dateform.type[i].checked)
	   {
	      rad_val = document.dateform.type[i].value;
	   }
	}
	AJAXGet(site_url+"/changeDate.php?Lang="+DateLang+"&type="+rad_val+"&day="+document.dateform.day.value+"&month="+document.dateform.month.value+"&year="+document.dateform.year.value+"&hday="+document.dateform.hday.value+"&hmonth="+document.dateform.hmonth.value+"&hyear="+document.dateform.hyear.value,changeDateHandler,false,false);
}




function changeSalatHandler(sText){
	document.getElementById('loading2').style.display="none";
	document.getElementById('go2').style.display="block";
	if(sText){
		document.getElementById('result2').innerHTML=sText;
	}else{
		document.getElementById('error2').innerHTML='<font color="#FF0000">نعتذر منك  لم نتمكن من الحصول على نتيجة </font>';
	}
}
function changeSalat(SalatLang)
{
	document.getElementById('loading2').style.display="block";
	document.getElementById('go2').style.display="none";

	AJAXGet(site_url+"/changeSalat.php?Lang="+SalatLang+"&city="+document.salatform.city.value,changeSalatHandler,false,false);
}









function changeVoteHandler(sText){
	document.getElementById('loading3').style.display="none";
	document.getElementById('go3').style.display="block";
	if(sText){
		document.getElementById('result3').innerHTML=sText;
	}else{
		document.getElementById('error3').innerHTML='<font color="#FF0000">نعتذر منك  لم نتمكن من الحصول على نتيجة </font>';
	}
}



function changeVote(VoteLang, VoteAction)
{
	document.getElementById('loading3').style.display="block";
	document.getElementById('go3').style.display="none";
	var vote_rad_val;
	for (var i=0; i < document.voteform.answer.length; i++)
   	{
	   if (document.voteform.answer[i].checked)
	   {
	      vote_rad_val = document.voteform.answer[i].value;
	   }
	}

      /* 	if(VoteAction == "result"){
        document.getElementById('result3').style.display="block";
        document.getElementById('questions').style.display="none";}
        if(VoteAction == "process"){document.getElementById('questions').style.display="block";}  */

	AJAXGet(site_url+"/changePoll.php?Lang="+VoteLang+"&VoteAction="+VoteAction+"&answer="+vote_rad_val,changeVoteHandler,false,false);
}




function DisplayVote(VoteLang, VoteAction)
{
	document.getElementById('loading3').style.display="block";
	document.getElementById('go3').style.display="none";

	AJAXGet(site_url+"/changePoll.php?Lang="+VoteLang+"&VoteAction="+VoteAction,changeVoteHandler,false,false);
}



