function setFieldValueAndSubmit(formname, field, val){
    document.getElementById(field).value = val;
    document.getElementById(formname).submit();
}

function charRecount(){ 
  area = document.getElementById('catalogueDesc'); 
  if(area.value.length > 1000) area.value = area.value.substr(0,1000); 
} 

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function branchHandler(val){
  (val==1) ? showBranchBlock() : hideBranchBlock();
}

function checkBranch(){
    value = readCookie('dbbl');
    newVal = (value==1) ? 0 : 1;
    document.cookie='dbbl='+newVal+';';
    (newVal==1)? showBranchBlock() : hideBranchBlock();  
 
}


function showBranchBlock(){
    document.getElementById('bannerData').style.display = 'block';
    document.getElementById('banner').style.height='100%';             
    document.getElementById('branchButton').src='obr/up_btn.png';
    document.getElementById('banner').className='banner';
}

function hideBranchBlock(){
    document.getElementById('bannerData').style.display = 'none';              
    document.getElementById('branchButton').src='obr/down_btn.png';
    document.getElementById('banner').style.height='20px';             
    document.getElementById('banner').style._height='20px';  
    document.getElementById('banner').className='banner_small';
               
}




/************* TOOLTIP **************/
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 05;
offsetY = 20;
var toolTipSTYLE = "";
function initToolTips() {
	var ttarea = document.createElement('div');
	ttarea.setAttribute('id','toolTipLayer');
	ttarea.style.position = "absolute";
	ttarea.style.width = "250px";
	if(document.appendChild){
		document.body.appendChild(ttarea);
	} else {
		alert("Your browser does not support the script used at this page, pleas switch browser");	
	}
	if(ns4||ns6||ie4) {
		if(ns4) {
			toolTipSTYLE = document.toolTipLayer;
		} else if(ns6) {
			toolTipSTYLE = document.getElementById("toolTipLayer").style;
		} else if(ie4) {
			toolTipSTYLE = document.all.toolTipLayer.style;
		}
		if(ns4) {
			document.captureEvents(Event.MOUSEMOVE);
		} else {
			toolTipSTYLE.visibility = "visible";
			toolTipSTYLE.display = "none";
		}
		document.onmousemove = moveToMouseLoc;
	}
}
function toolTip(msg, fg, bg, border)
{ 
	if(toolTip.arguments.length < 1) {
		if(ns4) {
			toolTipSTYLE.visibility = "hidden";
		} else {
			toolTipSTYLE.display = "none";
		}
	} else {
		if(!fg) {
			fg = "#777777";
		}
		if(!bg) {
			bg = "#FFFFFF";
		}
		if(!border){
			border = fg;	
		}
		var content = '<table border="0" style="z-index: 10" cellspacing="0" cellpadding="1" bgcolor="';
		content += border;
		content += '"><td>';
		content += '<table border="0" cellspacing="0" cellpadding="1" bgcolor="';
		content += bg;
		content += '"><td align="left"><font face="sans-serif" color="';
		content += fg;
		content += '" size="-2">&nbsp\;';
		content += msg;
		content += '&nbsp\;</font></td></table></td></table>';
		if(ns4) {
		  //alert('tool ns4');
			toolTipSTYLE.document.write(content);
			toolTipSTYLE.document.close();
			toolTipSTYLE.visibility = "visible";
		}
		if(ns6) {
		  //alert('tool :' content);
		  
			document.getElementById("toolTipLayer").innerHTML = content;
			toolTipSTYLE.display='block';
		}
		if(ie4) {
			document.all("toolTipLayer").innerHTML=content;
			toolTipSTYLE.display='block';
		}
	}
}
function moveToMouseLoc(e) {
	if(ns4||ns6) {
		x = e.pageX;
		y = e.pageY;
	} else {
		x = event.x + document.body.scrollLeft;
		y = event.y + document.body.scrollTop;
	}
	if(ns4||ns6){
    //alert('inside');
    toolTipSTYLE._left = x + offsetX;
  	toolTipSTYLE._top = y + offsetY;
  }else{
  	toolTipSTYLE.left = x + offsetX;
  	toolTipSTYLE.top = y + offsetY;  
  }
	return true;
}
function setToolTip(object, msg, fg, bg, border){
	if(setToolTip.arguments.length < 2) {
		return false;
	} else {
		switch (setToolTip.arguments.length) {
			case 2:
				object.onmouseover = function(){
					toolTip(msg);	
				}
				break;
			case 3:
				object.onmouseover = function(){
					toolTip(msg, fg);	
				}
				break;
			case 4:
				object.onmouseover = function(){
					toolTip(msg, fg, bg);	
				}
				break;
			case 5:
				object.onmouseover = function(){
					toolTip(msg, fg, bg, border);	
				}
				break;
			default:
				object.onmouseover = function(){
					toolTip(msg, fg, bg);	
				}
				break;
		}
		object.onmouseout = function(){
			toolTip();	
		}
	}
}
/************ END TOOLTIP ***********/



/*Edit the counter/limiter value as your wish Example: var count = "175";*/
function limitTA2tChr(){
  window.alert(limit);
  var count = "2000";
  var texObj = document.getElementById('catalogueDesc');
  var tex = texObj.value;
  var len = tex.length;

  if(len > count){
          tex = tex.substring(0,count);
          texObj.value = tex
          return false;
  }
  document.getElementById('ctnCatDescChar').value = count-len;
}

function limitTA2tChr(area, elem){
  var count = "2000";
  var strRestChar = 'Zbývající počet znaků:';
  var texObj = document.getElementById(area);
  var tex = texObj.value;
  var len = tex.length;
  var res = 0;
  if(len > count){
          tex = tex.substring(0,count);
          texObj.value = tex
          return false;
  }
  res = count-len;
  document.getElementById(elem).value = 'Zbývající počet znaků:'+res;
}

function submitFormIndex(id){
  document.getElementById('idbr').value = id;
  document.getElementById('formIndex').submit();
}


function submitForm(form, input, value){
  document.getElementById(input).value = value;
  document.getElementById(form).submit();
}

//hash function
function md5form(f) {
    f["password_hmac"].value = hex_hmac_md5(hex_md5(f["password"].value), f["challenge"].value);
    f["password"].disabled = true;
    f.submit();
    f["password"].disabled = false;
    return false;
}

function md5form2(f) {
    f["pwd_hmac"].value = hex_md5(f["pwd"].value);
    f["pwd"].disabled = true;
    f["newpwd_hmac"].value = hex_md5(f["newpwd"].value);
    f["newpwd"].disabled = true;
    f["pwdcheck_hmac"].value = hex_md5(f["pwdcheck"].value);
    f["pwdcheck"].disabled = true;

    f.submit();

    f["pwd"].disabled = false;
    f["newpwd"].disabled = false;
    f["pwdcheck"].disabled = false;    

    return false;
}


