/*common javascript routines*/
var agt=navigator.userAgent.toLowerCase();
var isFirefox=(agt.indexOf('firefox')!=-1);
var isIE=(agt.indexOf('msie')!=-1);
var isNetscape=(agt.indexOf('netscape')!=-1);
var isOpera = agt.indexOf("opera")!=-1;
var isIE = agt.indexOf("msie")!=-1 && !isOpera;
var isMoz = agt.indexOf("mozilla/5.") == 0 && !isOpera;
/* Define document.getElementById for Internet Explorer 4 */
if (typeof(document.getElementById) == "undefined")
	document.getElementById = function (id)
	{
		// Just return the corresponding index of all.
		return document.all[id];
	}
/* Code so that insertAdjacentHTML works in Mozilla Browsers*/
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode){
		switch (where){
			case 'beforeBegin':
				this.parentNode.insertBefore(parsedNode,this)
				break;
			case 'afterBegin':
				this.insertBefore(parsedNode,this.firstChild);
				break;
			case 'beforeEnd':
				this.appendChild(parsedNode);
				break;
			case 'afterEnd':
				if (this.nextSibling){
					this.parentNode.insertBefore(parsedNode,this.nextSibling);
					}
				else{this.parentNode.appendChild(parsedNode);}
				break;
			}
		}
	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr){
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
		}
	HTMLElement.prototype.insertAdjacentText = function(where,txtStr){
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
		}
	}
/*get all attributes*/
function getAllAttributes(obj){
	var node=getObject(obj);
	var rv = {};
    for(var i=0; i<node.attributes.length; i++){
        if(node.attributes.item(i).specified){
            rv[node.attributes.item(i).nodeName]=node.attributes.item(i).nodeValue;
			}
		}
    return rv;
	}
