/* Popup Functions */
function popup(U,W,H,b){
var s=(typeof(screen)=='object'?screen:false); var SW=(s?(s.availWidth?s.availWidth:s.width):640),SH=(s?(s.availHeight?s.availHeight:s.height):480),X=(SW>W?((SW/2)-(W/2)):0),Y=(SH>H?((SH/2)-(H/2)):0);var k=window.open(U,"","scrollbars="+((b||SW<W||SH<H)?'1':'0')+",toolbar=0,status=1,menubar=0,directories=0,resizable="+((SW<W||SH<H)?'1,maximized=1':'1')+",location=0,"+(s?"width="+(SW<W?SW:W)+",height="+(SH<H?SH:H)+",":'')+"left="+X+",top="+Y+",screenX="+X+",screenY="+Y+',modal=1');if(k.focus){k.focus()};
return k;
}
function wpopup(U,W,H,b){
 popup(U,W,H,b);
}
function ppopup(U,W,H){
 var k=popup('',W,H);var d=k.document;d.write("<html><head><title>"+W+"x"+H+"</title></head><body leftmargin='0' topmargin='0' marginheight='0' marginwidth='0'><a href='javascript:close()' style='display: block' title='Click to close'><img src='"+U+"' width='"+W+"' height='"+H+"' border='0' alt='Click to close'></a></body></html>");d.close();
}
function tpopup(T,W,H){
var k=popup('',W,H);var d=k.document;d.write("<html><head><title>"+W+"x"+H+"</title></head><body bgcolor='#ffffff' leftmargin='0' topmargin='0' marginheight='0' marginwidth='0'>"+T+"</body></html>");d.close();
}
function _GID(id){
        if(document.getElementById){return document.getElementById(id.toString());}else{return false;}
}



/* Hook Functions */
/* Last Modified: 10/04/04 by -IGI- */
var __hooks = new Array();
function addHook(name, func)
{
        name = name.toString();
        func = func.toString();

	if(typeof(__hooks[name]) != 'object')
	{
		__hooks[name] = new Array();
	}
	__hooks[name][func] = true;
}


function delHook(name, func)
{
        name = name.toString();
        func = func.toString();

	if(typeof(__hooks[name]) != 'object')
	{
		return;
	}
	__hooks[name][func] = false;
}



function resetHook(name)
{
        name = name.toString();
	__hooks[name] = new Array();
}



function countHook(name)
{
  var i, func;
        name = name.toString();

	if(typeof(__hooks[name]) != 'object')
	{
		return 0;
	}

        i = 0;
	for(func in __hooks[name])
	{
		if(__hooks[name][func])
		{
			i++;
		}
	}
	return i;
}


function doHook(name, reset, param1, param2, param3)
{
  var func;

        name = name.toString();
	if(typeof(__hooks[name]) == 'object')
	{
		for(func in __hooks[name])
		{
			if(__hooks[name][func] == true && typeof(eval(func)) == 'function')
			{
				eval(func)(param1, param2, param3);
			}
		}

		if(reset)
		{
			resetHook(name);
		}
	}
}


/* Basic hooks/events */
window.onload = function(){
	doHook('OnWindowLoad');
}
window.onmousedown = function(){
	doHook('OnWindowClick');
}
window.onfocus = function(){
	doHook('OnWindowFocus');
}
window.onunload = function(){
	doHook('OnWindowUnload');
}


if(typeof(window.onresizeend) == 'function')
{
	window.onresizeend = function(){
		doHook('OnWindowResize');
	}
}else{
	window.onresize = function(){
		doHook('OnWindowResize');
	}
}







function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function setCookie(cookieName, cookieValue, nDays)
{
	var today = new Date();
	var expire = new Date();

	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName + "=" + escape(cookieValue) + "; expires=" + expire.toGMTString() + '; path=/';
}


function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}







function days_in_month (y, m)
{
  var days = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

        y*=1; m*=1;

	if((y % 4) == 0)
		days[1] = 29;

	return days[m-1];
}





var img_dir = "../web-common/images/";
var sort_case_sensitive = false;


