// generic JS
	 var tags = /[<>;]+/; // One or more of any tag.
	 var alnum= /[\W]/; // nothing except alphanumeric or underscore

// ============ JS for nn-input-news ==============

function checkform(form){ 

	 var web = /^[a-zA-Z0-9\-\.]+\.(com|org|net|info|edu|co\.uk|ac\.uk).*$/i;
	 var ddmmyy =/^(?:0?[1-9]|[1-2]\d|3[0-1])\/(?:0?[1-9]|1[0-2])\/(?:\d{2})$/; // p171 apress 
// Start string. One or more of anything. Escaped full stop. jpg or gif. End string.

// check start 
	 if (!ddmmyy.test(form.start.value)){
	 alert ("Error! Start Date not in right format:\n\r(DD/MM/YYY)"); 
	 form.start.focus(); return false;}

// check stop 
	 if (!ddmmyy.test(form.stop.value)){
	 alert ("Error! Stop Date not in right format:\n\r(DD/MM/YYY)"); 
	 form.stop.focus(); return false;}	 

// stop date > start date 
	 var startdate = form.start.value;
	 var startyear = "20" + startdate.substring(6,8);
	 var startmonth = startdate.substring(3,5)-1; // months start at 0!
	 var startday = startdate.substring(0,2);
	 var start = new Date(startyear,startmonth,startday);
	 var start = start.getTime();		
	 
   var stopdate = form.stop.value;
	 var stopyear = "20" + stopdate.substring(6,8);
	 var stopmonth = stopdate.substring(3,5)-1;
	 var stopday = stopdate.substring(0,2);
	 var stop = new Date(stopyear,stopmonth,stopday);
	 var stop = stop.getTime();

	 if (stop <= start){alert("Error! Stop Date must be after Start Date.");
	 form.start.focus(); return false;}
	 
// stop is in future (otherwise never stop)
	 var now = new Date; 
	 var now = now.getTime();
	 if (stop <= now){alert("Error! The Stop Date has already expired.");
	 form.stop.focus(); return false;} 
 
// photo - caption
	 if (tags.test(form.caption.value)){
		  alert ("Error! Caption under photo: can not use '<', '>' or ';'");
		  form.caption.focus(); return false;}

// text
	 if ((tags.test(form.text.value))||(form.text.value.length > 800)||(form.text.value.length < 1)){
	 alert ("Error! Text of Entry, can not use '<', '>' , ';' or \n\r Text is empty or over 800 chars (including spaces)");
	 form.text.focus(); return false;} 
		
// title
	 if ((tags.test(form.title.value))||(form.title.value.length<1)) {
		 alert ("Error! No Title entered or used '<', '>', ';'.");
		 form.title.focus(); return false;}
		 
// contact
	 if (tags.test(form.contact.value)) {
		 alert ("Error! Contact, can not use '<', '>', ';'");
		 form.contact.focus(); return false;}		 

// check website
	 if (form.web.value.length>1){
	 if (!(web.test(form.web.value))) {	 
	 		alert ("Error! Not a valid website address");
	 		form.web.focus(); return false;}
	 if (tags.test(form.web.value)){
			alert ("Error! Not a valid website address");
	 		form.web.focus(); return false;}
			}
			
return true; // if not false, "return" as true		
} // end function


// =============== JS for summary page  ======================

function checkpass(form){

// check user and password are OK
   var alnum=/[\W]/; // nothing except alphanumeric or underscore
	 var alpha = /[a-zA-Z]/; // look for alpha part
	 var numeric = /[0-9]/; // look for numeric part

   if ((alnum.test(form.user.value))||(form.user.value.length<1)){ 
   alert ("Error! User name is wrong.");
	 form.user.focus(); return false;}
		
	 if ((form.password.value.length<7)||(alnum.test(form.password.value))||(form.password.value.length>15)){
		 alert ("Error! Password is wrong.");
		 form.password.focus(); return false;}

	 if (!((alpha.test(form.password.value))&&(numeric.test(form.password.value)))){
				alert ("Error! Password must have both letters and numbers.");
				form.password.focus(); return false;}
	
// confirm delete (loop thru all the ae's p.173  ae="125de"))
	 for (i=0; i<form.ae.length; i++){
	 if ((form.ae[i].value.charAt(form.ae[i].value.length-1)=="d")&&(form.ae[i].checked)){
	 	  if(confirm("Are you sure you want to delete this entry AND all the downloads (if any) linked to it?")){true}
			else {return false;}
		} // end of for	
		} // end of if
	 
return true; 
} // end function


// ================ CHECK PHOTOS ===================

