function open_window($url,$name,$w,$h,$scroll)
{
  var $l = (screen.width - $w) / 2;
  var $t = (screen.height - $h) / 2;

  window.open($url,$name,'COPYHISTORY=NO,SCROLLBARS='+($scroll ? 'YES' : 'NO')+',RESIZABLE=1,WIDTH='+$w+',HEIGHT='+$h+',LEFT='+$l+',TOP='+$t);
}

//MM functions
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

//search
function SZListSrchSubmit(projekt, kod_objektu, kategorie, plocha_od, plocha_do, balkon, cena_od, Xdisp, Xblok, Xprod){
  document.dataf.projekt.value=projekt;
  document.dataf.kod_objektu.value=kod_objektu;
  document.dataf.kategorie.value=kategorie;
  document.dataf.plocha_od.value=plocha_od;
  document.dataf.plocha_do.value=plocha_do;
  document.dataf.balkon.value=balkon;
  document.dataf.cena_od.value=cena_od;
  document.dataf.disp.value=Xdisp;
  document.dataf.blok.value=Xblok;
  document.dataf.prod.value=Xprod;
  document.dataf.submit();
}

function XBGS(aksn, projekt, order, ord){
  document.dataf.projekt.value=projekt;
  document.dataf.order.value=order;
  document.dataf.ord.value=ord;
  document.dataf.action = aksn;
	document.dataf.str.value = '1';
  document.dataf.submit();
}

function existTest() {
  return true;
}
//other functions
function reloadSource() {
  document.location.reload();
}
function reloadMainSource() {
  opener.reloadSource();
}
function otherSource(where) {
  document.location.href=where;
}
function otherMainSource(where){
  opener.otherSource(where);
}
function returnOP(IDOP){
  document.dataf.idop.value=IDOP;
  document.dataf.submit();
}
function vlozOso(mail, prij, tel){
  document.dataf.prijmeni.value=prij;
  document.dataf.mail.value=mail;
  document.dataf.mobil.value=tel;
}
//open function's
function openSearch(idpr) 
{
	open_window('search.php?idpr='+idpr,'win_srch_new',400,300,false);
}

//open smlouva_menu
function openSmlMenu(a,b) {
  open_window("smlouva_menu.php?IDOP="+a+"&smltyp="+b,"smlouvy",500,400,true);
}
function openKal(a) {
  //alert("kal2.php?nacti=1&IDOP="+a);
  //window.open("kal2.php?nacti=1&IDOP="+a,"Příloha","width=750,height=470,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=yes,copyhistory=0");
  //window.open("pk/start.kal.php?print=1&IDOP="+a,"Příloha","width=750,height=470,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=yes,copyhistory=0");
  open_window("pk2/print.php?start&print&IDOP="+a,"Příloha",750,470,true);
}

function openSmlouva(a) {
  open_window("smlouva_ichbin.php?source="+a,"",750,470,true);
}
function openSmlEdit(a,b,d) {
  open_window("smlouva_editor.php?IDOP="+a+"&smltyp="+b+"&dodatek="+d,"",720,500,false);
}
function openSmlEditKZ(IDOP,i,IDKZ) {
	open_window('smlouva_generator.php?smltyp=kz&dodatek='+i+'&IDOP='+IDOP+'&IDKZ='+IDKZ,'',720,500,true);
}
function openSmlDel(a,b,d) {
  document.location.href = "smlouva_menu.php?IDOP="+a+"&smltyp="+b+"&dodatek="+d+"&del";
}

function openSmlGener(a,b,d) {
  if(d == "d") b = b + "&dodatek";
  else if(d == "NnV") b = b + "&navrhNaVklad";
  else if(d) b = b + "&prijmovyDoklad01&poplatekZaloha=" + d;
  //alert("smlouva_generator.php?IDOP="+a+"&smltyp="+b);
  open_window("smlouva_generator.php?IDOP="+a+"&smltyp="+b,"",720,500,false);
}

