function eraseDefault(me) 
{
	if (me.defaultValue == me.value) 
	{
		me.value = "";
	}
}

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 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
  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 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
  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 (theForm.homenumbercode.value == "")
  {
	if (theForm.homenumber.value != "")
	  {
		  alert("Please select an area code for your home telephone number.");
		  theForm.homenumbercode.focus();
		  return (false);
	  }
  }
  
 /* 
 if (theForm.worknumbercode.value == "")
  {
	if (theForm.worknumber.value != "")
	  {
		  alert("Please select an area code for your work telephone number.");
		  theForm.worknumbercode.focus();
		  return (false);
	  }
  }
  */
  if (theForm.homenumber.value == "")
  {
	if (theForm.worknumber.value == "")
  	{
		if (theForm.mobilenumber.value == "")
		{
			alert("Please enter at least one of your home number, work number or mobile number.");
			theForm.homenumber.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 (isNaN(theForm.worknumber.value))
  {
	alert("Please enter digits only for your work telephone number.");
	theForm.worknumber.focus();
	return (false);
  }
  
  if (theForm.worknumber.value != "")
  {
	  if (theForm.worknumber.value.length < 8)
	  {
		alert("Please enter 8 digits for your work telephone number.");
		theForm.worknumber.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.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.totaldebts.value == "")
  {
	alert("Please enter your total unsecured debt.");
	theForm.totaldebts.focus();
	return (false);
  }
  
  if (isNaN(theForm.totaldebts.value))
  {
	alert("Please enter digits only for your amount of unsecured debt.");
	theForm.totaldebts.focus();
	return (false);
  }
  
  if (theForm.totaldebts.value < 6000)
  {
	alert("You need to have over $6,000 in unsecured debt to apply.");
	theForm.totaldebts.focus();
	return (false);
  }
  
  if (theForm.timetocall.value == "")
  {
	alert("Please select a best time to call.");
	theForm.timetocall.focus();
	return (false);
  }
 
 if (theForm.postcode.value.charAt('0')=='6') {
	  for(var i=0;i<theForm.timetocall.length;i++){
		   if(theForm.timetocall[i].value=="5pm-8pm" && theForm.timetocall[i].checked){
				alert("The 5pm - 8pm call time is unavailable in WA. Please tick another box.");
				theForm.timetocall[i].checked = false;
				return (false);
		   }
	  }
	
	}
	
	if (theForm.postcode.value.charAt('0')=='4') {
	  for(var i=0;i<theForm.timetocall.length;i++){
		   if(theForm.timetocall[i].value=="5pm-8pm" && theForm.timetocall[i].checked){
				alert("The 5pm - 8pm call time is unavailable in QLD. Please tick another box.");
				theForm.timetocall[i].checked = false;
				return (false);
		   }
	  }
	
	}

 
     var el=theForm.elements;
	 for(var i=0;i<el.length;i++)
	 if(el[i].type=="checkbox" && el[i].checked && el[i+1] && el[i+1].selectedIndex==0)
	 {
		  alert("Please select the best number that you can be reached on at each specified time.");
		  el[i+1].focus();
		  return false;
	 }
 
  hasSelected = false;
  allElements = document.forms[0].elements;
  for (i = 0; i < allElements.length; i++)
  {
	   if(allElements[i].type == "checkbox" && allElements[i].name == "timetocall")
	   {                    
			if(allElements[i].checked == true)
			{
				 hasSelected = true;
				 checkObjValue = allElements[i].value;
				 for (j = 0; j < allElements.length; j++)
				 {
					  if(allElements[j].type == "select-one" && allElements[j].name.indexOf("numbertocall") != -1)
					  {
						   if(allElements[j].name.indexOf(checkObjValue) != -1 && allElements[j].selectedIndex == 0)
						   {
								alert("Please select the best number that you can be reached on at each specified time.");
								allElements[j].focus();
								return false;
						   }
					  }
				 }
			}
	   }
  }
  if(hasSelected)
  {
	   return true;
  }
  else
  {
	   alert("Please select the best times to reach you.");
	   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;

      }
   }
}
