function confirmRemove(url) //not used so far
{
    var agree=confirm("Are you sure you wish to continue?");
    if (agree) {
	window.location = url;
    }
}

//Check input

function inputValidation(entered, alertbox)
{
    with (entered) {
	if(value == null || value == "") {
	    if (alertbox!="") {	
		alert(alertbox);
		entered.focus(); //not working on Windows XP
	    } 
	    return false;
	}
	else {
	    return true;
	}
    }
}

//The next function validates the login form

function loginvalidation(thisform,uidtxt,pwtxt,uiderror,pwerror)
{
    with (thisform) {
	if (!inputValidation(uidtxt, uiderror)) {
	    uidtxt.focus(); 
	    return false;
	}
	//		Password checks commented out for now because it is possible that a user logins with a null password 
	//		(i.e. when the password has been previously reset due to the user forgetting it)
	//		if (!inputValidation(pwtxt, pwerror)) {
	//			pwtxt.focus(); 
	//			return false;
	//		}
    }
} 

//The next function validates the change password form

function changepassvalidation(thisform,oldpasstxt,newpasstxt,newpassconftxt,oldpasserror,newpasserror,newpassconferror)
{
    with (thisform) {
	//		Old password checks commented out for now because it is possible that a user logins with a null password 
	//		(i.e. when the password has been previously reset due to the user forgetting it)
	//		if (!inputValidation(oldpasstxt, oldpasserror)) {
	//			oldpasstxt.focus(); 
	//			return false;
	//		}
	if (!inputValidation(newpasstxt, newpasserror)) {
	    newpasstxt.focus(); 
	    return false;
	}
	if (!inputValidation(newpassconftxt, newpassconferror)) {
	    newpassconftxt.focus(); 
	    return false;
	}
    }
}

//The next function validates the search form

function searchvalidation(thisform,searchtxt,searcherror)
{
    with (thisform) {
	if (!inputValidation(searchtxt, searcherror)) {
	    searchtxt.focus(); 
	    return false;
	}
	if(searchtxt.value.length > 35) {
	    alert('Too much data in the search box! Please remove ' + (searchtxt.value.length - 35) + ' characters');
	    return false; 
	}
    }
}

//The next function validates the contact form for logged in users

function contactvalidation(thisform,contacttxt,contacterror)
{
    with (thisform) {
	if (!inputValidation(contacttxt, contacterror)) {
	    contacttxt.focus(); 
	    return false;
	}
    }
}

//The next function validates the contact form for unlogged in users

function contactvalidationunlogged(thisform,firstnametxt,firstnameerror,lastnametxt,lastnameerror,orgnametxt,orgnameerror,addresstxt,addresserror,postcodetxt,postcodeerror,countrytxt,countryerror,emailtxt,emailerror,passwordtxt,passworderror,passwordconfirmtxt,passwordconfirmerror,subjecttxt,subjecterror)
{
    with (thisform) {
	if (!inputValidation(firstnametxt, firstnameerror)) {
	    firstnametxt.focus(); 
	    return false;
	}
	if (!inputValidation(lastnametxt, lastnameerror)) {
	    lastnametxt.focus(); 
	    return false;
	}
	if (!inputValidation(orgnametxt, orgnameerror)) {
	    orgnametxt.focus(); 
	    return false;
	}
	if (!inputValidation(addresstxt, addresserror)) {
	    addresstxt.focus(); 
	    return false;
	}
	if (!inputValidation(postcodetxt, postcodeerror)) {
	    postcodetxt.focus(); 
	    return false;
	}
	if (!inputValidation(countrytxt, countryerror)) {
	    countrytxt.focus(); 
	    return false;
	}
	if (!inputValidation(emailtxt, emailerror)) {
	    emailtxt.focus(); 
	    return false;
	}
	if (!inputValidation(passwordtxt, passworderror)) {
	    passwordtxt.focus(); 
	    return false;
	}
	if (!inputValidation(passwordconfirmtxt, passwordconfirmerror)) {
	    passwordconfirmtxt.focus(); 
	    return false;
	}
	if (!inputValidation(subjecttxt, subjecterror)) {
	    subjecttxt.focus(); 
	    return false;
	}
    }
}

//The next function validates the registration form

function registervalidation(thisform,firstnametxt,firstnameerror,lastnametxt,lastnameerror,addresstxt,addresserror,postcodetxt,postcodeerror,countrytxt,countryerror,emailtxt,emailerror,passwordtxt,passworderror,passwordconfirmtxt,passwordconfirmerror)
{
    with (thisform) {
	if (!inputValidation(firstnametxt, firstnameerror)) {
	    firstnametxt.focus(); 
	    return false;
	}
	if (!inputValidation(lastnametxt, lastnameerror)) {
	    lastnametxt.focus(); 
	    return false;
	}
	if (!inputValidation(addresstxt, addresserror)) {
	    addresstxt.focus(); 
	    return false;
	}
	if (!inputValidation(postcodetxt, postcodeerror)) {
	    postcodetxt.focus(); 
	    return false;
	}
	if (!inputValidation(countrytxt, countryerror)) {
	    countrytxt.focus(); 
	    return false;
	}
	if (!inputValidation(emailtxt, emailerror)) {
	    emailtxt.focus(); 
	    return false;
	}
	if (!inputValidation(passwordtxt, passworderror)) {
	    passwordtxt.focus(); 
	    return false;
	}
	if (!inputValidation(passwordconfirmtxt, passwordconfirmerror)) {
	    passwordconfirmtxt.focus(); 
	    return false;
	}
    }
}

//The next 3 functions validate the add terminal form - NOT USED

function isnValidation(entered, min, max, alertbox)
{
    with (entered) {
	if(value.length<min || value.length>max) {
	    if (alertbox!="") {	
		alert(alertbox);
		value = "";
		entered.focus(); //not working on Windows XP
	    } 
	    return false;
	}
	else if(value.length>3) {
	    isnstart=(value.charAt(0) + value.charAt(1) + value.charAt(2)).toLowerCase();
	    if(isnstart != 'dst') {
		if (alertbox!="") {	
		    alert(alertbox);
		    value = "";
		    entered.focus(); //not working on Windows XP
		} 
		return false;
	    }
	}
	else {
	    return true;
	}
    }
} 

function serialValidation(entered, min, max, alertbox)
{
    with (entered) {
	if(value.length<min || value.length>max) {
	    if (alertbox!="") {	
		alert(alertbox);
		value = "";
		entered.focus(); //not working on Windows XP
	    } 
	    return false;
	}
	else {
	    return true;
	}
    }
} 

function addtermvalidation(thisform,isntxt,serialtxt,isnerror,serialerror,isnmin,isnmax,serialmin,serialmax)
{
    with (thisform) {
	if (!isnValidation(isntxt, isnmin, isnmax, isnerror)) {
	    isntxt.focus(); 
	    return false;
	}
	if (!serialValidation(serialtxt, serialmin, serialmax, serialerror)) {
	    serialtxt.focus(); 
	    return false;
	}
    }
}

