<!-- Hide

function addLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
    window.onload = func; 
  } else { 
    window.onload = function() { 
      oldonload(); 
      func(); 
    } 
  } 
} 
/* usage:
addLoadEvent(function() { 
	    windowLinks();  // run our new function as soon as the page loads.  
	    //otherFunctions(); 
	    //goHere(); 
	}); 
*/

// _w : which span ID
// _h : (h)ide or (s)how
function toggleT(_w,_h) {
	if (document.all) { // is IE
		if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
		if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
	} else { // is NS? 
		if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
		if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
	}
}

// toggle visibility of a form element
function toggleVis(_id) {
	if (document.all) { // is IE
		eval("var currentstate = document.all."+_id+".style.visibility;");
	}
	else { // NS
		eval("var currentstate = document.layers['"+_id+"'].visibility;");
	}
	if (currentstate=="visible" || currentstate=="show") {
		toggleT(_id,'h');
	} else {
		toggleT(_id,'s');
	}
}

function togglefields() {
	var theval = document.class_editor_form.t.options[document.class_editor_form.t.selectedIndex].value;
	var theval = document.class_editor_form.t.value;
	if (theval==1) {
		toggleT('divt1','s');
		toggleT('divt2','h');
		toggleT('divt3','h');
	}
	if (theval==2) {
		toggleT('divt1','h');
		toggleT('divt2','s');
		toggleT('divt3','h');
	}
	if (theval==3) {
		toggleT('divt1','h');
		toggleT('divt2','h');
		toggleT('divt3','s');
	}
}

// toggle on/off form elements for the scanner input form
function toggleScannerFields() {
	var theval = document.class_editor_form.scannertype.options[document.class_editor_form.scannertype.selectedIndex].value;
	var theval = document.class_editor_form.scannertype.value;
//	alert('val='+theval);
	if (theval==1) {
		toggleT('div_speed','h');
		toggleT('div_park','h');
	}
	if (theval==2) {
		toggleT('div_speed','s');
		toggleT('div_park','h');
	}
	if (theval==3) {
		toggleT('div_speed','h');
		toggleT('div_park','s');
	}
}

function getElement(id) { 
return document.getElementById ? document.getElementById(id) : 
document.all ? document.all(id) : null; 
} 

function displayEl(id) { 
var el = getElement(id); 
if (el && el.style) el.style.display = ''; 
} 

function undisplayEl(id) { 
var el = getElement(id); 
if (el && el.style) el.style.display = 'none'; 
} 
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-


function numOnly(oTxt) {
    if (!/^[\d\.]+$/.test(oTxt.value) || isNaN(oTxt.value)) {
        oTxt.value = oTxt.value.substring(0,oTxt.value.length-1);
    }
}

