/*Script for comments slider start*/
var sho=0;var nid=0;var x=1;
function sho_hide(){
	if(sho==0){
		if(document.getElementById("examples11dump")!=null){
			document.getElementById("examples11dump").style.display="none"
		}
		showregularly(30,0);
		sho=1;
	}
	else{hideregularly1(285,500);sho=0}
	if(document.getElementById("addnewsmain")!=null&&document.getElementById("addnewsmain").style.display=="block"){
		show_newspopup("close")
	}
}
function hidediv(b,a){
	if(b!=""){
		document.getElementById(b).style.display="none"
	}
	if(a!=""){
		document.getElementById(a).style.display="block"
	}
}
function hideregularly1(a,b){
	sho=0;
	if(a>10){
		document.getElementById("cmntsouter").style.height=a+"px";
		document.getElementById("examples1").style.height=a+"px";
		document.getElementById("incomments").style.clip="rect(0px, "+b+"px,"+a+"px, 0px)";
		b-=15;a=a-10;
		setTimeout("hideregularly1("+a+","+b+")",20)
	}
	else{
		document.getElementById("cmntsouter").style.display="none";
		document.getElementById("incomments").style.clip="rect(0px 600px 0px 0px)"
	}
}
function showregularly(b,d){
	document.getElementById("examples1").style.display="block";
	document.getElementById("cmntsouter").style.display="block";
	var c=document.getElementById("cmntsouter").style.height;
	var a=c.split("p");
	var var1;
	sho=1;c=Number(a[0]);
	var ccheck = document.getElementById('ccheck').value;
	if(ccheck==1){
		var1 = 220;
	}
	else{
		var1 = 290;
	}
	if(c<265){
		if(b<var1){
			document.getElementById("cmntsouter").style.height=b+"px";
			document.getElementById("examples1").style.height=b+"px";
			document.getElementById("incomments").style.clip="rect(0px, "+d+"px,"+b+"px, 0px)";
			b=b+10;d=d+45;setTimeout("showregularly("+b+","+d+")",20)
		}
	}
}
/*Script for comments slider end*/

/*Script for forward an articles start*/
function layerControlf(c){
	if(c=='openforwardlayer'){
		document.getElementById("Layer1").style.display="block";
		document.getElementById("Layer4").style.display="block";
	}
	else if(c=='closeforwardlayer'){
		document.getElementById("Layer1").style.display="none";
		document.getElementById("Layer4").style.display="none";
	}
}


function GetXmlHttpObject(){var a=null;try{a=new XMLHttpRequest()}catch(b){try{a=new ActiveXObject("Msxml2.XMLHTTP")}catch(b){a=new ActiveXObject("Microsoft.XMLHTTP")}}return a}
function trim(aa){return aa.replace(/^\s+|\s+$/g,"")}

function echeck(email,src){
	/*if(email==""){
		alert('Please enter receiver email-id');
		return false;
	}
	else{*/
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   if(reg.test(email) == false) {
	      if(src=="rcvermail")
		  	alert('Please enter a valid Email id');
		  	//alert('Please usecomma to separate multiple email-id');
		  else
		  	alert('Please enter your email-id');
	      return false;
	   }
	//}
}


