

/* ----- Empty form field validation function --------*/
function BlankField( stringValue ){
	if( stringValue.replace(/(^\s+)|(\s+$)/g, '').length < 1 )
		return true;
	else
		return false;
}


/* ----- Email address validation function -----------*/
function ValidEmail(strValue){
    var valid = true;
    var regExp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    var regExp2 = /(\s+)|(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;

    if ( (strValue.search(regExp)) == -1 || strValue.search(regExp2) != -1)
            valid = false;

    return valid;
}
function ValidateforAlphabets(strValue){
    var valid = true;
    var regExp = /^[a-zA-Z ]+$/;

    if ( (strValue.search(regExp)) == -1)
            valid = false;

    return valid;
}
function ValidateforAlphabetsWithHypen(strValue){
    var valid = true;
    var regExp = /^[a-zA-Z \- ']+$/;

    if ( (strValue.search(regExp)) == -1)
            valid = false;

    return valid;
}

function ValidateforAlphabetsWithPeriod(strValue){
    var valid = true;
    var regExp = /^[a-zA-Z \- , .]+$/;

    if ( (strValue.search(regExp)) == -1)
            valid = false;

    return valid;
}
function ValidateforNumeric(strValue){
    var valid = true;
    var regExp = /^[0-9]+$/;

    if ( (strValue.search(regExp)) == -1)
            valid = false;

    return valid;
}

function ValidateforAlphaNumeric(strValue){
    var valid = true;
    var regExp = /^[a-zA-Z0-9]+$/;

    if ( (strValue.search(regExp)) == -1)
            valid = false;

    return valid;
}

function ValidatePhoneNumber(strValue){
    var valid = true;
    var regExp = /^[0-9-]+$/;

    if ( (strValue.search(regExp)) == -1)
            valid = false;

    return valid;
}


/* ----- Login validation function -------------------*/
function validate_member_login( frm ) {
	var returnValue = false;
	
	if ( BlankField( frm.username.value ) ) {
		alert( "Please enter your username." );
		frm.username.focus();
	} else if ( BlankField( frm.password.value ) ) {
		alert( "Please enter your password." );
		frm.password.focus();
	} else {
		returnValue = true;
	}
	
	return returnValue;
}

function CalculatePoints(cmbCurrent,Points,txtCurrent,txtTotalPoints)
{
    var Totalpoints = 0;
    txtCurrent.value = cmbCurrent.value * Points;   
   for(i=0;i<document.form1.elements.length;i++)
   {
      if(document.form1.elements[i].type == 'text' && document.form1.elements[i].value != '' && document.form1.elements[i].id != 'txtTotalPoints' )
      {
          Totalpoints = Totalpoints + parseInt(document.form1.elements[i].value);
      }
   }
    txtTotalPoints.value = Totalpoints;
    Totalpoints = 0;
}

function validate_login( frm ) {
	var returnValue = false;
	
	if ( BlankField( frm.iata_number.value ) ) {
		alert( "Please enter your IATA number." );
		frm.iata_number.focus();
	} else {
		returnValue = true;
	}
	
	return returnValue;
}


/* ----- Generic validation function -----------------*/
function append_warning( elem ) {
	var img = document.createElement( "img" );
	img.src = "http://travelagents.princeresortshawaii.com/images/icon-warning.gif";
	img.style.margin = "0 0 0 5px";
	img.className = "validation-error";
	document.getElementById( elem ).parentNode.appendChild( img );
}

function validate() {
	var invalidElements = new Array();
	
	for ( var i = 0; i < requiredElements.length; i++ ) {
		var elem = document.getElementById( requiredElements[i] ).parentNode;
		if ( elem.lastChild.className == "validation-error" ) {
			elem.removeChild( elem.lastChild );
		}
	}
	
	for ( var i = 0; i < requiredElements.length; i++ ) {
		if ( requiredElements[i].indexOf( "email" ) != -1 ) {
			if ( !ValidEmail( document.getElementById( requiredElements[i] ).value ) ) {
				append_warning( requiredElements[i] );
				invalidElements.push( requiredElements[i] );
			}
		} else {
			if ( BlankField( document.getElementById( requiredElements[i] ).value ) ) {
				append_warning( requiredElements[i] );
				invalidElements.push( requiredElements[i] );
			}
		}
		
	}
	
	if ( invalidElements.length > 0 ) {
		alert( "One or more fields were not supplied. Please scroll back up and double-check the noted fields." );
		return false;
	}
}

function Validate_QuickBlock(cmbArrivalDay, cmbArrivalMonth, cmbArrivalYear, txtGroupCode, txtWholesalerCode, txtTourCode, txtSpecialService)
{
	if (cmbArrivalDay.value == '' )
    {
		alert( "Please Enter Arrival Day\n" );
		cmbArrivalDay.focus();
		return false;
	}
	if (cmbArrivalMonth.value == '' )
    {
		alert( "Please Enter Arrival Month\n" );
		cmbArrivalMonth.focus();
		return false;
	}
	if (cmbArrivalYear.value == '' )
    {
		alert( "Please Enter Arrival Year\n" );
		cmbArrivalYear.focus();
		return false;
	}
	if (txtGroupCode.value == '' )
    {
		alert( "Please Enter Group Code\n" );
		txtGroupCode.focus();
		return false;
	}
	if (txtWholesalerCode.value == '' )
    {
		alert( "Please Enter Wholesaler Code\n" );
		txtWholesalerCode.focus();
		return false;
	}
	if (txtTourCode.value == '' )
    {
		alert( "Please Enter Tour Code\n" );
		txtTourCode.focus();
		return false;
	}
	if (txtSpecialService.value == '' )
    {
		alert( "Please Enter Special Service\n" );
		txtSpecialService.focus();
		return false;
	}
	
	
}

function Validate_ContactUs(txtFirstName, txtLastName, txtEmail)
{   
    var returnValue = false;
    if (txtFirstName.value == '' )
    {
		alert( "Please Enter First Name\n" );
		txtFirstName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtFirstName.value))
	{
		alert( "First Name should contain alphabets with - or ' only.\n" );
		txtFirstName.focus();
		return false;
	}
	if (txtLastName.value == '' )
    {
		alert( "Please Enter Last Name\n" );
		txtLastName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtLastName.value))
	{
		alert( "Last Name should contain alphabets only.\n" );
		txtLastName.focus();
		return false;
	}
	if (txtEmail.value == '' ){
		alert( "Please enter Email address\n" );
		txtEmail.focus();
		return false;
	}
	else if(!ValidEmail(txtEmail.value))
	{
		alert( "Please enter valid email address.\n" );
		txtEmail.focus();
		return false;
	}
    return true;
}

