
/* JAVASCRIPT CORE */

    String.prototype.explode = function(separator, limit) {
	var count = 0;
        var string = this;
        array = new Array();
	        
        if(separator == '') return false;
		    
        while(true) {
            count++;
            if(limit != undefined && count == limit) break;
            pos = string.indexOf(separator);
            if(pos == -1) break;
            array.push(string.substr(0, pos));
            string = string.substr(pos+separator.length);
        }
	array.push(string);
	return array;
    }


/* BASICS */

DOM=(document.getElementById)?1:0;
NS4=(document.layers)?1:0;
IE4=(document.all)?1:0;
DHTML = (DOM || NS4 || IE4);
Op5=(navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1)?1:0;

function getObj(name) {
	if (DOM) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else
	if (IE4) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else
	if (NS4) {
		this.obj = getObjNN4(document.name);
		this.style = this.obj;
	}
	return this;
}

function getObjNN4(obj,name) {
	var x = obj.layers;
	var thereturn;
	for (var i=0;i<x.length;i++) {
		if(x[i].id == name) thereturn = x[i];
		else if (x[i].layers.length) var tmp = getObjNN4(x[i],name);
		if (tmp) thereturn = tmp;
	}
	return thereturn;
}

function sGetObj(name) {
	if (DOM) return document.getElementById(name);
	else if (IE4) return document.all[name];
	else if (NS4) return getObjNN4(document,name);
}

function getX(obj) {
	var curleft=0;
	if(DOM || IE4) {
		while(obj.offsetParent) {
			curleft+=obj.offsetLeft
			obj=obj.offsetParent;
		}
	} else
	if(NS4) curleft += obj.x;
	return curleft;
}

function getY(obj) {
	var curtop=0;
	if(DOM || IE4) {
		while (obj.offsetParent) {
			curtop+=obj.offsetTop
			obj = obj.offsetParent;
		}
	} else
	if (NS4) curtop += obj.y;
	return curtop;
}

function getWidth(obj) { return obj.offsetWidth; }
function getHeight(obj) { return obj.offsetHeight; }

function window_open(title, url, height, width, scrollbar) {
	window.open(url, title,'toolbar=no,scrollbars='+(scrollbar ? 'yes' : 'no')+',location=no,status=no,width='+width+',height='+height+',resizable=0');
}

function window_resize(w,h) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			top.outerWidth=w;
			top.outerHeight=h;
		}
		else top.resizeTo(w,h);
	}
}



/* FORM FUNCTIONS */



function Form() {
    this.name = '';
}

Form.prototype.init = function(name) {
    this.name = name;
}

Form.prototype.set = function(variable, value) {
    eval("document."+this.name+"."+variable+".value='"+value+"';");
}

Form.prototype.submit = function() {
    eval("document."+this.name+".submit()");
}

Form.prototype.get = function(name) {
    return eval("document."+this.name+"."+name+".value");
}

Form.prototype.change = function(name, value) {
    eval("document."+this.name+"."+name+"='"+value+"';");
}

/* COOKIE FUNCTIONS */



