// Easychange JavaScript library
// Rich Gray
// 23/05/2003 18:57

var IE  = (document.all);
var IE4 = (document.all && !document.getElementById);
var NS4 = (document.layers);
var IE6 = (document.all && document.getElementById);
var Moz = (document.getElementById && !document.all);
var Mac = (navigator.userAgent.indexOf("Mac") != -1);

function pop(pop_url) {
    window.open(pop_url,"","width=450,height=450,scrollbars");
}

function pop2(pop_url) {
    window.open(pop_url,"","width=500,height=500,scrollbars");
}

function pop_it(pop_url,pop_params) {
    window.open(pop_url,"",pop_params);
}

function popx(pop_url,w,h,sc) {
    window.open(pop_url,'noname','width='+w+',height='+h+(sc ? ',scrollbars=yes,resizable=yes' : '')+',location=no,status=no,toolbar=no');
}

// Clear a DDL
function clear_ddl(ddl) {
	var i;
	for (i=ddl.options.length;i>=1;i--) {
	    ddl.options[i] = null;
	}
	ddl.selectedIndex = -1;
}

// Populate DDL
function populate_ddl(ddl,keyValue,null_string,pArray,selected) {
	if (keyValue != "" && pArray[keyValue]) {
	    var myArr = pArray[keyValue];
	    var i;
        for (i=0;i<myArr.length;i=i+2) {
            if (myArr[i] != 'EOF') {
                ddl.options[ddl.options.length] = new Option(myArr[i + 1],myArr[i],false,(myArr[i] == selected));
	        }
		}
	}
	else {
		ddl.options[ddl.options.length] = new Option(null_string,0);
	}
}

// Repopulate ddl
function option_selected(ddl1,ddl2_name,null_string,pArray) {
    var thisForm = ddl1.form;
    var ddl2 = thisForm[ddl2_name];
    clear_ddl(ddl2);
    populate_ddl(ddl2,ddl1.options[ddl1.selectedIndex].value,null_string,pArray,-Infinity);
	return true;
}

// Make a hidden item appear or disappear
function toggle_display(id,type,but,htext,vtext) {
    if (NS4) {
        visible = (document.layers[id].visibility == 'hide' ? 'show' : 'hide');
        document.layers[id].visibility = visible;
        but.value = (visible == 'hide' ? vtext + ' >>' : '<< ' + htext);
        but.title = (visible == 'hide' ? vtext : htext);
        but.form.ao_tag.value = (visible == 'hide' ? 0 : 1);
    }
    else if (IE) {
        visible = (document.all[id].style.display == 'none' || document.all[id].style.display == '' ? type : 'none');
        document.all[id].style.display = visible;
        but.value = (visible == 'none' ? vtext + ' >>': '<< ' + htext);
        but.title = (visible == 'none' ? vtext : htext);
        but.form.ao_tag.value = (visible == 'none' ? 0 : 1);
    }
    else if (Moz) {
        visible = (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == '' ? type : 'none');
        document.getElementById(id).style.display = visible;
        but.value = (visible == 'none' ? vtext + ' >>': '<< ' + htext);
        but.title = (visible == 'none' ? vtext : htext);
        but.form.ao_tag.value = (visible == 'none' ? 0 : 1);
   }
}

var gv0 = null; // Initial %
var gv1 = null; // Text for second % display
var gv2 = null; // Target name
function show_other_percent() {
    var lp0 = null;
    var lp1 = null;
    var onl = (typeof this.value == 'undefined');
    var inp = (onl ? 0 : this.value.replace(',','.'));
    lp0     = (onl ? gv0 : (isNaN(inp) ? 0 : inp));
    if (lp0 == null) return false;

    lp0 = Math.min(100,Math.max(0,lp0));
    lp1 = 100.00 - lp0.toFixed(2);
    lp1 = (parseInt(lp1) == Math.ceil(lp1) ? parseInt(lp1) : lp1.toFixed(2));

    document.getElementById(gv2).innerHTML = '&nbsp;'+gv1+': ('+lp1+' %)';

    if (!onl && (lp0 == 100 || lp0 == 0)) this.value = lp0;
    return true;
}
