var alreadySubmitted = false;
function showBusy() {

      Dialog.info("<b>Your submission is processing</b>. Clicking the Back button in your browser or clicking on Sumbit more than once may result duplicate submission. We appreciate your patience.", {windowParameters: {width:400, height:115}, showProgress: true});

}
//setup states
	var states = new Array();

	states[0] = new Array('N/A', 'N/A');

	states[1] = new Array(
	'PL','Please Select',
	'AL','Alabama',
	'AK','Alaska',
	'AZ','Arizona',
	'AR','Arkansas',
	'CA','California',
	'CO','Colorado',
	'CT','Connecticut',
	'DE','Delaware',
	'DC','District of Columbia',
	'FL','Florida',
	'GA','Georgia',
	'HI','Hawaii',
	'ID','Idaho',
	'IL','Illinois',
	'IN','Indiana',
	'IA','Iowa',
	'KS','Kansas',
	'KY','Kentucky',
	'LA','Louisiana',
	'ME','Maine',
	'MD','Maryland',
	'MA','Massachusetts',
	'MI','Michigan',
	'MN','Minnesota',
	'MS','Mississippi',
	'MO','Missouri',
	'MT','Montana',
	'NE','Nebraska',
	'NV','Nevada',
	'NH','New Hampshire',
	'NJ','New Jersey',
	'NM','New Mexico',
	'NY','New York',
	'NC','North Carolina',
	'ND','North Dakota',
	'OH','Ohio',
	'OK','Oklahoma',
	'OR','Oregon',
	'PA','Pennsylvania',
	'PR','Puerto Rico',
	'RI','Rhode Island',
	'SC','South Carolina',
	'SD','South Dakota',
	'TN','Tennessee',
	'TX','Texas',
	'UT','Utah',
	'VT','Vermont',
	'VA','Virginia',
    'VI','U.S. Virgin Islands',
	'WA','Washington',
	'WV','West Virginia',
	'WI','Wisconsin',
	'WY','Wyoming'
    );

    states[2] = new Array(
	'PL','Please Select',
    'AB','Alberta',
	'BC','British Columbia',
	'MB','Manitoba',
	'NB','New Brunswick',
	'NF','Newfoundland',
	'NWT','Northwest Territories',
	'NS','Nova Scotia',
	'NU','Nunavut',
	'ON','Ontario',
	'PE','Prince Edward Island',
	'PQ','Quebec',
	'SK','Saskatchewan',
	'YT','Yukon Territory'
	);

	function populate()
	{
		countryId=0;
		document.SVO_Purchase.State.disabled=true;
		if(document.SVO_Purchase.Country.value=='United States of America'){
			document.SVO_Purchase.State.disabled=false;
			countryId=1;
		}

		if(document.SVO_Purchase.Country.value=='Canada'){
			document.SVO_Purchase.State.disabled=false;
			countryId=2;
		}

		var list = states[countryId];
		var box2 = document.SVO_Purchase.State;
		box2.options.length = 0;
		for(i=0;i<list.length;i+=2)
		{
			box2.options[i/2] = new Option(list[i+1],list[i]);
		}
	}