function Validate_JoinEmailClub(txtFirstName, txtLastName, txtEmail, chkUpdate)
{
    if (txtFirstName.value == '' )
    {
		alert( "Please Enter First Name\n" );
		txtFirstName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtFirstName.value))
	{
		alert( "First Name should contain alphabets only.\n" );
		txtFirstName.focus();
		return false;
	}
	if (txtLastName.value == '' )
    {
		alert( "Please Enter Last Name\n" );
		txtLastName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtLastName.value))
	{
		alert( "Last Name should contain alphabets only.\n" );
		txtLastName.focus();
		return false;
	}
	if (txtEmail.value == '' ){
		alert( "Please enter Email address\n" );
		txtEmail.focus();
		return false;
	}
	else if(!ValidEmail(txtEmail.value))
	{
		alert( "Please enter valid email address.\n" );
		txtEmail.focus();
		return false;
	}
	if (!chkUpdate.checked){
		alert( "In order to sign-up for our Email Club, please check the box\nas indicated below and then press the SUBMIT button\n" );
		chkUpdate.focus();
		return false;
	}
	return true;
}

function Validate_GuestAmenity(txtFirstName, txtLastName,cmbResort,cmbArrivalDay,cmbArrivalMonth,cmbArrivalYear,cmbDepartureDate,cmbDepartureMonth,cmbDepartureYear,txtRoomCategory,txtReservationNo,cmbBookingDay,cmbBookingMonth,cmbBookingYear,cmbBookedby,lblFromEmail) 
{
    var returnValue = false;
    if (txtFirstName.value == '' )
    {
		alert( "Please Enter Client's First Name\n" );
		txtFirstName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtFirstName.value))
	{
		alert( "First Name should contain alphabets only.\n" );
		txtFirstName.focus();
		return false;
	}
	if (txtLastName.value == '' )
    {
		alert( "Please Enter Client's Last Name\n" );
		txtLastName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtLastName.value))
	{
		alert( "Last Name should contain alphabets only.\n" );
		txtLastName.focus();
		return false;
	}
	if (cmbResort.value == '-1' )
    {
		alert( "Please Select the Resort\n" );
		cmbResort.focus();
		return false;
	}
	
	var arrivalMonth = cmbArrivalMonth.selectedIndex + 1;
	if(arrivalMonth < 10)
	    arrivalMonth = "0" + arrivalMonth;
	    
	var arrivalDate = arrivalMonth + "/" + cmbArrivalDay.value + "/" + cmbArrivalYear.value;
	
	var departureMonth = cmbDepartureMonth.selectedIndex + 1;
	if(departureMonth < 10)
	    departureMonth = "0" + departureMonth;
	    
	var departureDate = departureMonth + "/" + cmbDepartureDate.value + "/" + cmbDepartureYear.value;
	
	if(new Date(departureDate) < new Date(arrivalDate))
	{
		alert( "Please enter valid dates: Departure Date cannot be less than the Arrival Date.\n" );
		cmbDepartureDate.focus();
		return false;
	}
	if (document.getElementById('GuestAmenityRequest1_lblFromEmail').innerText=="")
    	{
		alert( "Please Update your Email Address in Profile\n" );
		return false;
	}
	return true;
}


