var base_src;
var base_db;
var cur_src;
var cur_db;
var hm_url;
var sc_url;

var lng_set;
var prvwdw;

var srtdir;
var curpage;
//var catno;
var catimgyn = new Array(20);
var cno;
var knd1no;

var hmwdw;
var tgtwdw;
var tgtwidth;
var tgtheight;


function set_base (hurl, lg, bsrc, bdb, csrc, cdb, scurl, hwdw, twdw, tgwd, tght)
{ base_src = bsrc; base_db = bdb; cur_src = csrc; cur_db = cdb; hm_url = hurl; sc_url = scurl; lng_set = lg; hmwdw = hwdw; tgtwdw = twdw; tgtwidth = tgwd; tgtheight = tght;}

function set_cat(sdir, cp, cn)
{srtdir = sdir; curpage = cp; cno = cn;} 

function base_echo()
{ alert ('bsrc: '+base_src+' ¦¦ bdb: '+base_db+' ¦¦ csrc: '+cur_src+' ¦¦ cdb: '+cur_db+' ¦¦ hm: '+hm_url+' ¦¦ sc: '+sc_url+' ¦¦ lg: '+lng_set);
}

function cat_echo()
{alert(' ¦¦ sd: '+srtdir+' ¦¦ cp: '+curpage+' ¦¦ cn: '+cno)}

function set_catimgno(catno, catstr, yn)
{
  catimgyn[catno] = new Array(); 
  catimgyn[catno][0] = catstr; 
  catimgyn[catno][1] = yn;
}


function preview()
{
  //par = par+'&keys='+document.getElementById('keywords').value;
  //par = par+'&imgurl='+document.getElementById('apaimageurl').value;
  //par = par+'&adurl='+document.getElementById('adurl').value;
  //par = par+'&address='+document.getElementById('address').value;
  //par = par+'&mail='+document.getElementById('mail').value;
  //par = par+'&phone='+document.getElementById('phone').value;
  //par = par+'&fax='+document.getElementById('fax').value;
  //par = par+'&country='+document.getElementById('country').value;
  //par = par+'&region='+document.getElementById('region').value;
  //par = par+'&usebox='+document.getElementById('usebox').checked;
  //par = par+'&boxid='+document.getElementById('boxid').value;
  //par = par+'&upload='+document.getElementById('upload').value;
  //par = par+'&useimg='+document.getElementById('useimg').value;  
  //par = par+'&pkind='+document.getElementById('pkind').value;  
  //par = par+'&imgsize='+document.getElementById('imgsize').value;  

  //prvwdw = window.open('./index.php?type=41'+par, 'apapreview', "dependent=yes,left=750,top=250,width=250,height=250,menubar=no,location=no,status=no,resizable=yes");

  prvwdw = window.open(base_db+'index.php?type=41', 'apapreview', "dependent=yes,left=750,top=250,width=305,height=420,menubar=no,location=no,status=no,resizable=yes");
  //prvwdw = window.open('./?type=41', 'apapreview', "dependent=yes,left=750,top=250,width=275,height=270,menubar=no,location=no,status=no,resizable=yes");
}

function setguilng()
{
window.open(hm_url+'index.php?lng='+document.getElementById('guilang').value,'apamain');
}

function setsorting(father)
{
  //document.getElementById('srtd').value = document.getElementById('sorting').value;
  srtdir = document.getElementById('sorting').value;
  switch(father)
  {
  case "1":
    parent.apa_split.overview.document.getElementById('srtd').value = srtdir;
    break;
  default:
  }

//window.open('./?srt='+document.getElementById('sorting').value+'&type=12','apa_header-r');
//window.open('./?srt='+document.getElementById('sorting').value,'apamain');
}

function open_window( url, windowname,left, top, width, height)
{
  window.open(url,windowname,'left='+left+',top='+top+',width='+width+',height='+height+',menubar=yes,location=yes,scrollbars=yes,toolbar=yes,status=yes,resizable=yes');
}

function show_pict1( url, title, width, height)
{
  wdw = window.open('../index.php?type=900&uf='+url+'&tt='+title, 'apadetailpic','width='+width+',height='+height+',menubar=no,location=no,scrollbars=no,toolbar=no,status=no,resizable=yes');
  //wdw.document.title = "APA - "+title;
}

function show_pict2( url, title )
{
  wdw.window.open('../index.php?type=900&uf='+url+'&tt='+title, 'apadetailpic','menubar=no,location=no,scrollbars=no,toolbar=no,status=no,resizable=yes');
  //wdw.document.title = "APA - "+title;
}

