/****************************************************************/
// This function ensures that a field has only the characters
// specified in the allowedCharacters String

function checkValidCharacters(field) 
{
	var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-/ ";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (allowedChars.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid characters!  Allowed characters are [A-Z], [a-z], [0-9], [-], and [.]");
		field.focus();
		field.select();
	}
} 

function checkPNRNumber(field) 
{
	var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (allowedChars.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid characters!  Allowed characters are [A-Z], [a-z] and [0-9]");
		field.focus();
		field.select();
	}
} 

function isValidPackageDesc(field) 
{
	var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!_.-/,;: ";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (allowedChars.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid characters!  Allowed characters are [A-Z], [a-z], [0-9], [-,!,_./,;,:] and [space]");
		field.focus();
		field.select();
	}
} 

function isValidPrice(field) 
{
	var allowedChars = "$1234567890.";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (allowedChars.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid characters!  Allowed characters are [0-9], [$], and [.]");
		field.focus();
		field.select();
	}
} 

function isValidTravelPeriod(field) 
{
	var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-/ ";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (allowedChars.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid characters!  Allowed characters are [A-Z], [a-z], [0-9], [-], [/] and [.]");
		field.focus();
		field.select();
	}
} 

function isValidPurchaseBefore(field) 
{
	var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-/ ";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (allowedChars.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid characters!  Allowed characters are [A-Z], [a-z], [0-9], [-], [/] and [.]");
		field.focus();
		field.select();
	}
} 

function isValidURL(field) 
{
	var allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-:/ ";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (allowedChars.indexOf(temp) == "-1") 
			ok = "no";
	}
	if (ok == "no") 
	{
		alert("Invalid characters!  Allowed characters are [A-Z], [a-z], [0-9], [-], and [.]");
		field.focus();
		field.select();
	}
} 

function isValidEmail(field) {
	var str
		
	str = field.value;
				
	if (str == null || str.length == 0) 
	{
		return true;
	}				
	
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) 
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) 
			supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  	if ((!r1.test(str) && r2.test(str)) == false) 
  	{
  		alert("Email entered is invalid.");
  		field.focus();  							
  		field.select();  							
  	}
}

/*****************************************************************************************
 * Add new customer form validation.
*****************************************************************************************/
function onAddCustomerClick()
{
	if (document.add_customer.phone.value == "")
	{
		alert("Phone is a required field.");
		document.add_customer.phone.select();
		document.add_customer.phone.focus();
		return false;
	}
	else if (document.add_customer.email.value == "")
	{
		alert("Email is a required field.");
		document.add_customer.email.select();
		document.add_customer.email.focus();
		return false;
	}
}


function onEditCustomerClick()
{
	if (document.edit_customer.phone.value == "")
	{
		alert("Phone is a required field.");
		document.edit_customer.phone.select();
		document.edit_customer.phone.focus();
		return false;
	}
	else if (document.edit_customer.email.value == "")
	{
		alert("Email is a required field.");
		document.edit_customer.email.select();
		document.edit_customer.email.focus();
		return false;
	}
}

/*****************************************************************************************
 * Add new specials form validation.
*****************************************************************************************/
function onAddSpecialClick()
{
	if (document.add_specials.leavingfrom.value == "")
	{
		alert("Leaving From is a required field.");
		document.add_specials.leavingfrom.select();
		document.add_specials.leavingfrom.focus();
		return false;
	}
	else if (document.add_specials.leavingto.value == "")
	{
		alert("Leaving To is a required field.");
		document.add_specials.leavingto.select();
		document.add_specials.leavingto.focus();
		return false;
	}
	else if (document.add_specials.price.value == "")
	{
		alert("Price is a required field.");
		document.add_specials.price.select();
		document.add_specials.price.focus();
		return false;
	}
	else if (document.add_specials.purchasebefore.value == "")
	{
		alert("Purchase Before is a required field.");
		document.add_specials.leavingto.select();
		document.add_specials.leavingto.focus();
		return false;
	}
	else if (document.add_specials.travelperiod.value == "")
	{
		alert("Travel Period is a required field.");
		document.add_specials.travelperiod.select();
		document.add_specials.travelperiod.focus();
		return false;
	}
	else if (document.add_specials.carrier.value == "")
	{
		alert("Carrier is a required field.");
		document.add_specials.carrier.select();
		document.add_specials.carrier.focus();
		return false;
	}

}

function onSubscribeClick()
{
	var strEmail
	var bSubscribe
	var strUsername;
									
	strUsername = document.subscriptions.username.value;                        		
	strEmail = document.subscriptions.email.value;
	bSubscribe = document.subscriptions.subscribe.value;
                        		
	if (strUsername == null || strUsername.length == 0) 
	{
		alert("Username is a required field.");
		return false;
	}
	else if (strEmail == null || strEmail.length == 0)
	{
		alert("Email is a required field.");
		return false;
	}
}

function onReferClick()
{
	var strEmail
	var strUsername;
									
	strUsername = document.refer_a_friend.username.value;                        		
	strEmail = document.refer_a_friend.email.value;
                        		
	if (strUsername == null || strUsername.length == 0) 
	{
		alert("Name is a required field.");
		return false;
	}
	else if (strEmail == null || strEmail.length == 0)
	{
		alert("Email is a required field.");
		return false;
	}
}

