function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function isEmail (s)
	{  
		/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : ' \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\'\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=s.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	alert("Incorrect e-mail address. (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Incorrect e-mail address. The username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Incorrect e-mail address. The domain name contains invalid characters.");
	return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid

	alert("Incorrect e-mail address. The username is invalid.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Incorrect e-mail address. Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
					 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("Incorrect e-mail address. The domain name is invalid.");
	return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("Incorrect e-mail address. The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
		alert("Incorrect e-mail address. This address is missing a hostname!");
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
		/*var reEmail = /^.+\@.+\..+$/;
		return reEmail.test(s);*/
	}	
	
function emptyvalidation(entered, alertbox) 
{ 
rExp = / /gi;
newString = new String ('');

with (entered) 
	{ 
	cString = new String(value)
	cCheck = cString.replace(rExp, newString)

	if (cCheck.length == 0 )
		{
		if (alertbox!="") 
			{
			alert(alertbox);
			} 
		return false;
		} 
		else 
			{
			return true;
			}
	 }
}

function valuevalidation(entered, min, max, alertbox, datatype)
{
rExp = / /gi;
newString = new String ('');
with (entered)
{
cString = new String(value)
cCheck = cString.replace(rExp, newString)
if (cCheck.length == 0 ) return true;
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 delEntry(xType, xQuery) {
	var bConfirm = confirm('Are you sure you want to delete this record?');
	if (bConfirm == false){
		return false;
	}
	window.location = "delete.asp?type=" + xType + "&" + xQuery
}

function Length(element)
{
rExp = / /gi;
newString = new String ('');
with(element)
	{
	cString = new String(value)
	cCheck = cString.replace(rExp, newString)
	return cCheck.length
	}
}

function putDate(element, evt)
{
	if (evt.keyCode == 68 || evt.keyCode == 100)
	{
	dToday 	= new Date()    //today's date
	cToday 	= new String('');
	cYear	= new String('');
	cMonth	= new String('');
	cDay	= new String('');
	//str = d.getFullYear + '-' + d.getMonth + d.getDay
	cYear = dToday.getFullYear();
	dMonth = dToday.getMonth()+1;
	if	(dMonth < 10) {
		cMonth = "0" + dMonth;
	} else {
		cMonth = dMonth;
	}
	if	(dToday.getDate() < 10) {
		cDay = "0" + dToday.getDate();
	} else {
		cDay = dToday.getDate();
	}
	cToday = cYear + "-" + cMonth + "-" + cDay;

	element.value= cToday;
	}
	return true;
}


function compareDate(tBox1, tBox2) {
	check1 = checkDate(tBox1);
	check2 = checkDate(tBox2);
	if ((check1 == false) || (check2 == false)) {
		return false;
		}
	
	myDate1str = new String(tBox1.value)
	myDate2str = new String(tBox2.value)
	
	myDate1 = new Date();
	myDate2 = new Date();
	
	myDate1.setFullYear(myDate1str.substr(0,4));
	myDate1.setMonth(parseInt(myDate1str.substr(5,2))-1);
	myDate1.setDate(myDate1str.substr(8,2));
	
	myDate2.setFullYear(myDate2str.substr(0,4));
	myDate2.setMonth(parseInt(myDate2str.substr(5,2))-1);
	myDate2.setDate(myDate2str.substr(8,2));

	//alert(myDate1);
	//alert(myDate2);
	
	//return(myDate1 > myDate2);
	if (myDate1 > myDate2) {
		return false;
	}
	
	//alert(myDate1 = myDate2);
	//alert(myDate1 > myDate2);
	
	//return false;
	
}

function checkDate(tBox){
	vErrorFormat = false;
	cErrorValue = "";
	myString = new String(tBox.value)
	dToday 	= new Date()    //today's date
	cToday 	= new String('');
	cYear	= new String('');
	cMonth	= new String('');
	cDay	= new String('');
	//str = d.getFullYear + '-' + d.getMonth + d.getDay
	cYear = dToday.getFullYear();
	dMonth = dToday.getMonth()+1
	if	(dMonth < 10) {
		cMonth = "0" + dMonth
	} else {
		cMonth = dMonth
	}
	if	(dToday.getDate() < 10) {
		cDay = "0" + dToday.getDate()
	} else {
		cDay = dToday.getDate()
	}
	cToday = cYear + "-" + cMonth + "-" + cDay
	
	//check format
	if	(myString.length > 10)
		{
		vErrorFormat = true;
		}
	if	((myString.substr(4,1) != "-") || (myString.substr(7,1) != "-")) {	//dash check
		vErrorFormat = true;
		}
	if	(isNaN(myString.substr(0,4))) { //yearcheck
		vErrorFormat = true;
	}
	if	(isNaN(myString.substr(5,2))) { //monthcheck
		vErrorFormat = true;
	}
	if	(isNaN(myString.substr(8,2))) { //daycheck
		vErrorFormat = true;
	}
	if	(vErrorFormat) {
		alert("Invalid Date Format.\nYYYY-MM-DD");
		//tBox.value = cToday;
		tBox.focus();
		return false;
	}

	//check values
	if (myString.substr(5,2) == 2){
		if (myString.substr(0,4) % 4 == 0) { //checkleap
			if	(myString.substr(8,2) > 29) {
				cErrorValue = "The month of February only has 29 days on a leap year.";
			}
		} else { //not leap
			if	(myString.substr(8,2) > 28) {
				cErrorValue = "The month of February only has 28 days on a non-leap year.";
			}			
		}
		//alert("FEB");
	} else if ((myString.substr(5,2) == 1) ||  (myString.substr(5,2) == 3) ||  
				(myString.substr(5,2) == 5) ||  (myString.substr(5,2) == 7) ||  (myString.substr(5,2) == 8) ||  
				(myString.substr(5,2) == 10) ||  (myString.substr(5,2) == 12))	{
		//alert("JAN, etc.")
		if	(myString.substr(8,2) > 31) {
			cErrorValue = "The months of Jan, Mar, May, July, Aug, Oct and Dec only has 31 days.";
		}
	} else if ((myString.substr(5,2) == 4) ||  (myString.substr(5,2) == 6) ||  (myString.substr(5,2) == 9) ||  
				(myString.substr(5,2) == 11))	{
		//alert("MARCH, etc.")
		if	(myString.substr(8,2) > 30) {
			cErrorValue = "The months of Apr, Jun, Sept and Nov only has 30 days.";
		}
	} else {
		cErrorValue = "Invalid Month.";
	}
	
	

	if	(cErrorValue != "") {
		alert(cErrorValue);
		//tBox.value = cToday;
		tBox.focus();
		return false;
	}
	//if (tBox.value == "RYAN"){
	//	alert(tBox.value);
	//	this.focus();
	//	return false;
	//}
	return true;
}


			function select_deselectAll (chkVal, idVal) {
                       	var frm = document.forms[0];
                        // loop through all elements
                        for (i=0; i<frm.length; i++) {
                        // Look for our Header Template's Checkbox
                         if (idVal.indexOf ('checkAll') != -1) {
                         // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
                             if(chkVal == true) {
                             frm.elements[i].checked = true;
                             } else {
                             frm.elements[i].checked = false;
                             }
                         // Work here with the Item Template's multiple checkboxes
                         } else if (idVal.indexOf('DeleteThis') != -1) {
                         // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
                         if(frm.elements[i].checked == false) {
                         frm.elements[2].checked = false;
                         }
                         }
                     }
                }



function valuevalidation(entered, min, max, alertbox, datatype)
{
rExp = / /gi;
newString = new String ('');
with (entered)
{
cString = new String(value)
cCheck = cString.replace(rExp, newString)
if (cCheck.length == 0 ) return true;
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;}
}
} 