// form validation
	function checkForm(){
		//function that checks the validity of the form
		//checks for empty required fields and if the emails equal
		
		if (alreadySubmitted) {
			return false;
		}
		
		var bolOK = true;		
		if(bolOK)
		{
			bolOK = notEmpty('custom','SVO_Purchase','Title','Please select a title.','FirstName','A first name is required.','LastName','A last name is required.','Address','A street address is required.','City','A city is required.');
		}
		if(bolOK)
		{
			if(document.SVO_Purchase.State[document.SVO_Purchase.State.selectedIndex].value == 'PL')
			{
				bolOK=false;
				alert("Please choose a state.");
				eval("document.SVO_Purchase.State.focus();");
			}

		}
		if(bolOK)
		{
			bolOK = notEmpty('custom','SVO_Purchase','PostalCode', 'Please enter a postal code.','Country','A country is required.','PhoneNumber','A phone number is required.');
		}
		if(bolOK)
		{
			bolOK = checkEmailNoAlerts(document.SVO_Purchase.Email.value);
			if(!bolOK)
			{
				alert('An email address is required.');
				eval("document.SVO_Purchase.Email.focus();");
			}
		}
		if(bolOK)
		{
			if(document.SVO_Purchase.SVOOwner[document.SVO_Purchase.SVOOwner.selectedIndex].value == 'PL')
			{
				bolOK=false;
				alert("Please tell us if you presently own vacation ownership or timeshare real estate interest(s).");
				eval("document.SVO_Purchase.SVOOwner.focus();");
			}

		}
		if(bolOK)
		{
			if(document.SVO_Purchase.HomeOwnership[document.SVO_Purchase.HomeOwnership.selectedIndex].value == 'PL')
			{
				bolOK=false;
				alert("Please tell us if you are a home owner.");
				eval("document.SVO_Purchase.HomeOwnership.focus();");
			}

		}
		if(bolOK)
		{
			if(document.SVO_Purchase.Income_of_Household[document.SVO_Purchase.Income_of_Household.selectedIndex].value == 'PL')
			{
				bolOK=false;
				alert("Please tell us your annual household income.");
				eval("document.SVO_Purchase.Income_of_Household.focus();");
			}

		}
		if(bolOK) {
			alreadySubmitted = true;
			showBusy();
		}
		return bolOK;
	}
	function readDaCookie(){
            //cookie for referers
            var readCookie = document.cookie;
           //alert(document.cookie);
            var cookieArray = readCookie.split(";");
            var rdCookie = '';
            for(i=0;i<cookieArray.length;i++){
                rdCookie = cookieArray[i];
                if(rdCookie.indexOf('referer')>=0){
                    i = cookieArray.length;
                    rdCookieArray = rdCookie.split("^");
                    rdCookie = rdCookieArray[1];
                    //alert(rdCookie);
                }
            }
            document.SVO_Purchase.refererURL.value = rdCookie;
            //alert(document.SVO_Purchase.refererURL.value);  
        }
//-->

// show/hide fields stuff
<!--
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

function showOwnerField()
    {
        var choice = document.SVO_Purchase.SVOOwner.options[document.SVO_Purchase.SVOOwner.selectedIndex].value;

        if(choice == "Yes")
        {
            document.getElementById('OwnerField-div').style.display = "";
		   
        }
		else if(choice == "No")
        {
            document.getElementById('OwnerField-div').style.display = "none";
		   
        }
		else
		{
			document.getElementById('OwnerField-div').style.display = "none";
			   
		}
    }

function showMemberField()
    {
        var choice = document.SVO_Purchase.spgMember.options[document.SVO_Purchase.spgMember.selectedIndex].value;

        if(choice == "Yes")
        {
            document.getElementById('MemNumber-div').style.display = "";
			document.getElementById('nonMember-div').style.display = "none";
		   
        }
		else if(choice == "No")
        {
            document.getElementById('MemNumber-div').style.display = "none";
			document.getElementById('nonMember-div').style.display = "";
		   
        }
		else
		{
			document.getElementById('MemNumber-div').style.display = "none"; 
			document.getElementById('nonMember-div').style.display = "none";
			   
		}
    }

function textCounter(theField, charsLeft, maxChars) {
	if (theField.value.length > maxChars) {
		theField.value = theField.value.substring(0, maxChars);
	} else {
		charsLeft.value = maxChars - theField.value.length;
	}
}
// -->

// s Referral Div Script -->
  <!--
  var temp_data;
  function selectDiv(option, display){
	var the_div = getOptionSelected(option);
	changeDiv(the_div, display);

  }
  function changeDiv(the_div, display){
	var the_style = getStyleObject(the_div);
	if (the_style != false){
	  the_style.display = display;
	  
	  if (document.SVO_Purchase.Broker.value != 0) {
		document.SVO_Purchase.Broker.value ="";
	  }
	  if (document.SVO_Purchase.Promo_Code.value != 0) {
		document.SVO_Purchase.Promo_Code.value ="";
	  }
	  if (document.SVO_Purchase.Friend_Referral.value != 0) {
		document.SVO_Purchase.Friend_Referral.value ="";
	  }
	  if (document.SVO_Purchase.Other.value != 0) {
		document.SVO_Purchase.Other.value ="";
	  }
	}
   }
	
  function getOptionSelected(opt_group){
	return document.SVO_Purchase[opt_group].options[document.SVO_Purchase[opt_group].selectedIndex].value;
  }
	
  function hideAll(){
	changeDiv("Broker","none");
	changeDiv("Promo_Code","none");
	changeDiv("Friend_Referral","none");
	changeDiv("Other","none");
	}  
  
  function getStyleObject(objectId){
	if (document.getElementById && document.getElementById(objectId)){
	  return document.getElementById(objectId).style;
	  }
	else if (document.all && document.all(objectId)){
	  return document.all(objectId).style;
	  }
	else {
	  return false;
	  }
	}
  // -->