//***************************************************************
// Added by Tulasikrishna 
//****************************************************************

//**********************************************************************
//function for main registion pages	

function CheckTheFields()
{
		//***************For First Name*****************************
		
		if (document.forms[0].txtFirstName.value == "")
		{
		  alert("Please enter a value for the \"First Name\" field.");
		  document.forms[0].txtFirstName.focus();
		  return (false);
		}
		
		//***************For Last Name*****************************
		
		if (document.forms[0].txtLastName.value == "")
		{
		  alert("Please enter a value for the \"Last Name\" field.");
		  document.forms[0].txtLastName.focus();
		  return (false);
		}
		
		//***************For Title Field*****************************
		
		if (document.forms[0].txtTitle.value == "")
		{
		  alert("Please enter a value for the \"Title\" field.");
		  document.forms[0].txtTitle.focus();
		  return (false);
		}
		
		// *******************For Email Field*************************
		var txtemailID=document.forms[0].txtEmail

		if ((txtemailID.value==null)||(txtemailID.value==""))
		{
			alert("Please Enter your Email ID")
			document.forms[0].txtEmail.focus()
			return false
		}
		if (echeck(txtemailID.value)==false)
		{
			//alert("Krishna this is in Echeck")
			document.forms[0].txtEmail.focus()
			return false
		}
		
		//*******************For Phone Number***************************	
		
		var varPhone=document.forms[0].txtPhone
			
		if ((varPhone.value==null)||(varPhone.value=="")){
			alert("Please Enter your Phone Number")
			document.forms[0].txtPhone.focus()
			return false
		}
		if (checkInternationalPhone(varPhone.value)==false){
			alert("Please Enter a Valid Phone Number")
			document.forms[0].txtPhone.value=""
			document.forms[0].txtPhone.focus()
			return false
		}
		
		//***************For Organization Field*****************************
		
		if (document.forms[0].txtCompany.value == "")
		{
		  alert("Please enter a value for the \"Company \" field.");
		  document.forms[0].txtCompany.focus();
		  return (false);
		}
		
		//***************For Address1 Field*****************************
		
		if (document.forms[0].txtAddress1.value == "")
		{
		  alert("Please enter a value for the \"Address1 \" field.");
		  document.forms[0].txtAddress1.focus();
		  return (false);
		}
		//***************For City Field*****************************
		
		if (document.forms[0].txtCity.value == "")
		{
		  alert("Please enter a value for the \"City \" field.");
		  document.forms[0].txtCity.focus();
		  return (false);
		}
		//***************For ZipCode Field*****************************
		
		if (document.forms[0].txtZip.value == "")
		{
		  alert("Please enter a value for the \"Zip Code \" field.");
		  document.forms[0].txtZip.focus();
		  return (false);
		}
		//***************For State Field*****************************
		
		if (document.forms[0].txtState.value == "")
		{
		  alert("Please enter a value for the \"State \" field.");
		  document.forms[0].txtState.focus();
		  return (false);
		}
		//***************For Country Field*****************************
		
		if (document.forms[0].txtCountry.value.length<1)
		{
		  alert("Please enter a value for the \"Country \" field.");
		  document.forms[0].txtCountry.focus();
		  return (false);
		}
	 //***************For ReadLegal Field*****************************
	  if (document.forms[0].chkReadLegal.checked == false)
	  {
				alert("Please verify you have read Unisys Privacy Notice.");
				document.forms[0].chkReadLegal.focus();
				return (false);
	  }

		
	return true		
}	

//*******************Functionality for Phone Number Validation***************************		
		
			// Declaring required variables
					var digits = "0123456789";
			// non-digit characters which are allowed in phone numbers
					var phoneNumberDelimiters = "()- ";
			// characters which are allowed in international phone numbers
			// (a leading + is OK)
					var validWorldPhoneChars = phoneNumberDelimiters + "+";
			// Minimum no of digits in an international phone no.
					var minDigitsInIPhoneNumber = 10;

			function isInteger(s)
			{   var i;
			    for (i = 0; i < s.length; i++)
			    {   
			        // Check that current character is number.
			        var c = s.charAt(i);
			        if (((c < "0") || (c > "9"))) return false;
			    }
			    // All characters are numbers.
			    return true;
			}

			function stripCharsInBag(s, bag)
			{   var i;
			    var returnString = "";
			    // Search through string's characters one by one.
			    // If character is not in bag, append to returnString.
			    for (i = 0; i < s.length; i++)
			    {   
			        // Check that current character isn't whitespace.
			        var c = s.charAt(i);
			        if (bag.indexOf(c) == -1) returnString += c;
			    }
			    return returnString;
			}

			function checkInternationalPhone(strPhone){
			s=stripCharsInBag(strPhone,validWorldPhoneChars);
			return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
			}

//******************Function for Email Validation*****************************
function echeck(str) 
{
		//alert("krishna this is echeck function")
		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
		 }
			//alert("krishna! Correct Email ID")
 		 		
}