


function setCookie(key, value, minutes) {
  value = encodeURIComponent(value); // hodnota value by měla být minimálně escapována pomocí funkce escape()
  value+='; path=/';
  // expirace
  var date = new Date();
  date.setTime(date.getTime() + minutes * 60 * 1000);
  value+='; expires=' + date.toGMTString();
  document.cookie = key + '=' + value;
}


function otevri_objednavku(typ,parm1,parm2) {
  if(typ == 1) {
    window.open("/objednavka.htm/radek="+parm1+"/sloupec="+parm2+"/co=vizitky", "_blank", "width=500,height=820,menubar=0,scrollbars=yes");
  }else if(typ == 2) {
    window.open("/objednavka.htm/co=bannery/typ="+parm1, "_blank", "width=500,height=850,menubar=0,scrollbars=yes");
  }else if(typ == 3) {
    window.open("/objednavka.htm/co=razitka/typ="+parm1, "_blank", "width=500,height=850,menubar=0,scrollbars=yes");
  }else if(typ == 4) {
    window.open("/objednavka.htm/co=tabule/typ="+parm1, "_blank", "width=500,height=850,menubar=0,scrollbars=yes");  
  }else if(typ == 5) {
    window.open("/objednavka.htm/co=svetelnereklamy", "_blank", "width=500,height=850,menubar=0,scrollbars=yes");
  }else if(typ == 6) {
    window.open("/objednavka.htm/co=reklamnipredmety", "_blank", "width=500,height=850,menubar=0,scrollbars=yes");
  }else if(typ == 7) {
    window.open("/objednavka.htm/co=polepyautvyloh", "_blank", "width=500,height=850,menubar=0,scrollbars=yes");
  }else if(typ == 8) {
    window.open("/objednavka.htm/co=reklamniplochy/typ="+parm1, "_blank", "width=500,height=850,menubar=0,scrollbars=yes");
  }
}

