//
// $Id: utilities.js,v 1.4 2006/01/27 11:56:27 amoe Exp $
//
//****************** global variables *********************//
var ns4			= document.layers?1:0
var ie4			= document.all?1:0
var ns6			= document.getElementById&&!document.all?1:0
var oWindows	= new Array();
onerror 		= stopError;
	

//****************** subroutines **************************//
function stopError() {
	return true;
}

function openWindow(url, percent, name, left, top, toolbar, location, status, menubar, scrollbars, resizable) {
        var width = window.screen.availWidth * percent / 100;
        var height = window.screen.availHeight * percent / 100;
        var left = (left)?left:(window.screen.availWidth - width)/2;
        var top = (top)?top:(window.screen.availHeight - height)/2;

        openWindowScaled(url, width, height, name, left, top, toolbar, location, status, menubar, scrollbars, resizable);
}

function openWindowScaled(url, width, height, name, left, top, toolbar, location, status, menubar, scrollbars, resizable) {

        if(url) {
                var _wobj = new Object();
                var name = (name)?name:'_new';
                var toolbar = (toolbar)?toolbar:'no';
                var location = (location)?location:'no';
                var status = (status)?status:'no';
                var menubar = (menubar)?menubar:'yes';
                var scrollbars = (scrollbars)?scrollbars:'yes';
                var resizable = (resizable)?resizable:'yes';

                var ref = window.open(url,name,'left='+left+',top='+top+',toolbar='+toolbar+',location='+location+',status='+status+',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable+',width='+width+',height='+height+'');

                _wobj.name = name;
                _wobj.ref = ref;

                oWindows[oWindows.length] = _wobj;

                ref.focus();
        }

}

function closeWindow(name){
	
	if(name){
		for(i=0;i<top.oWindows.length;i++){
		var e = top.oWindows[i];
			if(e.ref && (e.ref == name)){
				e.ref.close();
			}
		}
	}
	else{
		for(i=0;i<top.oWindows.length;i++){
		var e = top.oWindows[i];
			if(e.ref){
				e.ref.close();
			}
		}
	}
}

function GetElementRef(id, wref){
		
	var wref = (wref)?wref:self;
	
		if (ie4  || ns6) {
				return wref.document.getElementById(id);
		}
		else {
			return wref.document.layers[id];
		}
}

function RefreshOpener(){
	
	var is_frameset = (opener.frames.length != 0)?true:false;
		if(is_frameset){
			opener.glMainRef.location.reload();
		}
		else{
			opener.location.reload();
		}
}

function Visible(id, wref){
	
	var eref = (wref)?wref.document.getElementById(id):self.document.getElementById(id);
	var disp = eref.style.display;
	disp = (disp == 'none')? "block":"none";
	eref.style.display = disp;
}

function SetSelected(name, val, wref){
	
	var f = (wref)?wref.document.forms:self.document.forms;
	
	for(i=0;i<f.length;i++){
		if(f[i][name]){
			for(j=0;j < f[i][name].length;j++){
				s = f[i][name][j];	
					if(s.value == val){
						s.selected = true;
						break;
					}
			}
		break;
		}
	}
}

function SwitchText(r, tfirst, tsecond){
	r.innerHTML = (r.status == 1)?tsecond:tfirst;
	r.status = (r.status == 1)?0:1;
}

function ChangeLogo(img, width, height, alt, targeturl){
	var eref = top.glFrameHeaderRef.document.images["imgLogo"];
	var aref = GetElementRef('aLogo', top.glFrameHeaderRef);
	
		if(!eref.status){
			var oImg = new Image;
			oImg.src = img;
			eref.src = oImg.src;
			aref.href = (targeturl)?targeturl:aref.href;
			width = (width)?width:eref.width;
			height = (height)?height:eref.height;
			alt = (alt)?alt:eref.alt;
			eref.width = width;
			eref.height=height;
			eref.alt = alt;
			eref.status = 1;
		}
}

function pround(n){
	var s = String(n);
	var pchar = s.split("");
	var roundup = false;
	for(var i=0;i<pchar.length;i++){
		if((pchar[i] == '.') && (pchar[i+1] >= 5)){
			roundup = true;
		}
	}
	return(roundup)?parseInt(n)+1:parseInt(n);
}

function setFormField(f, name, value, type){
	
	var type = (type)?type:'HIDDEN';
	var eref = (f)?f:self;
	var input = document.createElement('INPUT');
	input.type = type;
	input.name = name;
	input.value = value;
	eref.appendChild(input);
}

function SwapNode (from, to) {
    var source = document.getElementById(from);
    var destin = document.getElementById(to);
    var j=0;
    var abs=source.length;
    for(var i=0; i<abs; i++) {
        //reduced index, by "nulled option".
        var k=i-j;;
        if (source[k].selected==true) {
                destin[destin.length]=new Option(source[k].text, source[k].value);
                source[k]=null;
                j++;
        }
    }
    return true;
}

function MarkList(Id) {
        var SwapList = document.getElementById(Id);
        var abs=SwapList.length;
        for(var i=0; i<abs; i++) {
                SwapList[i].selected=true;
        }
}


