// JavaScript Documet

function voted(rd,frm)
{
	val1 = rd.value;
	document.getElementById('poll_fr').src="poll.php?polid="+rd.form.hdnpid.value+"&vot="+val1;
	//document.getElementById('apDiv1').style.display="block";
	$("#apDiv1").fadeIn(1000);
	document.getElementById("poll_after").innerHTML="";
	document.getElementById("poll_after").innerHTML="<a href=\"javascript:after_vote("+frm.hdnpid.value+")\"><strong>&#1593;&#1585;&#1590; &#1575;&#1604;&#1606;&#1578;&#1575;&#1574;&#1580;</strong></a>";
}


function divClose(block)
{
	document.getElementById(block).style.display="none";
	
}


//if alredy voted
function after_vote(rd)
{
	document.getElementById('poll_fr').src="poll.php?polid="+rd;
	$("#apDiv1").fadeIn(1000);
}

function emailed(ef)
{
	with(ef)
	{
		if(temail.value!=null && !emailcheck(temail.value))
		{
			document.getElementById('poll_fr').src="email.php?email="+temail.value;
			//document.getElementById('apDiv1').style.display="block";
			$("#apDiv1").fadeIn(1000);
			document.getElementById("email_div").innerHTML="";
			return false;
		}
		else
		{
		 	temail.focus();
			return false;
		}
	}
}


function emailcheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return true
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return true
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return true
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return true
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return true
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return true
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return true
		 }

 		 return false					
}