/*scrollableTable*/
function scrollableTable (tableId, tableHeight, tableWidth) {
	/*
		Scrollable HTML table JavaScript code can be used to convert tables in ordinary HTML 
		into scrollable ones. No additional coding is necessary. All you need to do is put 
		header rows (if you need them) in THEAD section, table body rows in TBODY section, 
		footer rows (if you need them) in TFOOT section and give your table an ID field, 
		include the webtoolkit.scrollabletable.js file and create ScrollableTable() object after each table.
		example:
		var t = new scrollableTable('myScrollTable', 100);
	*/
	var tableEl=getObject(tableId);
	if(undefined == tableHeight){tableHeight=400;}
	this.initIEengine = function () {
 
		this.containerEl.style.overflowY = 'auto';
		if (this.tableEl.parentElement.clientHeight - this.tableEl.offsetHeight < 0) {
			this.tableEl.style.width = this.newWidth - this.scrollWidth +'px';
		} else {
			this.containerEl.style.overflowY = 'hidden';
			this.tableEl.style.width = this.newWidth +'px';
		}
 
		if (this.thead) {
			var trs = this.thead.getElementsByTagName('tr');
			for (x=0; x<trs.length; x++) {
				trs[x].style.position ='relative';
				trs[x].style.setExpression("top",  "this.parentElement.parentElement.parentElement.scrollTop + 'px'");
			}
		}
 
		if (this.tfoot) {
			var trs = this.tfoot.getElementsByTagName('tr');
			for (x=0; x<trs.length; x++) {
				trs[x].style.position ='relative';
				trs[x].style.setExpression("bottom",  "(this.parentElement.parentElement.offsetHeight - this.parentElement.parentElement.parentElement.clientHeight - this.parentElement.parentElement.parentElement.scrollTop) + 'px'");
			}
		}
 
		eval("window.attachEvent('onresize', function () { document.getElementById('" + this.tableEl.id + "').style.visibility = 'hidden'; document.getElementById('" + this.tableEl.id + "').style.visibility = 'visible'; } )");
	};
 
 
	this.initFFengine = function () {
		this.containerEl.style.overflow = 'hidden';
		this.tableEl.style.width = this.newWidth + 'px';
 
		var headHeight = (this.thead) ? this.thead.clientHeight : 0;
		var footHeight = (this.tfoot) ? this.tfoot.clientHeight : 0;
		var bodyHeight = this.tbody.clientHeight;
		var trs = this.tbody.getElementsByTagName('tr');
		if (bodyHeight >= (this.newHeight - (headHeight + footHeight))) {
			this.tbody.style.overflow = '-moz-scrollbars-vertical';
			for (x=0; x<trs.length; x++) {
				var tds = trs[x].getElementsByTagName('td');
				tds[tds.length-1].style.paddingRight += this.scrollWidth + 'px';
			}
		} else {
			this.tbody.style.overflow = '-moz-scrollbars-none';
		}
 
		var cellSpacing = (this.tableEl.offsetHeight - (this.tbody.clientHeight + headHeight + footHeight)) / 4;
		this.tbody.style.height = (this.newHeight - (headHeight + cellSpacing * 2) - (footHeight + cellSpacing * 2)) + 'px';
 
	};
 
	this.tableEl = tableEl;
	this.scrollWidth = 16;
 
	this.originalHeight = this.tableEl.clientHeight;
	this.originalWidth = this.tableEl.clientWidth;
 
	this.newHeight = parseInt(tableHeight);
	this.newWidth = tableWidth ? parseInt(tableWidth) : this.originalWidth;
 
	this.tableEl.style.height = 'auto';
	this.tableEl.removeAttribute('height');
 
	this.containerEl = this.tableEl.parentNode.insertBefore(document.createElement('div'), this.tableEl);
	this.containerEl.appendChild(this.tableEl);
	this.containerEl.style.height = this.newHeight + 'px';
	this.containerEl.style.width = this.newWidth + 'px';
 
 
	var thead = this.tableEl.getElementsByTagName('thead');
	this.thead = (thead[0]) ? thead[0] : null;
 
	var tfoot = this.tableEl.getElementsByTagName('tfoot');
	this.tfoot = (tfoot[0]) ? tfoot[0] : null;
 
	var tbody = this.tableEl.getElementsByTagName('tbody');
	this.tbody = (tbody[0]) ? tbody[0] : null;
 
	if (!this.tbody) return;
 
	if (document.all && document.getElementById && !window.opera) this.initIEengine();
	if (!document.all && document.getElementById && !window.opera) this.initFFengine();
}
/* showClock - shows current time based on offset in hrs */
function showClock(divid,offset){
	// create Date object for current location
    d = new Date();
   	// convert to msec
    // add local time zone offset
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
	// create new Date object for different city using supplied offset
    nd = new Date(utc + (3600000*offset));
   	// return time as a string
    var t = nd.toLocaleString();
    setText(divid,t);
    setTimeout("showClock('"+divid+"',"+offset+")",1000);
	}
/* isDST - returns true if Daylight Savings Time */
function isDST(){
	var today = new Date;
	var yr = today.getFullYear();
	var dst_start = new Date("March 14, "+yr+" 02:00:00"); // 2nd Sunday in March can't occur after the 14th
	var dst_end = new Date("November 07, "+yr+" 02:00:00"); // 1st Sunday in November can't occur after the 7th
	var day = dst_start.getDay(); // day of week of 14th
	dst_start.setDate(14-day); // Calculate 2nd Sunday in March of this year
	day = dst_end.getDay(); // day of the week of 7th
	dst_end.setDate(7-day); // Calculate first Sunday in November of this year
	if (today >= dst_start && today < dst_end){ 
		//does today fall inside of DST period?
		return true; //if so then return true
		}
	else{
		return false; //if not then return false
		}
	}
/* abort - shows alert msg and returns false */
function abort(msg){
	alert(msg);
	return false;
	}
//includeScript - a way to include a js file in a js file
function includeScript(url){
	document.write('<script type="text/javascript" src="'+ url + '"></script>');
	}

//apendText(fld,$val)
function appendText(obj,val,lf){
	var cObj=getObject(obj);
	if(undefined == cObj){return abort("undefined object passed to appendText");}
	var cval=trim(getText(obj));
	var newval = cval + val;
	if(lf){
		newval += "\r\n";
		}
	setText(obj,newval);
	}
//containsHtml - returns true if txt contains HTML tags
function containsHtml(txt){
	return (/[\<\>]/.test(txt));
	}
//containsHtml - returns true if txt contains HTML tags
function containsSpaces(txt){
	return (/[\ ]/.test(trim(txt)));
	}
