var xmlhttp;
var var_state = '';


Array.prototype.in_array = function ( obj ) {
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( this[x] == obj ) return true;
	}
	return false;
}


function getObj(name)
{
  if (document.getElementById)
    {this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;}
  else if (document.all)
    {this.obj = document.all[name];
    this.style = document.all[name].style;}
  else if (document.layers)
    {this.obj = document.layers[name];
    this.style = document.layers[name];}
}

function hidestyle(whichid)
{
  mainobject = new getObj(whichid);
  if (mainobject.style.display=='none')
    {mainobject.style.display='';}
  else
    {mainobject.style.display='none';}
}
function hidestyleON(whichid)
{
  mainobject = new getObj(whichid);
  mainobject.style.display='none';
}

function hidestyleOFF(whichid)
{
  mainobject = new getObj(whichid);
  mainobject.style.display='';
}
function ChangeClass(whichid,clssname)
{
  mainobject = new getObj(whichid);
  mainobject.obj.className=clssname;
}

function DomWriteIn(whichid,str) {
  mainobject = new getObj(whichid);
  mainobject.obj.innerHTML = str;
}
function DomGetVal(whichid) {
  mainobject = new getObj(whichid);
  return mainobject.obj.value;
}
function DomGetHTML(whichid) {
  mainobject = new getObj(whichid);
  return mainobject.obj.innerHTML;
}
function DomSetVal(whichid,str) {
  mainobject = new getObj(whichid);
  mainobject.obj.value = str;
}
function WindowOpen(uri,w,h) {
  window.open(uri,'','width='+w+',height='+h+',status=yes,resizable=yes,scrollbars=yes');
}
function FotoOpen(uri,w,h) {
  window.open('/foto.php?f='+uri,'','width='+w+',height='+h+',left='+(screen.width/2-w/2)+',top='+(screen.height/2-h/2)+',status=yes,resizable=no,scrollbars=no');
}
function FotoGalleryOpen(id,ext,w,h,sekce) {
  window.open('/foto.php?id='+id+'&sekce='+sekce+'&ext='+ext,'','width='+w+',height='+h+',left='+(screen.width/2-w/2)+',top='+(screen.height/2-h/2)+',status=yes,resizable=no,scrollbars=no');
}

function RadioValue(r) {
  for(c=0;c<r.length;c++) {
    if(r[c].checked) return(r[c].value);
  }
  return false;
}

function GetFileName(p) {
  var pole = p.split('\\');
  var file = pole[pole.length-1];
  var pole = file.split('.');
  if(pole.length>=2) return pole[pole.length-2];
  if(pole.length>=1) return pole[pole.length-1];
}

function GetNumber(str) {
  return parseFloat(str);
}

function OpenWithAjax(url,div) {
  loadXMLdata(url+'&ajaxdiv='+div);
}

function loadXMLdata(url) {
  if(window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=state_Change;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
  }
  else if(window.ActiveXObject) {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if(xmlhttp) {
      xmlhttp.onreadystatechange=state_Change;
      xmlhttp.open("GET",url,true);
      xmlhttp.send();
    }
  }
  return true;
}

function state_Change() {
  var src,sources,i;
  if(xmlhttp.readyState==4) {
    var src = xmlhttp.responseText;
    if(src && src!='') {
      sources = src.split('#nextajax#');
      for(i=0;i<sources.length;i++) {

        var id = sources[i].substring(0,10);
        source = sources[i].substring(10,sources[i].length);
        tmp = source.split('#javascript#');
        
        if(tmp.length>0) source = tmp[0]; else source = '';
        if(tmp.length>1) javascript = tmp[1]; else javascript = '';
        
        //pokud nejde jen o js tak vlepit kod dovnitr
        if(id!='noajaxfunc') {
        
          mainobject = new getObj('product001');
          mainobject.obj.innerHTML = source;
        }
        
        if(javascript) {
          eval(javascript);
        }
      }
    }
  }
}


function CheckCheckBoxes(nm,bool) {
  alert('Při velkém počtu může tato funkce trvat i minutu. Vydržte prosím.');
  var inpts = document.getElementsByTagName('input');
  var i = 0;
  for (i=0;i<inpts.length;i++) {
    if (inpts[i].type=='checkbox' && inpts[i].name!='') {
      if(inpts[i].name.substring(0,nm.length)==nm) {
        inpts[i].checked = bool;
      }
    }
  }
}
