function validate() {
	var thisf; 
	var errstr = "";
	if (typeof cvld != 'undefined') {
		for(i = 0; i < document.frm.length; i++) {
			thisf = document.frm[i];
			
			if(cvld[i] != null && cvld[i] != ''){  
				// N   is this variable not supposed to be left blank? 
				if (cvld[i] == 'N' && (thisf.value == '' || isNaN(thisf.value))){ 
					errstr += "* "+cvldmsg[i]+" (Valid Number)\r";
					rowbg(cvldrow[i],i);
				}
				
				// B   is this variable not supposed to be left blank? 
				if (cvld[i] == 'b' && (thisf.value == '' || thisf.type == 'checkbox' && thisf.checked != true)){ 
					errstr += "* "+cvldmsg[i]+"\r";
					rowbg(cvldrow[i],i);
				}				
				// F  is this FILE variable not supposed to be left blank? (works for file filds too)
				if (cvld[i] == 'f' && thisf.value == ''){ 
					var nextf = i+1; 
					if(document.frm[nextf].type != 'hidden'){
						errstr += "* "+cvldmsg[i]+"\r";
						rowbg(cvldrow[i],i);
					}
				}				
				// SB    is this DD list variable not supposed to be left blank? 
				else if (cvld[i] == 'sb' && thisf.options[thisf.options.selectedIndex].value == ''){ 
					errstr += "* "+cvldmsg[i]+"\r";
					rowbg(cvldrow[i],i);
				}
				// EE    is this variable supposed to be in email format
				else if (cvld[i] == 'ee'){
					if (thisf.value.indexOf("@") == -1 || thisf.value.indexOf(".") == -1 || thisf.value.indexOf(" ") != -1){ 
						errstr += "* "+cvldmsg[i]+" (ex. yourname@somedomain.com)\r";
						rowbg(cvldrow[i],i);
					}
				}
				// is this variable supposed to be an EXACT length?
				else if (cvld[i].indexOf("el") != -1) {
					len = cvld[i].substr(cvld[i].indexOf("l")+1, cvld[i].length);
					if(parseInt(len) != thisf.value.length){
						errstr += "* "+cvldmsg[i]+"\r";
						rowbg(cvldrow[i],i);
					}
				}
				// is this variable supposed to be at least a certain length?
				else if (cvld[i].indexOf("l") != -1) {
					len = cvld[i].substr(cvld[i].indexOf("l")+1, cvld[i].length);
					if(parseInt(len) > thisf.value.length){
						errstr += "* "+cvldmsg[i]+"\r";
						rowbg(cvldrow[i],i);
					}
				}
			}
		}
	}

	if(errstr != ""){
		alert("Please complete the required fields now before proceeding\n\n"+errstr);
		eval(getfocus);
		getfocus = '';
		recolor = '';
		nohilite = 1;
		return false;
	}
}

var getfocus = '';
var nohilite = 0;
var outrowid = '';
var recolor = '';
var rowcbg = new Array(); 
 
function rowbg(rowid,onoff){
	var table = 'formtab'; 
	var r=document.getElementById(table).getElementsByTagName( "tr" )[rowid]; 
	
	if(rowcbg[rowid] == null || rowcbg[rowid].length < 5) {
		rowcbg[rowid] = r.getAttribute('bgcolor');
	}
	
	if(onoff == 'off'){
		r.style["backgroundColor"]=rowcbg[rowid];
	}
	else if(onoff == 'on' &&  nohilite == 0){
		r.style["backgroundColor"]='#FFF5C3';
	}
	else if(onoff != 'on' && onoff != 'off')  {
		r.style["backgroundColor"]='#FFBBBB';
		if(getfocus == '' && recolor == ''){
			getfocus = "document.frm["+onoff+"].focus();"; 
		}
		if(outrowid == rowid && recolor == ''){
			getfocus += " rowbg("+rowid+",3000);";
			recolor = 'done';
		}
	}

	if(onoff == 'on')	
		outrowid = rowid;
	nohilite = 0;
}

function go2url(thiss,urlA,conf){
	var id = thiss.options[thiss.options.selectedIndex].value;
	var url = urlA+id;
	if(conf == 1){
		var upd= confirm ('Go to new record '+id+' ?');
		if(upd)
			window.location.href(url);
		else
			alert('Cancelled move');
	}
	else
		window.location.href = url;
}	

		
function confirmdelete(url,msg){
	window.status = 'Delete';
	var del= confirm (msg);

	if(del){
		window.location.href = url;
	}
	else{
//		alert('User Deletion Cancelled');
	}
}	

