// JavaScript Document
function setEmail(isChecked)
{
	with (window.document.registrarionFrm) {
		if (isChecked) {
			txtUserName.value  = txtEmail.value;
			txtUserName.readOnly  = true;
			
		} else {
			txtUserName.readOnly  = false;
		}
	}
}


function checkRegistrationInfo()
{
	with (window.document.registrarionFrm) {
		if (isEmpty(txtFirstName, 'Enter first name')) {
			return false;
		} else if (isEmpty(txtLastName, 'Enter last name')) {
			return false;
		} else if (isEmpty(txtEmail, 'Enter Email Address ')) {
			return false;
		} else if (echeck(txtEmail.value)==false){
			txtEmail.value="";
			txtEmail.focus();
			return false;
		} else if (isEmpty(txtUserName, 'Enter User Name')) {
			return false;
		} else if(!validateUserName()) {
			return false;
		} else if (!validatePwd2()) {
			txtPass.focus();
			return false;
		}  else if (isEmpty(numPhone, 'Enter Phone Number ')) {
			return false;
		} else if (isEmpty(numMobile, 'Enter Mobile Number')) {
			return false;
		} else if (cboCountry.selectedIndex == 0) {
			alert('Choose the Country');
			cboCountry.focus();
			return false;
		} else if (isEmpty(txtCompany, 'Enter Company Name')) {
			return false;
		} else {
			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
		 }

 		 return true					
	}

function notConfirm(formPass1, formPass2, message) {
	formPass1.value = trim(formPass1.value);
	formPass2.value = trim(formPass2.value);
	
	_notConfirm = false;
	if (formPass1.value != formPass2.value) {
		_notConfirm = true;
		alert(message);
		formPass2.value = '';
		formPass1.value = '';
		formPass1.focus();
	}
	
	return _notConfirm;
}
function validatePwd2() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = trim(document.registrarionFrm.txtPass.value);
var pw2 = trim(document.registrarionFrm.txtConfPass.value);
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
document.registrarionFrm.txtPass.focus();
return false;
}
// check for minimum length
if (document.registrarionFrm.txtPass.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');

return false;
}
// check for spaces
if (document.registrarionFrm.txtPass.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter your password.");
return false;
}
else {
return true;
      }
   }
}
function FormValidate()
{
   if(document.registrarionFrm.numPhone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1 )
   {
      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
      return false;
   } else  {
	   return true;
	   
	   }
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
	if (sText == '')
	IsNumber = false;
  //alert(sText);
   for (i = 0; i < sText.length && IsNumber == true ; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
			
         IsNumber = false;
         }
      }
	 if ( i < 11 )
	 IsNumber = false;
   return IsNumber;
   
   }


function validateUserName() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
//var pw1 = trim(document.registrarionFrm.txtUserName.value);

// check for minimum length
if (document.registrarionFrm.txtUserName.value.length < minLength) {
alert('Your User Name must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.registrarionFrm.txtUserName.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
return true;
   
}
