// JavaScript Document

var is_msie = document.all ? 1 : 0;

function openwindow(url_address,window_width,window_height,framename,additional,is_picture,title) {
  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) {
  	var metatitle = title ? title : "Photo";
    nw.document.open();
    nw.document.write("<html><head><title>" + metatitle + "</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 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 showProgramGallery(program_id, lang, pc_apc) {
	openwindow(
		"/programs/gallery.php?id="+program_id+"&lang="+lang+(pc_apc ? "&pc_apc="+pc_apc : ""),
		700,
		600,
		"ProgramGallery",
		"status=yes");
	return false;
}

function stopPaste(obj,event) {
	if(document.all) {
		if(event.type=="beforepaste") {
			event.cancelBubble = true;
			obj.blur();
		}
	}
  else {
  	if(
			(event.keyCode==45 && event.shiftKey==true) ||
			(event.charCode==118 && event.ctrlKey==true)
		) obj.blur();
		//event.stopPropagation();
  }
	return false;
}

function format_number(number, with_decimal) {
	number = number.toFixed(with_decimal);
	number += '';
	x = number.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? (currency=='HUF' ? ',' : '.') + '<div style="vertical-align:top;display:inline; font-size:0.9em !important;">'+x[1]+'</div>&nbsp; ' : '';
	var rgx = /(\d+)(\d{3})/;
	var sep = currency=='HUF' ? '.' : ',';
	while(rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + sep + '$2');
	}
	return x1 + x2;
}

function checkemail(str) {
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(str)) return true;
	else return false;
}

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;
}
