	function getElemByID(whichLayer){
		var elem;
		if( document.getElementById ) // this is the way the standards work
			elem = document.getElementById( whichLayer );
		else if( document.all ) // this is the way old msie versions work
			elem = document.all[whichLayer];
		else if( document.layers ) // this is the way nn4 works
			elem = document.layers[whichLayer];
		//alert(elem);
		return elem;
	}
	
	function showApplyChanges(){
		var apprvid = getElemByID('apprvid');
		if (apprvid){
			apprvid.value = '<?=$apprvid?>';
		}
		var div_applychanges = getElemByID('div_applychanges');
		if (div_applychanges){
			div_applychanges.style.display='block';
		}
	}

	function isEmail (s) {
		if (isEmpty(s)) 
			if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);

    //if (isWhitespace(s)) return false;
	
	    var i = 1;
	    var sLength = s.length;
	    // look for @
	    while ((i < sLength) && (s.charAt(i) != "@")) {
			i++;
	    }

	    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	    else i += 2;

	    // look for .
	    while ((i < sLength) && (s.charAt(i) != ".")) {
			i++;
	    }
		if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	    else return true;
	}
	
	function isEmpty(s){   
		return ((s == null) || (s.length == 0));
	}
	
	function trim(str, chars) {
		 return ltrim(rtrim(str, chars), chars);
	}	
	
	function is_numeric( mixed_var ) {
	   if (mixed_var === '') {
	        return false;
	    }
		
	    return !isNaN(mixed_var * 1);
	}
	
	function isUpperCase(myString, pos){
	  return (myString.charAt(pos) == myString.charAt(pos).toUpperCase()); 
    } 


	function isLowerCase(myString, pos){
		return (myString.charAt(pos) == myString.charAt(pos).toLowerCase()); 
    }

	function ltrim(str, chars) {
		 chars = chars || "\\s";
		 return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}

	function rtrim(str, chars) {
		 chars = chars || "\\s";
		 return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	function mouseLocation(evt){		
		//var dg = document.getElementById('DBUG');
		
		// create cross-browser event detector:
		////var node = (evt.target) ? evt.target : ((evt.srcElement)?evt.srcElement : null );
		////evt = (evt) ? evt : ((event) ? event : null);		
		
		// create mouse coordinates objects:		
		////xpo = evt.clientX;		
		////ypo = evt.clientY;				
		//if (dg)			
			//dg.innerHTML = xpo+', '+ypo;
		////alert(xpo +"\n"+ ypo);
		
	}
	
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj){
			if (obj.offsetParent) {
				do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
				} while (obj = obj.offsetParent);
			}
		}else{
			return [0,0];
		}
		return [curleft,curtop];
	}
	
	
	

	
	function toggleLayer( whichLayer, showit ){
		var elem, vis;
		if( document.getElementById ) // this is the way the standards work
			elem = document.getElementById( whichLayer );
		else if( document.all ) // this is the way old msie versions work
			elem = document.all[whichLayer];
		else if( document.layers ) // this is the way nn4 works
			elem = document.layers[whichLayer];
			
		vis = elem.style;
		// if the style.display value is blank we try to figure it out here
		if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
			vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
			
		//vis.display = (vis.display==''||vis.display=='block')?'none':'block';
		vis.display = (showit==false)?'none':'block';
		
	}
	function toggleALayer( whichLayer){
		var elem, vis;
		if( document.getElementById ) // this is the way the standards work
			elem = document.getElementById( whichLayer );
		else if( document.all ) // this is the way old msie versions work
			elem = document.all[whichLayer];
		else if( document.layers ) // this is the way nn4 works
			elem = document.layers[whichLayer];
			
		vis = elem.style;
		// if the style.display value is blank we try to figure it out here
		if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
			vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
			
		//vis.display = (vis.display==''||vis.display=='block')?'none':'block';
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
		
	}
	
	function URLEncode (clearString) {
	  var output = '';
	  var x = 0;
	  clearString = clearString.toString();
	  var regex = /(^[a-zA-Z0-9_.]*)/;
	  while (x < clearString.length) {
	    var match = regex.exec(clearString.substr(x));
	    if (match != null && match.length > 1 && match[1] != '') {
	    	output += match[1];
	      x += match[1].length;
	    } else {
	      if (clearString[x] == ' ')
	        output += '+';
	      else {
	        var charCode = clearString.charCodeAt(x);
	        var hexVal = charCode.toString(16);
	        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
	      }
	      x++;
	    }
	  }
	  return output;
	}	
	
	function str_replace(search, replace, subject) {
	    var f = search, r = replace, s = subject;
	    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];
	}
	function chr(ascii){
		return String.fromCharCode(ascii);
	}
	
	function explode( delimiter, string, limit ) {
	    var emptyArray = { 0: '' };
	    
	    // third argument is not required
	    if ( arguments.length < 2 ||
	        typeof arguments[0] == 'undefined' ||
	        typeof arguments[1] == 'undefined' )
	    {
	        return null;
	    }
	 
	    if ( delimiter === '' ||
	        delimiter === false ||
	        delimiter === null )
	    {
	        return false;
	    }
	 
	    if ( typeof delimiter == 'function' ||
	        typeof delimiter == 'object' ||
	        typeof string == 'function' ||
	        typeof string == 'object' )
	    {
	        return emptyArray;
	    }
	 
	    if ( delimiter === true ) {
	        delimiter = '1';
	    }
	    
	    if (!limit) {
	        return string.toString().split(delimiter.toString());
	    } else {
	        // support for limit argument
	        var splitted = string.toString().split(delimiter.toString());
	        var partA = splitted.splice(0, limit - 1);
	        var partB = splitted.join(delimiter.toString());
	        partA.push(partB);
	        return partA;
	    }
	}
	
	function urldecode( str ) {
	    // http://kevin.vanzonneveld.net
	    var histogram = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
	    
	    var replacer = function(search, replace, str) {
	        var tmp_arr = [];
	        tmp_arr = str.split(search);
	        return tmp_arr.join(replace);
	    };
	    
	    // The histogram is identical to the one in urlencode.
	    histogram["'"]   = '%27';
	    histogram['(']   = '%28';
	    histogram[')']   = '%29';
	    histogram['*']   = '%2A';
	    histogram['~']   = '%7E';
	    histogram['!']   = '%21';
	    histogram['%20'] = '+';
	    histogram['\u00DC'] = '%DC';
	    histogram['\u00FC'] = '%FC';
	    histogram['\u00C4'] = '%D4';
	    histogram['\u00E4'] = '%E4';
	    histogram['\u00D6'] = '%D6';
	    histogram['\u00F6'] = '%F6';
	    histogram['\u00DF'] = '%DF'; 
	    histogram['\u20AC'] = '%80';
	    histogram['\u0081'] = '%81';
	    histogram['\u201A'] = '%82';
	    histogram['\u0192'] = '%83';
	    histogram['\u201E'] = '%84';
	    histogram['\u2026'] = '%85';
	    histogram['\u2020'] = '%86';
	    histogram['\u2021'] = '%87';
	    histogram['\u02C6'] = '%88';
	    histogram['\u2030'] = '%89';
	    histogram['\u0160'] = '%8A';
	    histogram['\u2039'] = '%8B';
	    histogram['\u0152'] = '%8C';
	    histogram['\u008D'] = '%8D';
	    histogram['\u017D'] = '%8E';
	    histogram['\u008F'] = '%8F';
	    histogram['\u0090'] = '%90';
	    histogram['\u2018'] = '%91';
	    histogram['\u2019'] = '%92';
	    histogram['\u201C'] = '%93';
	    histogram['\u201D'] = '%94';
	    histogram['\u2022'] = '%95';
	    histogram['\u2013'] = '%96';
	    histogram['\u2014'] = '%97';
	    histogram['\u02DC'] = '%98';
	    histogram['\u2122'] = '%99';
	    histogram['\u0161'] = '%9A';
	    histogram['\u203A'] = '%9B';
	    histogram['\u0153'] = '%9C';
	    histogram['\u009D'] = '%9D';
	    histogram['\u017E'] = '%9E';
	    histogram['\u0178'] = '%9F';
	 
	    for (unicodeStr in histogram) {
	        hexEscStr = histogram[unicodeStr]; // Switch order when decoding
	        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
	    }
	    
	    // End with decodeURIComponent, which most resembles PHP's encoding functions
	    ret = decodeURIComponent(ret);
	 
	    return ret;
	}
	
	
