function urlencode(str) {
	// http://www.phpbuilder.com/board/showthread.php?t=10318476
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function urldecode(str) {
	return unescape(str.replace('+', ' '));
	}

//function urlencode(str) {
//	return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
//	}


function chkEkey(e,mybutton) {

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
		}
		else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
		}
	if (characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		characterCode=0;
		document.getElementById(mybutton).click();	
		}	
}


function NewWindow(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars,resizable'
	win = window.open(mypage, myname, winprops);
	win.opener=self;
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	}


function popper(url, name, ww,  wh) {
	  popupWin = window.open(url, name, 'width='+ww+',height='+wh+',scrollbars,top=150,left=150');
	}
	
	

function gohere($xx){
    location.href=$xx;
  }

function pophere($xx,$rel){
    location.rel=$rel;
    location.href=$xx;
  }

function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}
	 
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 GetSelectedRadioItem($r) {
	$radio=document.getElementsByName($r);
	len = $radio.length;
	for (i = 0; i <len; i++) {
		if ($radio[i].checked==true) {
	      return $radio[i].value;
	      break;
		}
	  }
    return '';
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";
 function encode64(input) {
	      input = escape(input);
	      var output = "";
	      var chr1, chr2, chr3 = "";
	      var enc1, enc2, enc3, enc4 = "";
	      var i = 0;
	  
	      do {
	         chr1 = input.charCodeAt(i++);
	         chr2 = input.charCodeAt(i++);
	         chr3 = input.charCodeAt(i++);
	  
	         enc1 = chr1 >> 2;
	         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	         enc4 = chr3 & 63;
	  
	         if (isNaN(chr2)) {
	            enc3 = enc4 = 64;
	         } else if (isNaN(chr3)) {
	            enc4 = 64;
	         }
	  
	         output = output +
	            keyStr.charAt(enc1) +
	            keyStr.charAt(enc2) +
	            keyStr.charAt(enc3) +
	            keyStr.charAt(enc4);
	         chr1 = chr2 = chr3 = "";
	         enc1 = enc2 = enc3 = enc4 = "";
	      } while (i < input.length);
	  
	      return output;
	   }



var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		//input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}