function onMakePayClick()
{
	var strNameOnCard;
	var strCardNo;
	var strExpirationMonth;
	var strExpirationYear;
	var strBillingAddress;
	var strBillingCity;
	var strBillingState;
	var strBillingCountry;
	var strBillingZip;
	var strHomePhone;
	var strAuthorize;

	if (document.makepay.nameoncard.value == null || document.makepay.nameoncard.value.length == 0)
	{
		alert("Name on Card is a required field");
		document.makepay.nameoncard.focus();
		return false;
	}
	else if (document.makepay.cardno.value == null || document.makepay.cardno.value.length == 0)
	{
		alert("Card Number is a required field");
		document.makepay.cardno.focus();
		return false;
	}
	else if (document.makepay.amount.value == null || document.makepay.amount.value.length == 0)
	{
		alert("Amount is a required field");
		document.makepay.amount.focus();
		return false;
	}
	else if (document.makepay.billingaddr.value == null || document.makepay.billingaddr.value.length == 0)
	{
		alert("Billing Address is a required field");
		document.makepay.billingaddr.focus();
		return false;
	}
	else if (document.makepay.billingcity.value == null || document.makepay.billingcity.value.length == 0)
	{
		alert("Billing City is a required field");
		document.makepay.billingcity.focus();
		return false;
	}
	else if (document.makepay.billingstate.value == null || document.makepay.billingstate.value.length == 0)
	{
		alert("Billing City is a required field");
		document.makepay.billingcity.focus();
		return false;
	}
	else if (document.makepay.billingcountry.value == null || document.makepay.billingcountry.value.length == 0)
	{
		alert("Billing Country is a required field");
		document.makepay.billingcountry.focus();
		return false;
	}
	else if (document.makepay.billingzip.value == null || document.makepay.billingzip.value.length == 0)
	{
		alert("Billing Zip is a required field");
		document.makepay.billingzip.focus();
		return false;
	}
	else if (document.makepay.homephone.value == null || document.makepay.homephone.value.length == 0)
	{
		alert("Home Phone is a required field");
		document.makepay.homephone.focus();
		return false;
	}
	else if (document.makepay.authorize.value == null || document.makepay.authorize.value.length == 0)
	{
		alert("You have to authorize the payment before you submit.");
		document.makepay.authorize.focus();
		return false;
	}

}

function onChangePasswordClick()
{
	var strOldPassword;
	var strNewPassword;
	var strReenterPassword;

	strOldPassword = document.change_password.oldpassword.value;
	strNewPassword = document.change_password.newpassword.value;
	strReenterPassword = document.change_password.reenterpassword.value;

	if (strOldPassword == null || strOldPassword.length == 0) {
		alert("Old Password is a required field");
		document.change_password.oldpassword.focus();
		return false;
	}	
	else if (strNewPassword == null || strNewPassword.length == 0) {
		alert("New Password is a required field");
		document.change_password.newpassword.focus();
		return false;
	}
	else if (strReenterPassword == null || strReenterPassword.length == 0) {
		alert("Reenter Password is a required field");
		document.change_password.reenterpassword.focus();
		return false;
	}
	else if (strReenterPassword != strNewPassword) {
		alert("Password do not match");
		document.change_password.newpassword.focus();
		return false;
	}
	else if (strNewPassword.length < 5) {
		alert("Password should be atleast 5 characters.");
		document.change_password.newpassword.focus();
		return false;
	}
}

function onLoginClick()
{
	var strUsername;
	var strPassword;
									
	strUsername = document.login.username.value;
	strPassword = document.login.password.value;
									
	if (strUsername == null || strUsername.length == 0)
	{	
		alert("Username cannot be blank.");
		return false;
	}
	else if (strPassword == null || strPassword.length == 0)
	{
		alert("Password cannot be blank.");
		return false;
	}
	return true;
}

function onAddUserClick()
{
	var strUsername;
	var strPassword;
									
	strUsername = document.add_user.username.value;
	strPassword = document.add_user.password.value;
									
	if (strUsername == null || strUsername.length == 0)
	{	
		alert("Username cannot be blank.");
		return false;
	}
	else if (strPassword == null || strPassword.length == 0)
	{
		alert("Password cannot be blank.");
		return false;
	}
	return true;
}

function onCheckStatusClick()
{
	var strPNRNumber;
	var strLastName;
								
	strPNRNumber = document.chkstatus.PNRNumber.value;
	strLastName = document.chkstatus.lastname.value;
									
	if (strPNRNumber == null || strPNRNumber.length == 0)
	{	
		alert("PNRNumber cannot be blank.");
		return false;
	}									
	else if (strLastName == null || strLastName.length == 0)
	{	
		alert("LastName cannot be blank.");
		return false;
	}

	return true;
}

function onFindSpecialClick(type)
{
	document.add_specials.action="edit_specials.asp?type=" & type;
	document.add_specials.submit();	
}

function addbookmark(){
	if (document.all)
		window.external.AddFavorite("http://www.lawsontravel.com","Lawson Travel")
}