function open_close( url, windowname, left, top, width, height)
{
  window.open(url,windowname,'left='+left+',top='+top+',width='+width+',height='+height+',resizable=yes');
  self.close();
}

function DefStat()
{
  window.defaultStatus = 'TheAdPanel';
}

function aparesize(minwidth, minheight)
{
  width = minwidth; height = minheight;
//  if (window.width < minwidth) width = minwidth;
//  if (window.height < minheight) height = minheight;
  if (screen.availWidth < width) width = screen.availWidth;
  if (screen.availHeight < height) height = screen.availHeight;
  window.resizeTo (width,height);
}

function main_window_setup(minwidth,minheight,name)
{
  width = minwidth; height = minheight;
//  if (window.width < minwidth) width = minwidth;
//  if (window.height < minheight) height = minheight;
  if (screen.availWidth < width) width = screen.availWidth;
  if (screen.availHeight < height) height = screen.availHeight;
  window.name = name;
  window.defaultStatus = 'TheAdPanel';
  window.resizeTo (width,height);
}


function icatch()
{
  wdw = window.open('http://www.icatch.ch', 'icatch', "left=100,top=100,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}



function gtob()
{
  wdw = window.open(base_src+'?type=30&lng='+lng_set, 'apainfo', "left=10,top=10,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}

function impressum()
{
  wdw = window.open(base_src+'?type=31&lng='+lng_set, 'apainfo', "left=10,top=10,menubar=no,location=no,status=no,resizable=yes,width=400,height=500");
  wdw.focus();
}

function help(hno)
{

  //helpwdw = window.open(cur_db+'?type=90&hno='+hno, 'apahelp', "dependent=yes,left=650,top=10,width=400,height=200,menubar=no,location=no,status=no,resizable=yes");
  helpwdw = window.open('/index.php?type=90&hno='+hno, 'apahelp', "dependent=yes,left=650,top=10,width=400,height=200,menubar=no,location=no,status=no,resizable=yes");
  //helpwdw.setTimeout ('self.close()','120000');  // 120'000: TimeOut: close window nach 2 min.
  helpwdw.focus();

}

function setimgupl(width, height, pname)
{
  document.getElementById('imgup').src = "../_temp/"+pname;
  document.getElementById('imgup').width = width;
  document.getElementById('imgup').height = height;
  document.getElementById('imgup').visibility = "visible";
}

function setcatimgyn(catno, ulok)
{
 if (catimgyn[catno][1] == '1')
 {
   if(document.getElementById('photoyny').disabled)
   {
    document.getElementById('photoyny').disabled = false;
    document.getElementById('photoynn').disabled = false;
    document.getElementById('photoyny').checked = true;
    document.getElementById('photoynn').checked = false;
   }
   changepfmt(ulok);
 }
 else
 {
   document.getElementById('photoyny').disabled = true;
   document.getElementById('photoynn').disabled = true;
   document.getElementById('photoyny').checked = false;
   document.getElementById('photoynn').checked = true;
   changepfmt(ulok);
 }
 
}
function setimgscl()
{
 for (var i = 1; i <= 4; i++)
 {
   if(document.getElementById('photoyny').checked && 
      document.getElementById('apaimagen').checked &&
      document.getElementById('pkind'+i).checked)
   {
     document.getElementById('imgscl'+i).style.visibility = "visible";
   }
   else
   {
     document.getElementById('imgscl'+i).style.visibility = "hidden";
   }
 }
}

function setelement(el1,val1,el2,val2)
{
  if (el1 != "") {document.getElementById(el1).value= val1;}
  if (el2 != "") {document.getElementById(el2).value= val2;}
}

function chktal(maxl,id,fb,rm)
// check text area lenght
// max length, form input id, feedback value id, if >0 remove LF,CR
{
  var setStr = false;
  var txtStr = document.getElementById(id).value;
  if (rm > 0)
  {
   if (txtStr.indexOf('\n') >= 0)
   {setStr = true;txtStr = txtStr.replace('\n',', ');}
   if (txtStr.indexOf('\r') >= 0)
   {setStr = true; txtStr = txtStr.replace('\r',', ');}
  }
  var txtLen = txtStr.length;
  if (txtLen > maxl) 
  {
    setStr = true;
    txtStr = txtStr.substring(0,(maxl-1));
    txtLen = maxl;
    //document.getElementById(id).value = txtStr;
  }
  document.getElementById(fb).value = maxl - txtLen; 
  if (setStr) 
  {document.getElementById(id).value = txtStr;}
  //alert(prvwdw.document.title);
}

function changecat(width,height,uplok)
{ catkind = document.getElementById('catplace').value;
  //document.getElementById('catimg').src = "./_cat-s/cat-"+catimgyn[catkind][0]+".gif";
  //=>recall  from page by place()
  setcatimgyn(parseInt(catkind), uplok);
  document.apaplace01.submit.click()
  //document.apaplace01.submit();
  //document.forms[0].submit();
  //place('0',parseInt(catkind));
  //document.images[1].width = width;
  //document.images[1].height = height;
}



function changepld (uplValid)
{
  setimgscl();
  if (document.getElementById('apaimagen').checked)
  { document.getElementById('required2').value = "apaimageurl";
    document.getElementById('imgupl').src = "./_main/images/upload_bw.gif";
    document.getElementById('upload').value = "1";
    if(uplValid)
    {document.getElementById('imguplok').src = "./_main/images/ok_bw.gif";}
    else
    {document.getElementById('imguplok').src = "./_main/images/exclamation_bw.gif";}
    document.getElementById('apaimageurl').style.backgroundColor= "#FFFFFF";
    document.getElementById('pkind1').disabled= false;
    document.getElementById('pkind2').disabled= false;
    document.getElementById('pkind3').disabled= false;
    document.getElementById('pkind4').disabled= false;
    document.getElementById('imgup').style.visibility = "hidden";
  }
  else
  { document.getElementById('required2').value = "";
    document.getElementById('imgupl').src = "./_main/images/upload_cl.gif";
    document.getElementById('upload').value = "0";
    if(uplValid)
    {
     document.getElementById('imguplok').src = "./_main/images/ok.gif";
     document.getElementById('imgup').style.visibility = "visible";
    }
    else
    {
     document.getElementById('imguplok').src = "./_main/images/exclamation_red.gif";
     document.getElementById('imgup').style.visibility = "hidden";
    }
    //document.getElementById('apaimageurl').disabled= true;
    document.getElementById('apaimageurl').style.backgroundColor= "#CCCCCC";
    document.getElementById('pkind1').disabled= true;
    document.getElementById('pkind2').disabled= true;
    document.getElementById('pkind3').disabled= true;
    document.getElementById('pkind4').disabled= true;
  }
}

function changepfmt(uplValid)
{
  setimgscl();
  if (document.getElementById('photoynn').checked)
  {
    document.getElementById('useimg').value = "0";
    document.getElementById('imgplc').src =  "./_main/images/place1.gif";
    document.getElementById('imgplc').border =  "0";
    document.getElementById('useimg').border =  "0";
  }
  else
  {
    document.getElementById('useimg').value = "1";
    document.getElementById('imgplc').src =  "./_main/images/place2.gif";
    document.getElementById('imgplc').border =  "1";
    document.getElementById('useimg').border =  "1";
  }

  if (document.getElementById('photoynn').checked)
  {
    document.getElementById('apaimagey').disabled= true;
    document.getElementById('apaimagen').disabled= true;
    document.getElementById('pkind1').disabled= true;
    document.getElementById('pkind2').disabled= true;
    document.getElementById('pkind3').disabled= true;
    document.getElementById('pkind4').disabled= true;
    //document.getElementById('apaimageurl').disabled= true;
    document.getElementById('imgupl').src = "./_main/images/upload_bw.gif";
    if(uplValid)
    {document.getElementById('imguplok').src = "./_main/images/ok_bw.gif";}
    else
    {document.getElementById('imguplok').src = "./_main/images/exclamation_bw.gif";}
    document.getElementById('apaimageurl').style.backgroundColor= "#CCCCCC";
    document.getElementById('imgup').style.visibility = "hidden";
  }
  else
  {
    document.getElementById('apaimagey').disabled= false;
    if (document.getElementById('apaimagey').checked)
    {
      if(uplValid)
      {document.getElementById('imguplok').src = "./_main/images/ok.gif";
       document.getElementById('imgup').style.visibility = "visible";
      }
      else
      {document.getElementById('imguplok').src = "./_main/images/exclamation_red.gif";}
      document.getElementById('imgupl').src = "./_main/images/upload_cl.gif";
    }
    document.getElementById('apaimagen').disabled= false;
    if (document.getElementById('apaimagen').checked)
    {
      //document.getElementById('apaimageurl').disabled= false;
      document.getElementById('pkind1').disabled= false;
      document.getElementById('pkind2').disabled= false;
      document.getElementById('pkind3').disabled= false;
      document.getElementById('pkind4').disabled= false;      
      document.getElementById('apaimageurl').style.backgroundColor= "#FFFFFF";
    }
  }
}

function place(pno,catno)
{ 
  var str = "&pno=0";
  var cat = 0;
  if (catno > 0) {cat = catno;} else {cat = cno;}
  if (pno > 0) str = "&pno=1";
  str = str+"&lng="+lng_set;
  str = str+"&hm="+hm_url;
  str = str+"&catno="+cat;
  wdw = window.open(sc_url+'index.php?type=40'+str, 'apaplace'+pno, "left=10,top=10,menubar=no,location=no,status=yes,resizable=yes,scrollbars=yes");
  wdw.focus();
}

function llcwdw()
{
  wdw = window.open('./index.php?type=20', 'apainfo', "left=10,top=10,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}

function srch()
{
  var str = "";
  //str = str+"&lng="+lng_set;
  //str = str+"&db="+cur_db;
  //str = str+"&hm="+hm_url;
  str = str+"&srt="+srtdir;
  str = str+"&catno="+cno;
  str = str+"&knd1no="+knd1no;
  str = str+"&srch=1";
  searchresults = window.open(cur_db+'index.php?type=50'+str, 'apasearch', "left=50,top=50,menubar=no,location=no,status=no,dependent=yes,resizable=yes");
  searchresults.focus();
}


function openSelResult(cp)
{
  var str = './index.php?type=54';
  str = str+"&lng="+lng_set;
  str = str+"&hm_url="+hm_url;
  str = str+"&db_url="+cur_db;
  str = str+"&catno="+cno;
  str = str+"&srtd="+srtdir;
  if (cp == 0) {cp = document.getElementById('cp').value;}
  str = str+"&cp="+cp;
  window.open(str, tgtwdw, "left=50,top=50,width="+tgtwidth+",height="+tgtheight+",menubar=no,status=no,location=no,resizable=yes"); 
}

function openSetSelection(ctno,type)
{ 
  if (ctno > 0) 
  {catval = ctno;} 
  else 
  {
   catval = document.getElementById('cattoshow').value;
  }
  if(type <= 50)
  { cno = catval; 
    if (type == 49){knd1no = document.getElementById('knd1toshow').value;}
    srch();
  }
  else
  {
    if (catval > 0)
    { 
      if(type == 52)
      {
        var str = cur_db+type+lng_set+catval+'.php?';
      }
      else
      {
        var str = cur_db+'?type='+type;
        str = str+"&lng="+lng_set;
        str = str+"&catno="+catval+'&';
      }
      str = str+"hmurl="+hm_url;
      str = str+"&dburl="+cur_db;
      str = str+"&cp=0";
      if(ctno < 1 )
      {
        document.getElementById('cattoshow').style.backgroundColor= "";
      }
      if(ctno < 1){str = str+"&srtd="+srtdir;}
      else{str = str+"&srtd="+document.getElementById('srtd').value;}
      if(type == 51)
      {
       /*
       str = str+"&region="+document.getElementById('region').value;
       str = str+"&searchkeys="+document.getElementById('searchkeys').value;
       str = str+"&refno="+document.getElementById('refno').value;
       str = str+"&selcountry="+document.getElementById('selcountry').value;
       str = str+"&lng_srh="+document.getElementById('lng_srh').value;
       str = str+"&knd1_srh="+document.getElementById('knd1toshow').value;
       if(document.getElementById('knd2toshow')){str = str+"&knd2_srh="+document.getElementById('knd2toshow').value;}       
       str = str+"&validfrom="+document.getElementById('validfrom').value;
       str = str+"&validuntil="+document.getElementById('validuntil').value;
       str = str+"&pricefrom="+document.getElementById('pricefrom').value;
       str = str+"&priceuntil="+document.getElementById('priceuntil').value;
       str = str+"&currency="+document.getElementById('currency').value;
       
       */
      }
    window.open(str, tgtwdw, "left=50,top=50,width="+tgtwidth+",height="+tgtheight+",menubar=no,status=no,location=no,resizable=yes");
    }
    else
    {if (type == 51) {document.getElementById('cattoshow').style.backgroundColor= "#FF7D7D";}}
  }
}

function mailapa()
{
  wdw = window.open('./index.php?type=60&lng='+lng_set, 'apamail', "left=1,top=1,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}

function mailrcmt()
{
  wdw = window.open('./index.php?type=85&lng='+lng_set, 'apamail', "left=1,top=1,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}

function mailcat(mailname)
{
  wdw = window.open('../../?type=61&mailname='+mailname+'&lng='+lng_set, 'apamail', "left=1,top=1,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}

function mailid(mailname,cat)
{
  wdw = window.open('../../?type=62&mailname='+mailname+'&mailcat='+cat+'&lng='+lng_set, 'apamail', "left=1,top=1,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}

function mailprvid()
{
  wdw = window.open('./index.php?type=66&value='+document.getElementById('value').value+'&lng='+lng_set, 'apamail', "left=1,top=1,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}
function mailprvadr()
{
  wdw = window.open('./index.php?type=65&value='+document.getElementById('value').value+'&lng='+lng_set, 'apamail', "left=1,top=1,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}

function costs(catno)
{ if(catno != '000') {catno = document.getElementById('cattoshow').value;}
  wdw = window.open('./index.php?type=70&catno='+catno, 'apainfo', "left=10,top=10,menubar=no,location=no,status=no,resizable=yes");
  wdw.focus();
}


function ccrdd(id, no, nmnt, optest)
{ 
  n = document.getElementsByName(id)[no].value;
  v = document.getElementById(n+'d').value;
  
  if((v == nmnt) || (optest == 1))
  { 
    document.getElementById('ccardno').style.backgroundColor= "#CCCCCC";
    //document.getElementById('ccardno').disabled= true;
    document.getElementById('ccardm').style.backgroundColor= "#CCCCCC";
    //document.getElementById('ccardm').disabled= true;
    document.getElementById('ccardy').style.backgroundColor= "#CCCCCC";
    //document.getElementById('ccardy').disabled= true;
    document.getElementById('ccardvc').style.backgroundColor= "#CCCCCC";
    //document.getElementById('ccardvc').disabled= true;
    document.getElementById('ccardn').style.backgroundColor= "#CCCCCC";
    //document.getElementById('ccardn').disabled= true;
  }
  else
  { document.getElementById('ccardno').style.backgroundColor= "";
    //document.getElementById('ccardno').disabled= false;
    document.getElementById('ccardm').style.backgroundColor= "";
    //document.getElementById('ccardm').disabled= false;
    document.getElementById('ccardy').style.backgroundColor= "";
    //document.getElementById('ccardy').disabled= false;
    document.getElementById('ccardvc').style.backgroundColor= "";
    //document.getElementById('ccardvc').disabled= false;
    document.getElementById('ccardn').style.backgroundColor= "";
    //document.getElementById('ccardn').disabled= false;
  }
}

function ccrdd2(id, no, nmnt, optest, free, pay)
{ 
  n = document.getElementsByName(id)[no].value;
  v = document.getElementById(n+'d').value;
  
  //if((v == nmnt) || (optest == 1))
  if(v == nmnt)
  { document.getElementById('doplace').value= free;
    document.getElementById('doplace').style.backgroundColor= "#CFF4B8";
  }
  else
  { document.getElementById('doplace').value= pay;
    document.getElementById('doplace').style.backgroundColor= "#F4CABC";
  }
}



function disable_submit(id1, id2)
{
  document.apaplace03.submit();
  if( id1 != "" )
  { document.getElementById(id1).disabled= true; 
    document.getElementById(id1).style.backgroundColor= "#C0C0C0";
      }
  if( id2 != "" )
  { document.getElementById(id2).disabled= true;
    document.getElementById(id2).style.backgroundColor= "#C0C0C0";
  }

}

function boxnoctrl()
{ 
  if (document.getElementById('apaboxno').checked )
  {document.getElementById('mailr').style.color = "#DDEEFE";
   document.getElementById('phoner').style.color = "#DDEEFE";
   document.getElementById('faxr').style.color = "#DDEEFE";
   document.getElementById('required3').value = "apamail";
   document.getElementById('oneof').value = "";
  }
  else
  {document.getElementById('mailr').style.color = "black";
   document.getElementById('phoner').style.color = "black";
   document.getElementById('faxr').style.color = "black";
   document.getElementById('required3').value = "";
   document.getElementById('oneof').value = "apaphone,apafax,apamail";
  }
}

function mark_error(fldid)
{
document.getElementById(fldid).style.backgroundColor= "#FFC1C1";
}