function popup(src, w, h, unique, scrollbars) {
	if (w == null) w = 450;
	if (h == null) h = 550;
	
	if (!scrollbars)
		scrollbars = 'no';
	else
		scrollbars = 'yes';
	
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	
	var wname = (unique) ? 'myPopup' : '';
	window.open(src, wname, 'scrollbars='+ scrollbars +',width='+w+',height='+h+', top='+ wint +',left='+ winl);
}

function popup_image(imageName,alt) {
  newWindow = window.open("","newWindow","scrollbars=no");
  newWindow.document.open();
  newWindow.document.write('<html>');
  newWindow.document.write('<script language="javascript">\n');
  newWindow.document.write('var NS = (navigator.appName=="Netscape")?true:false;\n');
  newWindow.document.write('function FitPic(){iWidth = (NS)?window.innerWidth:document.body.clientWidth; iHeight = (NS)?window.innerHeight:document.body.clientHeight; iWidth = document.images[0].width - iWidth; iHeight = document.images[0].height - iHeight; window.resizeBy(iWidth, iHeight); self.focus(); };')
  newWindow.document.write('</script>');
  newWindow.document.write('<title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onLoad="FitPic()" onBlur="self.close()">'); 
  newWindow.document.write('<img src=\"'+imageName+'\" alt=\"'+alt+'\" name=\"imgz\">');
  newWindow.document.write('</body></html>');
  newWindow.document.close();
  newWindow.focus();
}

function toggle(id) {
	var d = document.getElementById(id);
	d.style.display = (d.style.display == 'none') ? 'block' : 'none';
}

function do_rollovers() {
	if (!document.getElementById) return
		var imgOriginSrc;
		var imgTemp = new Array();
		var imgarr = document.getElementsByTagName('img');
		
		for (var i = 0; i < imgarr.length; i++) {
			if (imgarr[i].getAttribute('hsrc')) {
				imgTemp[i] = new Image();
				imgTemp[i].src = imgarr[i].getAttribute('hsrc');
				
				imgarr[i].onmouseover = function() {
					imgOriginSrc = this.getAttribute('src');
					this.setAttribute('src',this.getAttribute('hsrc'))
				}
				
				imgarr[i].onmouseout = function() {
					this.setAttribute('src',imgOriginSrc)
				}
				
			}
		}
}

function getMinutesFromTwoTimes(d_from,d_to) {
	var hourFrom = d_from.split(":")[0];
  var minFrom = d_from.split(":")[1];
  
  var hourTo = d_to.split(":")[0];
  var minTo = d_to.split(":")[1];
  
  var dateFrom = new Date(0000,00,00,hourFrom,minFrom);
  var dateTo = new Date(0000,00,00,hourTo,minTo);
  
  return ((dateTo.getTime() - dateFrom.getTime()) / 1000 / 60);
}

function checkEnter(event) {
	var NS4 = (document.layers) ? true : false;
  var code = 0;
    
  if (NS4)
		code = event.which;
	else
		code = event.keyCode;
		
	if (code==13)	return true;
}

function copy2clipboard(s) {
	if (window.clipboardData && clipboardData.setData )	{
		clipboardData.setData("Text", s);
	}	else {
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=meintext;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);	   
	}
}

function vScroll(content,container,speed) {
	var content = document.getElementById(content);
	var container = document.getElementById(container);
	var interval;
	
	if (speed == null) var speed = 2;
	
	content.style.top = container.style.height;
	
	var move = function() { 
		interval = setInterval(
			function() {
				var actual_top = content.style.top.substr(0,content.style.top.length - 2);
				if (-(actual_top) > content.offsetHeight) content.style.top = container.style.height;
				else content.style.top = (actual_top - 1) + "px";
			}
		,Math.round(40 / speed));
	}
	
	var stop = function() { clearInterval(interval); }
	
	container.onmouseover = function() { stop(); }
	container.onmouseout = function() { move(); }
	
	move();
}

function centerize(id) {
	var NS = (navigator.appName == "Netscape") ? true : false;
	var container = document.getElementById(id);
	var screen_h = (NS) ? window.innerHeight : document.documentElement.clientHeight;
	
	container.style.height = screen_h +"px";
}

function getXY(obj) {
	return [getX(obj),getY(obj)];
}

function getX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
		return curleft;
	}
}

function getY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return curtop;
	}
}

function view_props(obj) {
	for (prop in obj)
		alert('Property: '+ prop +'\nValue: '+ obj[prop]);
}

function msgPopup(msg, redirect) {
	var dd = confirm(msg);
	
	if (dd)
		window.location = redirect;
}

function toggler(id) {
	var d = document.getElementById(id);
	d.style.display = (d.style.display == 'none') ? 'inline' : 'none';
}

function updateHiddenDateField(name) {
	var date_hf = document.getElementById('f_'+ name);
	
	var date_toggler = document.getElementById('f_'+ name +'__toggler');
	
	var day_f = document.getElementById('f_'+ name +'__d');
	var month_f = document.getElementById('f_'+ name +'__m');
	var year_f = document.getElementById('f_'+ name +'__y');
	var hour_f = document.getElementById('f_'+ name +'__hour');
	var min_f = document.getElementById('f_'+ name +'__min');
	
	var date_value = year_f.value +"-"+ month_f.value +"-"+ day_f.value + (hour_f ? " "+ hour_f.value +":"+ min_f.value : "");
	
	if (date_toggler) {
		if (date_toggler.checked)
			date_hf.value = date_value;
		else
			date_hf.value = '';
	} else
		date_hf.value = date_value;
}

////////////////////////// PROTOTYPES //////////////////////////
Array.prototype.in_array = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

Array.prototype.multi_search = function (value,key) {
	var i;
	for (i=0; i < this.length; i++) {
		var cur_value = eval('this[i].'+ key);
		if (cur_value.toLowerCase() === value.toLowerCase()) {
			return i;
		}
	}
	return false;
};
