// JavaScript Document
 // JavaScript Document
//Scritp for validating  
var isNew=0;
var isNS4=0;
var isIE4=0;
var isIE5=0;
var isNS3=0;
var isIE3=0;
var EquPassword;
var ValidString;
var ValidEmail;
function Print()
{
	if(this.ValidString!=null)
	document.write(this.ValidString);	
}


function ClearAll()
{
		this.EquPassword="";
		this.ValidString="";
		this.ValidEmail="";
}


function CheckAll(form)
{

  
			 //alert(form)	
		//checking whether the field is empty or not
		var subjectSelected = false;
		//var checkagree = false
		if(IsBlank(form.Fname.value))
		{
			//alert('Enter first name');
			//hideAllErrors();
			//field = form.Fname;
			//document.getElementById("nameError").style.display = "inline";
			//alertmsg("Please enter your First Name ");
			alert("Please enter your First Name ");
			form.Fname.focus();
			form.Fname.select();
			//form.Submit3.disabled=true;
			return false;
		}
		
		if(form.Fname.value!="")
		{
			if (isProper(form.Fname.value) == false)
			{
				//hideAllErrors();
				//document.getElementById("nameValidError").style.display = "inline";
				//document.getElementById("Fname").style.visible = false;
				//alertmsg("Please enter a valid Name");
				alert("Please enter a valid Name");
				form.Fname.focus();
				form.Fname.select();
				//form.Submit3.disabled=true;
				return false;
			}
		}
		
	if(form.Fname.value!="")
	{
		if(IsNumber(form.Fname.value))
		{
			//hideAllErrors();
			//document.getElementById("nameAlphaError").style.display = "inline";
			//alertmsg("Please enter alphabets");
			alert("Please enter alphabets");
			form.Fname.focus();
			form.Fname.select();
			//form.Submit3.disabled=true;
			return false;
		}
	}
	if(form.Fname.value!="")
	{
		str=form.Fname.value;
		if(str.length<2)
		{
			//alert("Your password should contain atleast 4 characters!!");
			//hideAllErrors();
			//document.getElementById("nameThreeletterError").style.display = "inline";
			//alertmsg("First name should contain 3 characters");
			alert("First name should contain atlest 2 characters");
			form.Fname.focus();
			form.Fname.select();
			//form.Submit3.disabled=true;
			return false;	
		}
	}
	
	if(form.Lname.value!="")
	{
		if (isProper(form.Lname.value) == false)
		{
			//hideAllErrors();
			//document.getElementById("nameValidError").style.display = "inline";
			//document.getElementById("Fname").style.visible = false;
			//alertmsg("Please enter a valid Name");
			alert("Please enter a valid Last Name");
			form.Lname.focus();
			form.Lname.select();
			//form.Submit3.disabled=true;
			return false;
		}	
	}
		//checking whether the field last name is empty or not
	   /*if(IsBlank(form.Lname.value))
		{
			//alert('Enter Last name');
			hideAllErrors();
			document.getElementById("lnameError").style.display = "inline";
			form.Lname.focus();
			return false;	
		}*/
	/********************* EMAIL Validation ***********************************/
	if(IsBlank(form.Email.value))
	{	
		//alert("Enter email!!");
		//hideAllErrors();
		//document.getElementById("emailError").style.display = "inline";
		//alertmsg("Enter email!");
		alert("Enter email!");
		form.Email.focus();
		form.Email.select();
		//form.Submit3.disabled=true;
		return false;	
	}
	if(form.Email.value!="")
	{
		email = form.Email.value;
		/*if (email.indexOf(" ") !=-1)
		{
   			alert('You have typed a space - IN - your e-mail address');
  			 return false;
  		 }*/
		if(!isValidEmail(form.Email.value))
		{
			//alert("Enter a Valid Email");
			//hideAllErrors();
			//document.getElementById("validemailError").style.display = "inline";
			//alertmsg("Enter a valid Email!");
			alert("Enter a valid Email!");
			form.Email.focus();
			form.Email.select();
			//form.Submit3.disabled=true;
			return false;
		}	
    }
	/*if(form.UserAddress1.value!="")
	{
		if (isProper(form.UserAddress1.value) == false)
		{
			//hideAllErrors();
			//document.getElementById("nameValidError").style.display = "inline";
			//document.getElementById("Fname").style.visible = false;
			alertmsg("Please enter a valid address");
			form.UserAddress1.select();
			form.Submit3.disabled=true;
			return false;
		}	
	}
	if(form.UserBillAddress.value!="")
	{
		if (isProper(form.UserBillAddress.value) == false)
		{
			//hideAllErrors();
			//document.getElementById("nameValidError").style.display = "inline";
			//document.getElementById("Fname").style.visible = false;
			alertmsg("Please enter a valid address");
			form.UserBillAddress.select();
			form.Submit3.disabled=true;
			return false;
		}	
	}*/	/********************* End e-mail Validation ***********************************/
	/********************* Validation for country  ***********************************/	
	if(form.Country.value=="" || form.Country.value=="--Select--")
	{
			
			//hideAllErrors();
			//document.getElementById("validCountry").style.display = "inline";
			//alertmsg("Please select a Country");
			alert("Please select a Country");
			form.Country.focus();
			//form.Country.select();
			//form.Submit3.disabled=true;
			return false;
		
	}
	
	/********************* Validation for city       ***********************************/	
	/*if(form.City.value=="" || form.City.value=="--Select--")
	{
			hideAllErrors();
			document.getElementById("validCity").style.display = "inline";
			form.City.focus();
			return false;

	}
	/********************* End Validation for city       ***********************************/	
		/********************* Zip Code Validation   ***********************************/	
	if(IsBlank(form.PinCode.value))
	{
			//hideAllErrors();
			//document.getElementById("pinBlankError").style.display = "inline";
			//alertmsg("Enter Pin Code !");
			alert("Enter Pin Code !");
			form.PinCode.focus();
			form.PinCode.select();
			//form.Submit3.disabled=true;
			return false;
	}
	
	/*if(form.PinCode.value!="")
	{
		if(!IsNumber(form.PinCode.value))
		{
			//hideAllErrors();
			//document.getElementById("pinError").style.display = "inline";
			alertmsg("Enter only numbers !");
			form.PinCode.focus();
			form.PinCode.select();
			form.Submit3.disabled=true;
			return false;
		}
	}*/
	/*********************End  Zip Code Validation   ***********************************/	
	/********************* Day Phone Validation   ***********************************/	
	if(form.UserDayPhone.value!="")
	{
		if(!IsNumber(form.UserDayPhone.value))
		{
			//hideAllErrors();
			//document.getElementById("phonedayError").style.display = "inline";
			//alertmsg("Enter only numbers !");
			alert("Enter only numbers. Avoid special characters");
			form.UserDayPhone.focus();
			form.UserDayPhone.select();
			//form.Submit3.disabled=true;
			return false;
		}
	}
	if(form.SystemInfo.value=="" || form.SystemInfo.value=="--Select--")
	{
			//hideAllErrors();
			//document.getElementById("validState").style.display = "inline";
			//alertmsg("Please specify how you heard about the system");
			alert("Please specify how you heard about the system");
			form.SystemInfo.focus();
			//form.Submit3.disabled=true;
			//form.State.select();
			return false;
	
	}
	
  for (var e=0;e<form.elements.length;e++)
  {
	  var str=form.elements[e].name;
	  if(str.match("cust_id"))
	  {
		if(IsBlank(form.cust_id.value))
		  {
			//alert('Enter first name');
			//hideAllErrors();
			//field = form.Fname;
			//document.getElementById("nameError").style.display = "inline";
			//
			Text_val = document.getElementById('cust_txtname').innerHTML;
			//alertmsg("Please enter the "+Text_val);
			alert("Please enter the "+Text_val);
			form.cust_id.focus();
			form.cust_id.select();
			//form.Submit3.disabled=true;
			return false;
		 }
		
	 }
  }
/********************* End Night Phone Validation   ***********************************/		

	/********************* Username Validation   ***********************************/
	if(IsBlank(form.UserName.value))
	{
			//alert("Enter username");
			//hideAllErrors();
			//document.getElementById("usernameError").style.display = "inline";
			//alertmsg("Please enter a User Name");
			alert("Please enter a User Name");
			form.UserName.focus();
			form.UserName.select();			
			//form.Submit3.disabled=true;
			return false;
	}
		
	if(form.UserName.value!="")
	{
		var str=form.UserName.value;
		var x=parseInt(str.charAt(0));
		if(x==(str.charAt(0)))
		{
			//hideAllErrors();
			//document.getElementById("usernamealphaError").style.display = "inline";
			//alertmsg("User name must start with an alphabet");
			alert("User name must start with an alphabet");
			form.UserName.focus();
			form.UserName.select();
			//form.Submit3.disabled=true;
			return false;
		}
	 }
		
	if(form.UserName.value!="")
	{
		if (isProper(form.UserName.value) == false)
		{
			//alert("Please enter a valid username.");
			//Print("Please enter a valid username.");
			//alert(this.ValidString);
			//hideAllErrors();
			//document.getElementById("usernameValidError").style.display = "inline";
			//alertmsg("Please enter a valid username.");
			alert("Please enter a valid username.");
			form.UserName.focus();
			form.UserName.select();
			//form.Submit3.disabled=true;
			return false;
		}
	}
	if(form.UserName.value!="")
	{
		str=form.UserName.value;
		
		if(str.length<5)
		{
			//alert("Your password should contain atleast 4 characters!!");
			//hideAllErrors();
			//document.getElementById("usernamefiveletterError").style.display = "inline";
			//alertmsg("Username should contain at least 5 characters!");
			alert("Username should contain at least 5 characters!");
			form.UserName.focus();
			form.UserName.select();
			//form.Submit3.disabled=true;
			return false;	
		}
	}
	if(form.UserName.value!="")
	{
		var invalid = " "; // Invalid character is a space
		if (form.UserName.value.indexOf(invalid) > -1) {
		//alertmsg("Sorry, space not allowed in Username!");
		alert("Sorry, space not allowed in Username!");
		form.UserName.focus();
		form.UserName.select();
		//form.Submit3.disabled=true;
		return false;
		}
	
	}
	/********************* End Username Validation   ***********************************/
		
	/********************* Password Validation   ***********************************/	
		if(IsBlank(form.Password.value))
		{	
			//alert("Enter password!!");
			//hideAllErrors();
			//document.getElementById("passwordError").style.display = "inline";
			//alertmsg("Please enter password");
			alert("Please enter password");
			form.Password.focus();
			form.Password.select();
			//form.Submit3.disabled=true;
			return false;	
		}
		if(form.Password.value!="")
		{	
			str=form.Password.value;
			if(str.length<4)
			{
				//alert("Your password should contain atleast 4 characters!!");
				//hideAllErrors();
				//document.getElementById("passfourletterError").style.display = "inline";
				//alertmsg("Your password should contain at least 4 characters!");
				alert("Your password should contain at least 4 characters!");
				form.Password.focus();
				form.Password.select();
				//form.Submit3.disabled=true;
				return false;	
			}
		}
		if(form.Password.value!="")
		{
			if (isProper(form.Password.value) == false)
			{
				//hideAllErrors();
				//document.getElementById("nameValidError").style.display = "inline";
				//document.getElementById("Fname").style.visible = false;
				//alertmsg("Please enter a valid Password");
				alert("Please enter a valid Password");
				form.Password.focus();
				form.Password.select();
				//form.Submit3.disabled=true;
				return false;
			}	
		}
		if(IsBlank(form.ConfirmPassword.value))
		{
			//alert("Enter confirm password !!");
			//hideAllErrors();
			//document.getElementById("passconfirmError").style.display = "inline";
			//alertmsg("Enter conformation password !");
			alert("Enter conformation password !");
			form.ConfirmPassword.focus();
			form.ConfirmPassword.select();
			//form.Submit3.disabled=true;
			return false;
       }
	
	  if(form.Password.value!=form.ConfirmPassword.value)
	  {
	    	//alert("Your password doesnot mach confirm password!!");
			//hideAllErrors();
			//document.getElementById("retypepassError").style.display = "inline";
			//alertmsg("Your password does not mach confirm password!! ");
			alert("Your password does not mach confirm password!! ");
			form.ConfirmPassword.focus();
			form.ConfirmPassword.select();
			//form.Submit3.disabled=true;
			return false;
      }
	  /********************* End Password Validation   ***********************************/	
	  /***************** Student validation part *******************************/
	 	 if(IsBlank(form.Fname1.value))
		{
			//alertmsg("Please enter your First Name");
			alert("Please enter your First Name");
			form.Fname1.focus();
			form.Fname1.select();
			//form.Submit3.disabled=true;
			return false;
		}
		if(!isNaN(form.Fname1.value))
		{
			//alertmsg("Please enter only string");
			alert("Please enter only string");
			form.Fname1.focus();
			form.Fname1.select();
			//form.Submit3.disabled=true;
			return false;
		}
		if (isProper(form.Fname1.value) == false)
		{
			//alertmsg("Please enter a valid Name");
			alert("Please enter a valid Name");
			form.Fname1.focus();
			form.Fname1.select();
			//form.Submit3.disabled=true;
			return false;
		}
		if(form.Lname1.value!="")
		{
			if(!isNaN(form.Lname1.value))
			{
				//alertmsg("Please enter only string");
				alert("Please enter only string");
				form.Lname1.focus();
				form.Lname1.select();
				//form.Submit3.disabled=true;
				return false;
			}
			if (isProper(form.Lname1.value) == false)
			{
				//alertmsg("Please enter a valid Name");
				alert("Please enter a valid Name");
				form.Lname1.focus();
				form.Lname1.select();
				//form.Submit3.disabled=true;
				return false;
			}
		}
		if(IsBlank(form.UserName1.value))
		{
			//alertmsg("Please enter the user name");
			alert("Please enter the user name");
			form.UserName1.focus();
			form.UserName1.select();
			//form.Submit3.disabled=true;
			return false;
		}
		if(form.UserName1.value!="")
		{
			var str=form.UserName1.value;
			var x=parseInt(str.charAt(0));
			if(x==(str.charAt(0)))
			{
				//hideAllErrors();
				//document.getElementById("usernamealphaError").style.display = "inline";
				//alertmsg("User name must start with an alphabet");
				alert("User name must start with an alphabet");
				form.UserName1.focus();
				form.UserName1.select();
				//form.Submit3.disabled=true;
				return false;
			}
		}
		if(form.UserName1.value!="")
		{
			if (isProper(form.UserName1.value) == false)
			{
				//alert("Please enter a valid username.");
				//Print("Please enter a valid username.");
				//alert(this.ValidString);
				//hideAllErrors();
				//document.getElementById("usernameValidError").style.display = "inline";
				//alertmsg("Please enter a valid username.");
				alert("Please enter a valid username.");
				form.UserName1.focus();
				form.UserName1.select();
				//form.Submit3.disabled=true;
				return false;
			}
		}
		if(form.UserName1.value!="")
		{
			str=form.UserName1.value;
			if(str.length<5)
			{
				//alert("Your password should contain atleast 4 characters!!");
				//hideAllErrors();
				//document.getElementById("usernamefiveletterError").style.display = "inline";
				//alertmsg("Username should contain at least 5 characters!");
				alert("Username should contain at least 5 characters!");
				form.UserName1.focus();
				form.UserName1.select();
				//form.Submit3.disabled=true;
				return false;	
			}
		}
		if(form.UserName1.value!="")
		{
			var invalid = " "; // Invalid character is a space
			if (form.UserName1.value.indexOf(invalid) > -1) {
			//alertmsg("Sorry, space not allowed in Username!");
			alert("Sorry, space not allowed in Username!");
			form.UserName1.focus();
			form.UserName1.select();
			//form.Submit3.disabled=true;
			return false;
			}
		
		}
		if(IsBlank(form.Password1.value))
		{	
			//alert("Enter password!!");
			//hideAllErrors();
			//document.getElementById("passwordError").style.display = "inline";
			//alertmsg("Please enter password");
			alert("Please enter password");
			form.Password1.focus();
			form.Password1.select();
			//form.Submit3.disabled=true;
			return false;	
		}
		if(form.Password1.value!="")
		{	
			str=form.Password1.value;
			if(str.length<4)
			{
				//alert("Your password should contain atleast 4 characters!!");
				//hideAllErrors();
				//document.getElementById("passfourletterError").style.display = "inline";
				//alertmsg("Your password should contain at least 4 characters!");
				alert("Your password should contain at least 4 characters!");
				form.Password1.focus();
				form.Password1.select();
				//form.Submit3.disabled=true;
				return false;	
			}
		}
		if(form.Password1.value!="")
		{
			if (isProper(form.Password1.value) == false)
			{
				//alertmsg("Please enter a valid password!");
				alert("Please enter a valid password!");
				form.Password1.focus();
				form.Password1.select();
				//form.Submit3.disabled=true;
				return false;	
			}
		}
	  
	  	for (var e=0;e<form.elements.length;e++)
		{
			  var str=form.elements[e].name;
			  if(str.match("bvsubject"))
			  {
				subvalue = form.elements[e].checked;
				if(subvalue == true)
				{
					subjectSelected = true;
				}
			 }/*
			 if(str.match("agree"))
			 {	
			 	agreevalue = form.elements[e].checked;
				if(agreevalue == true)
				{
					checkagree = true;
				}
			 }
			 else
			 {
				checkagree = false;
			 }*/
			 
		}
		if(subjectSelected == false)
		{
			//hideAllErrors();
			//document.getElementById("subjectError").style.display = "inline";
			//alertmsg("Please select a subject");
			alert("Please select a subject");
			//form.subjectSelected.focus();
			//form.Submit3.disabled=true;
			return  false;	
		}
   
	  	if(form.agree.checked == false)
		{
			//alertmsg("Please agree");
			alert("Please agree to the terms and condition");
			
			//form.Submit3.disabled=true;
			return false;
		}
		if(form.captcha_code.value == false)
		{
			//alertmsg("Please agree");
			alert("Please enter the code as shown in picture");
			form.captcha_code.focus();
			//form.Submit3.disabled=true;
			return false;
		}
		
		return true;
	
}//Main function