function urlencode(text) {
	text=text.replace(/\//g,"%2F");
	text=text.replace(/\?/g,"%3F");
	text=text.replace(/\\/g,"%2F");
	text=text.replace(/=/g,"%3D");
	text=text.replace(/&/g,"%26");
    return text;
  }

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validate(form,field) {
	var theval = eval("this.document." + form + "." + field + ".value");
	if (!theval || theval == "") {
		return false;
	}
	return true;
}

function validate_form(form,fields,fieldnames) {
	var field_array = fields.split(",");
	var fieldname_array = fieldnames.split(",");
	var res = true;
	var part_num=0;
	var req_fields = "";
	while (part_num < field_array.length) {
		if (!validate(form, field_array[part_num])) {
			req_fields = req_fields + '\n'+fieldname_array[part_num];
			res = false;
		}
		part_num+=1;
	}
	if (res==true) {
		eval (form+'.editor_submit_js.value=1;');
		eval (form+'.submit();');
	} else {
		alert('The following fields are required,\nbut were not filled:\n'+req_fields+'\n\nPlease review the form and try again.');
	}
}

function checkAll(field) {
	for (i = 0; i < field.length; i++) {
		field[i].checked = true;
	}
}

function uncheckAll(field) {
	for (i = 0; i < field.length; i++) {
		field[i].checked = false;
	}
}

var nn4 = (navigator.appName.indexOf("Netscape") > -1 && navigator.appVersion.indexOf("4") > -1) ? true:false
var ie = (document.all) ? true:false
var nn6 = (document.getElementById && !document.all) ? true:false

function browser(id) {
	var layer = (nn4) ? document.layers[id] : (ie) ? document.all[id] : document.getElementById(id)
	return layer;
}

function writeContent(id,text) {
	var layer = browser(id);  //get path to layer using global browser function
	var content;
	content = text;
	if (nn4) {
		layer.document.open();
		layer.document.write(content); //write content to layer
		layer.document.close();
//		layer.visibility="visible"	//change visibility to visible
	}
	else {
		layer.innerHTML = content  //write content to layer
//		layer.style.visibility="visible"	//change visibility to visible
	}
}

function showLayer(id) {
	var layer = browser(id);
	if (!nn4) {
		layer.style.visibility="visible";
	} else {
		layer.visibility="visible";
	}
}

function hideLayer(id) {
	var layer = browser(id);
	if (!nn4) {
		layer.style.visibility="hidden";
	} else {
		layer.visibility="hidden";
	}
}

function fill_shipping_data (form_name) {
	eval("document."+form_name+".ship_name.value = document."+form_name+".contact_name.value");
	eval("document."+form_name+".ship_company.value = document."+form_name+".company.value");
	eval("document."+form_name+".ship_address.value = document."+form_name+".address.value");
	eval("document."+form_name+".ship_city.value = document."+form_name+".city.value");
	eval("document."+form_name+".ship_state.value = document."+form_name+".state.value");
	eval("document."+form_name+".ship_zip.value = document."+form_name+".zip.value");
	return true;
}

// check validity of an email address
function emailcheck(cur, fieldname) {
	var string1 = eval("cur."+fieldname.name+".value");
	if ( (string1.indexOf("@") == -1) || (string1.indexOf(".") == -1) ) {
		alert("Please input a valid email address!\n");
		return false;
	}
}

// delete link confirmation popup message
function confirmLink(theLink, theSqlQuery) {
	var confirmMsg='Are you sure you want to';
    var is_confirmed = confirm(confirmMsg + '\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }
    return is_confirmed;
}

// table row color changer as mouse moves over
// stolen from PHPmySQLAdmin :\
function setPointer(theRow, thePointerColor) {
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') { return false; }
    if (typeof(document.getElementsByTagName) != 'undefined') {
		var theCells = theRow.getElementsByTagName('td');
    } else if (typeof(theRow.cells) != 'undefined') {
		var theCells = theRow.cells;
    } else {
		return false;
	}
    var rowCellsCnt  = theCells.length;
//    for (var c = 0; c < rowCellsCnt; c++) { theCells[c].style.backgroundColor = thePointerColor; }
    for (var c = 0; c < rowCellsCnt; c++) {
		theCells[c].className = thePointerColor;
	}
    return true;
}

// open an URL in a new window
function openNewWindow(URL,window_width,window_height) {
	day = new Date();
	id = day.getTime();
	if (window_width=="") {window_width='250';}
	if (window_height=="") {window_height='300';}
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+window_width+",height="+window_height+"');");
}

// open an URL in a new window
function openPalmWindow(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=230,height=370');");
}

function wait_and_redirect(delay,page) {
	string="pauseforalert("+page+");";
	setTimeout(string,delay);
}

function pauseforalert(page) {
	eval ("window.location="+page);
}

// email
function checkEmail (strng) {
	var error="";
	if (strng == "") {
	   error = "You didn't enter an email address.";
	}
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.";
    }
    else {
	//test email for illegal characters
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strng.match(illegalChars)) {
			error = "The email address contains illegal characters.";
		}
    }
	return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter a phone number.";
	}
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
      }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.";
    } 
	return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral
function checkPassword (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter a password.";
	}
    var illegalChars = /[\W_]/; // allow only letters and numbers
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.";
    }  
	return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.
function checkUsername (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter a username.";
	}
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.";
    } 
	return error;
}       


// non-empty textbox
function isEmpty(strng) {
	var error = "";
	if (strng.length == 0) {
		error = "The mandatory text area has not been filled in."
	}
	return error;	  
}

// was textbox altered
function isDifferent(strng) {
	var error = ""; 
	if (strng != "Can\'t touch this!") {
		error = "You altered the inviolate text area.";
	}
	return error;
}

// exactly one radio button is chosen
function checkRadio(checkvalue) {
	var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.";
    }
	return error;
}

// valid selector from dropdown list
function checkDropdown(choice) {
	var error = "";
    if (choice == 0) {
    	error = "You didn't choose an option from the drop-down list.";
    }    
	return error;
}    

//-->