//setOpacity
function setOpacity(obj,level) {
	var cObj=getObject(obj);
	cObj.style.opacity = level;
	cObj.style.MozOpacity = level;
	cObj.style.KhtmlOpacity = level;
	cObj.style.filter = "alpha(opacity=" + (level * 100) + ");";

	}
function fadeIn(id){
	for (i = 0; i <= 1; i += (1 / 20)) {
		setTimeout("setOpacity('"+id+"'," + i + ")", i * 1000);
  		}
	}

function fadeOut(id) {
	for (i = 0; i <= 1; i += (1 / 20)) {
		setTimeout("setOpacity('"+id+"'," + (1 - i) + ")", i * 1000);
		}
	}
//stripHtml - removes all html tags from string
function stripHtml(str){
	var re = /(<([^>]+)>)/gi;
	newstr=str.replace(re, "");
	return newstr;
	}
//expand - used to create expanding divs - createExpandDiv
function expand(index){
	var section=document.getElementById('expand_section_'+index);
	var icon=document.getElementById('expand_icon_'+index);
	if(section.style.display=='none'){
    	section.style.display='block';
        icon.innerHTML='<img src="/wfiles/minus.gif" border="0">';
        }
    else{
		section.style.display='none';
        icon.innerHTML='<img src="/wfiles/plus.gif" border="0">';
        }
    }
// fixE - Fix event object
function fixE(e){
	if (typeof e == 'undefined'){e = window.event;}
	if (typeof e.layerX == 'undefined'){e.layerX = e.offsetX;}
	if (typeof e.layerY == 'undefined'){e.layerY = e.offsetY;}
	return e;
	}
//getBrowserHeight
function getBrowserHeight() {
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myHeight = window.innerHeight;
		} 
	else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
		    myHeight = document.documentElement.clientHeight;
		    } 
		else{
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		        myHeight = document.body.clientHeight;
		      	}
			}
		}
	return myHeight;
	}
//get Cookie with said name
function getCookie(name){
	name = trim(name);
	var cookies = document.cookie.split(";");
	var tmp;
	for (var i=0; i<cookies.length; i++){
		tmp = cookies[i].split("=");
		var cname=trim(tmp[0]);
		var cval=trim(tmp[1]);
		//alert('Looking for ['+name+']\nName: ['+cname+']\nValue: ['+cval+']');
		if (cname == name){return unescape(cval);}
		}
	return null;
	}
//Preload images passed in : preloadImages('image1.jpg,image2.jpg,image3.jpg');
function preloadImages(images) {
    if (document.images){
        var i = 0;
        var imageArray = new Array();
        imageArray = images.split(',');
        var imageObj = new Image();
        for(i=0; i<=imageArray.length-1; i++) {
            imageObj.src=images[i];
        	}
    	}
	}

// GetElementsByAttribute - returns an array of tags that have an attribute of value.
function GetElementsByAttribute(tag, att, val){
        //GetElementsByAttribute(tagname, attributename,stringtomatch)
        val=val.replace(/\[\]$/,"\\\[\\\]");
        var a, list, found = new Array(), re = new RegExp(val, 'i');
        //if(undefined != document.getElementsByTagName(tag)){return found;}
        list = document.getElementsByTagName(tag);
        //if(att=='name'){alert("Found "+list.length+" tags with name of "+tag+" ,checking for "+att+" with a val of "+val);}
        for (var i = 0; i < list.length; ++i) {
            a = list[i].getAttribute(att);
            if (undefined == a){a = list[i][att];}
            //if(att=='name'){alert(i+", a="+a+" type="+typeof(a));}
            if (typeof(a)=='string' && (val.length==0 || a.search(re) != -1)) {
               found[found.length] = list[i];
               //alert("Found a match");
               }
            }
        return found;
        }
