function destinationOK()
    {
    if (document.forms[ 0 ].destination.options[document.forms[ 0 ].destination.selectedIndex].value == "")
        {
        alert("You must select a destination from the drop-down list to continue.");
        return false;
        }
    return true;
    }

function otherdestination()
   {
    if (document.forms[ 0 ].destination.options[document.forms[ 0 ].destination.selectedIndex].value == "Other")
        {
        document.form1.other.disabled=false;
		return false;
		}
	    document.form1.other.disabled=true;
		document.form1.other.value="";
		return true;
   }
   
function destinationotherOK()
    {
    if (document.forms[ 0 ].destination.options[document.forms[ 0 ].destination.selectedIndex].value == "Other" && document.forms[ 0 ].other.value.length == 0)
        {
        alert("Please enter the destination which was not listed in the provided text box to continue.");
        return false;
        }
    return true;
    }


function oneweekchosenOK()
    {
    if (document.forms[ 0 ].checkin.value == "SELECT CHECK-IN DATE")
        {
        alert("Please select a check-in day.");
        return false;
        }
    if (document.forms[ 0 ].checkout.value == "SELECT CHECK-OUT DATE")
        {
        alert("Please select a check-out day.");
        return false;
        }
    return true;
    }



function oneweekdestinationOK()	{
	var checkin = 0;
	var checkout = 0;
	checkin = new Date(document.forms[ 0 ].checkin.value);
	checkout = new Date(document.forms[ 0 ].checkout.value);
	difference = checkout - checkin;
	days = Math.round(difference/(1000*60*60*24));
	if (days > "7")
        {
        alert("You have select a period longer than seven days. Please select a check-in date and check-out date which totals seven days");
        return false;
        }
	if (days < "7")
        {
        alert("You have select a period shorter than seven days. Please select a check-in date and check-out date which totals seven days");
        return false;
        }
    return true;
    }

function unitsizeOK()
    {
    if (document.forms[ 0 ].unitsize.options[document.forms[ 0 ].unitsize.selectedIndex].value == "")
        {
        alert("You must select how many rooms you require per condo.");
        return false;
        }
    return true;
    }


function selfcheck()
{
document.form1.guestname.disabled=true;
document.form1.guestname.value="";
}
function guestcheck()
{
document.form1.guestname.disabled=false;
}


function GuestOK()
    {
    if (document.forms[ 0 ].whofor[1].checked == true && document.forms[ 0 ].guestname.value.length == 0)
        {
        alert("Please enter the name of your guest. ");
        return false;
        }
    return true;
    }

function partynumberOK()
    {
    if (document.forms[ 0 ].partynumber.options[document.forms[ 0 ].partynumber.selectedIndex].value == "")
        {
        alert("You must select how many people will be in your party.");
        return false;
        }
    return true;
    }

function childrenperpartyOK()
    {
    if (document.forms[ 0 ].childrenperparty.options[document.forms[ 0 ].childrenperparty.selectedIndex].value == "")
        {
        alert("You must select how many children will be in your party.");
        return false;
        }
    return true;
    }

function nameOK()
    {
    if (document.forms[ 0 ].Fname.value.length == 0)
        {
        alert("Please enter your first name.");
        return false;
        }
    if (document.forms[ 0 ].Lname.value.length == 0)
        {
        alert("Please enter your last name.");
        return false;
        }
    return true;
    }


function addressOK()
    {
    if (document.forms[ 0 ].Address1.value.length == 0 && (document.forms[ 0 ].City.value.length != 0 || document.forms[ 0 ].City.value.length != 0 || document.forms[ 0 ].State.options[document.forms[ 0 ].State.selectedIndex].value != "" || document.forms[ 0 ].Zip.value.length != 0))
        {
        alert("Please enter a complete address.");
        return false;
        }
    if (document.forms[ 0 ].City.value.length == 0 && (document.forms[ 0 ].Address1.value.length != 0 || document.forms[ 0 ].City.value.length != 0 || document.forms[ 0 ].State.options[document.forms[ 0 ].State.selectedIndex].value != "" || document.forms[ 0 ].Zip.value.length != 0))
        {
        alert("Please enter a city.");
        return false;
        }
    if (document.forms[ 0 ].State.options[document.forms[ 0 ].State.selectedIndex].value == "" && (document.forms[ 0 ].City.value.length != 0 || document.forms[ 0 ].Address1.value.length != 0 || document.forms[ 0 ].City.value.length != 0 || document.forms[ 0 ].Zip.value.length != 0))
        {
        alert("Please select a state.");
        return false;
        }
    if (document.forms[ 0 ].Zip.value.length == 0 && (document.forms[ 0 ].State.options[document.forms[ 0 ].State.selectedIndex].value != "" || document.forms[ 0 ].City.value.length != 0 || document.forms[ 0 ].Address1.value.length != 0 || document.forms[ 0 ].City.value.length != 0))
        {
        alert("Please enter your zip code.");
        return false;
        }
    return true;
    }