function forwardForm(){
	var a=trim(document.forward.subject.value);
	var i=trim(document.forward.tomail.value);
	var f=trim(document.forward.name.value);
	var b=trim(document.forward.urmail.value);
	var h=trim(document.forward.message.value);
	var ccheck = document.getElementById('ccheck').value;
	if(ccheck!=1)
		var g=trim(document.forward.captcha.value);
	if(a==""){
		alert("Please enter subject");
		document.forward.subject.focus();
		return false
	}
	if(i==""){
		alert("Please enter receiver\'s email-id, to separate multiple email-id use comma");
		document.forward.tomail.focus();
		return false
	}
	if(i!=""){
		var emailvalue12=i;
		var mytool_array=emailvalue12.split(",");
		for(i=0;i<mytool_array.length;i++){
			if (echeck(trim(mytool_array[i]),"rcvermail")==false){
				document.forward.tomail.focus();
				return false;
			}
		}
	}
	//alert(emailvalue);
	if(f==""){
		alert("Please enter your name");
		document.forward.name.focus();
		return false
	}
	if(f!=''){
		var alphaExp = /^[a-z A-Z]+$/;
		if(!f.match(alphaExp)){
			alert("Name field should not contain numeric digit");
			document.forward.name.focus();
			return false;
		}
	}

	if(b==""){
		alert("Please enter your email id");
		document.forward.urmail.focus();
		return false;
	}
	if(b!=""){
		emailvalue=b;
		if (echeck(trim(emailvalue),"urmail")==false){
			document.forward.urmail.focus();
			return false;
		}
	}

	if(h==""){
		alert("Please enter your message");
		document.forward.message.focus();
		return false;
	}
	if(g=="" && ccheck!=1){
		alert("Please type the characters you see in the picture");
		document.forward.captcha.focus();
		return false;
	}
	else{
		if(ccheck!=1)
			var e="sub="+a+"&tom="+emailvalue12+"&name="+f+"&urm="+b+"&mes="+h+"&captchaid="+g+"&storyid="+document.forward.storyid.value+"&ccheck="+ccheck;
		else
			var e="sub="+a+"&tom="+emailvalue12+"&name="+f+"&urm="+b+"&mes="+h+"&storyid="+document.forward.storyid.value+"&ccheck="+ccheck;



			//alert(e);
		xmlHttp4=GetXmlHttpObject();

		var c="/magazine/forwardarticle.php";
		xmlHttp4.open("POST",c,true);
		xmlHttp4.onreadystatechange=function(){
			if(xmlHttp4.readyState==4&&xmlHttp4.status==200){

				if(xmlHttp4.responseText=="RES|5"){
					document.getElementById("response").innerHTML="Captcha code is wrong, please try again.";
					document.getElementById("submitbutton1").value="Forward";
					document.getElementById("submitbutton1").disabled=false;
					document.getElementById("cancelbutton1").disabled=false;
					document.images.capt_forward.src="/news/captcha/CaptchaSecurityImages.php?"+Date.parse(new Date().toString());
					document.forward.captcha.value="";
					document.forward.captcha.focus();
					document.getElementById("capmessage").style.color="red";
				}
				else if(xmlHttp4.responseText=="RES|9"){
					document.getElementById("response").innerHTML="You message content some restricted words.";
					document.getElementById("submitbutton1").value="Forward";
					document.getElementById("submitbutton1").disabled=false;
					document.getElementById("cancelbutton1").disabled=false;
					document.images.capt_forward.src="/news/captcha/CaptchaSecurityImages.php?"+Date.parse(new Date().toString());
					document.forward.captcha.value="";
					document.forward.name.value="";
					document.forward.message.value="";
					document.getElementById("capmessage").style.color="red";
				}
				else if(xmlHttp4.responseText=="RES|6"){
					document.getElementById("response").innerHTML="Sorry, error occoured. Please try again.";
					document.forward.captcha.value='';
					document.images.capt_forward.src="/news/captcha/CaptchaSecurityImages.php?"+Date.parse(new Date().toString());
					setTimeout("resetValue()",5000);
				}
				else if(xmlHttp4.responseText=="RES|7"){
					document.getElementById("response").innerHTML="Article forwarded successfully.";
					document.forward.captcha.value='';
					document.images.capt_forward.src="/news/captcha/CaptchaSecurityImages.php?"+Date.parse(new Date().toString());
					setTimeout("resetValue()",5000);
				}
			}
			else{
				document.getElementById("submitbutton1").disabled=true;
				document.getElementById("submitbutton1").value="Forwarding";
				document.getElementById("response").innerHTML="Forwarding...";
				document.getElementById("cancelbutton1").disabled=true;

			}
		} //end of ajax function
		xmlHttp4.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlHttp4.setRequestHeader("Content-length",e.length);
		xmlHttp4.setRequestHeader("Connection","close");
		xmlHttp4.send(e);
		return false;
	} //end of else
} //end of forwardForm()

function resetValue(){
	document.getElementById("capmessage").style.color='';
	document.getElementById('submitbutton1').value='Forward';
	document.getElementById('cancelbutton1').disabled = false;
	document.forward.tomail.value='';
	document.forward.name.value='';
	document.forward.urmail.value='';
	document.forward.captcha.value='';
	document.getElementById('submitbutton1').disabled=false;
	document.getElementById("response").innerHTML="";
	layerControl('closeforwardlayer');
}