// GetElementsByAttribute - returns an array of tags that have an attribute of value.
function jsDocs(id){
        list = document.getElementsByTagName('script');
        //alert("Found "+list.length+" tags with name of "+tag+" ,checking for "+att+" with a val of "+val);
        for (var i = 0; i < list.length; ++i) {
			var cObj=list[i];
			var txt=getText(cObj);
			if(txt.length){}
			else{
				var vals;
				for(name in cObj){
					var type=typeof(cObj[name]);
					vals += name+' = '+type+'<br>\n';
                    if(type == 'function'){}
                    else if(type == 'string'){vals += name+' = ['+getText(cObj[name])+']<hr>\n';}
                    else if(type == 'object'){vals += name+' = '+cObj[name]+'<hr>\n';}
                	}
                if(id){setText(id,vals);}
                else{alert(vals);}
            	}
            }
        return;
        }
// getHeight - height of object. defaults to window object
function getHeight(id){
	if(undefined == id){return document.body.clientHeight;}
	var idObj=getObject(id);
	if(undefined == idObj){return null;}
	if(undefined != idObj.innerHeight){return idObj.innerHeight;}
	return idObj.offsetHeight;
	}
function getViewportHeight(){
	if (typeof window.innerHeight != 'undefined'){return window.innerHeight;}
  	else if (typeof document.documentElement != 'undefined'
    	&& typeof document.documentElement.clientHeight !=
    	'undefined' && document.documentElement.clientHeight != 0){
       		return document.documentElement.clientHeight
 		}
 	else{return document.getElementsByTagName('body')[0].clientHeight;}
 	}
function getViewportWidth(){
	if (typeof window.innerWidth != 'undefined'){return window.innerWidth;}
  	else if (typeof document.documentElement != 'undefined'
    	&& typeof document.documentElement.clientWidth !=
    	'undefined' && document.documentElement.clientWidth != 0){
       		return document.documentElement.clientWidth
 		}
 	else{return document.getElementsByTagName('body')[0].clientWidth;}
 	}
// methods for returning the scroll area width and height, that work on all browsers
function getScrollHeight(){
	var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
	return h ? h : 0;
	}
function getScrollWidth(){
	var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
	return w ? w : 0;
	}
//getText - returns object text
function getObject(obj){
	if(typeof(obj)=='object'){return obj;}
    else if(typeof(obj)=='string'){
		if(undefined != document.getElementById(obj)){return document.getElementById(obj);}
		else if(undefined != document.getElementsByName(obj)){
			var els=document.getElementsByName(obj);
			if(els.length ==1){return els[0];}
        	}
		else if(undefined != document.all[obj]){return document.all[obj];}
    	}
    return null;
	}
/* getParent - gets parent object or its parent if parent is P or FORM */
function getParent(obj){
	var cObj=getObject(obj);
	if(undefined == cObj){return abort("undefined object passed to getParent");}
	if(undefined == cObj.parentNode){return cObj;}
	var pobj=cObj.parentNode;
	if(typeof(cObj.parentNode) == "object"){return cObj.parentNode;}
	else{return getParent(pobj);}
	}
//getSelText - returns selected text on the page.
//<input type="button" value="Get selection" onmousedown="getSelText()">
function getSelText(fld){
	var txt = '';
	if(undefined != fld){
		if(document.selection){
			fld.focus();
		    txt = document.selection.createRange();
	    	}
		else{
			var len = fld.value.length;
			var start = fld.selectionStart;
			var end = fld.selectionEnd;
			txt = fld.value.substring(start, end);
	    	}
		}
	else{
	    if (window.getSelection){
	        txt = window.getSelection();
	        }
	    else if (document.getSelection){
	        txt = document.getSelection();
			}
	    else if (document.selection){
	        txt = document.selection.createRange().text;
	        }
		}
	return txt;
	}
//getText - returns object text
function getText(obj){
	var cObj=getObject(obj);
	if(undefined == cObj){return '';}
	if(undefined != cObj.value){return cObj.value;}
    else if(undefined != cObj.innerHTML){return cObj.innerHTML;}
    else if(undefined != cObj.innerText){return cObj.innerText;}
    else{
		//alert('unable to getText on '+cObj);
    	}
    return '';
	}
// getWidth - width of object. defaults to window object
function getWidth(id){
	if(undefined == id){return document.body.clientWidth;}
	var idObj=getObject(id);
	if(undefined == idObj){return '?';}
	if(undefined != idObj.innerWidth){return idObj.innerWidth;}
	return idObj.offsetWidth;
	}