function _sort(a, b) {
    var a = a[0];
    var b = b[0];
    if (Number(a) && Number(b)) return sort_numbers(a, b);
    else if (!sort_case_sensitive) return sort_insensitive(a, b);
    else return sort_sensitive(a, b);
}

function sort_numbers(a, b)
{
    return a - b;
}

function sort_insensitive(a, b)
{
    var anew = a.toLowerCase();
    var bnew = b.toLowerCase();
    if (anew < bnew) return -1;
    if (anew > bnew) return 1;
    return 0;
}

function sort_sensitive(a, b) {
    if (a < b) return -1;
    if (a > b) return 1;
    return 0;
}

function getConcatenedTextContent(node)
{
    var _result = "";
    if (node == null)
	{
        return _result;
    }
    var childrens = node.childNodes;
    var i = 0;
    while (i < childrens.length) {
        var child = childrens.item(i);
        switch (child.nodeType) {
            case 1: // ELEMENT_NODE
            case 5: // ENTITY_REFERENCE_NODE
                _result += getConcatenedTextContent(child);
                break;
            case 3: // TEXT_NODE
            case 2: // ATTRIBUTE_NODE
            case 4: // CDATA_SECTION_NODE
                _result += child.nodeValue;
                break;
            case 6: // ENTITY_NODE
            case 7: // PROCESSING_INSTRUCTION_NODE
            case 8: // COMMENT_NODE
            case 9: // DOCUMENT_NODE
            case 10: // DOCUMENT_TYPE_NODE
            case 11: // DOCUMENT_FRAGMENT_NODE
            case 12: // NOTATION_NODE
            // skip
            break;
        }
        i++;
    }
    return _result;
}



function sort(e)
{
    var el = window.event ? window.event.srcElement : e.currentTarget;
    while (el.tagName != "TH") el = el.parentNode;
    var a = new Array();
    var name = el.lastChild.nodeValue;
    var dad = el.parentNode;
    var table = dad.parentNode.parentNode;
    var up = table.up;
    var node, arrow, curcol;

    for (var i = 0; (node = dad.getElementsByTagName("th").item(i)); i++)
    {
        if (node.lastChild.nodeValue == name)
        {
            curcol = i;
            if (node.className == "curcol")
            {
				node.className = "";

                table.up = Number(!up);
				node.id = "sort-up";
            }else{
				node.className = "curcol";
				table.up = 0;
				node.id = "sort-down";
            }
        }else{
			node.className = "";
			node.id = "";
        }
    }

    var tbody = table.getElementsByTagName("tbody").item(0);
    for (var i = 0; (node = tbody.getElementsByTagName("tr").item(i)); i++)
    {
        a[i] = new Array();
        a[i][0] = getConcatenedTextContent(node.getElementsByTagName("td").item(curcol));
        a[i][1] = getConcatenedTextContent(node.getElementsByTagName("td").item(1));
        a[i][2] = getConcatenedTextContent(node.getElementsByTagName("td").item(0));
        a[i][3] = node;
    }
    a.sort(_sort);
    if (table.up) a.reverse();
    for (var i = 0; i < a.length; i++)
	{
        tbody.appendChild(a[i][3]);
    }
}

function sort_init(e) 
{
    if (!document.getElementsByTagName) return;

    for (var j = 0; (thead = document.getElementsByTagName("thead").item(j)); j++)
    {
        var node;
        for (var i = 0; (node = thead.getElementsByTagName("th").item(i)); i++)
        {
            if (node.addEventListener) node.addEventListener("click", sort, false);
            else if (node.attachEvent) node.attachEvent("onclick", sort);
            node.title = "Click to sort";
//node.innerHTML = '<a>' + node.innerHTML + '</a>';
        }
        thead.parentNode.up = 0;
    }
}

//addHook('OnWindowLoad', 'sort_init');






/* BEGIN: ComboList Functions */
function ctlComboListSet2(sName, V, sForm)
{
  var a, b, i, j, ret;

        i = 0;
        j = 0;

	a = V.split("|");

	ret = Array();

	while(i<a.length)
	{
		ret[j] = Array(a[i], a[i+1], a[i+2]);
		i+=3;
		j+=1;
	}
	ctlComboListSet(sName, ret, sForm);
}