function IsString(field,msg, min, max)
{

	//function validateString(field, msg, min, max) {
	if (!min) { min = 3 }
	if (!max) { max = 65535 }

	if (!field.value || field.value.length < min || field.value.max > max) {
		//alert(msg);
		field.focus();
		field.select();
		return false;
	}
	
	

	return true;
}


function IsNumber(value)
{
	if (isNaN(value)) 
	 {
		return false;
  	}
	return true;
}

function isValidEmail(str)
{
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


function IsBlank(val)
{
	if(val==null){return true;}
	if(val==""){return true;}
	for(var i=0;i<val.length;i++)
	{
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}

	return true;

	
}

function isProper(string) {

   if (!string) return false;
   var iChars = "(-=!//\\)+*|,\":<>[]{}`\';()@&$#%";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
}             


function isValidZip(s) {

   var checkStr = s;
   var i, j, ch;
   var checkOK = "0123456789";
    // Must be 5 or 10 chars in length
   if (checkStr.length != 5 && checkStr.length != 10) {
      return (false);
   }

   // 6th char must be a "-"
   if (checkStr.length == 10 && checkStr.charAt(5) != "-") {
      return (false);
   }

   // Must contain numbers only (except "-" in 6th position)
   var allValid = true;
   for (i = 0; i < checkStr.length; i++) {
    ch = checkStr.charAt(i);
    if (i != 5) {
      for (j = 0; j < checkOK.length; j++) {
         if (ch == checkOK.charAt(j))
         break;
         }
      if (j == checkOK.length) {
         allValid = false;
         break;
      }
   } // if
   } // for

   if (!allValid) {
      return (false);
   }

   return (true);
}
Obj=new Object(this);






/*function ValidEmail(email,msg,optional)
{

	if (!email && optional)
	{
		alert("");
		return true;
	}

	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email)) {
		alert(msg);
		email.focus();
		email.select();
		return false;
	}

	return true;
}*/
/*
if(x.txtEmail.value!="")

	{
 
		if(isValidEmail(x.txtEmail.value))

			x.checkCrsi.focus();

		else

		{

			alert("Enter a Valid Email");

			x.txtEmail.focus();

			return false;*/
//added by rathish


/*function hideAllErrors()
{
	
	document.getElementById("nameError").style.display = "none"
	document.getElementById("nameValidError").style.display = "none"
	document.getElementById("nameAlphaError").style.display = "none"
	document.getElementById("nameThreeletterError").style.display = "none"
	document.getElementById("lnameError").style.display = "none"
	document.getElementById("emailError").style.display = "none"
	document.getElementById("validemailError").style.display = "none" 
	document.getElementById("validState").style.display = "none"
	document.getElementById("validCountry").style.display = "none"
	document.getElementById("pinBlankError").style.display = "none"
	document.getElementById("pinError").style.display = "none"
	document.getElementById("phonedayError").style.display = "none"
	document.getElementById("phonenightError").style.display = "none"
	document.getElementById("usernameError").style.display = "none"
	document.getElementById("usernameValidError").style.display = "none"
	document.getElementById("usernamealphaError").style.display = "none"
	document.getElementById("usernamefiveletterError").style.display = "none"
	document.getElementById("passwordError").style.display = "none"
	document.getElementById("passfourletterError").style.display = "none"
	document.getElementById("passconfirmError").style.display = "none"
	document.getElementById("retypepassError").style.display = "none"
	
	
	document.getElementById("validCity").style.display = "none"


}*/
function alertmsg(msg)
{	
   var brow=((navigator.appName) + (parseInt(navigator.appVersion))); 
  
 if(parseInt(navigator.appVersion >=5))
    {
		if(brow == "Microsoft Internet Explorer5") 
		  isIE5=1;
		else isNew=1;
    }
  else if(brow == "Netscape4" || brow == "Netscape5") 
   {
	   
	  isNS4 = 1;
   }
  else if(brow == "Microsoft Internet Explorer4") 
   {
	   
	   isIE4=1;
   }
  
 
   
	alObj=document.createElement("div");
    document.body.appendChild(alObj);
	if(isIE4==1 || isIE5==1)
	{
		 alData='<table cellpadding="0" cellspacing="0" border="0" style="width:25%;height:10%;position:absolute;left:355;top:450;z-index:1;"><tr><td align="center" valign="middle">'
		 //alert("IE")
	}
	else
	{
		alData='<table cellpadding="0" cellspacing="0" border="0" style="width:100%;height:30%;position:fixed;left:370;top:0;z-index:1;"><tr><td align="center" valign="middle">'
		 //alert("Firefox")
	}
  	
  	alData+='<table cellpadding="0" cellspacing="12" border="0" style="-moz-box-sizing:border-box;font:15px comic sans  ms,arial;color:#1d4fa8;font-weight:bold;background-color:#CCCCCC;border:1px solid #1d4fa8;width:250px;filter:progid:DXImageTransform.Microsoft.Shadow(color=#1d4fa8,direction=135,strength=5);">'
 	alData+='<tr>';
 	alData+='<td align="center">'+msg+'</td>';
 	alData+='</tr>';
  	alData+='<tr>';
 	alData+='<td align="center"><input type="button" onClick="clal()" value="Ok" style="border:1px inset #1d4fa8;background:#f4f887;color:#1d4fa8;font-weight:bold;height:20;">';
    alData+='</tr>';
    alData+='</table>';
    alData+='</td></tr></table>';
    alObj.innerHTML = alData;
}
function clal()
{
  document.body.removeChild(alObj);
  alObj=null;
  document.ParentRegn.Submit3.disabled=false;
}