function checkphoto(form){ 

// check photo format		
	 var path = (form.the_photo.value);
	 if (path.substring((path.length-4),path.length) != ".jpg"){
	 alert("Picture must be in .jpg (with .jpg written in lower case)"); 
	 form.the_photo.focus(); return false;}
	 
// file name in lower case
	 var path = (form.the_photo.value);
	 var photoname = path.substr(path.lastIndexOf("\\")+1);
	 if (photoname != photoname.toLowerCase()){
	 alert("The name of the photo (and .jpg) must all be lower case \n\n Nigel.JPG = Wrong,\n nigel.jpg = Right\n\nRe-name the file in lowercase and try again");
	 form.the_photo.focus(); return false;}

// check name of photo not too long (<16 characters and >1) (15 + .jpg = 19)
	 if ((photoname.length<1)||(photoname.length>19)){
	 alert("The name of the photo is too long (max 19 chars)");
	 form.the_photo.focus(); return false;}
	 
// check only alphanumric and underscore
	 var just_photo =  photoname.substring(0,photoname.length-4) // just photoname without the .jpg
	 if (alnum.test(just_photo)){
	 alert("Photo name must be just alphanumeric, underscores allowed, eg nigel_24.jpg");
	 form.the_photo.focus(); return false;}
		 	
// warning to check
	 var warn="If you resized it:\n\r";
	 warn+="Is it between 100-250px (wide/height)and less than 50KB?\n\n\r";
	 warn+="If automatic re-sizing:\n\rJust press OK";
	 if(confirm(warn)){true;}
	 else {return false;}

return true;
} // end of function


// ======== confirm delete from list of customers ============
function checklist(form) {

// confirm delete (loop thru all the lc's p.173  ae="125de"))
	 for (i=0; i<form.lc.length; i++){
	 if ((form.lc[i].value.charAt(form.lc[i].value.length-1)=="e")&&(form.lc[i].checked)){
	 	  if(confirm("Are you sure you want to delete this Customer?")){true}
			else {return false;}
		} // end of for	
		} // end of if
return true;
} // end of function

// ======== counter for textarea =======================

function counter(used){
   var leftover=800-used;
	 document.getElementById("caption").innerHTML = "Approx space left = " + leftover;
} // end of function


// ================ CHECK UPLOADS ===================

function checkupload(form){ 

// generic tags
	 var tags = /[<>;]+/; // One or more of any tag.
	 var alnum= /[\W]/; // nothing except alphanumeric or underscore

// Desscription 
	 if ((form.description.value.length<1)||(form.description.value.length>40)){
	 alert("The description is missing or too long");
	 form.description.focus(); return false;}

	 if (tags.test(form.description.value)){
	 alert ("Error! In the description you can not use '<', '>' or ';'");
	 form.description.focus(); return false;}
	 
// check length of upload 
	 if ((form.upload.value.length<1)||(form.upload.value.length>70)){
	 alert("The path to the upload file is missing"); 
	 form.upload.focus(); return false;}
	 
// length of upload
	 var path = (form.upload.value);
	 var uploadname = path.substr(path.lastIndexOf("\\")+1);
	 if(uploadname.length>19){
	 alert("File name must be less then 15 chars");
	 form.upload.focus(); return false;} 

// check upload format		
	 var extension = path.substring((path.length-4),path.length);
	 var ok = /^\.(jpg|doc|wav|xls|pdf|ppt)$/;
	 if (!ok.test(extension)){
	 alert("File must be one of the following: .jpg .doc .wav .xls .pdf"); 
	 form.upload.focus(); return false;}
	 
// file name in lower case
	 if (uploadname != uploadname.toLowerCase()){
	 alert("The name of the upload must all be lower case \n\n Nigel.JPG = Wrong,\n nigel.jpg = Right\n\nRe-name the file in lowercase and try again");
	 form.upload.focus(); return false;} 
	 
// check only alphanumric and underscore
	 just_upload = uploadname.substring(0,uploadname.length-4)
	 if (alnum.test(just_upload)){
	 alert("Upload name must be just alphanumeric, underscores allowed, eg nigel_24.jpg");
	 form.upload.focus(); return false;}
	 
// warning to check
	 var warn="Are you sure the file size is less than 500KB?,\n\r";
	 warn+="If not you will have to start all over again!";
	 if(confirm(warn)){true;}
	 else {return false;} 
	 	 
return true;
}

// ========== CHECK RADIO BUTTON SELECTED IN DELETE UPLOAD =========

function checkdeleteupload(form) {

// confirm delete (if there is only one radio button the looping on p173 does not work)
	 if (form.du[0].checked){
			alert("You did not select a upload to delete");
			return false;
	 }else{
	  if(confirm("Are you sure you want to delete this entry?")){true}
		else {return false;}
	 } // end of if
		
return true;
} // end of function
	