function Validate_PointRedemption(txtTotalPoints,cmbArrivalDay,cmbArrivalMonth,cmbArrivalYear,cmbDepartureDay,cmbDepartureMonth,cmbDepartureYear,cmbSelectBed,cmbSmokingPreference,cmbNoOfAdults,cmbOneRoundCourse,cmbTwoHourTennis,txtPointsOneRoundGolf,txtTwoHourTennis,cmbBuffetBreakFastProperty,txtPointsBuffetBreakFast,cmbTwoRoundGolfProperty,txtTwoRoundGolf) 
{
    var returnValue = false;
    if (txtTotalPoints.value == '' )
    {
		alert( "No Points Selected for Redemtion\n" );
		txtTotalPoints.focus();
		return false;
	}
	if(txtPointsOneRoundGolf.value != '' && cmbOneRoundCourse.value == "Select Course")
	{
	   
	    alert( "Please Select Course for One round of Golf\n" );
		cmbOneRoundCourse.focus();
		return false;
	}
	if(txtPointsBuffetBreakFast.value != '' && cmbBuffetBreakFastProperty.value == "-1")
	{
	    alert( "Please Select Property for Buffet Breakfast\n" );
		cmbBuffetBreakFastProperty.focus();
		return false;
	}
	if(txtTwoRoundGolf.value != '' && cmbTwoRoundGolfProperty.value == "Select Course")
	{
	    alert( "Please Select Course for Two rounds of golf\n" );
		cmbTwoRoundGolfProperty.focus();
		return false;
	}
	
	var arrivalMonth = cmbArrivalMonth.selectedIndex + 1;
	if(arrivalMonth < 10)
	    arrivalMonth = "0" + arrivalMonth;
	    
	var arrivalDate = arrivalMonth + "/" + cmbArrivalDay.value + "/" + cmbArrivalYear.value;
	
	var departureMonth = cmbDepartureMonth.selectedIndex + 1;
	if(departureMonth < 10)
	    departureMonth = "0" + departureMonth;
	    
	var departureDate = departureMonth + "/" + cmbDepartureDay.value + "/" + cmbDepartureYear.value;
	
	if(new Date(departureDate) < new Date(arrivalDate))
	{
		alert( "Please enter valid dates: Departure Date cannot be less than the Arrival Date.\n" );
		cmbDepartureDay.focus();
		return false;
	}
	if (cmbSelectBed.value == '-1' && ((new Date(departureDate) > new Date()) || (new Date(arrivalDate) > new Date())))
    {
		alert( "Please Select the Bed Preference\n" );
		cmbSelectBed.focus();
		return false;
	}
	if (cmbSmokingPreference.value == '-1' && ((new Date(departureDate) > new Date()) || (new Date(arrivalDate) > new Date())))
    {
		alert( "Please Select the Smoking Preference\n" );
		cmbSmokingPreference.focus();
		return false;
	}
	if (cmbNoOfAdults.value == '0' && ((new Date(departureDate) > new Date()) || (new Date(arrivalDate) > new Date())))
    {
		alert( "Please Select No of Adults\n" );
		cmbNoOfAdults.focus();
		return false;
	}
    return true;
}
function Validate_ForgotUserName(txtFirstName, txtLastName, txtAgencyCompanyName)
{
	var returnValue = false;
	if (txtFirstName.value == '' ){
		alert( "Please enter First Name\n" );
		txtFirstName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtFirstName.value))
	{
		alert( "First Name should contain alphabets only.\n" );
		txtFirstName.focus();
		return false;
	}
	if (txtLastName.value == '' ){
		alert( "Please enter Last Name\n" );
		txtLastName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtLastName.value))
	{
		alert( "Last Name should contain alphabets only.\n" );
		txtLastName.focus();
		return false;
	}
	if (txtAgencyCompanyName.value == '' ){
		alert( "Please enter Agency/Company Name\n" );
		txtAgencyCompanyName.focus();
		return false;
	}
	else if(!ValidateforAlphabetsWithPeriod(txtAgencyCompanyName.value))
	{
		alert( "Agency/Company Name should contain alphabets with - , .  only.\n" );
		txtAgencyCompanyName.focus();
		return false;
	}
	return true;
}