function openView(idsz) {
	open_window("prod_view.php?idszAr[]="+idsz,"win_view",646,440,false);
}
function openSklView(idsz) {
  window.open("prod_view.php?idszAr[]="+idsz,"win_view","width=646,height=440,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0");
}
function openGarView(idsz) {
  window.open("prod_view_g.php?idszAr[]="+idsz,"win_view","width=646,height=440,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0");
}
function openPrint() {
	open_window('print_engine.php','win_print',900,600,true);
}
function openSklPrint() {
  window.open("pr_engine_s.php","win_print","width=746,height=444,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0");
}
function openGarPrint() {
  window.open("pr_engine_g.php","win_print","width=746,height=444,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0");
}
function openSprint(idszAr) {

	queryStr = "";
	if(idszAr[1])
	{
		for (var n = 0; n < idszAr.length; n++)
	    {
			queryStr += "&idszAr[]="+idszAr[n];
		}
	}
	else
	{
		queryStr = "&idszAr[]="+idszAr.length;
	}

	//idsz="+idsz+"&
	window.open("prod_view.php?print=1&"+queryStr,"win_sprint","width=646,height=494,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0");
}
function openSklSprint(idsz) {
  window.open("pr_list_jedn_s.php?idsz="+idsz,"win_sprint","width=646,height=494,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0");
}
function openGarSprint(idsz) {
  window.open("pr_list_jedn_g.php?idsz="+idsz,"win_sprint","width=646,height=494,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0");
}

function openRez(idszAr, clr) 
{
//alert(idszAr.length);
	//alert(idszAr[1]);
	queryStr = "";
	if(idszAr[1])
	{
		for (var n = 0; n < idszAr.length; n++)
	    {
			queryStr += "&idszAr[]="+idszAr[n];
		}
	}
	else
	{
		queryStr = "&idszAr[]="+idszAr.length;
	}

	//idsz="+idsz+"&
	open_window("rez_form.php?caller="+clr+queryStr,"win_rez",670,580,true);
}

function openOP(mother,id) {
	open_window("obch_prip_vypis.php?motherID="+mother+"&userID="+id,"win_op",700,600,true);
}
function openDirectOP(idop) {
	open_window("obchodni_pripad.php?IDOP="+idop,"win_op",670,540,true);
}
function openSet(caller) {
  open_window("settings.php?caller="+caller,"win_st",270,140,false);
}
function openOso() {
  window.open("vloz_oso.php","win_st","width=410,height=440,toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=yes,copyhistory=0");
}

function resajzni(w)
{
	window.resizeTo(w,document.body.scrollHeight + 50);
}

function check(exp,str) {
  if (exp !="" && str!="") {
    if (str.match(exp)) {
      return true;
    }
    else {
      return false;
	}
  }
}
function checkform(prvek,typ) {
switch(typ){
	  /*case 'jmeno':
		//rstring = "^[^0-9]*$";
	  	break;*/
	  case 'email':
		rstring = "^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$";
	  	break;
	  case 'telefon':
		rstring = "^[ 0-9\.\+\/\-]{8,}$";
	  	break;
	  case 'psc':
		rstring = "^[ a-zA-Z0-9]{4,10}$";
	  	break;
	  case 'rico':
		rstring = "^[ 0-9]{6,12}$";
	  	break;
	  case 'ucet':
		//rstring = "^([ 0-9]{1,6}[\-]){0,1}([ 0-9]{6,10}[\/])[ 0-9]{4}$";
		rstring = "^[ 0-9\.\+\/\-]{5,}$";
	  	break;
	  default:
		rstring = "^.*$";
}
rres = check(rstring,document.getElementById(prvek).value);
//alert(document.getElementById(prvek).value+" / "+rstring);
if(document.getElementById(prvek).value.length>0 && !rres) return false;
else return true;
}

function keyer(f) 
{
	var kC = event.keyCode;
	if(kC==13)
	f.submit();
}

function skovejSplashky()
{
	MM_showHideLayers('splashky','','hide');
}

function showHideLayer(id)
{
  try
  {  
    if(document.getElementById(id).style.display != "block")
    {
      document.getElementById(id).style.display = "block";
    }
    else
    {
      document.getElementById(id).style.display = "none";
    }
  } catch(e) {}
  //alert(document.getElementById(id).style.display);
}

function page(i)
{
	document.dataf.str.value = i;
	document.dataf.submit();
}

/* --------------------------------------------------------------------------------- */

function systemMessages()
{
	open_window('sysmessages.php','sysmessages',850,600,true);
}

function sort(id,order)
{
	document.dataf.order.value = id;
	document.dataf.ord.value = order ? " ASC" : " DESC";
	document.dataf.submit();
}

function hint(text)
{
	window.status = text ? text : 'systém připraven';
	return true;
}

function highlight(id,yes)
{
	var obj = document.getElementById('ciara_'+id);
	obj.className = 'ciara '+(yes ? 'radek_podtrh_on' : 'radek_podtrh_off');
}
