// JavaScript Document

 // id browsers
 var iex=(document.all);   //explorer
 var moz=(window.sidebar); //mozilla


function changeMenuColor(nameElem)
{
 element=document.getElementById(nameElem);
 if (element.style.color=='white')
  element.style.color='#E7D1C2';
 else
  element.style.color='white';
}

//schovej a ukaz mapu
function changeMap(which)
{    
 elem="map"+which;
 if (document.getElementById(elem).style.visibility=='visible')
  {
   for (i=1;i<15;i++)
    {
     elem="map"+i;
     document.getElementById(elem).style.visibility='hidden';
    }
  }
 else
  {
   for (i=1;i<15;i++)
    {
     elem="map"+i;
     document.getElementById(elem).style.visibility='hidden';
    }     
   elem="map"+which;
   document.getElementById(elem).style.visibility='visible';
  }
}

//schovej a ukaz mapu 2
function changeMap1(which,namek)
{    
 elem="map"+which;
 if (document.getElementById(elem).style.visibility=='visible')
  {
   for (i=1;i<15;i++)
    {
     elem="map"+i;
     document.getElementById(elem).style.visibility='hidden';
    }
  }
 else
  {
   for (i=1;i<15;i++)
    {
     elem="map"+i;
     document.getElementById(elem).style.visibility='hidden';
    }     
   elem="map"+which;
   document.getElementById(elem).style.visibility='visible';
   document.getElementById("selectKraj").selectedIndex=which;
  }
}

//vyber regionu a okresu maska: index.php?select=1&idR=-1&idD=-1
function selectObject(category,id)
{
 if (category=="selectKraj")
  {
   if (id==0) id=-1;
   if (iex) window.location="index.php?select=1&amp;idR="+id+"&amp;idD=-1";
   else if (moz) window.location="index.php?select=1&idR="+id+"&idD=-1";
  }
 else if ((category=="selectOkres") && (id.lastIndexOf("idR=&")!=0))
  {
   if (iex) window.location="index.php?select=1&amp;"+id;
   else if (moz) window.location="index.php?select=1&"+id;
  }
}

//vyber regionu a okresu pro rozsirene vyhledavani maska: index.php?select=1&idR=-1&idD=-1&extSearch=1
function selectObject2(category,id)
{
 if (category=="selectKrajES")
  {
   if (id==0) id=-1;
   if (iex) window.location="index.php?select=1&amp;idR="+id+"&amp;idD=-1&amp;extSearch=1";
   else if (moz) window.location="index.php?select=1&idR="+id+"&idD=-1&extSearch=1";
  }
 else if ((category=="selectOkresES") && (id.lastIndexOf("idR=&")!=0))
  {
   if (iex) window.location="index.php?select=1&amp;"+id+"&amp;extSearch=1";
   else if (moz) window.location="index.php?select=1&"+id+"&extSearch=1";
  }
}

//vyber regionu pro last moment maska: index.php?select=2&region=1
function selectObject3(id)
{
 if (iex) window.location="index.php?select=2&amp;region="+id;
 else if (moz) window.location="index.php?select=2&region="+id;
}

//vyber regionu pro hledam ubytovani maska: index.php?select=2&region=1
function selectObject4(id)
{
 if (iex) window.location="index.php?select=3&amp;region="+id;
 else if (moz) window.location="index.php?select=3&region="+id;
}

//vyber regionu pro hledam ubytovani maska: index.php?select=5&inmenu=3&region=6 v klientskem centru
function selectObject5(id)
{
 if (iex) window.location="index.php?select=5&amp;inmenu=3&amp;region="+id;
 else if (moz) window.location="index.php?select=5&inmenu=3&region="+id;
}

//vyber regionu a okresu maska pro area city: index.php?select=1&idR=-1&idD=-1
function selectObject6(category,id)
{
 if (category=="selectKraj")
  {
   if (id==0) id=-1;
   if (iex) window.location="../index.php?select=1&amp;idR="+id+"&amp;idD=-1";
   else if (moz) window.location="../index.php?select=1&idR="+id+"&idD=-1";
  }
 else if ((category=="selectOkres") && (id.lastIndexOf("idR=&")!=0))
  {
   if (iex) window.location="../index.php?select=1&amp;"+id;
   else if (moz) window.location="../index.php?select=1&"+id;
  }
}