function zipOK()
    {
    if (document.forms[ 0 ].Zip.value.length != 0)
		{
		var zip = document.forms[ 0 ].Zip.value;
    	if (zip.length == 5)
        	{
        	var result = isAllDigits(zip);
        	if (result == false)
            	{
            	alert("Invalid character in zip code.");
            	}
        	return result;
        	}
    	else if (zip.length == 10)
        	{
        	var result = isAllDigits(zip.substring(0,5));
        	if (result == true)
            	{
            	if (zip.substring(5,6) != "-")
                	{
                	result = false;
                	}
            	else
                	{
                	result = isAllDigits(zip.substring(6,10));
                	}
            	}
        	if (result == false)
            	{
            	alert("Invalid character in zip code.");
            	}
        	return result;
        	}
    	else
        	{
        	alert("Invalid zip code.");
        	return false;
        	}
        return false;
        }
    return true;
    }


function isDigit(c)
    {
    var test = "" + c;
    if (test == "0" || test == "1" || test == "2" || test == "3" || test == "4" || test == "5" || test == "6" || test == "7" || test == "8" || test == "9")
        {
        return true;
        }
    return false;
    }


function isAllDigits(s)
    {
    var test = "" + s;
    for (var k = 0; k < test.length; k++)
        {
        var c = test.substring(k, k+1);
        if (isDigit(c) == false)
            {

            return false;
            }
        }
    return true;
    }


function hphoneOK()
    {
    if (document.forms[ 0 ].hphone1.value.length != 3)
        {
        alert("Please enter your home phone number area code.");
        return false;
        }
    if (document.forms[ 0 ].hphone2.value.length != 3)
        {
        alert("Please enter the first three digits of your home phone number.");
        return false;
        }
    if (document.forms[ 0 ].hphone3.value.length != 4)
        {
        alert("Please enter the last four digits of your home phone number.");
        return false;
        }
    if (isAllDigits(document.forms[ 0 ].hphone1.value) == false)
        {
        alert("Invalid character in home phone number area code.");
        return false;
        }
    if (isAllDigits(document.forms[ 0 ].hphone2.value) == false)
        {
        alert("Invalid character in the first three digits of your home phone number.");
        return false;
        }
    if (isAllDigits(document.forms[ 0 ].hphone3.value) == false)
        {
        alert("Invalid character in last four digits of your home phone number.");
        return false;
        }
    return true;
    }

