
function $_(a) { return document.getElementById(a); }

function isBrowserIE() { if (document.all) { return true; } }

function toggleImgSrc(imgID, src1, src2) { var oImg = $_(imgID); if (oImg.src.search(src1) > 0) { oImg.src = src2; } else { oImg.src = src1; } }

function formatPrice(o) { var price = o.value; var regex = new RegExp("[^0-9.,]", "ig"); price = price.replace(regex, ""); price = price.replace(",", "."); price = new Number(price); var price = (price.toFixed(2)); o.value = price; }

function switchTree(a) {
	var b = $_('node'+a);
	if (b.className.indexOf('minus') > -1) {
		rollTree(a);
	} else {
		unrollTree(a);
	}
}

function rollTree(a) {
	$_('tree'+a).style.display = 'none';
	$_('node'+a).className = 'plus';
}
function unrollTree(a) {
	$_('tree'+a).style.display = 'block';
	$_('node'+a).className = 'minus';
}

function changeInputType(o, oType) {
	var o2 = document.createElement('input');
	o2.type = oType;
	if(o.size) o2.size = o.size;
	if(o.value) o2.value = o.value;
	if(o.name) o2.name = o.name;
	if(o.id) o2.id = o.id;
	if(o.className) o2.className = o.className;
	o.parentNode.replaceChild(o2,o);
	return o2;
}

function getSelectedOptionValue(sid) { if ($_(sid).selectedIndex >= 0) return $_(sid).options[$_(sid).selectedIndex].value; }

function removeSelectOptions(selectID) { var selectbox = $_(selectID); var i; for(i=selectbox.options.length-1;i>=0;i--) { selectbox.remove(i); } selectbox.options.length = 0; }

function addOptionToSelect(selectID, value, text, selected) { var el = document.createElement('option'); el.text = text; el.value = value; el.selected = selected; var elSelect = $_(selectID); try { elSelect.add(el, null); } catch(ex) { elSelect.add(el); } }

function clearoectHTML(oid) { $_(oid).innerHTML = ''; }

function addoectHTML(oid, value) { $_(oid).innerHTML += value; }

function isTrue(a) { var value = $_(a).Value; if (value) { return true; } return false; }

function confirmLink(href, message) { var confirmBox = confirm(message); if (confirmBox) { location = href; } }

function confirmForm(formId, message) { confirmBox = confirm(message); if (confirmBox) $_(formId).submit(); }
	
function getDisplayType(el) { var tag = el.tagName.toLowerCase() ; var displayType = ''; if (isBrowserIE()) { switch (tag) { case 'span': displayType = 'inline'; break; default: displayType = 'block'; } } else { switch (tag) { case 'tr': displayType = 'table-row'; break; case 'tbody': case 'thead': case 'tfoot': displayType = 'table-row-group'; break; case 'table': displayType = 'table'; break; case 'span': displayType = 'inline'; } } return displayType; }

function hideElement(a) { $_(a).style.display = 'none';
}

function showElement(a) { var el = $_(a); var displayType = getDisplayType(el); el.style.display = displayType; 
}

function toggleElement(a) { var el = $_(a); if(el.style.display == 'none'){showElement(a);}else hideElement(a); }

function visibleElement(a) { $_(a).style.visibility = 'visible'; }

function invisibleElement(a) { $_(a).style.visibility = 'hidden'; }

var slide_timer = new Array();
var slide_timer2 = new Array();

function slideOutElement(a,b) {
	clearTimeout(slide_timer2[a]);
	var o = $_(a);
	var h = parseInt(o.scrollHeight);
	var h2 = parseInt(o.style.height);
	var c = 25;
	if (h2 < h) {
		visibleElement(a);
		if (h2+c > h) {
			c = h2+c-h;
		}
		o.style.height = (h2 + c) + 'px';
		slide_timer[a] = setTimeout('slideOutElement(\''+a+'\',\''+b+'\');',20);
	} else {
		o.style.height = h + 'px';
		clearTimeout(slide_timer[a]);
	}
}

function slideInElement(a,b) {
	clearTimeout(slide_timer[a]);
	var o = $_(a);
	var h = 0;
	var h2 = parseInt(o.style.height);
	var c = 25;
	if (h2 > h) {
		if (h2 - c < h) {
			c = h2;
		}
		o.style.height = (h2 - c) + 'px';
		slide_timer2[a] = setTimeout('slideInElement(\''+a+'\',\''+b+'\')',20);
	} else {
		o.style.height = 0+'px';
		invisibleElement(a);
	}
}

function addElement(parentId, tagName, a, name, value, type) { var parent = $_(parentId); var newElement = document.createElement(tagName); newElement.setAttribute('id', a); if (type != '') newElement.setAttribute('type', type); if (value != '') newElement.setAttribute('value', value); if (name != '') newElement.setAttribute('name', name); parent.appendChild(newElement); }

function focusElement(a) { $_(a).focus(); }
	
