
// <!--


function doFormError(message)
{
   alert(message);
   return false;
}

function eCheck(str)
{
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    var error = false;

    if(str.indexOf(at)==-1)
    {
        error = true;

        return false;
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
          error = true;
          return false;
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
          error = true;
          return false;
    }

    if (str.indexOf(at,(lat+1))!=-1)
    {
          error = true;
          return false;
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
          error = true;
          return false;
    }

    if (str.indexOf(dot,(lat+2))==-1)
    {
          error = true;
          return false;
    }

    if (str.indexOf(" ")!=-1)
    {
          error = true;
          return false;
    }

    return (error == false) ? null : 'Invalid Email Address';
}
	
function returnValidate(formName)
{
   var theForm;

   if(document.all)
   {
       theForm = document.all[formName];
   }

   if(document.getElementById)
   {
       theForm = document.getElementById(formName);
   }

   if(document.forms)
   {
       theForm = document.forms[formName];
   }

   var textInputs = new Array('firstname', 'lastname', 'First_Cust_Name', 'Cust_Name', 'DonateName', 'DonateAddress', 'DonateCity', 'ownerfirstname', 'ownerlastname', 'Name', 'Name2');
   var emails = new Array('email', 'Email', 'Cust_Email', 'DonateEmailAddress', 'owneremail');
   var phones = new Array('contact_phone', 'Cust_DayPh', 'DonateDaytimePhone', 'ownerhomephone', 'DayPhone', 'home_phone');

   if(theForm.offer_type)
   {
       //if the offer form value offer_type is not set immediately throw an error//
       if(theForm.offer_type.value == '')
       {
           doFormError('The Offer Type is required!\nPlease select Purchase or Rent.');
           return false;
       }
   }

   if(theForm.ShowResortID)
   {
       var resort = theForm.ShowResortID.value;
       if(resort == null || resort == '' || isNaN(resort))
       {
           doFormError('Resort Name is required to continue!');
           return false;
       }
   }
      if(document.getElementById('ShowResortDiv'))
      {
          var resortsDiv = document.getElementById('ShowResortDiv');

          if(resortsDiv.innerHTML == 'loading ...')
          {
              doFormError('Please Select a Resort Name to Continue');
              return false;
          }
      }

      for(var i = 0; i <= theForm.elements.length; i++)
      {
          if((textInputs.indexOf(theForm.elements[i].name) >= 0) && theForm.elements[i].value == '' )
          {
              theForm.elements[i].focus();
              doFormError('All required fields must be completed.\nPlease complete the required fields and click submit again.');
              theForm.elements[i].style.backgroundColor = '#ffffdf';

              return false;
          }

          if((emails.indexOf(theForm.elements[i].name) >= 0) && (eCheck(theForm.elements[i].value) !== null) )
          {
              theForm.elements[i].focus();
              doFormError('Email Address in incomplete or Invalid.');
              theForm.elements[i].style.backgroundColor = '#ffffdf';

              return false;
          }

          if((phones.indexOf(theForm.elements[i].name) >= 0) && (isNaN(theForm.elements[i].value) == true || theForm.elements[i].value == '' || theForm.elements[i].value == '0' || theForm.elements[i].value.length < 10 ))
          {
              theForm.elements[i].focus();
              doFormError('Phone numbers must include numbers only.');
              theForm.elements[i].style.backgroundColor = '#ffffdf';

              return false;
          }

          if((theForm.elements[i].name == 'Offer') && (isNaN(theForm.elements[i].value) == true || theForm.elements[i].value == '' || theForm.elements[i].value == '0' ))
          {
              theForm.elements[i].focus();
              doFormError('Please include an offer amount.');
              theForm.elements[i].style.backgroundColor = '#ffffdf';

              return false;
          }
      }
}

if(document.getElementById("OfferForm2") !== null)
{
	document.forms["OfferForm2"].onsubmit = function(){
		 return returnValidate("OfferForm2");
	}
}

if(document.getElementById("customcare") !== null)
{
	document.forms["customcare"].onsubmit = function(){
		 return returnValidate("customcare");
	}
}

if(document.getElementById("SellForm") !== null)
{
	document.forms["SellForm"].onsubmit = function(){
		return returnValidate("SellForm");
	}
	document.getElementById('SellForm').country.onchange = function()
	{
			if(document.getElementById('SellForm').country.options[document.getElementById('SellForm').country.selectedIndex].value != 231)
			{
				document.getElementById('SellForm').zip_code.value = '00000';
			}
				
			if(document.getElementById('SellForm').country.options[document.getElementById('SellForm').country.selectedIndex].value == 231)
			{
				document.getElementById('SellForm').zip_code.value = '';
			}
	}
}	



// -->


