// podpora IE4 a NS odstranena
var isDyn=isDOM=(document.getElementById);
// T_gobj = getRef
function T_gobj(id){return document.getElementById(id);}

/* nospam */
function nospamf(box, domain) {
 if(typeof(domain)=="undefined") domain="topinfo.cz";
 var proto=String.fromCharCode(109,97,105,108,116,111,58)
 w=window.open(proto+box+String.fromCharCode(64)+domain);
 if (w!=null) w.close(); //FF
}
function nospam(box, domain, title, attr) {
 if(typeof(domain)=="undefined") domain="topinfo.cz";
 if(typeof(attr)=="undefined") attr="";
 if(typeof(title)=="undefined") title=box+String.fromCharCode(64)+domain;
 document.write("<a href=\"javascript:nospamf('"+box+"', '"+domain+"')\""+(attr.length>0?" ":"")+attr+">"+title+"</a>");
}
function zavinac() {
 document.write(String.fromCharCode(64));
}
/* /nospam */

function checkEmail(email) {
 var re = /^[_\w\.\-]+@\w+((\-|\.)\w+)*\.[a-zA-Z]{2,4}$/;
 if (re.test(email)) return 1; else return 0;
}

// predelat na objekt, doplnit vlastnosti css, body class, close obrazkem dynamicky nahore, a tlacitka predchozi dalsi ?pole obrazku/AJAX
function oWin(pFileName, i_width, i_height, pTitle, pClose, pDir) {
  if (typeof pDir=="undefined") pdir=''
  var swidth=screen.width, sheight=screen.height;
  //doplnit testovani (0, None ?) spravne nacteni jinak nastavit swidth=590 a sheight=410 (pro 800x600)
  var min_x=100, min_y=100, max_x=swidth-50, max_y=sheight-190;
  var owidth=i_width>max_x?max_x:i_width<min_x?min_x:i_width, oheight=i_height>max_y?max_y:i_height<min_y?min_y:i_height;
  if ((owidth!=i_width) || (oheight!=i_height))
    photoWin = window.open("", "", "width="+(owidth+50)+",height="+(oheight)+",menubar=0,scrollbars,resizable,screenX=20,screenY=40,left=20,top=40");
  else
    photoWin = window.open("", "", "width="+(owidth+50)+",height="+(oheight+86)+",screenX=20,screenY=40,left=20,top=40");
  photoWin.document.writeln('<html><head>');
  photoWin.document.writeln('<meta http-equiv="Cache-control" content="no-cache" />');
  photoWin.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
  photoWin.document.writeln('<link rel="stylesheet" href="' + pDir + '/project.css" type="text/css" media="all">');
  photoWin.document.writeln('<title>' + pTitle + '</title>');
  photoWin.document.writeln('</head>');
  photoWin.document.writeln('<body class="owin">');
  photoWin.document.writeln('<div align="center"><b>' + pTitle + '</b><br />');
  photoWin.document.writeln('<a class="window" href="javascript:self.close()">');
  photoWin.document.writeln('<img src="' + pFileName + '" width="' + i_width + '" height="' + i_height + '" border="1" alt="' + pClose + '" /><br />');
  photoWin.document.writeln('<small>' + pClose + '</small></a><br /></div>');
  photoWin.document.writeln('</body></html>');
  photoWin.document.close();
  photoWin.focus();
  return false;
}

function pWin(url,p_width,p_height,win_title) {
  var swidth=screen.width, sheight=screen.height;
  //doplnit testovani (0, None ?) spravne nacteni jinak nastavit swidth=590 a sheight=410 (pro 800x600)
  var min_x=100, min_y=100, max_x=swidth-50, max_y=sheight-190;
  var width=p_width>max_x?max_x:p_width<min_x?min_x:p_width, height=p_height>max_y?max_y:p_height<min_y?min_y:p_height;
  var title = (typeof win_title == 'undefined')?'':win_title;
  pageWin = window.open(url,title,"width="+width+",height="+height+",menubar=0,scrollbars,resizable,screenX=20,screenY=40,left=20,top=40");
  pageWin.focus();
  return false;
}

// skryje/zobrazi element s danym elmID + zmeni src ikonky s danym imgID
function ShowHideElement(elmID, imgID) {
  var obj = T_gobj(elmID);
  if (obj) {
  	if(obj.style.display=='none') {
  		obj.style.display = 'block';
  		if(imgID) T_gobj(imgID).src = 'cms/img/ico/hide.gif';
  	} else {
  		obj.style.display = 'none';
  		if(imgID) T_gobj(imgID).src = 'cms/img/ico/show.gif';
  	}
  }
  return true;
}

// skryje/zobrazi element s danym elmID + zmeni src ikonky s danym imgID
var showhideelement1_init = false;
function ShowHideElement1() {
  if (!showhideelement1_init) {
    showhideelement1_init = true;
    $(".cms-showhide").click(function() {
      obj = $(this);
      var obj_img = $("img", obj);
      var img_src = obj_img.attr('src');
      img_src = img_src.substring(0, img_src.lastIndexOf('/')+1);
      var obj1 = obj.next();

      if (obj1.is(":visible")) {
        obj1.hide('fast', function() {
          obj.addClass('cms-box-header-radius')
          obj_img.attr('src', img_src+'show.gif');
        });
      }
      else {
        obj.removeClass('cms-box-header-radius');
        obj1.show('fast');
    	obj_img.attr('src', img_src+'hide.gif');
      }
    });
  }
}

// pro formsy - moznost pridavani dalsich policek se stejnym name
function multiFieldAppend(name) {
  var div = T_gobj('div_multi_'+name);
  var divChildren = div.getElementsByTagName('div');
  var lastChildObject = divChildren[divChildren.length-1];
  var id = lastChildObject.id;
  var index = id.substring(('line_'+name+'_').length, id.length); //zjistit index id posledni polozky a pripsat jednicku
  var fieldType = T_gobj('fid_'+name+'_'+index).type;
  if(fieldType=='select-one') fieldType='select';
  else if(fieldType=='textarea') fieldType='textarea';
  else fieldType='input';
  index = parseInt(index)+1;

  var newId = 'fid_'+name+'_'+index; //id pro novy element
  var newIdSup = 'line_'+name+'_'+index;  // id pro novy nadrazeny element
  var newChildObject = lastChildObject.cloneNode(true);
  var inputElement = newChildObject.getElementsByTagName(fieldType)[0];

  if (newChildObject.getElementsByTagName('a').length!=0){ //podminka pro fm => prace s tagem <a>
	  var anchorElement = newChildObject.getElementsByTagName('a')[0];
	  var re = new RegExp ("&field=.*");
	  anchorElement.href = anchorElement.href.replace(re,'&field=' + newId); // zmeni href pro novy <a>
  }

  newChildObject.id = newIdSup;
  inputElement.id = newId;
  inputElement.value = '';
  div.appendChild(newChildObject);
  return true;
}

var objselectall_init = false;
function selectAll() {
  if (!objselectall_init) {
    objselectall_init = true;
    $(':checkbox[name=selectAll]').each(function() {
      obj = $(this);
      obj.change(function() {
        obj = $(this);
        var skupina = obj.val();
        if (obj.is(':checked')) $(':checkbox[name='+skupina+']').attr('checked','checked');
        else $(':checkbox[name='+skupina+']').removeAttr('checked');
      });
    });
  }
}