function unCheckElement(a) { $_(a).checked=false; }

function checkElement(a) { $_(a).checked=true; }

function switchCheckElement(a) { var o = $_(a); if (o.checked) unCheckElement(a); else checkElement(a)};

function copyInputValue(to, from) { $_(to).value = $_(from).value; }

function setInputValue(a, value) { $_(a).value = value; }

function isChecked(a) { if ($_(a).checked || $_(a).checked == 'true') return 1; return 0; } 

function isCheckedOne(field) { var o = document.getElementsByName(field); for (j=0; j < o.length; j++ ) { if (o[j].checked) { return 1; } } return 0; }

function isElementEmpty(a) { return ($_(a).value == ''); }

function removeElement(parentId, a) { var parent = $_(parentId); var element = $_(a); parent.removeChild(element); }

function inputCheck(inputId, parentId, tagName, a, name, value, type) { var input = $_(inputId); if (input.checked == true) { addElement(parentId, tagName, a, name, value, type); } else { removeElement(parentId, a); } }

function enableElement(a) { $_(a).disabled = false; }

function disableElement(a) { $_(a).disabled = true; }

function toggleEnableElement(a) { if ($_(a).disabled == true) { $_(a).disabled = false; } else { $_(a).disabled = true; } } 

function enableAll(options) { for(var i=0; i < options.length; i++) { options[i].style.color = 'black'; } }

function disableSelectedOnOther(select, otherSelect) { var index = select.selectedIndex; otherSelect[index].style.color = 'white'; }

function selectAll(options) { for(var i=0; i < options.length; i++) { options[i].selected = true; } }

function clearSelect(a) { var element = $_(a); element.options.selectedIndex = 0; }

function clearInput(a) { var element = $_(a); element.value = ''; }

function copySelectedIndex(a, toId) { var from = $_(a); var to = $_(toId); to.options.selectedIndex = from.options.selectedIndex; }

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 checkAll(field) { var o = document.getElementsByName(field); for (j=0; j < o.length; j++ ) o[j].checked = true ; }

function uncheckAll(field) { var o = document.getElementsByName(field); for (j=0; j < o.length; j++ ) o[j].checked = false ; }

function reverseAll(field) { var o = document.getElementsByName(field); for (i = 0; i < o.length; i++) { if (o[i].checked == false) { o[i].checked = true; } else { o[i].checked = false; } } }

