function Empty(entered, alertbox){
// checks a value is specified (not empty)
with (entered)
	{
	if (value==null || value=="")
		{if (alertbox!="") {alert(alertbox);} return true;}
	else {return false;}
	}
}

function deletekey(e) {
    var thekeycode;

    if (document.all) {
        e = window.event;
		var thekeycode = e.keyCode;
    	}
    else
        if (document.layers)
		var thekeycode = e.which;
 	
	// 46 Delete, 8 Backspace
    if (thekeycode  == 46 || thekeycode == 8) {
        if (document.layers){
            return true;}
        else if (document.all){
            //e.returnValue = true;
			return true;}
    	}
	
}

function MaxCharsKeydown(entered,maxChars,label)
// checks a field has not exceeded max characters
{
with (entered)
	{
	if (value.length > maxChars-1)
		{
		if (label== null){label=entered.name;}
		alert('This field can have a maximum of ' + maxChars + ' characters.');return true;
		}
	else 
		{return false;}
	}
}

function MaxChars(entered,maxChars,label)
// checks a field has not exceeded max characters
{
with (entered)
	{
	if (value.length > maxChars)
		{
		if (label== null){label=entered.name;}
		alert('This field can have a maximum of ' + maxChars + ' characters.');return true;
		}
	else 
		{return false;}
	}
}

function isValidEmail(entered, alertbox) {
// checks for a valid email address
with (entered)
	{
	apos=value.indexOf("@"); 
	dotpos=value.lastIndexOf(".");
	lastpos=value.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
		{if (alertbox) {alert(alertbox);} return false;}
	else {return true;}
	}
}

function inRange(entered, min, max, alertbox, datatype){
// checks a value is in the max and min range specified
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)
			{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
	}
}

function isInteger(entered, alertbox){
// checks for an integer (+ or -)
with (entered)
	{
	if (value!=parseInt(value))
		{if (alertbox!="") {alert(alertbox);} return false;}
	else {return true;}
	}
}

function isFloat(entered, alertbox){
// checks for a decimal 
with (entered)
	{
	if (value!=parseFloat(value))
		{if (alertbox!="") {alert(alertbox);} return false;}
	else {return true;}
	}
}


function isSelected(entered, alertbox, thistype){
// checks for a selected item (mandatory check)
with (entered)
	{
	if (thistype.toLowerCase()=='select')
		{
		if (selectedIndex==-1 || options[selectedIndex].value=="")
			{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
		}
	if (thistype.toLowerCase()=='multiselect')
		{
		if (selectedIndex==-1)
			{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
		}	
	if (thistype.toLowerCase()=='radio' || thistype.toLowerCase()=='checkbox')
		{
		var count=0;
		for (var i=0;i<entered.length;i++)
			{if (entered[i].checked==true){count++;}}
		if (count==0)
			{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
		}
	}
}


function validateform(thisform)
{
// This function checks the entire form before it is submitted
// note: This function needs to be customized to fit your form

with (thisform)
	{
	//if !(isValidEmail(email,"Illegal E-mail")) {Email.focus(); return false;}
	//if !(inRange(myvalue,0,5,"Value MUST be in the range 0-5")) {Value.focus(); return false;}
	//if !(isInteger(ints,"You MUST enter an integer value","I")) {Digits.focus(); return false;}
	//if !(isFloat(floats,"You MUST enter a decimal value","I")) {Digits.focus(); return false;}
	//if !(isSelected(myselect,"You MUST select something","I")) {Digits.focus(); return false;}
	//if (MaxChars(teaser,150)) {teaser.focus(); return false;};
	if (Empty(title,"The title cannot be empty")) {title.focus(); return false;};
	}
}