function createCookie(name,value,sec) {
	if (sec) {
		var date = new Date();
		date.setTime(date.getTime()+(sec*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



/* QUEUE FUNCTIONS */



function Queue() {
	this.queue = new Array();
}

Queue.prototype.add = function(name) {
	this.queue.push(name);
}

Queue.prototype.process = function() {
	var func = '';
	while(this.queue.length > 0) {
		func = this.queue.shift();
		eval(func);
	}
}



/* QUEUE */



init_queue = new Queue();                                                                     
dest_queue = new Queue();                                                                     
form = new Form(); form.init('main');                                                         



/* TABBED BROWSING */



function TabMenu(first) {
	this.active = first;
}

TabMenu.prototype.init = function() {
	this.change(this.active, true);
}

TabMenu.prototype.getid = function(id) {
	pos = id.lastIndexOf('_');
	return id.substring(0,pos);
}

TabMenu.prototype.swap = function(new_obj) {
	/*  new_obj.blur(); */
	new_id = this.getid(new_obj.id);
	this.change(this.active, false);
	this.active = new_id;
	this.change(this.active, true);
}

TabMenu.prototype.swap_by_id = function(new_id) {
	this.change(this.active, false);
	this.active = new_id;
	this.change(this.active, true);
}

TabMenu.prototype.change = function(id, state) {
	pos = id.lastIndexOf('_');
	while(pos!=-1) {
		if(state) this.select(id); else this.blur(id);
		id = id.substring(0,pos);
		pos = id.lastIndexOf('_');
	}
}

TabMenu.prototype.select = function(obj) {
	cnt = sGetObj(obj+'_cnt');
	if(cnt) cnt.className = cnt.className.replace(/lo/,'hi');
	tab = sGetObj(obj+'_tab');
	if(tab) tab.style.display = 'block';
}

TabMenu.prototype.blur = function(obj) {
	cnt = sGetObj(obj+'_cnt');
	if(cnt) cnt.className = cnt.className.replace(/hi/,'lo');
	tab = sGetObj(obj+'_tab');
	if(tab) tab.style.display = 'none';
}


/* STATS TREE */

    function StatsTree() {
    }

    StatsTree.prototype.change = function(obj) {
	if(!obj) return;

	var regx = new RegExp(/minus/);
    	if(regx.test(obj.src)) {
	    obj.src = obj.src.replace(/minus/, 'plus');
	} else {
	    obj.src = obj.src.replace(/plus/, 'minus');
	}
    }

    StatsTree.prototype.update = function(name) {
	var cont = sGetObj(name);

	hide_lev = 0;
	hide = 0;
	clb_vis = 0;

	for(var idx=0; idx < cont.childNodes.length; idx++)
	    if(cont.childNodes[idx].tagName == 'TR') {
		id = cont.childNodes[idx].id;
		obj = getObj(id);

		if(id.indexOf('clb') >= 0) {
		    clb_img = id.explode('_');
		    clb_img.pop();
		    clb_img = clb_img.toString().replace(/,/g, '_').replace(/clb/, 'clbt');
		    clb_img = sGetObj(clb_img);
		    if(clb_img) {
		        clb_vis = (clb_img.src.indexOf('minus') > 0 ? 1 : 0);
		    }

		    if(clb_vis==1 && hide==0) {
			obj.style.display = '';
		    } else {
		        obj.style.display = 'none';
		    }
	
		} else {
		
		    con_lev = ((id.explode("_")).length - 1);
		    clb_vis = 0;

		    if(hide == 1 && con_lev < hide_lev) {
			hide = 0;
		        hide_lev = 0;
		    }

		    if(hide == 1) {
		        obj.style.display = 'none';
		    } else {
		        obj.style.display = '';
		    }

		    con_img = sGetObj(id.replace(/cnt/, 'cntt'));
		    if(con_img) {
		        if(hide == 0)
		    	    if(con_img.src.indexOf('plus') > 0) {
		    	        hide = 1;
			        hide_lev = (id.explode("_")).length;
		    	    } else {
		    	        hide = 0;
			    }
		    }

		}
	    }		
    }

/* FIX */

function fix_div_columns_height(cols) {
    var hmax = 0;
    for(var idx=0; cols[idx]; idx++) {
        h = getHeight(sGetObj(cols[idx]));
		if(h > hmax) hmax = h;
    }
    for(var idx=0; cols[idx]; idx++) {
	document.getElementById(cols[idx]).style.height = hmax+'px';
    }
}

/* CHECK */

function check_email(val){                                                                                      
    re = /^[a-z0-9\-\._]+@([0-9a-z\-]*[a-z0-9]\.){1,}[a-z]{1,4}$/i;
    return val.match(re);
}                                                                                                              

function zobr_img(file, title) {
		 okno = window.open('', '', 'fullscreen=0,titlebar=0,locationbar=0,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,hotkeys=0,width=200,height=200');
		okno.document.open("text/html", "replace");
		okno.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
		okno.document.write('<HTML>');
		if (title == null) {
			title = 'Picture';
		}
		okno.document.write('<HEAD><title>'+title+'</title></HEAD>');
		okno.document.write('<BODY BOTTOMMARGIN="0" TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" BGCOLOR="#FFFFFF" onload="resizeTo((document.images.picture.width+15),(document.images.picture.height+35))">');
		okno.document.write('<img src="'+file+'" border=0 name="picture" onclick="window.close(self)">');			
		okno.document.write('<SCRIPT language=\"Javascript\">');
		//okno.document.write('moveTo(0,0);');
		okno.document.write('<\/SCRIPT>');
		okno.document.write('</body></html>');		
		okno.document.close();
		okno.focus();
	}	