function ctlComboListSet(sName, aV, sForm)
{
  var i, aT, a, oOpt, oSRC, oDST, fV;
	sForm = 'fm-' + sForm;

        fV = '';
        oSRC = document.forms[sForm].elements[sName+'-src'];
        oDST = document.forms[sForm].elements[sName+'-dest'];

	for(i=oSRC.options.length-1; i>=0; i--)
	{
		oSRC.options[i] = null;
	}
	for(i=oDST.options.length-1; i>=0; i--)
	{
		oDST.options[i] = null;
	}


	var tSRC, tDST, tOPT;

	tSRC = '';
	tDST = '';

	for(i=0; i<aV.length; i++)
	{
		aT = aV[i];

                oOpt = document.createElement("OPTION");

                if(aT[0] == 0)
                {
			oSRC.options.add(oOpt);
		}else{
		        fV += (fV?'|':'') + aT[1];

			oDST.options.add(oOpt);
		}

		oOpt.value = aT[1];
		oOpt.text = aT[2];
	}

	document.forms[sForm].elements[sName].value = fV;
}


function ctlComboListAdd(sName, sForm, bAll)
{
  var oOpt, oSRC, oDST, fV;
	sForm = 'fm-' + sForm;

        fV = '';

        oSRC = document.forms[sForm].elements[sName+'-src'];
        oDST = document.forms[sForm].elements[sName+'-dest'];

	for(i=oSRC.options.length-1; i>=0; i--)
	{
		if(oSRC.options[i].selected || bAll)
		{
			oOpt = document.createElement("OPTION");

			oDST.options.add(oOpt);

			oOpt.value = oSRC.options[i].value;
			oOpt.text = oSRC.options[i].text;

			oSRC.options[i] = null;
		}

	}

	for(i=oDST.options.length-1; i>=0; i--)
	{
	        fV += (fV?'|':'') + oDST.options[i].value;
	}

	document.forms[sForm].elements[sName].value = fV;
}



function ctlComboListDel(sName, sForm, bAll)
{
  var oOpt, oSRC, oDST, fV;
	sForm = 'fm-' + sForm;

        fV = '';

        oSRC = document.forms[sForm].elements[sName+'-src'];
        oDST = document.forms[sForm].elements[sName+'-dest'];

	for(i=oDST.options.length-1; i>=0; i--)
	{
		if(oDST.options[i].selected || bAll)
		{
			oOpt = document.createElement("OPTION");

			oSRC.options.add(oOpt);

			oOpt.value = oDST.options[i].value;
			oOpt.text = oDST.options[i].text;

			oDST.options[i] = null;
		}else{
		        fV += (fV?'|':'') + oDST.options[i].value;
		}
	}

	document.forms[sForm].elements[sName].value = fV;
}
/* END: ComboList Functions */



















var base64_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(inp)
{
	var out = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;

	do {
		chr1 = inp.charCodeAt(i++);
		chr2 = inp.charCodeAt(i++);
		chr3 = inp.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;
		}

		out = out + base64_keyStr.charAt(enc1) + base64_keyStr.charAt(enc2) + base64_keyStr.charAt(enc3) +
		base64_keyStr.charAt(enc4);

		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";
	}while(i < inp.length);

	return out;
}


function decode64(inp)
{
	var out = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;

	var base64test = /[^A-Za-z0-9\+\/\=]/g;

	if(base64test.exec(inp))
	{
		alert("There were invalid base64 characters in the input text.\nValid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?\nExpect errors in decoding.");
	}

	inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do {
		enc1 = base64_keyStr.indexOf(inp.charAt(i++));
		enc2 = base64_keyStr.indexOf(inp.charAt(i++));
		enc3 = base64_keyStr.indexOf(inp.charAt(i++));
		enc4 = base64_keyStr.indexOf(inp.charAt(i++));

		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		out = out + String.fromCharCode(chr1);

		if (enc3 != 64)
		{
			out = out + String.fromCharCode(chr2);
		}
		if(enc4 != 64)
		{
			out = out + String.fromCharCode(chr3);
		}

		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";

	}while(i < inp.length);

	return out;
}