//zmeni mapu v danem okrese
function prevMap(kraj,okres,stav)
{
 var typ=new Array("a","b","c","d","e","f","g","h","i","j");
 if (iex)
  {
   var str=new String(mapaOkresu.src);
   var okr=str.substr(str.lastIndexOf("reg")+4,1);
   if (stav==1)
    mapaOkresu.src="maps/reg"+kraj+typ[okres]+".gif";
   else if (okr!=".")
    mapaOkresu.src="maps/reg"+kraj+typ[okres]+".gif";
   else
    mapaOkresu.src="maps/reg"+kraj+".gif";
  }
 else if (moz)
  {
   var str=new String(document.getElementById("mapaOkresu").src);
   var okr=str.substr(str.lastIndexOf("reg")+4,1);
   if (stav==1)
    document.getElementById("mapaOkresu").src="maps/reg"+kraj+typ[okres]+".gif";
   else if (okr!=".")
    document.getElementById("mapaOkresu").src="maps/reg"+kraj+typ[okres]+".gif";
   else
    document.getElementById("mapaOkresu").src="maps/reg"+kraj+".gif";
  }
}

//vytvori a otevre nove okno
function openWindow(ref,width,height)
{
 if (width==0) width=window.screen.width-100;
 if (height==0) height=window.screen.height-100;
  iMyWidth = (window.screen.width/2) - ((width/2) + 10)
  iMyHeight = (window.screen.height/2) - ((height/2) + 25)   
  window.open(ref, "JSL","height="+height+",width="+width+",resizable=no,left=" +
    iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + 
    iMyHeight + ",scrollbars=no");
}

//zobrazi/schova element
function showHideElement(elem)
{
 if (document.getElementById(elem).style.visibility=='visible') 
  document.getElementById(elem).style.visibility='hidden';
 else
  document.getElementById(elem).style.visibility='visible';
}

function setSize(width,height)
{
 if (iex) resizeTo(width,height);
 else resizeTo(width,height+150);
}

//ulozi data pro ext. vyhledavani
function saveData()
{
 document.getElementById("uRegion").value=document.getElementById("idselectKrajES").selectedIndex;
 document.getElementById("uDistrict").value=document.getElementById("idselectOkresES").options[document.getElementById("idselectOkresES").selectedIndex].text;
 document.getElementById("uArea").value=document.getElementById("idselectPohoriES").selectedIndex;
 document.getElementById("uBaths").value=document.getElementById("idselectLazneES").options[document.getElementById("idselectLazneES").selectedIndex].text;
 document.getElementById("uPrise").value=document.getElementById("idselectCenaES").options[document.getElementById("idselectCenaES").selectedIndex].text;
 document.getElementById("uCapacity").value=document.getElementById("idselectKapacitaES").options[document.getElementById("idselectKapacitaES").selectedIndex].text;
}

//smeruj a hledej
function fullSearch(elem)
 {
  if (iex)
   window.location='http://www.apartma.cz/index.php?select=1&amp;idR=-1&amp;idD=-1&amp;fulltext='+document.all.item(elem).value;
  else if (moz)
   window.location='http://www.apartma.cz/index.php?select=1&idR=-1&idD=-1&fulltext='+document.getElementById(elem).value;
 }

//pocitadlo poctu znaku
function counter(source,dest)
{
 document.getElementById(dest).innerHTML=source.value.length+1;
 if ((source.value.length+1)>151)
  {
   var str=source.value;
   source.value=str.substr(0,150);
  }
}

//vyber typu tur. cile
function selectTypeTD(category,id)
 {
  //kategorie
  typ=0;
  if (category=="selMesto") typ=1;
  if (category=="selOstatni") typ=5;
  if ((typ==1) || (typ==5))
   {
    if (id=="0") id="1";
    var adress=new String(window.location);
    var loc="";
    loc=adress.substr(0,adress.lastIndexOf("typeTD")-1);
    window.location=loc+"&typeTD="+typ+"&idTD="+id;
   }
  //kraj a okres
  else
   {
    kraj="";
    okres="";
    if (category=="selKraj")
     {
      if (id==0) id=-1;
      kraj="&region="+id;
     }
    if (category=="selOkres") okres="&district="+(id-1);
    var adresa=window.location;
    var adr=new String(adresa);
    var smeruj="";
    if (kraj!="")
     {
      //vyrez region
      smeruj1=adr.substr(0,adr.lastIndexOf("region")-1);
      smeruj2=adr.substr(adr.lastIndexOf("district")-1,adr.length-adr.lastIndexOf("region")-1);
      smeruj=smeruj.concat(smeruj1,kraj,smeruj2);
        //vyrez okres
        okres="&district=-1";
        smeruj3=smeruj.substr(0,smeruj.lastIndexOf("district")-1);
        smeruj4=smeruj.substr(smeruj.lastIndexOf("typeTD")-1,smeruj.length-smeruj.lastIndexOf("typeTD")+1);
        delete(smeruj);
        var smeruj="";
        smeruj=smeruj3.concat(okres,smeruj4);
        okres="";
     }
    if (okres!="")
     {
      //vyrez okres
      smeruj1=adr.substr(0,adr.lastIndexOf("district")-1);
      //smeruj2=adr.substr(adr.lastIndexOf("typeTD")-1,adr.length-adr.lastIndexOf("typeTD")+1);
      smeruj2=adr.substr(adr.lastIndexOf("typeTD")-1,adr.length);
      smeruj=smeruj.concat(smeruj1,okres,smeruj2);
     }
    if (smeruj.indexOf("idP")!=-1)
     {
      //vyrez stranku
      var pom1="";
      pom1=smeruj.substr(0,smeruj.lastIndexOf("idP")-1);
      smeruj=pom1;
     }
    window.location=smeruj;
   }
 }