function wphoneOK()
    {
    if (document.forms[ 0 ].wphone1.value.length == 0 && (document.forms[ 0 ].wphone2.value.length != 0 || document.forms[ 0 ].wphone3.value.length != 0))
        {
        alert("Please enter your work (day) phone number area code.");
        return false;
        }
    if (document.forms[ 0 ].wphone2.value.length == 0 && (document.forms[ 0 ].wphone1.value.length != 0 || document.forms[ 0 ].wphone3.value.length != 0))
        {
        alert("Please enter the first three digits of your work (day) phone number.");
        return false;
        }
    if (document.forms[ 0 ].wphone3.value.length == 0 && (document.forms[ 0 ].wphone1.value.length != 0 || document.forms[ 0 ].wphone2.value.length != 0))
        {
        alert("Please enter the last four digits of your work (day) phone number.");
        return false;
        }
    if (document.forms[ 0 ].wphone1.value.length != 0 && document.forms[ 0 ].wphone1.value.length != 3)
        {
        alert("Please completely enter your area code.");
        return false;
        }
    if (document.forms[ 0 ].wphone2.value.length != 0 && document.forms[ 0 ].wphone2.value.length != 3)
        {
        alert("Please completely enter the first three digits of your work (day) phone number.");
        return false;
        }
    if (document.forms[ 0 ].wphone3.value.length != 0 && document.forms[ 0 ].wphone3.value.length != 4)
        {
        alert("Please completely enter the last four digits of your work (day) phone number.");
        return false;
        }
    if (document.forms[ 0 ].wphone1.value.length != 0 && isAllDigits(document.forms[ 0 ].wphone1.value) == false)
        {
        alert("Invalid character in work (day) phone number area code.");
        return false;
        }
    if (document.forms[ 0 ].wphone2.value.length != 0 && isAllDigits(document.forms[ 0 ].wphone2.value) == false)
        {
        alert("Invalid character in the first three digits of your work (day) phone number.");
        return false;
        }
    if (document.forms[ 0 ].wphone3.value.length != 0 && isAllDigits(document.forms[ 0 ].wphone3.value) == false)
        {
        alert("Invalid character in last four digits of your work (day) phone number.");
        return false;
        }
    return true;
    }

function doubleForMod10(c)
    {
    var d = 0 + c;
    if (d == 0) return 0;
    if (d == 1) return 2;
    if (d == 2) return 4;
    if (d == 3) return 6;
    if (d == 4) return 8;
    if (d == 5) return 1; // 5+5 = 10; 1+0 = 1
    if (d == 6) return 3; // 6+6 = 12; 1+2 = 3
    if (d == 7) return 5; // 7+7 = 14; 1+4 = 5
    if (d == 8) return 7; // 8+8 = 16; 1+6 = 7
    return 9; // (digit must be 9) 9+9 = 18; 1+8 = 9
    }

function sumForMod10(s)
    {
    var v = parseInt(s, 10); // get the value
    var result = doubleForMod10(Math.floor(v / 1000));
    v = v % 1000;
    result += Math.floor(v / 100);
    v = v % 100;
    result += doubleForMod10(Math.floor(v / 10));
    v = v % 10;
    result += v;
    return result;
    }
	
function emailOK() {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.forms[ 0 ].email.value)){
	return true;
		}
	alert("Invalid email address. Please re-enter.")
	return false;
	}	

function EmailConfirmOK() 
{
var em = document.forms[ 0 ].email.value;
var em2 = document.forms[ 0 ].email2.value;
// check for a value in both fields.
if (em == '' || em2 == '') {
alert('Please confirm your email.');
return false;
}
// check for matching passwords
if (em != em2) {
alert ("You did not enter the same email twice. Please re-enter your email.");
return false;
}
return true;
      }


function Disab() {
frm=document.forms[0]
if(frm.chk.checked)
{frm.Button.disabled=false}
else {frm.Button.disabled=true}
}

function checkOK()
    {
    if (document.forms[ 0 ].chk.checked == 0)
        {
        alert("You must authorize WholesaleResorts.com and its affliates to contact you regarding this and any future promotions by clicking the checkbox to continue. ")
        return false;
        }
    return true;
    }


function validationcheck()
    {
    if (destinationOK() == false)
         {
        return;
        }
    if (destinationotherOK() == false)
         {
        return;
        }
    if (oneweekchosenOK() == false)
         {
        return;
        }
    if (oneweekdestinationOK() == false)
         {
        return;
        }
    if (unitsizeOK() == false)
         {
        return;
        }
    if (GuestOK() == false)
         {
        return;
        }
    if (partynumberOK() == false)
        {
        return;
        }
    if (childrenperpartyOK() == false)
        {
        return;
        }
    if (nameOK() == false)
        {
        return;
        }
    if (addressOK() == false)
        {
        return;
        }
    if (zipOK() == false)
        {
        return;
        }
    if (hphoneOK() == false)
        {
        return;
        }
    if (wphoneOK() == false)
        {
        return;
        }
    if (emailOK() == false)
        {
        return;
         }
    if (EmailConfirmOK()  == false)
        {
        return;
        }
    if (checkOK()  == false)
        {
        return;
        }
    document.forms[ 0 ].submit();
  }