// Register.js

function validateStep3() {
  var address = document.getElementsByName('address')[0].value;
  var state = document.getElementsByName('state')[0].value;
  var zip = document.getElementsByName('zip_code')[0].value;
  var phone = document.getElementsByName('Phone_1')[0].value + document.getElementsByName('Phone_2')[0].value; + document.getElementsByName('Phone_3')[0].value;
  var payment = document.getElementsByName('payment_type')[0].value;
  var date = document.getElementsByName('date1')[0].value;
  var time = document.getElementsByName('time')[0].value;
  var timezone = document.getElementsByName('timezone')[0].value;
  var city = document.getElementsByName('city')[0].value;
  
 
  if (address.length < 1){
    alert("Please Enter your Address")
    return false
  }
  else if (city.length < 1) {
	  alert("Please enter your City.")
	  return false
  }
  else if (state.length < 1){
	  alert("Please enter your State.")
	  return false
  }
  else if (zip.length < 1){
	  alert("Please enter your Zip Code.")
	  return false
  }
  else if (phone.length < 1){
	  alert("Please enter your Phone Number.")
	  return false
  }
  else if (payment.length < 1){
	  alert("Please enter your Payment Type.")
	  return false
  }
  else if (timezone.length < 1){
	  alert("Please enter your Timezone.")
	  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 ValidateForm(){
  var emailID = document.step1.email
  var pw1 = document.step1.pass.value
  var pw2 = document.step1.pass2.value
  var username = document.step1.username.value
  var foundus = document.step1.foundus.value
  
  if ((emailID.value==null)||(emailID.value=="")){
    alert("Please Enter your Email ID")
    emailID.focus()
    return false
  }
  else if (echeck(emailID.value)==false){
    emailID.value=""
    emailID.focus()
    return false
  }
  else if(validatePwd(pw1,pw2) == false) {
	  pw1=""
	  pw2=""
	  document.step1.pass.focus()
	  return false
  }
  else if(username.length < 1) {
	  alert("Please enter a username.")
	  document.step1.username.focus()
	  return false
  }
  else if(foundus == "Please Select") {
	alert("Please tell us how you found us.")
	return false
	document.step1.found_us.focus()
  }
  else {
	 return true
  }
}

function validatePwd(pw1,pw2) {
var invalid = " "; // Invalid character is a space
var minLength = 4; // Minimum length
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.step1.pass.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters long. Try again.');
return false;
}
// check for spaces
if (document.step1.pass.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 checkCapsLock( e ) {
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg='Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

	// Internet Explorer 4+
	if ( document.all ) {
		myKeyCode=e.keyCode;
		myShiftKey=e.shiftKey;

	// Netscape 4
	} else if ( document.layers ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	// Netscape 6
	} else if ( document.getElementById ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	}

	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
		alert( myMsg );

	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
		alert( myMsg );

	}
}

function validatephone(xxxxx) {
	var maintainplus = '';
 	var numval = xxxxx.value
 	if ( numval.charAt(0)=='+' ){ var maintainplus = '+';}
 	curphonevar = numval.replace(/[\\A-Za-z!"£$%^&*+_={};:'@#~,.¦\/<>?|`¬\]\[]/g,'');
 	xxxxx.value = maintainplus + curphonevar;
 	var maintainplus = '';
 	xxxxx.focus;
}