// non-empty textbox
function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter a comment.\n"
  }
return error;	  
}

// valid title
function checkTermsBox(checked) {
var error = "";
    if (checked == "0") {
    error = "You need to agree to the terms and conditions.\n";
    }    
return error;
}  


// valid title
function checkTitle(choice) {
var error = "";
    if (choice == 0) {
    error = "Please select a title.\n";
    }    
return error;
}  


// name - 4-10 chars, uc, lc, and underscore only.
function checkName (strng) {
var error = "";

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 2)) {
       error = "The name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The name contains illegal characters.\n";
} 

if (strng == "") {
   error = "Please enter your name.\n";
}
return error;
}   


// name - 4-10 chars, uc, lc, and underscore only.
function checkSurname (strng) {
var error = "";

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 2)) {
       error = "The surname is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The surname contains illegal characters.\n";
} 

if (strng == "") {
   error = "Please enter your surname.\n";
}
return error;
}       


// international tel number - strip out delimiters and check for tel number
function checkIntTel (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\+\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
		error = "The tel number contains illegal characters.\n";
}

if (strng == "") {
   error = "Please enter a valid tel number.\n";
}
return error;
}

// cell number - check for 10 digits and strip out non-numeric characters
function checkCell (strng) {
var error = "";
var stripped = strng.replace(/[\(\)\.\-\ ]/g, "");
var illegalChars = strng.replace(/[\(\)\.\-\ \0-9]/g, "");
	if (strng == "") {
   	error = "Please enter your cell number.\n";
	}
	else if (illegalChars.length != 0) {
       	error = "The cell number contains illegal characters.\n";
	}	
	else if (stripped.length !=10) {
		error = "The cell number is the wrong length.\n";
	}
return error;
}


// international fax number - strip out delimiters and check for tel number
function checkIntFax (strng) {
var error = "";

var stripped = strng.replace(/[\(\)\.\-\+\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The fax number contains illegal characters.\n";
    }

if (strng == "") {
   error = "Please enter a valid fax number.\n";
}
return error;
}


// email
function checkEmail (strng) {
var error="";

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "The email address is invalid.\n";
    }
    else {
	//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }

if (strng == "") {
   error = "Please enter an email address.\n";
}

return error;
}



// valid party
function checkRoom(choice) {
var error = "";
    if (choice == 0) {
    error = "Please select the type of room.\n";
    }    
return error;
}  

// valid party
function checkBed(choice) {
var error = "";
    if (choice == 0) {
    error = "Please select the type of bed.\n";
    }    
return error;
}  


// valid party
function checkAdults(choice) {
var error = "";
    if (choice == 0) {
    error = "Please select the number of adults.\n";
    }    
return error;
}  

// valid party
function checkChildren(choice) {
var error = "";
    if (choice == 0) {
    error = "Please select the number of children.\n";
    }    
return error;
}  

// arrival day
function checkArrivDay(choice) {
var error = "";
    if (choice == 0) {
    error = "Please enter your day of arrival.\n";
    }    
return error;
}
// arrival month
function checkArrivMonth(choice) {
var error = "";
    if (choice == 0) {
    error = "Please enter your month of arrival.\n";
    }    
return error;
}

// arrival year
function checkArrivYear(choice) {
var error = "";
    if (choice == 0) {
    error = "Please enter your year of arrival.\n";
    }    
return error;
}

// departure day
function checkDepDay(choice) {
var error = "";
    if (choice == 0) {
    error = "Please enter your day of departure.\n";
    }    
return error;
}

// departure month
function checkDepMonth(choice) {
var error = "";
    if (choice == 0) {
    error = "Please enter your month of departure.\n";
    }    
return error;
}

// departure year
function checkDepYear(choice) {
var error = "";
    if (choice == 0) {
    error = "Please enter your year of departure.\n";
    }    
return error;
}

// non-empty codebox
function checkCode(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter the security code.\n"
  }
return error;	  
}

// non-empty textbox
function editHeading(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter a heading.\n"
  }
return error;	  
}

// non-empty textbox
function editDate(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter a date.\n"
  }
return error;	  
}

// non-empty textbox
function editDetails(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please enter a description.\n"
  }
return error;	  
}


/* ----------------------------------------  unused functions  ------------------------------------  

// passort number
function checkPassport (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a valid passport number.\n";
}
var stripped = strng.replace(/[\(\)\.\-\+\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The passport number contains illegal characters.\n";
    }
return error;
}

function checkNationality(strng) {
var error = "";
  if (strng.length < 2) {
     error = "The nationality is incorrect.\n"
  }
return error;
}

// passort expire
function checkPassExpire (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a valid expiry date.\n";
}
return error;
}

function checkHeading (strng) {
var error = "";
var maxwords=15
		var temp=strng.split(" ")
		if ((temp.length>maxwords)){
		error = "Please limit the heading to 15 words.\n";
		}
		else if(strng == "maximum 15 words"){
		error = "Please unput an appropriate heading.\n";
		}
		return error;
}


function checkKey(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please fill in at least 2 keywords.\n"
  }
return error;
}


function checkCopy (strng) {
var error = "";
var maxwords=300
		var temp=strng.split(" ")
		if ((temp.length>maxwords)){
		error = "Please limit the copy to 300 words.\n";
		}
		else if(strng.length<30){
		error = "Please unput some appropriate copy.\n";
		}
		return error;
}

 

// tel number - strip out delimiters and check for 10 digits
function checkTel (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a tel number.\n";
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The tel number contains illegal characters.";
      }
    if (!(stripped.length == 10)) {
	error = "The tel number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}

// fax number - strip out delimiters and check for 10 digits
function checkFax (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a fax number.\n";
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The fax number contains illegal characters.";
      }
    if (!(stripped.length == 10)) {
	error = "The fax number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}

// cell number - strip out delimiters and check for 10 digits
function checkCell (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a cell number.\n";
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The cell number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The cell number is the wrong length.\n";
    } 
return error;
}

// non-empty textbox
function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

// was textbox altered
function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen
function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list
function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}  

  ----------------------------------  end unused functions  --------------------------*/