// JavaScript Document
function emptyvalidation(entered, errID)
{
// Emptyfield Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
//alertbox --text that will show in an alertbox if content is illegal.
  with (entered)
  {
    if (value==null || value=="")
    {
   document.getElementById(errID).style.display=""; 
	  return false;
	}
    else 
	{
   document.getElementById(errID).style.display="none"; 
	  return true;
	}
  }
} 

function lengthvalidation(entered, errID, minlength, maxlength)
{
// Emptyfield Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
//alertbox --text that will show in an alertbox if content is illegal.
  with (entered)
  {
    if (value==null || value=="")
    {
	//alert("empty value");
   document.getElementById(errID).style.display=""; 
	  return false;
	}
    else 
	{
	  if (value.length>=minlength && value.length<=maxlength)
	  {
	  //alert("ok");
   document.getElementById(errID).style.display="none"; 
	  return true;
	  }
	  else
	  {
	  //alert("wrong length");
   document.getElementById(errID).style.display=""; 
	  return false;
	  }
	}
  }
} 

function digitvalidation(entered, min, max, errID, datatype)
{
// Digit Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
//min --minimum number of digits allowed in the field.
//max --maximum number of digits allowed in the field.
//alertbox --text that will show in an alertbox if content is illegal.
//type --enter "I" if only integers are allowed.
  with (entered)
  {
    checkvalue=parseFloat(value);
    if (datatype)
      {smalldatatype=datatype.toLowerCase();
    if (smalldatatype.charAt(0)=="i")
      {checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
    }
    if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
      {document.getElementById(errID).style.display="";  return false;}
    else {document.getElementById(errID).style.display="none"; return true;}
  }
} 

function valuevalidation(entered, min, max, errID, datatype)
{
//checks the value in 'entered'. If not within the bounds (min, max), shows error.
//takes document.formname.elementname and ID of error message.
//min --minimum value allowed in the field.
//max --maximum value allowed in the field.
//datatype --enter "I" if only integers are allowed.
  with (entered)
  {
    checkvalue=parseFloat(value);
    if (datatype)
      {
	    smalldatatype=datatype.toLowerCase();
        if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
      }
    if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
      {document.getElementById(errID).style.display="";  return false;}
    else {document.getElementById(errID).style.display="none"; return true;}
  }
} 

function emailvalidation(entered, errID)
{
//checks to see if 'entered' is an email address.
//if not, shows the error message.
//takes document.formname.elementname and ID of error message.
with (entered)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
{document.getElementById(errID).style.display="";  return false;}
else {document.getElementById(errID).style.display="none"; return true;}
}
}
 
function radiovalidation(entered, errID) {
//checks to see if 'entered' is empty.
//if so, shows the error message.
//takes document.formname.elementname and ID of error message.
//alert("radio val started");
    var cnt = -1;
    for (var i=entered.length-1; i > -1; i--) 
	{
		//alert(i);
    if (entered[i].checked) {
		//alert("checked");
		cnt = i; 
		i = -1; 
	  }
	}
		
    
}

function checkboxvalidation(entered, errID) {
//checks to see if 'entered' is empty.
//if so, shows the error message.
//takes document.formname.elementname and ID of error message.
	  //alert("checking!");
    if (entered.checked) {
	  document.getElementById(errID).style.display="none";
	  //alert("good!");
	  return true;
	} else {
	  document.getElementById(errID).style.display="";
	  //alert("bad!");
	  return false;
	}
}

function showNext(ID,ID2) {
//shows ID2 only if ID is not empty.
    if(ID.value > 0){
	Show(ID2)
	}else{
	Hide(ID2)
	}
}

function ClearRadio(entered) {
//takes 'document.formname.elementname'
//clears the selections in that radio group.
    for (var i=entered.length-1; i > -1; i--) 
	{
    entered[i].checked=false
	}
}

function Show(id) {
document.getElementById(id).style.display='';
}
function Hide(id) {
document.getElementById(id).style.display='none';
}
function Clear(id) {
document.getElementById(id).value='';
}

function country() {
if (document.getElementById('Country').value=='Australia'){
//alert("you are Australian");
document.getElementById('phoneHeading').className='subHeadingRed';
document.getElementById('phonelabel').className='warning';
document.getElementById('phonelabel2').className='labelred';
} else {
//alert("Foreigner!");
document.getElementById('phoneHeading').className='subHeadingBlue';
document.getElementById('phonelabel').className='pagetext';
document.getElementById('phonelabel2').className='label';
}

}
