//====================================================
// Common JS Functions
//====================================================

function toggleCheck(thisField) {
	checkSet = eval("document.form1."+thisField)
	checkSet.checked = !(checkSet.checked)
                     document.form1.submit();
	}

function toggleRadio(thisField,thisValue) {
	radioSet = eval("document.form1."+thisField)

	for (i=0;i<radioSet.length;i++) {
		if (radioSet[i].value == thisValue)
			radioSet[i].checked = true
			document.form1.submit();
	}
}
	
function autoSubmit(){
	document.form1.submit();
}

//================================
// Browser Detection
// returns obj of browser type
//================================
function elemObj(id)
{
	var el;
	if (document.all)
	{
		el = document.all[id];
	}
	else
	{
		el = document.getElementById(id);
	}
	return el;
}

//===========================================================
// Function.....:	URLencode
// Summary......:	encode a string for URL trans
// Return.......:	encoded (string)
//===========================================================
function URLencode(str)
{
    return escape(str).
             replace(/\+/g, '%2B').
                replace(/\"/g,'%22').
                   replace(/\'/g, '%27');
}
  
//============================================================
// Function.....:	URLdecode
// Summary......:	decode a string that has been encoded
// Return.......:	decoded (string)
//============================================================
function URLdecode(str)
{
	return unescape(str);
}

//============================================================
// Function.....:	createCookie
// Summary......:	create a clientside cookie
// Return.......:	boolean
//============================================================
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

//============================================================
// Function.....:	readCookie
// Summary......:	read a clientside cookie
// Return.......:	string cookie
//============================================================
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//============================================================
// Function.....:	eraseCookie
// Summary......:	erase a clientside cookie
// Return.......:	boolean
//============================================================
function eraseCookie(name) {
	createCookie(name,"",-1);
}