function prepocitej_cenu(page,pointer) {

  kusu = document.getElementById("c_kusu").value;
  cena = document.getElementById("cena").value;
    if(kusu.length == 0 || kusu < ks_omezeni) {
      document.getElementById("cena").value = "";
      alert("Nesprávně zadáno počet kusů (minimálně "+ks_omezeni+")");
      document.getElementById("c_kusu").focus();
    }else{
      if(kusu.search(/^[0-9]{1,4}$/) == 0) {
        //document.getElementById("cena").value = kusu * cenapolozky;
        zmen_typ(page,0,pointer);
      }else{
        document.getElementById("cena").value = "";
        alert("Nesprávně zadáno počet kusů");
        document.getElementById("c_kusu").focus();        
      }
    }
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


function getpointer() { // kvuli focusu zpet do policka po refreshi
  if(Get_Cookie("pointer")) {
    a = document.getElementById(Get_Cookie("pointer"));
    a.focus();
  }
}

function zmen_typ(page,norefresh,pointer) {
  setCookie("a_firma",document.getElementById("a_firma").value,60*24*30);
  setCookie("a_jmeno",document.getElementById("a_jmeno").value,60*24*30);
  setCookie("a_prijmeni",document.getElementById("a_prijmeni").value,60*24*30);
  setCookie("a_ulice",document.getElementById("a_ulice").value,60*24*30);
  setCookie("a_mesto",document.getElementById("a_mesto").value,60*24*30);
  setCookie("a_psc",document.getElementById("a_psc").value,60*24*30);
  setCookie("a_email",document.getElementById("a_email").value,60*24*30);
  setCookie("a_telefon",document.getElementById("a_telefon").value,60*24*30);
  setCookie("b_firma",document.getElementById("b_firma").value,1);
  setCookie("b_jmeno",document.getElementById("b_jmeno").value,1);
  setCookie("b_prijmeni",document.getElementById("b_prijmeni").value,1);
  setCookie("b_ulice",document.getElementById("b_ulice").value,1);
  setCookie("b_mesto",document.getElementById("b_mesto").value,1);
  setCookie("b_psc",document.getElementById("b_psc").value,1);
  setCookie("b_email",document.getElementById("b_email").value,1);
  setCookie("b_telefon",document.getElementById("b_telefon").value,1);
  setCookie("c_poznamka",document.getElementById("c_poznamka").value,1);
  if(document.getElementById("c_kusu")) setCookie("c_kusu",document.getElementById("c_kusu").value,0.1);
  if(document.getElementById("parm1")) setCookie("parm1",document.getElementById("parm1").value,0.1);
  if(document.getElementById("parm2")) setCookie("parm2",document.getElementById("parm2").value,0.1);
  if(document.getElementById("parm3")) setCookie("parm3",document.getElementById("parm3").value,0.1);
  if(document.getElementById("typ")) setCookie("parm1",(document.getElementById("typ").selectedIndex+1),0.1);
  if(pointer) setCookie("pointer",(pointer.id),1); // kvuli focusu zpet do policka po refreshi
  if(!norefresh) {
    /*
    if(document.getElementById("typ")) {
      location.replace("/objednavka.htm/co="+page+"/radek="+typid);
    }else{
    */
      location.replace("/objednavka.htm/co="+page);
    /*}*/
  }
}

function check_mail() {
    what = document.getElementById("a_email");
    if(what.value.search(/^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/) == 0) {
      what.style.backgroundColor = 'white';
    }else{
      what.style.backgroundColor = '#FF0033';
      what.focus();
    }
    return what.value.search(/^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/)==0;  
}
function check_jmeno() {
  what = document.getElementById("a_jmeno");
  if(what.value.search(/^[a-zA-ZáÁčČďĎěĚéÉíÍňŇóÓřŘšŠťŤúÚýÝžŽ]{3,15}$/) == 0){
    what.style.backgroundColor = 'white';
    return 1;
  }else{
    what.style.backgroundColor='#FF0033';
    what.focus();  
    return 0;
  }
}
function check_prijmeni() {
  what = document.getElementById("a_prijmeni");
  if(what.value.search(/^[a-zA-ZáÁčČďĎěĚéÉíÍňŇóÓřŘšŠťŤúÚýÝžŽ]{3,15}$/) == 0){
    what.style.backgroundColor = 'white';
    return 1;
  }else{
    what.style.backgroundColor='#FF0033';
    what.focus();  
    return 0;
  }
}
function check_kusu() {
    what = document.getElementById("c_kusu");
    if(!(what.value > 0)) {
      what.style.backgroundColor='#FF0033';
      what.focus();  
      return 0;
    }else{
      what.style.backgroundColor = 'white';
      return 1;    
    }
}
function check_sirka() {
    what = document.getElementById("c_sirka");
    if(!(what.value > 0)) {
      what.style.backgroundColor='#FF0033';
      what.focus();  
      return 0;
    }else{
      what.style.backgroundColor = 'white';
      return 1;    
    }
}
function check_vyska() {
    what = document.getElementById("c_vyska");
    if(!(what.value > 0)) {
      what.style.backgroundColor='#FF0033';
      what.focus();  
      return 0;
    }else{
      what.style.backgroundColor = 'white';
      return 1;    
    }
}
function check_cena() {
    what = document.getElementById("cena");
    if(what.value == "individuální") {
      what.style.backgroundColor = 'white';
      return 1;    
    }else if(!(what.value > 0)) {
      what.style.backgroundColor='#FF0033';
      what.focus();  
      return 0;
    }else{
      what.style.backgroundColor = 'white';
      return 1;    
    }
}

function check_obj() {
  ok = true;
  if(!check_jmeno()) ok = false;
  if(!check_prijmeni()) ok = false;
  if(!check_mail()) ok = false;
  if(!check_cena()) ok = false;
  if(document.getElementById("c_kusu")) {
    if(!check_kusu()) ok = false;
  }
  if(document.getElementById("c_sirka")) {
    if(!check_sirka()) ok = false;
  }
  if(document.getElementById("c_vyska")) {
    if(!check_vyska()) ok = false;
  }    
  zmen_typ(1,1) // ulozi hodnoty do cookie kdyby chyba php a vracel se formular
  return ok;
}