if(document.all) var is_msie = 1;
else var is_msie = 0;

function openwindow(url_address,window_width,window_height,framename,additional,is_picture) {
  sx = (screen.availWidth - window_width) / 2;
  sy = (screen.availHeight - window_height) / 2;
  params = "width="+window_width+",height="+window_height+",Left="+sx+",Top="+sy+",screenX="+sx+",screenY="+sy;
  if(additional>"") params += "," + additional;
  nw = window.open(url_address, framename, params);
  if(is_picture) {
    nw.document.open();
    nw.document.write("<html><head><title>Photos</title></head>\n");
    nw.document.write("<body marginwidth='0' marginheight='0' topmargin='0' leftmargin='0'>\n");
    nw.document.write("<table border=0 cellpadding=0 cellspacing=0 style='border:thin outset;height:"+window_height+"px;width:"+window_width+"px'><tr><td align='center' style='background-color:#D4D0C8'><img src='"+url_address+"' alt='photo' align='middle'></td></tr></table>\n");
    nw.document.write("</body>\n");
    nw.document.write("</html>\n");
    nw.document.close();
  }
  nw.focus();
  return nw;
}

function openmodal(obj,url_address,window_width,window_height,scroll,debug) {
  if(debug) {
    sx = (screen.availWidth-12 - window_width) / 2;
		sy = (screen.availHeight-50 - window_height) / 2;
    params = "width="+window_width+",height="+window_height+",Left="+sx+",Top="+sy+",screenX="+sx+",screenY="+sy;
    if(scroll=="no") nw = window.open(url_address, "_blank", params);
    else nw = window.open(url_address, "_blank", params+",scrollbars=yes");
    FromModalWindow = "";
  }
  else {
    if(scroll=="no") FromModalWindow = obj.showModalDialog(url_address, null, "help:no;scroll:no;status:no;center:yes;statusbar:no;minimize:no;maximize:no;border:thin;statusbar:no;dialogWidth:"+window_width+"px;dialogHeight:"+window_height+"px");
    else FromModalWindow = obj.showModalDialog(url_address, null, "help:no;status:no;center:yes;statusbar:no;minimize:no;maximize:no;border:thin;statusbar:no;dialogWidth:"+window_width+"px;dialogHeight:"+window_height+"px");
  }
  return FromModalWindow;
}

function disable_history_back() {
	//if(history.length>0) history.go(1-history.length);
	//if(window.history.length>0) window.history.go(+1);
	window.history.forward(1);
}

function changeuser(user_name) {
	if(self.parent.frames[0]) {
		var x = self.parent.frames[0].document.getElementById("usercell");
		if(x) x.innerHTML = user_name;
	}
}
function paint_login() {
	/*
	if(self.parent.frames[0]) {
		var x = self.parent.frames[0].document.getElementById("logout");
		if(x) self.parent.frames[0].paintme(x);
	}
	*/
	changeuser("<i>ismeretlen</i>");
}

function paint_home() {
	if(self.parent.frames[0]) {
		self.parent.frames[0].paint_home();
	}
}

function showpath(newpath) {
	if(self.parent.frames[0]) {
		self.parent.frames[0].putpath(newpath);
	}
}

function format_price(price) {
	if(price<0) {
		sign = "-";
		price = -price;
	}
	else sign = "";
  return sign + FormatNumberBy3(price, ",", ".");
}

function FormatNumberBy3(num, decpoint, sep) {
  // check for missing parameters and use defaults if so
  if (arguments.length == 2) {
    sep = ",";
  }
  if (arguments.length == 1) {
    sep = ",";
    decpoint = ".";
  }
  // need a string for operations
  num = num.toString();
  // separate the whole number and the fraction if possible
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = a[1]; // fraction
  z = "";


  if (typeof(x) != "undefined") {
    // reverse the digits. regexp works from left to right.
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    // add seperators. but undo the trailing one, if there
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    // reverse again to get back the number
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    // add the fraction back in, if it was there
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}

  
function check_number_input(obj) {
	if(obj.ownerDocument.parentWindow.event) {
		ch = obj.ownerDocument.parentWindow.event.keyCode;
		if(ch<48 || ch>57) return true;
	}
  number = obj.value;
  if(number=="-") return;
  re = /\./gi;
  number = number.replace(re, "");
  if(isNaN(number)) { obj.value = ""; return; }
  if(number<0) sign = -1;
  else sign = 1;
  number = sign * number;
  number = format_price(number);
  //if(number=="0") obj.value = "";
  //else obj.value = number;
  obj.value = number;
  return true;
}

function clear_inputs() {
	for(var i=1; i<=20; i++) {
		x = document.getElementById("xsrch_" + i);
		if(x) x.value = "";
	}
	return false;
}

function checkitemdates(type) {
	if(document.getElementById(type).checked || document.getElementById(type).value==" CHECKED") {
		if(document.getElementById(type+"_active")) document.getElementById(type+"_active").style.display = "";
		if(document.getElementById(type+"_none")) document.getElementById(type+"_none").style.display = "none";
	}
	else {
		if(document.getElementById(type+"_active")) document.getElementById(type+"_active").style.display = "none";
		if(document.getElementById(type+"_none")) document.getElementById(type+"_none").style.display = "";
	}
}
