// External Functions not written by me.
var winW = 0;
var winH = 0;

function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: urlencode("Kevin van Zonneveld!");
    // *     returns 1: "Kevin+van+Zonneveld%21"
                                     
    var ret = str;
    
    ret = ret.toString();
    ret = encodeURIComponent(ret);
    ret = ret.replace(/%20/g, "+");
 
    return ret;
}

function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: urldecode("Kevin+van+Zonneveld%21");
    // *     returns 1: "Kevin van Zonneveld!"
    
    var ret = str;
       
    ret = ret.replace(/\+/g, "%20");
    ret = decodeURIComponent(ret);
    ret = ret.toString();
 
    return ret;
}

function getWH() {
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof(window.innerWidth) != "undefined") {
      winW = window.innerWidth;
      winH = window.innerHeight; }
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof(document.documentElement) != "undefined" && typeof(document.documentElement.clientWidth) != "undefined" && document.documentElement.clientWidth != 0) {
winW = document.documentElement.clientWidth;
winH = document.documentElement.clientHeight; }
 
// older versions of IE
 
else {
	winW = document.getElementsByTagName("body")[0].clientWidth;
	winH = document.getElementsByTagName("body")[0].clientHeight; } }
    
function trim( str, charlist ) {
    // http://kevin.vanzonneveld.net
    var whitespace, l = 0;
    if (!charlist) { whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000'; }
    else { whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1'); }
    l = str.length;
    for (var i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) { str = str.substring(i); break; } }
    l = str.length;
    for (i = l - 1; i >= 0; i--) { 
    	if (whitespace.indexOf(str.charAt(i)) === -1) { str = str.substring(0, i + 1); break; } }
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : ''; }
    
    
function base64_encode( data ) {
    // http://kevin.vanzonneveld.net
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, enc="", tmp_arr = [];
    data = utf8_encode(data);
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++); o2 = data.charCodeAt(i++); o3 = data.charCodeAt(i++);
        bits = o1<<16 | o2<<8 | o3;
        h1 = bits>>18 & 0x3f; h2 = bits>>12 & 0x3f; h3 = bits>>6 & 0x3f; h4 = bits & 0x3f;
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch( data.length % 3 ){
        case 1: enc = enc.slice(0, -2) + '=='; break;
        case 2: enc = enc.slice(0, -1) + '='; break; }
    return enc; }
    
function base64_decode( data ) {
    // http://kevin.vanzonneveld.net

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, dec = "", tmp_arr = [];
 
    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++)); h2 = b64.indexOf(data.charAt(i++)); h3 = b64.indexOf(data.charAt(i++)); h4 = b64.indexOf(data.charAt(i++));
        bits = h1<<18 | h2<<12 | h3<<6 | h4;
        o1 = bits>>16 & 0xff; o2 = bits>>8 & 0xff; o3 = bits & 0xff;
 
        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1); } 
        else if (h4 == 64) { tmp_arr[ac++] = String.fromCharCode(o1, o2); }
        else { tmp_arr[ac++] = String.fromCharCode(o1, o2, o3); } }
    while (i < data.length);
    
    dec = tmp_arr.join('');
    dec = utf8_decode(dec);
    return dec; }
    
function utf8_encode ( string ) {
    // http://kevin.vanzonneveld.net
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
    var start, end;
    start = end = 0;
    for (var n = 0; n < string.length; n++) {
        var c = string.charCodeAt(n);
        var enc = null;
        if (c < 128) { end++; } 
        else if((c > 127) && (c < 2048)) { enc = String.fromCharCode((c >> 6) | 192) + String.fromCharCode((c & 63) | 128); }
        else { enc = String.fromCharCode((c >> 12) | 224) + String.fromCharCode(((c >> 6) & 63) | 128) + String.fromCharCode((c & 63) | 128); }
        if (enc != null) {
            if (end > start) { utftext += string.substring(start, end); }
            utftext += enc;
            start = end = n+1; } }
    if (end > start) { utftext += string.substring(start, string.length); }
    return utftext; }

function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    var tmp_arr = [], i = ac = c = c1 = c2 = 0;
    while ( i < str_data.length ) {
        c = str_data.charCodeAt(i);
        if (c < 128) { tmp_arr[ac++] = String.fromCharCode(c); i++; }
        else if ((c > 191) && (c < 224)) { c2 = str_data.charCodeAt(i+1); tmp_arr[ac++] = String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; }
        else { c2 = str_data.charCodeAt(i+1); c3 = str_data.charCodeAt(i+2); tmp_arr[ac++] = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } }
    return tmp_arr.join(''); }
	
// Modified from blazonry version
function sel2sel(objSrc, objDes ) {
	selS = getObj( objSrc ); selD = getObj( objDes ); 
    theLen = selS.length;
    for ( i=0; i<theLen ; i++){
        if (selS.options[i].selected == true ) { desLen = selD.length; selD.options[desLen]= new Option(selS.options[i].text, selS.options[i].value); } }

    for ( i = (theLen -1); i>=0; i--){
        if (selS.options[i].selected == true ) { selS.options[i] = null; } } }