function Validate_ForgotPassword(txtLastName, txtEmail)
{
	var returnValue = false;
	if (txtLastName.value == '' ){
		alert( "Please enter Last Name\n" );
		txtLastName.focus();
		return false;
	}
	else if(!ValidateforAlphabets(txtLastName.value))
	{
		alert( "Last Name should contain alphabets only.\n" );
		txtLastName.focus();
		return false;
	}
	if (txtEmail.value == '' ){
		alert( "Please enter Email address\n" );
		txtEmail.focus();
		return false;
	}
	else if(!ValidEmail(txtEmail.value))
	{
		alert( "Please enter valid email address.\n" );
		txtEmail.focus();
		return false;
	}
	return true;
}

function Validate_Login(txtUserName, txtPassword)
{
	var returnValue = false;
	if (txtUserName.value == '' ){
		alert( "Please enter User Name\n" );
		txtUserName.focus();
		return false;
	}
	
	if (txtPassword.value == '' ){
		alert( "Please enter Password address\n" );
		txtPassword.focus();
		return false;
	}
	return true;
}
function Validate_IATA(txtUserName)
{
	var returnValue = false;
	if (txtUserName.value == '' ){
		alert( "Please enter your IATA number\n" );
		txtUserName.focus();
		return false;
	}
	return true;
}
function Validate_AgentProfile(txtUserName, txtPassword, txtRePassword, txtEmail, txtConfirmEmail, txtFirstName, txtMiddleName,txtLastName, txtSuffix, txtCompany, txtAddress1, txtCity, txtUsStates, txtZipcode, txtCountry,  txtBusinessPhone, txtBusinessFax, cmbBirthMonth, cmbBirthDate) 
{
	var returnValue = false;
		
	if (txtUserName.value == '' )
	{
		alert( "Please enter user name\n" );
		txtUserName.focus();
		return false;
	}
	if (txtPassword.value == '' )
	{
		alert( "Please enter password.\n" );
		txtPassword.focus();
		return false;
	}
	else if(txtPassword.value.length < 6)
	{
		alert( "Password should contain minimum of 6 characters.\n" );
		txtPassword.focus();
		return false;
	}
	if (txtRePassword.value == '' )
	{
		alert( "Please Re-enter your Password.\n" );
		txtPassword.focus();
		return false;
	}
	if(txtRePassword.value != txtPassword.value)
	{
		alert("Passwords are not matching");
		txtRePassword.focus();
		return false;
	}
	if (txtEmail.value == '' )	    
	    {
		    alert( "Please enter email address.\n" );
		    txtEmail.focus();
		    return false;
	    }
    if (txtEmail.value != '' ){
	    if(!ValidEmail(txtEmail.value))
	    {
		    alert( "Please enter valid email address.\n" );
		    txtEmail.focus();
		    return false;
	    }
	    //if (txtConfirmEmail.value != '' ){
		if(!ValidEmail(txtConfirmEmail.value))
	    {
		    alert( "Please confirm valid email address.\n" );
		    txtConfirmEmail.focus();
		    return false;
	    }
        	
	    else if (txtConfirmEmail.value != txtEmail.value ){
		    alert( "Confirm correct Email address.\n" );
		    txtConfirmEmail.focus();
		    return false;
	    }
	    //}
	}
    
	if (txtFirstName.value == '' )
	{
		alert( "Please enter First Name\n" );
		txtFirstName.focus();
		return false;
	}
	else if(!ValidateforAlphabetsWithHypen(txtFirstName.value))
	{
		alert( "First Name should contain alphabets with - or ' only .\n" );
		txtFirstName.focus();
		return false;
	}
	if (txtLastName.value == '' )
	{
		alert( "Please enter Last Name\n" );
		txtLastName.focus();
		return false;
	}
	else if(!ValidateforAlphabetsWithHypen (txtLastName.value))
	{
		alert( "Last Name should contain alphabets with - or ' only.\n" );
		txtLastName.focus();
		return false;
	}
	if(!ValidateforAlphabets(txtMiddleName.value) && txtMiddleName.value != '')
	{
		alert( "Middle Initial should contain alphabets only.\n" );
		txtMiddleName.focus();
		return false;
	}
	else if(txtMiddleName.value.length > 1)
	{
		alert( "Middle Initial should contain only one character.\n" );
		txtMiddleName.focus();
		return false;
	}
	if(!ValidateforAlphabets(txtSuffix.value) && txtSuffix.value != '' )
	{
		alert( "Suffix  should contain alphabets only.\n" );
		txtSuffix.focus();
		return false;
	}
	if(txtCompany.value == '' )
	{
		alert( "Please Enter Company Name.\n" );
		txtCompany.focus();
		return false;
	}
	if (txtAddress1.value == '' ){
		alert( "Please enter Address\n" );
		txtAddress1.focus();
		return false;
	}
	if(!ValidateforAlphabets(txtCity.value) && txtCity.value != '')
	{
		alert( "City Name should contain alphabets only.\n" );
		txtCity.focus();
		return false;
	}
	if(txtUsStates.value == '')
	{
		alert( "Please Select the State\n" );
		txtUsStates.focus();
		return false;
	}
	if (txtZipcode.value == '' ){
		alert( "Please enter Zip Code\n" );
		txtZipcode.focus();
		return false;
	}
	
	if (txtCountry.value == '' )
	{
		alert( "Please Select the Country\n" );
		txtCountry.focus();
		return false;
	}
	if(!ValidatePhoneNumber(txtBusinessPhone.value) && txtBusinessPhone.value != '')
	{
		alert( "Please enter a valid Phone Number.\n" );
		txtBusinessPhone.focus();
		return false;
	}
	if(!ValidatePhoneNumber(txtBusinessFax.value) && txtBusinessFax.value != '')
	{
		alert( "Please enter a valid Fax Number.\n" );
		txtBusinessFax.focus();
		return false;
	}
//	if(!ValidateforNumeric(txtYear.value) && txtYear.value != '')
//	{
//		alert( "Please enter valid Year\n" );
//		txtYear.focus();
//		return false;
//	}
	
//	if(txtYear.value != '')
//	{
//	    today = new Date(); 
//        year = today.getYear();
//        month = today.getMonth(); 
//        
//        if(txtYear.value.length != 4)
//	    {
//		    alert( "Year should be 4 digits.\n" );
//		    txtYear.focus();
//		    return false;
//	    }
//	    else if(!ValidateforNumeric(txtYear.value))
//		{
//		    alert( "Year should be numbers only.\n" );
//		    txtYear.focus();
//		    return false;
//		}
//	    else if(txtYear.value < 1900)
//	    {
//	        alert( "Year should start from 1900.\n" );
//		    txtYear.focus();
//		    return false;
//	    }
//	    
//	    else if(txtYear.value > year)
//	    {
//            alert( "Please enter valid year.\n" );
//		    txtYear.focus();
//		    return false;
//	    }
//	    
//		var DOBMonth = cmbBirthMonth.selectedIndex + 1;
//		
//		if(DOBMonth < 10)
//	        DOBMonth = "0" + DOBMonth;
//	    if(cmbBirthMonth.selectedIndex)
//	    var DOBDate = DOBMonth + "/" + cmbBirthDate.value + "/" + 1900;
//        
//        if(today <= new Date(DOBDate))
//        {
//            alert("Please enter valid date");
//            cmbBirthMonth.focus();
//            return false;        
//        }

//	}
	
	
	return true;
}

/* ----- Table striper function ----------------------*/
function stripe() {
	var even = false;
	var evenColor = "#fafafa";
	var oddColor = "";
	
	if ( document.getElementById && document.createTextNode ) {
		var tables = document.getElementsByTagName( 'table' );
		for ( var i = 0; i < tables.length; i++ ) {
			// if ( tables[i].className == 'striped' ) {
			if ( tables[i].className.indexOf( 'striped' ) != -1 ) {
				var trs = tables[i].getElementsByTagName( "tr" );
				for ( var j = 0; j < trs.length; j++ ) {
					if ( trs[j].parentNode.nodeName == 'TBODY' ) {
						trs[j].style.backgroundColor = even ? evenColor : oddColor;
						even = !even;
					}
				}
			}
			even = false; // resets value for multiple striped tables per page
		}
	}
}


/* ----- Onload --------------------------------------*/
window.onload = function() {
	stripe();
}