function eraseDefault(me) 
{
	if (me.defaultValue == me.value) 
	{
		me.value = "";
	}
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;

	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function Validator(theForm)
{
  
  
  if (theForm.salutation.value == "")
  {
	alert("Please select your salutation.");
	theForm.salutation.focus();
	return (false);
  }
  
  if (theForm.firstname.value == "")
  {
	alert("Please enter your first name.");
	theForm.firstname.focus();
	return (false);
  }
  
  if (theForm.firstname.value == "First Name")
  {
	alert("Please enter your first name.");
	theForm.firstname.focus();
	return (false);
  }
  
  if (theForm.lastname.value == "")
  {
	alert("Please enter your last name.");
	theForm.lastname.focus();
	return (false);
  }
  
  if (theForm.lastname.value == "Surname")
  {
	alert("Please enter your last name.");
	theForm.lastname.focus();
	return (false);
  }
  
  
   var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz-'ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ ";
  var checkStr = theForm.firstname.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
	if (j == checkOK.length)
	{
	  allValid = false;
	  break;
	}
  }
  if (!allValid)
  {
	alert("Please enter only letters and hyphens for your first name.");
	theForm.firstname.focus();
	return (false);
  }
  
  var checkOK = " ABCDEFGHIJKLMNOPQRS TUVWXYZabcdefghijklmnopqrstuvwxyz-'ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ ";
  var checkStr = theForm.lastname.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
	if (j == checkOK.length)
	{
	  allValid = false;
	  break;
	}
  }
  if (!allValid)
  {
	alert("Please enter only letters and hyphens for your last name.");
	theForm.lastname.focus();
	return (false);
  }
  
   if (isNaN(theForm.homenumber.value))
  {
	alert("Please enter digits only for your home telephone number.");
	theForm.homenumber.focus();
	return (false);
  }
      
  if (theForm.homenumber.value != "")
  {
	  if (theForm.homenumber.value.length < 8)
	  {
		alert("Please enter 8 digits for your home telephone number.");
		theForm.homenumber.focus();
		return (false);
	  }
  }	
  
  if (theForm.homenumbercode.value == "")
  {
	if (theForm.homenumber.value != "")
	  {
		  alert("Please select an area code for your home telephone number.");
		  theForm.homenumbercode.focus();
		  return (false);
	  }
  }
  
 
  if (isNaN(theForm.mobilenumber.value))
  {
	alert("Please enter digits only for your mobile telphone number");
	theForm.mobilenumber.focus();
	return (false);
  }

  if (theForm.mobilenumber.value != "")
  {
	  if (theForm.mobilenumber.value.length < 10)
	  {
		alert("Please enter 10 digits for your mobile telephone number.");
		theForm.mobilenumber.focus();
		return (false);
	  }
  }


  if (theForm.homenumber.value == "")
  {
		if (theForm.mobilenumber.value == "")
		{
			alert("Please enter at least one of your landline or mobile number.");
			theForm.homenumber.focus();
			return (false);
		}
  }
  
  if (theForm.postcode.value == "")
  {
	alert("Please enter your postcode.");
	theForm.postcode.focus();
	return (false);
  }
  
  if (isNaN(theForm.postcode.value))
  {
	alert("Please enter digits only with no spaces for your postcode.");
	theForm.postcode.focus();
	return (false);
  }

	if (theForm.postcode.value.length < 4)
	  {
		alert("Please enter 4 digits for your postcode.");
		theForm.postcode.focus();
		return (false);
	  }  
	  
  if (theForm.totaldebts.value == "")
  {
	alert("Please select your total unsecured debt level.");
	theForm.totaldebts.focus();
	return (false);
  }
      
  if (theForm.property.value == "")
  {
	alert("Please select whether you have a home loan or property.");
	theForm.property.focus();
	return (false);
  }  
  


if (theForm.property.value  == "No")
  {
		if (theForm.totaldebts.value  == 0)
		  {
			alert("You need to have over $8,000 in unsecured debt to apply.");
			theForm.totaldebts.focus();
			return (false);
		  }
	
  }
	
var postcode = document.getElementById('postcode').value;


if ( (postcode >= 6000 && postcode <= 6999) )
{ 
	if (theForm.timetocall.value  == "5pm-8pm")
	{
		  alert("Fox Symes is unable to complete callbacks from enquiries from WA after 5pm, please select another time.");
			  theForm.timetocall.focus();
			  return (false);
	
	}
}	
	
  
}




function maskIt(fld)
{
   fldVal = fld.value;

   var tmpStr = "";
   keyCount = fldVal.length;
   keyEntered =fldVal.substring(keyCount-1,keyCount);

   if (keyCount < 2)   isNamedFone = false;
   //if (!isNamedFone)   isNamedFone = chkNAN(keyEntered);

   keyCount++;
   with (document.foneMask)
   {
      switch (keyCount)
      {
         case 2:
            tmpStr +=  fldVal;
            fld.value = tmpStr;
            break;
         case 5:
            fld.value +=  " ";
            break;
          case 9:
            fld.value += ""; 
            break;
      }
   }
}

function maskItMobile(fld)
{
   fldVal = fld.value;

   var tmpStr = "";
   keyCount = fldVal.length;
   keyEntered =fldVal.substring(keyCount-1,keyCount);

   if (keyCount < 2)   isNamedFone = false;
   //if (!isNamedFone)   isNamedFone = chkNAN(keyEntered);

   keyCount++;
   with (document.foneMask)
   {
      switch (keyCount)
      {
         case 2:
            tmpStr +=  fldVal;
            fld.value = tmpStr;
            break;
         case 5:
            fld.value +=  " ";
            break;
          case 9:
            fld.value += " "; 
            break;

      }
   }
}

