/*	Auto tabbing script- http://www.javascriptkit.com	*/

function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}



// Special Form
function formValidator_B(){

	// Make quick references to our fields
	var name = document.getElementById('name');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	var email1 = document.getElementById('email1');
	var email2 = document.getElementById('email2');
	var guest = document.getElementById('guest');
	var txtNumber = document.getElementById('txtNumber');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(name, "Your Name must be filled out")){
	if(isNumeric(phone1, "Please enter a valid Area Code for your Phone Number")){
	if(lengthRestrictionA(phone1, 3)){
	if(isNumeric(phone2, "Please enter a valid Phone Number (middle 3 digits)")){
	if(lengthRestrictionB(phone2, 3)){
	if(isNumeric(phone3, "Please enter a valid Phone Number (last 4 digits)")){
	if(lengthRestrictionC(phone3, 4)){
	if(notEmpty(email1, "Your Email Address must be filled out")){
	if(notEmpty(email2, "Confirm Email must be filled out")){
	if(emailValidator(email1, "Please enter valid Your Email Address")){
	if(emailValidator(email2, "Please enter valid Confirm Email")){
	if(notEmpty(guest, "Please select Number of Guests")){
	if(notEmpty(txtNumber, "Verification Code must be filled out")){
			
		return true;
				}
			}
		}
	}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	return false;
	
}




// Contact Form
function formValidator_A(){

	// Make quick references to our fields
	var name = document.getElementById('name');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	var email1 = document.getElementById('email1');
	var email2 = document.getElementById('email2');
	var comments = document.getElementById('comments');
	var txtNumber = document.getElementById('txtNumber');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(name, "Your Name must be filled out")){
	if(isNumeric(phone1, "Please enter a valid Area Code for your Phone Number")){
	if(lengthRestrictionA(phone1, 3)){
	if(isNumeric(phone2, "Please enter a valid Phone Number (middle 3 digits)")){
	if(lengthRestrictionB(phone2, 3)){
	if(isNumeric(phone3, "Please enter a valid Phone Number (last 4 digits)")){
	if(lengthRestrictionC(phone3, 4)){
	if(notEmpty(email1, "Your Email Address must be filled out")){
	if(notEmpty(email2, "Confirm Email must be filled out")){
	if(emailValidator(email1, "Please enter valid Your Email Address")){
	if(emailValidator(email2, "Please enter valid Confirm Email")){
	if(isAlphanumeric(comments, "Numbers and Letters Only for Comments")){
	if(notEmpty(txtNumber, "Verification Code must be filled out")){
			
		return true;
			}
		}
	}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	return false;
	
}



// Adriatic Advantage
function formValidator(){

	// Make quick references to our fields
	var name = document.getElementById('name');
	var street = document.getElementById('street');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip1 = document.getElementById('zip1');
	var zip2 = document.getElementById('zip2');
	var phone1 = document.getElementById('phone1');
	var phone2 = document.getElementById('phone2');
	var phone3 = document.getElementById('phone3');
	var email1 = document.getElementById('email1');
	var email2 = document.getElementById('email2');
	var txtNumber = document.getElementById('txtNumber');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(name, "Your Name must be filled out")){
	if(notEmpty(street, "Street Address must be filled out")){
	if(notEmpty(city, "City must be filled out")){
	if(notEmpty(state, "Please select State")){
	if(isNumeric(zip1, "Please enter a valid Zip Code (5 digits)")){
	if(lengthRestrictionD(zip1, 5)){
	if(isNumeric(phone1, "Please enter a valid Area Code for your Phone Number")){
	if(lengthRestrictionA(phone1, 3)){
	if(isNumeric(phone2, "Please enter a valid Phone Number (middle 3 digits)")){
	if(lengthRestrictionB(phone2, 3)){
	if(isNumeric(phone3, "Please enter a valid Phone Number (last 4 digits)")){
	if(lengthRestrictionC(phone3, 4)){
	if(notEmpty(email1, "Your Email Address must be filled out")){
	if(notEmpty(email2, "Confirm Email must be filled out")){
	if(emailValidator(email1, "Please enter valid Your Email Address")){
	if(emailValidator(email2, "Please enter valid Confirm Email")){
	if(notEmpty(txtNumber, "Verification Code must be filled out")){
			
										return true;
							}
						}
					}
				}
			}
		}
	}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	return false;
	
}








// If a text input is Empty or Not or Your Name...
function notEmpty(elem, helperMsg){
	var nameField = /^[Your Name...]+$/;
	if(elem.value.length == 0||elem.value.match(nameField)){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}


// If a text input is all numbers 
function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


// If a text input is all letters 
function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


// If a text input is all alphanumeric characters (numbers & letters) 
function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z !@$%.?]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


// If a text input has the correct number of characters in it (useful when restricting the length of a username and/or password)
function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}


// If a selection has been made from an HTML select input (the drop down selector) 
function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}


// If an email address is valid 
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}






// need to enter 3 digits numbers - Phone Area code
function lengthRestrictionA(elem, min){
	var uInputA = elem.value;
	if(uInputA.length >= min){
		return true;
	}else{
		alert("Please enter a valid Area Code for your Phone Number (" +min+ " digits)");
		elem.focus();
		return false;
	}
}

// need to enter 3 digits numbers - Phone number
function lengthRestrictionB(elem, min){
	var uInputB = elem.value;
	if(uInputB.length >= min){
		return true;
	}else{
		alert("Please enter a valid Phone Number (middle " +min+ " digits)");
		elem.focus();
		return false;
	}
}

// need to enter 4 digits numbers - Phone number
function lengthRestrictionC(elem, min){
	var uInputC = elem.value;
	if(uInputC.length >= min){
		return true;
	}else{
		alert("Please enter a valid Phone Number (last " +min+ " digits)");
		elem.focus();
		return false;
	}
}

// need to enter 5 digits numbers - Zip code
function lengthRestrictionD(elem, min){
	var uInputD = elem.value;
	if(uInputD.length >= min){
		return true;
	}else{
		alert("Please enter a valid Zip Code (first " +min+ " digits)");
		elem.focus();
		return false;
	}
}






function check_compare(){
	var eM1 = document.getElementById('email1');
	var eM2 = document.getElementById('email2');
	var pW1 = document.getElementById('pass_1');
	var pW2 = document.getElementById('pass_2');

   if(eM1.value !== eM2.value){
        alert('Both emails are not matching');
        return false;
   }
   
   if(pW1.value !== pW2.value){
        alert('Both Passwords are not matching');
        return false;
   }else{
        return true;
   }
   
}