//vyber okresu a regionu u tur. cile
function selectRegDisTD(kra,okr)
 {
  kraj="&region="+(kra);
  okres="&district="+(okr);
  var adresa=window.location;
  var adr=new String(adresa);
  var smeruj="";
  //vyrez region
  smeruj1=adr.substr(0,adr.lastIndexOf("region")-1);
  smeruj2=adr.substr(adr.lastIndexOf("district")-1,adr.length-adr.lastIndexOf("region")-1);
  smeruj=smeruj.concat(smeruj1,kraj,smeruj2);
  adr=new String(smeruj);
  smeruj="";
  //vyrez okres
  smeruj1=adr.substr(0,adr.lastIndexOf("district")-1);
  smeruj2=adr.substr(adr.lastIndexOf("typeTD")-1,adr.length);
  smeruj=smeruj.concat(smeruj1,okres,smeruj2);
  window.location=smeruj;   
 }

//filtrovani turistickych cilu
function selectTD(elem)
 {
  var adress=new String(window.location);
  var innerText1="";
  var innerText="";
  innerText1=adress.substr(0,adress.lastIndexOf("typeTD")-1);
  if (innerText1.indexOf("idP")!=-1)
   {
    //vyrez stranku
    var pom1="";
    var pom2="";
    pom1=innerText1.substr(0,innerText1.lastIndexOf("idP")-1);
    pom2=innerText1.substr(innerText1.lastIndexOf("idTD")-1,innerText1.length);
    innerText=innerText.concat(pom1,pom2);
   }
  else
   innerText=innerText1;
  if (iex)
   {
    if (uTypeTD[0].checked) innerText=innerText.concat("&typeTD=2");
    else if (uTypeTD[1].checked) innerText=innerText.concat("&typeTD=3");
    else if (uTypeTD[2].checked) innerText=innerText.concat("&typeTD=4");
    else if (uTypeTD[3].checked) innerText=innerText.concat("&typeTD=6");
    else if (uTypeTD[4].checked) innerText=innerText.concat("&typeTD=7");
    else if (uTypeTD[5].checked) innerText="index.php?select=4&region=-1&district=-1&typeTD=8&idP=1";
   }
  if (moz)
   {
    var pole=new Array();
    pole=document.getElementsByTagName("input");
    if (pole[1].checked) innerText=innerText.concat("&typeTD=2");
    else if (pole[2].checked) innerText=innerText.concat("&typeTD=3");
    else if (pole[3].checked) innerText=innerText.concat("&typeTD=4");
    else if (pole[4].checked) innerText=innerText.concat("&typeTD=6");
    else if (pole[5].checked) innerText=innerText.concat("&typeTD=7");
    else if (pole[6].checked) innerText="index.php?select=4&region=-1&district=-1&typeTD=8&idP=1";
   }
  window.location=innerText;
 }

//zmeni jazyk ceniku a presmeruje pro klienta
function setLangPriseC(elem)
 {
  if (iex)
   window.location='index.php?select=5&amp;inmenu=4&amp;inmenu4=3&amp;lg='+elem.value;
  if (moz)
   window.location='index.php?select=5&inmenu=4&inmenu4=3&lg='+elem.value;
 }
  
//presmeruje na turisticke cile
function redirectTE()
 {
  if (iex)
   window.location='index.php?select=4&amp;region=-1&amp;district=-1&amp;typeTD=1&amp;idTD=2';
  if (moz)
   window.location='index.php?select=4&region=-1&district=-1&typeTD=1&idTD=2';
 }
  