function getWidthHeight(id){
	if(undefined == id){return [document.body.clientWidth,document.body.clientHeight];}
	var idObj=getObject(id);
	if(undefined == idObj){return undefined;}
	if(undefined != idObj.innerWidth){return [idObj.innerWidth,idObj.innerHeight];}
	return [idObj.offsetWidth,idObj.offsetHeight];
	}
function getXY(id){
	if(undefined == id){return [document.body.clientLeft,document.body.clientTop];}
	var idObj=getObject(id);
	if(undefined == idObj){return undefined;}
	if(undefined != idObj.offsetLeft){return [idObj.offsetLeft,idObj.offsetTop];}
	return undefined;
	}
function getPos(ctrl) {
	var pos = {x:0, y:0};
	if(undefined == ctrl){return pos;}
	if (ctrl.offsetParent){
	    while(ctrl){
	        pos.x += ctrl.offsetLeft;
	        pos.y += ctrl.offsetTop;
	        ctrl = ctrl.offsetParent;
	    	}
		}
	else if (ctrl.x && ctrl.y){
	    pos.x += ctrl.x;
	    pos.y += ctrl.y;
		}
	return pos;
	}
/* fadeOut - if remove ==1, the id will be destroyed after fading away */
function fadeId(eid,remove){
	var TimeToFade = 200.0;
  	var element=getObject(eid);
	if(undefined == element){return;}
	if(element.FadeState == null){
    	if(element.style.opacity == null || element.style.opacity == '' || element.style.opacity == '1'){
      		element.FadeState = 2;
    		}
		else{
      		element.FadeState = -2;
			}
  		}
   if(element.FadeState == 1 || element.FadeState == -1){
    	element.FadeState = element.FadeState == 1 ? -1 : 1;
    	element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  		}
	else{
    	element.FadeState = element.FadeState == 2 ? -1 : 1;
    	element.FadeTimeLeft = TimeToFade;
    	setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "','"+remove+"')", 33);
		}
	}
function animateFade(lastTick, eid, remove){
	var TimeToFade = 200.0;
	var curTick = new Date().getTime();
	var elapsedTicks = curTick - lastTick;
	var element=getObject(eid);
	if(undefined == element){return;}
	if(element.FadeTimeLeft <= elapsedTicks){
    	element.style.opacity = element.FadeState == 1 ? '1' : '0';
    	element.style.filter = 'alpha(opacity = ' + (element.FadeState == 1 ? '100' : '0') + ')';
    	element.FadeState = element.FadeState == 1 ? 2 : -2;
    	if(undefined != remove && remove==1){removeDiv(eid);}
    	return;
  		}
  	element.FadeTimeLeft -= elapsedTicks;
  	var newOpVal = element.FadeTimeLeft/TimeToFade;
  	if(element.FadeState == 1){newOpVal = 1 - newOpVal;}
	element.style.opacity = newOpVal;
	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
	setTimeout("animateFade(" + curTick + ",'" + eid + "','"+remove+"')", 33);
	}
//Replace text in a
function replaceText(obj,s,r,i){
	var cObj=getObject(obj);
	if(undefined == obj){return abort("undefined object passed to replaceText");}
	var opt = 'ig';
	if(i){opt = 'g';}
	var regexp = new RegExp(s,opt);
	var txt=getText(obj);
	var newval = txt.replace(regexp,r);
	setText(obj,newval);
	}
//resizeIframe
function resizeIframe(id){
	var fobj=getObject(id);
	if(undefined == fobj){
		window.status='pageframe not found. resize failed';
		return false;

		}
	var h=getBrowserHeight();
	fobj.style.height=h+'px';
	return 1;
    }
//setText - returns object text
function setText(obj,txt){
	var cObj=getObject(obj);
    if(undefined == cObj){return null;}
    //alert(cObj+'\n'+txt);
    if(undefined != cObj.value){cObj.value=txt;}
    else if(undefined != cObj.innerHTML){cObj.innerHTML=txt;}
    else if(undefined != cObj.innerText){cObj.innerText=txt;}
    else{
		return null;
    	}
	}
//setText - returns object text
function setStyle(obj,s,v){
	var cObj=getObject(obj);
    if(undefined == cObj){return abort("undefined object passed to setStyle:"+obj);}
    if(v.length==0){return;}
    if(s.length==0){return;}
    var str="cObj.style."+s+"='"+v+"';";
    eval(str);
	}