function utf8_encode ( string ) {
    // Encodes an ISO-8859-1 string to UTF-8  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/utf8_encode    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0; 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {            enc = string.fromCharCode((c1 >> 6) | 192) + string.fromCharCode((c1 & 63) | 128);
        } else {
            enc = string.fromCharCode((c1 >> 12) | 224) + string.fromCharCode(((c1 >> 6) & 63) | 128) + string.fromCharCode((c1 & 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;
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
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;
	}
 
}

function urlencode (str) {
    // URL-encodes string  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/urlencode    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
    str = (str+'').toString();
        // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function strtr (str, from, to) {
    // Translates characters in str using given translation tables  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/strtr    // +   original by: Brett Zamir (http://brett-zamir.me)
    // +      input by: uestla
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Alan C
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // +      input by: Taras Bogach
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: jpfle
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // -   depends on: krsort    // -   depends on: ini_set
    // *     example 1: $trans = {'hello' : 'hi', 'hi' : 'hello'};
    // *     example 1: strtr('hi all, I said hello', $trans)
    // *     returns 1: 'hello all, I said hi'
    // *     example 2: strtr('äaabaåccasdeöoo', 'äåö','aao');    // *     returns 2: 'aaabaaccasdeooo'
    // *     example 3: strtr('ääääääää', 'ä', 'a');
    // *     returns 3: 'aaaaaaaa'
    // *     example 4: strtr('http', 'pthxyz','xyzpth');
    // *     returns 4: 'zyyx'    // *     example 5: strtr('zyyx', 'pthxyz','xyzpth');
    // *     returns 5: 'http'
    // *     example 6: strtr('aa', {'a':1,'aa':2});
    // *     returns 6: '2'
    var fr = '', i = 0, j = 0, lenStr = 0, lenFrom = 0, tmpStrictForIn = false, fromTypeStr = '', toTypeStr = '', istr = '';    var tmpFrom = [];
    var tmpTo = [];
    var ret = '';
    var match = false;
     // Received replace_pairs?
    // Convert to normal from->to chars
    if (typeof from === 'object') {
        tmpStrictForIn = this.ini_set('phpjs.strictForIn', false); // Not thread-safe; temporarily set to true
        from = this.krsort(from);        this.ini_set('phpjs.strictForIn', tmpStrictForIn);
 
        for (fr in from) {
            if (from.hasOwnProperty(fr)) {
                tmpFrom.push(fr);                tmpTo.push(from[fr]);
            }
        }
 
        from = tmpFrom;        to = tmpTo;
    }
    
    // Walk through subject and replace chars when needed
    lenStr  = str.length;    lenFrom = from.length;
    fromTypeStr = typeof from === 'string';
    toTypeStr = typeof to === 'string';
 
    for (i = 0; i < lenStr; i++) {        match = false;
        if (fromTypeStr) {
            istr = str.charAt(i);
            for (j = 0; j < lenFrom; j++) {
                if (istr == from.charAt(j)) {                    match = true;
                    break;
                }
            }
        }        else {
            for (j = 0; j < lenFrom; j++) {
                if (str.substr(i, from[j].length) == from[j]) {
                    match = true;
                    // Fast forward                    i = (i + from[j].length)-1;
                    break;
                }
            }
        }        if (match) {
            ret += toTypeStr ? to.charAt(j) : to[j];
        } else {
            ret += str.charAt(i);
        }    }
 
    return ret;
}

function sha1 (str) {
    // Calculate the sha1 hash of a string  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/sha1    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // + namespaced by: Michael White (http://getsprink.com)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode    // *     example 1: sha1('Kevin van Zonneveld');
    // *     returns 1: '54916d2e62f65b3afa6e192e6a601cdbe5cb5897'
    var rotate_left = function (n,s) {
        var t4 = ( n<<s ) | (n>>>(32-s));
        return t4;    };
 
    /*var lsb_hex = function (val) { // Not in use; needed?
        var str="";
        var i;        var vh;
        var vl;
 
        for ( i=0; i<=6; i+=2 ) {
            vh = (val>>>(i*4+4))&0x0f;            vl = (val>>>(i*4))&0x0f;
            str += vh.toString(16) + vl.toString(16);
        }
        return str;
    };*/ 
    var cvt_hex = function (val) {
        var str="";
        var i;
        var v; 
        for (i=7; i>=0; i--) {
            v = (val>>>(i*4))&0x0f;
            str += v.toString(16);
        }        return str;
    };
 
    var blockstart;
    var i, j;    var W = new Array(80);
    var H0 = 0x67452301;
    var H1 = 0xEFCDAB89;
    var H2 = 0x98BADCFE;
    var H3 = 0x10325476;    var H4 = 0xC3D2E1F0;
    var A, B, C, D, E;
    var temp;
 
    str = this.utf8_encode(str);    var str_len = str.length;
 
    var word_array = [];
    for (i=0; i<str_len-3; i+=4) {
        j = str.charCodeAt(i)<<24 | str.charCodeAt(i+1)<<16 |        str.charCodeAt(i+2)<<8 | str.charCodeAt(i+3);
        word_array.push( j );
    }
 
    switch (str_len % 4) {        case 0:
            i = 0x080000000;
        break;
        case 1:
            i = str.charCodeAt(str_len-1)<<24 | 0x0800000;        break;
        case 2:
            i = str.charCodeAt(str_len-2)<<24 | str.charCodeAt(str_len-1)<<16 | 0x08000;
        break;
        case 3:            i = str.charCodeAt(str_len-3)<<24 | str.charCodeAt(str_len-2)<<16 | str.charCodeAt(str_len-1)<<8    | 0x80;
        break;
    }
 
    word_array.push( i ); 
    while ((word_array.length % 16) != 14 ) {word_array.push( 0 );}
 
    word_array.push( str_len>>>29 );
    word_array.push( (str_len<<3)&0x0ffffffff ); 
    for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
        for (i=0; i<16; i++) {W[i] = word_array[blockstart+i];}
        for (i=16; i<=79; i++) {W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);}
  
        A = H0;
        B = H1;
        C = H2;
        D = H3;        E = H4;
 
        for (i= 0; i<=19; i++) {
            temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
            E = D;            D = C;
            C = rotate_left(B,30);
            B = A;
            A = temp;
        } 
        for (i=20; i<=39; i++) {
            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
            E = D;
            D = C;            C = rotate_left(B,30);
            B = A;
            A = temp;
        }
         for (i=40; i<=59; i++) {
            temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
            E = D;
            D = C;
            C = rotate_left(B,30);            B = A;
            A = temp;
        }
 
        for (i=60; i<=79; i++) {            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
            E = D;
            D = C;
            C = rotate_left(B,30);
            B = A;            A = temp;
        }
 
        H0 = (H0 + A) & 0x0ffffffff;
        H1 = (H1 + B) & 0x0ffffffff;        H2 = (H2 + C) & 0x0ffffffff;
        H3 = (H3 + D) & 0x0ffffffff;
        H4 = (H4 + E) & 0x0ffffffff;
    }
     temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
    return temp.toLowerCase();
}

function f_eas(a) {
	var key = sha1('abra kadabra ole ale oh 1234 !@###'+a);
	var p1 = key.substr(0,13);
	var p2 = key.substr(13);
	var encoded = Base64.encode(a);
	encoded = strtr(encoded, '+/=', '-.,');
	encoded = urlencode(p1 + '__' + encoded + '__' + p2);
	return encoded;
}