/*Script for forward an articles end*/

/*Article comments validation start*/
function commentValidation(){
	var commtext = trim(document.getElementById('commenttext').value);
	var ccheck = document.getElementById('ccheck').value;
	if(ccheck!=1){
		var email = trim(document.getElementById('email_comm').value);
		var pass = trim(document.getElementById('password_comm').value);
	}
	var articleid = trim(document.forward.storyid.value);

	if(commtext==""){
		alert("Please enter your comment");
		document.getElementById('commenttext').focus();
		return false;
	}
	if(email=="" && ccheck!=1){
		alert("Please enter your siliconindia email-id");
		document.getElementById('email').focus();
		return false;
	}
	if(email!="" && ccheck!=1){
		var d=/(([a-zA-Z0-9\-?\.?]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})(\W?[,;]\W?(?!$))?)+$/i;
		if(!d.test(email)){
			alert("Please enter your valid siliconindia email-id");
			document.getElementById('email').focus();
			return false;
		}
	}
	if(pass=="" && ccheck!=1){
		alert("Please enter your password");
		document.getElementById('password').focus();
		return false;
	}
	else{
		var pattern=/([A-Z]|[a-z]|[0-9]|[@]|[!]|[#]|[%]|[^]|[&]|[*])(\1)(\1)(\1)/;
		if(pattern.test(commtext)){
			alert("Continuous entry of characters.Please remove those characters");
			document.getElementById('commenttext').focus();
			return false;
		}
		if(ccheck==1)
			var e="commtext="+escape(commtext)+"&articleid="+articleid+"&ccheck="+ccheck;
		else
			var e="commtext="+escape(commtext)+"&email="+email+"&pass="+pass+"&articleid="+articleid+"&ccheck="+ccheck;
		xmlHttp5=GetXmlHttpObject();
		var c="/magazine/savecomment.php";
		xmlHttp5.open("POST",c,true);
		xmlHttp5.onreadystatechange=function(){
		var aa =document.forward.subject.value;

		var bb = aa.replace(/ /g, "_");
		//alert(bb);
			if(xmlHttp5.readyState==4 && xmlHttp5.status==200){
				document.getElementById('midhun12').style.display="block";
				//document.getElementById('successsubmit').style.display="block";
				//document.getElementById('cancel').style.display="block";
				if(xmlHttp5.responseText=="RES|SUCCESS"){
					document.getElementById('authresponse').innerHTML = "Loading...";
					document.getElementById('commenttext').value = "";
					//window.location.href = "/magazine/articledesc.php?articleid="+articleid+"&r=1";
					window.location.href = "/magazine_articles/"+bb+"-"+articleid+".html_1";
				}
				else if(xmlHttp5.responseText=="RES|ABUSE"){
					document.getElementById('authresponse').innerHTML = "You comment content some restricted words.";
					document.getElementById('commenttext').value = "";
					document.getElementById('commenttext').focus();
				}
				else if(xmlHttp5.responseText=="RES|ERR"){
					document.getElementById('authresponse').innerHTML = "Your emailid or password not matched, please try again";
					document.getElementById('password_comm').value = "";
					document.getElementById('password_comm').focus();
				}
			}
			else{
				document.getElementById('authresponse').innerHTML = "Loading...";
				document.getElementById('midhun12').style.display="none";
				//document.getElementById('successsubmit').style.display="none";
				//document.getElementById('cancel').style.display="none";
			}
		}
		xmlHttp5.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlHttp5.setRequestHeader("Content-length",e.length);
		xmlHttp5.setRequestHeader("Connection","close");
		xmlHttp5.send(e);
		return false;
	}

	return false;
}
/*Article comments validation end*/
var globalvar1;
function sho_hide1(num,cntcount){
	examples="examples"+num;
	var ccheck = document.getElementById('ccheck').value;
	document.getElementById(examples).style.display='block';
	if(ccheck==1){
		document.getElementById(examples).style.height = 170+"px";
	}
	for(i=2;i<=cntcount+1;i++){
		if(i!=num){
		examples="examples"+i;
		document.getElementById(examples).style.display='none';
		}
	}
	globalvar1 = num;
}

function sho_hide2(num){
	examples="examples"+num;
	document.getElementById(examples).style.display='none';
}

function login_validate2(theform){
	var ccheck = document.getElementById('ccheck').value;
	var step = theform.step.value;
	var pid = theform.pid.value;
	var ppid = theform.ppid.value;
	var parentuser = theform.parentuser.value;
	var rcomment = theform.rcomment.value;
	var articleid = trim(document.forward.storyid.value);
	if(trim(theform.rcomment.value)==""){
		alert("Please enter comment");
		theform.rcomment.value='';
		theform.rcomment.focus();
		return false;
	}
	var str=theform.rcomment.value;
	if(str.length<4){
		alert("Please Enter at least one line Comment");
		theform.rcomment.focus();
		return false;
	}
	if(ccheck!=1){
		var return2=check_email(theform.remail.value);
		if(return2==false){
			alert("Please input a valid email address!");
			theform.remail.value="";
			theform.remail.focus();
			return false;
		}
		if(trim(theform.rpassword.value)==""){
			alert("Please Enter your Password");
			theform.rpassword.value='';
			theform.rpassword.focus();
			return false;
		}
	}
	if(trim(theform.rcomment.value)==""){
		alert("Please enter comment");
		theform.rcomment.value='';
		theform.rcomment.focus();
		return false;
	}
	else{
		if(ccheck==1)
			var e="step="+step+"&pid="+pid+"&ppid="+ppid+"&parentuser="+parentuser+"&rcomment="+rcomment+"&articleid="+articleid+"&ccheck="+ccheck+"&src=reply";
		else
			var e="step="+step+"&pid="+pid+"&ppid="+ppid+"&parentuser="+parentuser+"&rcomment="+rcomment+"&articleid="+articleid+"&remail="+trim(theform.remail.value)+"&rpass="+trim(theform.rpassword.value)+"&ccheck="+ccheck+"&src=reply";

		xmlHttp6=GetXmlHttpObject();
		var c="/magazine/savecomment.php";
		xmlHttp6.open("POST",c,true);
		var aa =document.forward.subject.value;

		var bb = aa.replace(/ /g, "_");
		xmlHttp6.onreadystatechange=function(){
			if(xmlHttp6.readyState==4 && xmlHttp6.status==200){
				//document.getElementById('midhun12').style.display="block";
				//document.getElementById('comments1').style.display="block";
				//document.getElementById('canccel').style.display="block";
				if(xmlHttp6.responseText=="RES|SUCCESS"){
					//document.getElementById('authresponse_'+gid).innerHTML = "Loading...";
					//document.getElementById('rcomment').value = "";
					//window.location.href = "/magazine/articledesc.php?articleid="+articleid+"&r=1";
					window.location.href = "/magazine_articles/"+bb+"-"+articleid+".html_1";
				}
				else if(xmlHttp6.responseText=="RES|ABUSE"){
					/*document.getElementById('authresponse_'+gid).innerHTML = "You comment content some restricted words.";*/
					//document.getElementById('rcomment').value = "";
					//document.getElementById('rcomment').focus();
					//window.location.href = "/magazine/articledesc.php?articleid="+articleid+"&r=2";
					window.location.href = "/magazine_articles/"+bb+"-"+articleid+".html_2";;
				}
				else if(xmlHttp6.responseText=="RES|ERR"){
					/*document.getElementById('authresponse_'+gid).innerHTML = "Your emailid or password not matched, please try again";*/
					//document.getElementById('rpassword').value = "";
					//document.getElementById('rpassword').focus();
					//window.location.href = "/magazine/articledesc.php?articleid="+articleid+"&r=3";
					window.location.href = "/magazine_articles/"+bb+"-"+articleid+".html_3";
				}
			}
			else{
				/*document.getElementById('authresponse_'+gid).innerHTML = "Loading...";*/
				document.getElementById('comments_'+globalvar1).style.display="none";
				document.getElementById('canccel_'+globalvar1).style.display="none";
			}
		}
		xmlHttp6.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlHttp6.setRequestHeader("Content-length",e.length);
		xmlHttp6.setRequestHeader("Connection","close");
		xmlHttp6.send(e);
		return false;
	}
}

function check_email(str)
{
	if(str=="")
	{
		return false;
	}
	else
	{
	if(str!="")
	{

	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
		if (!filter.test(str))
		{
			return false;
		}
	}
	}
return true;
}