//setClassName - returns object text
function setClassName(obj,v){
	var cObj=getObject(obj);
    if(undefined == cObj){return abort("undefined object passed to setClassName");}
    var current=cObj.className;
    if(!v){return;}
    if(v.length==0){return;}
    if(current==v){return;}

    var str="cObj.className='"+v+"';";
    eval(str);
	}
function showContextId(id){
	showId(id,-5,-30);
	hideOnExit(id);
	return false;
	}
function showId(id,xoff,yoff){
    if(undefined == document.getElementById(id)){
		alert('Error in showId\n"'+id+'" is not defined as a valid object');
		return;
    	}
	var formObj=document.getElementById(id);
	formObj.style.position='absolute';
	if(undefined != xoff){
		var x=MouseX;
		x=Math.round(x+xoff);
		formObj.style.left=x+"px";
		}
	if(undefined != yoff){
		var y=MouseY;
		y=Math.round(y+yoff);
		formObj.style.top=y+"px";
		}
    formObj.style.display='inline';
    //
	//alert(formObj.style.display);
    return true;
    }
function showDropDown(id){
	var cObj=getObject(id);
    if(undefined == cObj){return abort("undefined object passed to showIdBlock:"+id);}
    if(cObj.style.display=='block'){
		cObj.style.display='none';
		return false;
		}
    cObj.style.display='block';
    hideOnExit(cObj);
    return false;
	}
function hideId(id){
	var cObj=getObject(id);
    if(undefined == cObj){return abort("undefined object passed to showHide:"+id);}
    cObj.style.display='none';
	}
/* showDrop */
function showDrop(oid,h){
	var navEls = GetElementsByAttribute('div','id',oid);
	for (var i=0; i<navEls.length; i++) {
          if(undefined != h){
			if(h==1){navEls[i].style.display='none';}
			}
          else if(navEls[i].style.display=='block'){navEls[i].style.display='none';}
          else{navEls[i].style.display='block';}
	     }
     return false;
	}
/* showHide */
function showHide(id,scr){
	var cObj=getObject(id);
    if(undefined == cObj){return abort("undefined object passed to showHide:"+id);}
    if(cObj.style.display=='none'){
		cObj.style.display='block';
		}
    else{cObj.style.display='none';}
    if(undefined != scr && scr==1){showOnScreen(id);}
	}
// showProperties - shows the properties of any element
function showProperties(obj,id,v){
	var cObj=getObject(obj);
    if(undefined == cObj){return abort("undefined object passed to showProperties");}
	var str="Properties that have values for :" + cObj + "\n";
	var namestr='';
	for(name in cObj){
		if(cObj[name]){
			//typeof returns "number" "string" "boolean" "function" "undefined" "object"
			var type=typeof(cObj[name]); 
			if(v || (type != "object" && type != "function")){
				var val=cObj[name];
				str += "[" + name + "]["+type+"]";
				if(v || type == 'number'){str += val;}
				str += "<br>\r\n";
				}

			}
		namestr += name + ", ";
		}
	if(!id){
		alert(str);
		}
	else{
		setText(id,str);
    	}
  	}
function str_replace(search, replace, str) { 
    var f = search, r = replace, s = str;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}
//trim - remove beginning and ending spaces, tabs, and line returns
function trim(value){
	if (null != value && undefined != value && "" != value){
		var rval=value.replace(/^[\ \s\0\r\n\t]*/g,"");
		rval=rval.replace(/[\ \s\0\r\n\t]*$/g,"");
	    return rval;
		}
	else{return "";}
	}
// urlEncode
function urlEncode(str) {
	str=str+'';
	str=str.replace(/\//g,"%2F");
	str=str.replace(/\?/g,"%3F");
	str=str.replace(/\</g,"%3C");
	str=str.replace(/\>/g,"%3E");
	str=str.replace(/\"/g,"%22");
	str=str.replace(/=/g,"%3D");
	str=str.replace(/&/g,"%26");
	str=str.replace(/\#/g,"%23");
	//str=str.replace(/\s/g,"+");
    return str;
	}