function PopWin(url, wname, w, h, pl, pt) {
	var winX = pl;
	var winY = pt;
	// Nav 4 gives true screen pos %, while default assumes % on 640X480
	if (parseInt(navigator.appVersion) >= 4) {
		winX = (screen.availWidth - w)*pl*.01;
		winY = (screen.availHeight - h)*pt*.01;
	}

	pWin = window.open(url, wname,'scrollbars=yes,status=no,dependent,resizable=yes,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
	if (pWin.focus) {
		pWin.focus();
	}
}

function popDesc(menuName,on,l,t) {
	var DL_bNS4=(document.layers);
	var DL_bNS6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));
	var DL_bDOM=(document.getElementById);
	var DL_bIE=(document.all);
	var DL_bIE4=(DL_bIE && !DL_bDOM);
	var DL_bMac = (navigator.appVersion.indexOf("Mac") != -1);
	var DL_bIEMac=(DL_bIE && DL_bMac);
	var DL_bIE4Mac=(DL_bIE4 && DL_bMac);
	var DL_bNS =(DL_bNS4 || DL_bNS6);

	if (on) {
		if (DL_bNS4) {
			document.layers[menuName].left = l;
			document.layers[menuName].top = t;
			document.layers[menuName].visibility = "show";
		} 
		else {
			if(DL_bDOM)
				DL_oLayer=document.getElementById(menuName);
			else
				DL_oLayer = window[menuName];
			DL_oLayer.style.left = l;
			DL_oLayer.style.top = t;
			DL_oLayer.style.visibility="visible";
		}
	} else {
		if (DL_bNS4) {
			document.layers[menuName].visibility = "hide";
		} 
		else {
			if(DL_bDOM)
				DL_oLayer=document.getElementById(menuName);
			else
				DL_oLayer = window[menuName];
			DL_oLayer.style.visibility="hidden";
		}
	}
}

// php_admin row highlighter //

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 * <tr onmouseover="setPointer(this, 1, 'over', '#CCCCCC', '#CCFFCC', '#FFCC99');" onmouseout="setPointer(this, 1, 'out', '#CCCCCC', '#CCFFCC', '#FFCC99');" onmousedown="setPointer(this, 1, 'click', '#CCCCCC', '#CCFFCC', '#FFCC99');">
*/	

var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
  if (navigator.userAgent.indexOf('Opera') > -1) {
    return false;
  }
else {
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

	if(!currentColor)
		currentColor = '';
    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
}
} // end of the 'setPointer()' function



/************** Custom Functions **************/
// trim facility for sting
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function format(num) {
	if(num.length >= 2)	return num;
	return (num < 10) ? '0' + num : num; 
}

function togglediv(tagid,deftxt,alttxt) {
	var divtag;
	var linktag;
	if(document.getElementById) {
	 	if(document.getElementById(tagid))
			divtag = document.getElementById(tagid);
		if(document.getElementById(tagid + 'link'))	
			linktag = document.getElementById(tagid + 'link');
	}

	if(divtag && divtag.style){
		if(divtag.style.display == 'block') {				
			divtag.style.display = 'none';
			if(linktag)
				linktag.firstChild.nodeValue = deftxt;
		}	
		else {
			divtag.style.display = 'block';
			if(linktag)
				linktag.firstChild.nodeValue = alttxt;
		}	
	}
}

function showdiv(id) {
	var divtag;
	if(document.getElementById && document.getElementById(id)) {
		divtag = document.getElementById(id);
	}
		
	if(divtag && divtag.style){
		divtag.style.display = 'block';
	}
}

function hidediv(id) {
	var divtag;
	if(document.getElementById && document.getElementById(id)) {
		divtag = document.getElementById(id);
	}
		
	if(divtag && divtag.style){
		divtag.style.display = 'none';
	}
}

function writediv(id, content, append) {
	var divtag;
	if(document.getElementById && document.getElementById(id)) {
		divtag = document.getElementById(id);
	}
		
	if(divtag && divtag.innerHTML){
		if( append == 1 )
			divtag.innerHTML += content;
		else
			divtag.innerHTML = content;
	}
}

function readdiv(id) {
	var divtag;
	if(document.getElementById && document.getElementById(id)) {
		divtag = document.getElementById(id);
	}
		
	if(divtag && divtag.innerHTML){
		return divtag.innerHTML;
	}
	
	return '';
}

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(ckName) 
{ 
	var search = ckName + "=";
	var ckValue = "";
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search);
		if (offset != -1) 
		{ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) 
				end = document.cookie.length;
			ckValue = unescape(document.cookie.substring(offset, end));
		}
	}
	return ckValue;
}

function clearCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "; path=/") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


function reportError(req) {
	alert("Sorry. There was an error.");
}

function doSearch(frm) {
	window.location.href = frm.s.value + frm.keystr.value;
	return false;
}

// Given  : key is a string of the 26 letters in arbitrary order,
//          message is the string to be encoded using the key
// Returns: the coded version of message using the substitution key 
function Encode(message, key) {
	var alphabet, coded, i, ch, index;
	
	alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
	if( !key )
		key = "DXBqMdtfaxkFW7u5cpuq2JPyGyKcmqTT5XvfxqkSQCwxsdxD2MJjqye76NUb9rB";

	coded = "";                                      
	for (i = 0; i < message.length; i++) {        // for as many letters as there are
		ch = message.charAt(i);                   //   access the letter in the message
		index = alphabet.indexOf(ch);             //   find its position in alphabet
		if (index == -1) {                        //   if it's not a letter,
			coded = coded + ch;                   //     then leave it as is & add
		}                                         //   otherwise,
		else {                                    //     find the corresponding
			coded = coded + key.charAt(index);    //     letter in the key & add
		}
	}

	return coded;
}