// KOMPATIBILITA

var Br = new BrCheck()

function BrCheck()
{
	this.VER	= navigator.appVersion;
	this.AGENT	= navigator.userAgent.replace(/[\/]/g,' ');
	this.DOM	= document.getElementById ? true:false;

	this.OP5	= this.AGENT.indexOf("Opera 5")>-1							?true:false;
	this.OP6	= this.AGENT.indexOf("Opera 6")>-1							?true:false;
	this.OP7	= this.AGENT.indexOf("Opera 7")>-1							?true:false;
	this.OP8	= this.AGENT.indexOf("Opera 8")>-1							?true:false;
	this.OP		= (this.OP5 || this.OP6 || this.OP7 || this.OP8);

	this.IE4	= (document.all && !this.DOM && !this.OP)					?true:false;
	this.IE5	= (this.VER.indexOf("MSIE 5")>-1 && this.DOM && !this.OP)	?true:false; 
	this.IE6	= (this.VER.indexOf("MSIE 6")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE7	= (this.VER.indexOf("MSIE 7")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE		= (this.IE4 || this.IE5 || this.IE6 || this.IE7);

	this.NS4	= (document.layers && !this.DOM)							?true:false;
	this.NS7	= (this.DOM && parseInt(this.VER) >= 5 && this.AGENT.lastIndexOf('Netscape')<this.AGENT.lastIndexOf('7'))?true:false;
	this.NS6	= (this.DOM && parseInt(this.VER) >= 5 && !this.NS7)		?true:false;
	this.NS		= (this.NS4 || this.NS6 || this.NS7);

	return this;
}

function checkOrderContent(price){
	var sReturn;
	if(parseInt(price) != 0){
		sReturn = confirm('Při posledním odhlášení zůstaly v košíku nevyřízené položky. \n Chcete-li položky zanechat v košíku stiskněte "OK". \n Chcete-li položky z košíku odstranit, stiskněte "Cancel / Storno".');
		if(!sReturn){
			document.location.href = '/myaccount.asp?order=del';
		}
	}	
}

function getE(objectID) {
	return document.getElementById(objectID); 
}

function getF(formName) {

	return document.forms[formName];
}


function SetDSP(nDSP, sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (nDSP==1) {
//		alert(1);
		document.cookie="DSP=1; expires="+vyprs.toGMTString()+";";
	} else {
//		alert(0);
		document.cookie="DSP=0; expires="+vyprs.toGMTString()+";";
	}
}

function redirDSP(sURL){

	if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
	
	
}

function clearPgID(){

	var o = document.getElementsByName('PgID') ; 
	if(o==null) return;
	
	for(var i=0;i<o.length;i++){
		o[i].value="1" ;
	
	}

}
function SetAlsoNotStored(sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (ExtractCookies('COMANS')=='1') {
		document.cookie="COMANS=0; expires="+vyprs.toGMTString()+";";
	} else {
		document.cookie="COMANS=1; expires="+vyprs.toGMTString()+";";
	}
	if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
}

function SetCloseout(sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (ExtractCookies('COMCLO')=='1') {
		document.cookie="COMCLO=0; expires="+vyprs.toGMTString()+";";
	} else {
		document.cookie="COMCLO=1; expires="+vyprs.toGMTString()+";";
	}
	if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
}

// ###   FCE PRO zaskrtnutí a odeslání pk zboží pro Compare.asp   ###

function CompareSelected() {
	var sapkTblCommodity, CompareAdd;
	sapkTblCommodity = "";
	//aby to fungovalo vsude mozzila ie atd....
	for (var x=0; x<document.forms.length;x++){
		if (document.forms[x].name.indexOf("BuyFormBody")){
			if (document.forms[x].CompareAdd){
				if(document.forms[x].CompareAdd.checked){
					if (sapkTblCommodity=="") {
						sapkTblCommodity = document.forms[x].CompareAdd.value;
					}else{
						sapkTblCommodity += "|" + document.forms[x].CompareAdd.value;
					}
				}
			}
		}
	}
	if (sapkTblCommodity.indexOf('|') == -1) {

		alert('Pro porovnání je nutno vybrat nejméně 2 výrobky ...');
	} else {
		window.open('/Compare.asp?CMP=' + sapkTblCommodity, "Compare","scrollbars=1,status=0,toolbar=0,location=0,directories=0,height=500,width=720,left=10,top=10,resizable=1,");
	}
}

function CompareRemoveOne(sapkTblCommodity, sComToRem) {
	var apkTblCommodity, aLen;
	if (sapkTblCommodity == '') {
		window.close();
		return;
	}
	apkTblCommodity = sapkTblCommodity.split('|');
	aLen = apkTblCommodity.length;
	if (aLen == 1) {
		window.close();
		return;
	}
	sapkTblCommodity = '';
	for (var i=0; i<aLen; i++) {
		if (apkTblCommodity[i]!=sComToRem) {
			if (sapkTblCommodity=='') {
				sapkTblCommodity = apkTblCommodity[i];
			} else {
				sapkTblCommodity += "|" + apkTblCommodity[i];
			}
		}
	}
	window.location.href = '/Compare.asp?CMP=' + sapkTblCommodity;
}

// ###   FCE PRO BOXIKY SE SUBKATEGORIEMI   ###

var IdTimeToHideCategoryBox;

function ShowCategoryBox(img_id, cat_id)
{
	if ((IdTimeToHideCategoryBox!=null) && (cat_id!=cat_id_last)) HideAllCategoryBox(cat_id_last);

	var objElem = img_id;
    var x = 0;
    var y = 0;
    x += parseFloat(objElem.offsetLeft) + parseFloat(objElem.offsetWidth);
    y += parseFloat(objElem.offsetTop);

	getE('categoryBoxtable_' + cat_id).style.left = x;
	getE('categoryBoxtable_' + cat_id).style.top = y - 10;
	getE('categoryBoxtable_' + cat_id).style.display = 'block';
}

function HideCategoryBox(cat_id)
{
	cat_id_last = cat_id;
	IdTimeToHideCategoryBox = window.setTimeout('HideAllCategoryBox(' + cat_id + ')', 300);
}

function HideAllCategoryBox(cat_id)
{
	window.clearTimeout(IdTimeToHideCategoryBox);
	IdTimeToHideCategoryBox = null;
	getE('categoryBoxtable_' + cat_id).style.display = 'none';
}

// ###   FCE PRO DIALOG ZADANI VOLITELNYCH PARAMETRU   ###
var gsFormSuffix, gsFormIndex;

function BuyOrSetVariableParams(sFormSuffix,sFormIndex) {
	var sSelects, nWindowHeight;
	gsFormIndex = sFormIndex;
	gsFormSuffix = sFormSuffix;

	sSelects = getE("DivForPars" + sFormSuffix + sFormIndex).innerHTML;
	// ve skeletu musí být ve fci GetFormattedParams "ParamItem" psáno CASE-SENSITIVE !!!
	if (sSelects == "") {
		getF("BuyForm" + sFormSuffix + sFormIndex).submit();
	} else {
		// 22 je výška selectu - definováno raději i podle stylu!
		// nWindowHeight = 86 + 22 * (sSelects.split("ParamItem").length);
		getE('DivForParams').innerHTML = getE("DivForPars" + sFormSuffix + sFormIndex).innerHTML;
		getE('ParamCaption').innerHTML = getE("BuyForm" + sFormSuffix + sFormIndex).NameItem.value;
		getE('ParamTbl').style.top =  window.event.srcElement.offsetTop + 20;
		getE('ParamTbl').style.left =  window.event.srcElement.offsetLeft - 60;
		getE('ParamTbl').style.display = 'inline';
	}
}

function BuyOrSetParams(sFormIndex) {
	var e = getE( "ItemParameters" + sFormIndex );
	e.style.display = "inline";
	e.style.position = "relative";
	e.style.top =  window.event.srcElement.offsetTop + 20;
	e.style.left =  window.event.srcElement.offsetLeft - 60;	
	e.style.border =  "1px solid black";	
}
function CopyParamsBack() {
	getE("DivForPars" + gsFormSuffix + gsFormIndex).innerHTML = getE('DivForParams').innerHTML;
	getF("BuyForm" + gsFormSuffix + gsFormIndex).submit();
}

// ###   FCE PRO ROZKLIKAVANI KATEGORII   ###

function InsertCookiesCat(intId,idTree){
	document.cookie="category"+idTree+"="+intId+";";
	document.cookie="category"+idTree+"="+intId+";";
}
function checkParent(src, dest) {
	while (src!=null) {
		if (src.tagName == dest) return src;
		src = src.offsetParent;
	}
	return null;
}

function outlineCat(e) {
	var open = (e.target) ? e.target : e.srcElement;
	var el = checkParent(open, "TD");
	if (null!=el) {
		for (var pos=0; pos<el.childNodes.length; pos++) {
			if ((el.childNodes[pos].tagName=="TABLE")) {
				
				var nodeNum = (Br.IE ? 0 : 1);
				
				if (el.childNodes[nodeNum].src.indexOf("plus")>0) {
					el.childNodes[nodeNum].src = el.childNodes[nodeNum].src.replace("plus","minus");
				}else if (el.childNodes[nodeNum].src.indexOf("minus")>0) {
					el.childNodes[nodeNum].src = el.childNodes[nodeNum].src.replace("minus","plus");
				}

				break;
			}
		}
	    if (pos==el.childNodes.length) return;
	} else return;
	el = el.childNodes[pos];
	if ("TABLE"==el.tagName) {
		if (el.style.display!="none") {
			el.style.display = "none";
		} else {
			el.style.display = "block";
		}
	}
//	event.cancelBubble = true;
}

function controlMaxNumber(object,nMax){	
	
		if(object > nMax && object >= 1){    
        alert("Číslo stránky musí být v rozmezí od 1 - " + nMax);
        return false;
    }else{    
        return true;
    }
    
 
}

// 
// function getParentElementByTagName( sourceElement, parentTagName )
// { 
//  	var parentElement = sourceElement.parentNode; 
//  	if (parentElement) {
// 	  if (parentElement.nodeName!=parentTagName) { 
// 			return getParentElementByTagName(parentElement, parentTagName ) 
// 		}else{
// 	 		return parentElement
// 	 	} 
// 	}else{ 
// 	 return null 
// 	} 
// }
// function getChildElementByTagName( sourceElement, childTagName )
// { 
// 	for (var i=0;i<sourceElement.childNodes.length;i++)	{
// 	 if (sourceElement.childNodes[i].nodeName==childTagName) return	sourceElement.childNodes[i]; 
// 		}
// 	 return null;
// }






function GoToPage(nPage, sParam) {
	document.location.href = '?pgID=' + nPage + sParam;
}
/* COMPARE  */

var gCCompnTree = 1;
var gCCompIDs = ExtractCookies('CComp'+gCCompnTree).replace('none','');

function CCompChCli(o) {

	if (o)
	if (o.checked==true)
	{
		if (gCCompIDs.indexOf('|'+o.value+'|') < 0)	gCCompIDs += '|'+o.value+'|';
		if (gCCompIDs != '') CCompOn();
	}
	else
	{
		gCCompIDs = gCCompIDs.replace('|'+o.value+'|', '');
		if (gCCompIDs == '') CCompOff();
	}
	
	InsertCookies('CComp'+gCCompnTree,gCCompIDs);
}

function CCompChOn()
{
	var ch = document.getElementsByName('ccompCh');
	for (var i=0; i<ch.length; i++) {
		if (gCCompIDs.indexOf('|'+ch[i].value+'|') > -1)
			ch[i].checked = true;
	}
}	
function CCompChOff()
{
	var ch = document.getElementsByName('ccompCh');

	for (var i=0; i<ch.length; i++)
		ch[i].checked = false;

	gCCompIDs = '';
	InsertCookies('CComp'+gCCompnTree,'');

}

function CCompGo()
{
	var q = gCCompIDs;
	
	while(q.indexOf('||') > -1) q = q.replace('||', ',');
	while(q.indexOf('|') > -1) q = q.replace('|', '');
	
	if (gCCompIDs=='')	alert('Zvolte si zboží k porovnání')
	else				document.location = '/Compare.asp?DPGS='+q;
}


function CCompOn()
{
	var im = document.getElementById('idCCompGo');
	var de = document.getElementById('idCCompDel');
}


function CCompOff()
{
	var im = document.getElementById('idCCompGo');
	var de = document.getElementById('idCCompDel');
}


function CCompStartup(nTree)
{
	gCCompnTree = nTree.toString();
	gCCompIDs = ExtractCookies('CComp'+gCCompnTree).replace('none','');

	
	if (gCCompIDs != '')
	{
		CCompOn();
		CCompChOn();
	}
}


function CCompDel()
{
	gCCompIDs = '';
	InsertCookies('CComp'+gCCompnTree,gCCompIDs);
	CCompOff();
	CCompChOff();
}





// ###   FCE PRO PriceList ###

function SHModalDlgPricelist()
{
	var strReturn = showModalDialog("/Includes/EmailPricelist.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=320px;dialogHeight=124px;");

    if (strReturn == "") return;
	document.location.href = "/EmailPricelist.asp?EmailPricelist=" + strReturn;
}

// ##########

function onAction(imgName){
       getE(imgName).src = eval(imgName + "on.src")
}

function offAction(imgName){
	if (oldImgName.substring(0,4)!=imgName.substring(0,4)){
		getE(imgName).src = eval(imgName + "off.src")
	}
}

function OpenWnd(strURL){
	var objWnd = window.open(strURL,"InfoDetail","scrollbars=no,height=500,width=400,left=10,top=10");
	objWnd.focus();
}

function AddBuy(strName, intPrice, intDph, strCode) {
	var strData,strReturn
	strData = strName+"&"+intPrice+"&"+intDph+"&"+strCode
	strReturn = showModalDialog("/AddUpdBuy.asp",strData,"status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=200pt");
	if (strReturn == "1")
		ActionCookies('BZbuy');
	else if (strReturn == "2")
		window.location.href = "/order.asp";
}
function AddBuyDetail(strName, intPrice, intDph, strCode) {
	var strData,strReturn
	strData = strName+"&"+intPrice+"&"+intDph+"&"+strCode
	strReturn = showModalDialog("/AddUpdBuy.asp",strData,"status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=200pt");
	if (strReturn == "1"){
		window.opener.ActionCookies('BZbuy')
	}else if (strReturn == "2"){
		window.opener.location.href="/order.asp";
		window.close();
	}
}
function ActionCookies(strName){
	var strString,strSum1,strSum2,intSuma;
	strSum2 = new Array();
	intSuma = 0;

	strString = ExtractCookies(strName);
	if (strString > ""){
		strSum1 = strString.split("#");
		for (var i=0; i< strSum1.length-1; i++){
			strSum2[i] = strSum1[i].split("&");
			intSuma += BarterComma(strSum2[i][1])*BarterComma(strSum2[i][4]);
		}
		getE('CompletPrice').value =  FormatNumber(intSuma);
	}
}
function DeleteCookies(strName){
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() - 365);
	document.cookie=strName+"=; expires="+vyprs.toGMTString()+";";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie=strName+"=; expires="+vyprs.toGMTString()+";";
	getE('CompletPrice').value = "0.00";
}
function InsTreeCook(intId,idTree){
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() - 365);
	document.cookie="category"+idTree+"="+intId+"; expires="+vyprs.toGMTString()+";";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie="category"+idTree+"="+intId+"; expires="+vyprs.toGMTString()+";";
}
function InsertCookies(strName,strData){
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() - 365);
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+";";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+";";
}

function ExtractCookies(strName){
	var cookieList=document.cookie.split("; ");
	var cookieArray = new Array();
	var name = "#"
	for (var i=0; i < cookieList.length; i++){
		if(cookieList[i].indexOf(strName)>-1){
			if( cookieList[i].indexOf("=")>-1){name = cookieList[i].split("=");}
		}
	}
	if (name != "#"){
		return name[1];
	}else{
		return "none";
	}
}
/***************************************************************************/
/***************************************************************************/
	var cookie_expire=new Date();
	cookie_expire.setDate(cookie_expire.getDate() + 365);
function ExtractCookies_simple(strName){
	var cookieList=document.cookie.split("; ");
	var cookieArray = new Array();
	var name = "#"
	for (var i=0; i < cookieList.length; i++){
		if(cookieList[i].indexOf(strName+'=')==0){
			return cookieList[i].substr(cookieList[i].search('=')+1);
		}
	}
	return "";
}
function ExtractUserCookie(strKey){ // vyuziva hlavniho klice USER
	var strKeysValues = ExtractCookies_simple('USER');
	if ((strKeysValues=="none")||(strKeysValues=="")) return "";
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	aKeyValue = strKeysValues.split("&");
	for (var i = 0; i<aKeyValue.length; i++) {
		aOneKeyValue = aKeyValue[i].split("=");
		if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) { return unescape(aOneKeyValue[1]); }
	}
	return "";
}
function InsertUserCookie(strKey, strValue){
	var strKeysValues = ExtractCookies_simple('USER');
	var sTmp = '';
	var sDelimiter = '';
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	if ((strKeysValues=="none")||(strKeysValues=="")) {
		document.cookie = 'USER' + "=" + strKey + "=" + strValue + ";";
	} else if (("&"+strKeysValues.toLowerCase()).indexOf("&"+strKey.toLowerCase()+"=")==-1) {
		document.cookie = 'USER' + "=" + strKeysValues + "&" + strKey + "=" + strValue + ";";
	} else {
		aKeyValue = strKeysValues.split("&");
		for (var i = 0; i<aKeyValue.length; i++) {
			aOneKeyValue = aKeyValue[i].split("=");
			if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) aOneKeyValue[1] = strValue;
			sTmp += sDelimiter + aOneKeyValue[0] + "=" + aOneKeyValue[1];
			sDelimiter = "&";
		}
		document.cookie = 'USER' + "=" + sTmp + "; expires=" + cookie_expire.toGMTString() + ";";
	}
}
/***************************************************************************/
/***************************************************************************/

function ParseCookies(strName){
	var strCook = ExtractCookies(strName)
	if (strCook != "none"){
		var strList = strCook.split("a");
		for (var i=0; i < strList.length-1; i++){
			if (getE(strList[i]+'a')) if (getE(strList[i]+'a').tagName=='A') if(typeof(getE(strList[i]+'a')) == "object"){getE(strList[i]+'a').click();}
		}
	}
}
function FormatNumber(text){
	var mezi = BarterComma(text);
	mezi = ''+Math.round(parseFloat(mezi) * 100);
	var desetiny = mezi.substring(mezi.length-2, mezi.length);
	var cele = mezi.substring(0,mezi.length-2);
	if (parseFloat(mezi) < 1){
	        var mezi = "0."+desetiny;
	}else{
	        var mezi = cele+"."+desetiny;
	}
	return mezi;
}
function FormatFloat(nNumber,nDecimal){
	var sNumber = BarterComma(nNumber);
	sNumber = ''+Math.round(parseFloat(sNumber) * Math.pow(10,nDecimal));
	var sDedimal = sNumber.substring(sNumber.length-nDecimal, sNumber.length);
	var nInt = sNumber.substring(0,sNumber.length-nDecimal);
	if (parseFloat(sNumber) < 1){
	        var sNumber = "0."+sDedimal;
	}else{
	        var sNumber = nInt+"."+sDedimal;
	}
	return sNumber;
}
function FormatCurrency(nNumber,nDecimal){
	var sCurrency, iInsertSpace;
	sCurrency = FormatFloat(nNumber, nDecimal).replace('.',',');
	iInsertSpace = sCurrency.indexOf(',') - 3;
	while (iInsertSpace>0) {
		sCurrency = sCurrency.substring(0,iInsertSpace) + ' ' + sCurrency.substring(iInsertSpace,sCurrency.length);
		iInsertSpace -= 3;
	}
	if (nDecimal==0) sCurrency = sCurrency.substring(0,sCurrency.indexOf(","));
	return sCurrency;
}
function BarterComma(text){
	var mezi = ''+text;
	if (mezi.indexOf(',') != -1){
		mezi = mezi.split(",");
		mezi = mezi[0]+"."+mezi[1];
	}else{
		mezi = text;
	}
	return parseFloat(mezi);
}

function ControlNumber(){
	if (!Br.IE) return;
	if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}

function ControlFloat(){
	if (!Br.IE) return;
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode !=46)) event.returnValue = false;
}

function ControlNumber() {
	if (!Br.IE) return;
     if (((event.keyCode <48) || (event.keyCode >57)) && (event.keyCode!=13)) event.returnValue = false;
}
function ControlPhone() {
	if (!Br.IE) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32)  && (event.keyCode!=40) && (event.keyCode!=41) && (event.keyCode!=43))
		event.returnValue = false;
}
function ControlPSC() {
	if (!Br.IE) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32))
		event.returnValue = false;
}
//========Validation number=====================================================

function extractNumberEX(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;

	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;

}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

//=========================================================================

function getTxtTo(objThis,objTo,sTxt){
	objTo.value= objThis.value
}

//----------info okno-------------------------------------------------------
function InfoWindow(strAddress) {
       showModalDialog(strAddress,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=450pt;dialogHeight=320pt");
}
function WriteDate(){
	var strDay=new Date();
	var d=strDay.getDay();
	if (d==1) document.writeln('pondělí');
	else { if (d==2) document.writeln('úterý');
	else { if (d==3) document.writeln('středa');
	else { if (d==4) document.writeln('čtvrtek');
	else { if (d==5) document.writeln('pátek');
	else { if (d==6) document.writeln('sobota');
	else { if (d==0) document.writeln('neděle'); }}}}}};
	document.writeln(strDay.getDate(),'.',strDay.getMonth()+1,'.',strDay.getFullYear());
	}
function ShowSearchMenu(x){
    if (x == 1){
        getE('Searchtable').style.display='';
    }else{
        getE('Searchtable').style.display='none';
    }
}
function LocInfo(){
	getE('StateInfo2').innerHTML="  probíná připojování...";
	var e = event.srcElement;
	var y = 0;
	var x = 0;
	while (typeof e == 'object' && e.tagName != 'BODY'){
		y += e.offsetTop;
		e = e.offsetParent;
	};
	x = (window.screen.width/2)+375
	getE('StateInfo1').style.top=y-140;
	getE('StateInfo1').style.left=x;
}

function PositionInfo(strText){
	getE('StateInfo3').innerHTML=strText;
	getE('StateInfo2').innerHTML="  probíhá připojování...";
	var e = event.srcElement;
	var y = 0;
	var x = event.clientX;
	while (typeof e == 'object' && e.tagName != 'BODY'){
		y += e.offsetTop;
		e = e.offsetParent;
	};
	getE('StateInfo1').style.top=y-140;
	if (document.body.clientWidth < 933){
	  getE('StateInfo1').style.left=x-175;
	}else{
	  getE('StateInfo1').style.left=780;
	}
}
function LocState(strCode,intCount){
	window.parent.frames['WinStat'].location.href="/InfoState.asp?ID="+strCode+"&CN="+intCount
	PositionInfo("On-line stav");
}
function ChangeStorage(bState){
	if(bState){
		for(var i = 0; i < getE('S').length; i++){
			getE('S')[i].value="0"
		}
	}else{
		for(var i = 0; i < getE('S').length; i++){
			getE('S')[i].value="-1"
		}
	}
}
function ChangeCloseout(bState){
	if(bState){
		for(var i = 0; i < getE('C').length; i++){
			getE('C')[i].value="1"
		}
	}else{
		for(var i = 0; i < getE('C').length; i++){
			getE('C')[i].value="3"
		}
	}
}
function ValidateAccount(sAccount) {
	var u1,u2,t1,t2,i;
	var vahy = new Array("1","2","4","8","5","10","9","7","3","6")
	u1 = sAccount.substring(0,sAccount.length - 10);
	u2 = sAccount.substring(sAccount.length - 10,12);
	t1 = 0;t2 = 0;
	for(i=u1.length ;i>0;i--) {
		t1 += u1.charAt(i - 1)*vahy[10 - i];
	}	  
	for(i=u2.length ;i>0;i--) {
		t2 += u2.charAt(i - 1)*vahy[10 - i];
	}
	if (((t2%11) == 0)&&((t1%11 == 0))) {
		return true;
	} else {
		return false;
	}
}

// ##### PriceList BEEND #######################################################
function DelProducer(nProd) {
	if (nDeleted==nProducers-1) return;
	getE("bEnabled" + nProd).value='0';
	getE("Producer" + nProd).style.display="none";
	nDeleted += 1;
}

function PutCategoriesIdNameToSelect(saCatIdName, nIndex, bStart) {
	var arrData, arrSubData, saCatID, el;
	arrData = saCatIdName.split("*");
	saCatID = "";
	for (var i=0; i<arrData.length-1; i++) {
	    arrSubData = arrData[i].split("/")
			el = document.createElement("OPTION")
	    el.value = arrSubData[0];
	    el.text = arrSubData[1];
		saCatID += arrSubData[0] + "$"
		if (bStart==true) {
			if (i==0) {
				el.text='-Všechny kategorie-';
				document.PL['Categ'+nIndex].options.add(el);
			}
		} else
		    document.PL['Categ'+nIndex].options.add(el);
	}
		
	document.PL['CatID' + nIndex].value = saCatID.substr(0,saCatID.length - 1);
	if (saCatIdName == "") {
		document.PL['Categ'+nIndex].style.display = "none";
		getE("ChooseCateg"+nIndex).style.display  = "inline";
	} else {
		document.PL['Categ'+nIndex].style.display = "inline";
		getE("ChooseCateg"+nIndex).style.display  = "none";
	}
}

function GetCategoriesIdNameForSelect(nTree,bAlsoDisabled,nIndex,nUserType) {
	var saCatID,nProID,sProNM;
	var r;
	
	nProID = document.PL['ProdID'+nIndex].value;
	
	sProNM = document.PL['ProdID'+nIndex].options[document.PL['ProdID'+nIndex].selectedIndex].innerHTML
	saCatID = document.PL['CatID' + nIndex].value;
	if(Br.IE){
		var strReturn = showModalDialog("/Includes/PriceListSelectCatsOfProd.asp?TREE="+nTree+"&ProID="+nProID+"&DIS="+bAlsoDisabled+"&CatIDs="+saCatID+"&ADM="+nUserType+"&ProNM="+sProNM,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=470px;dialogHeight=450px");
		if (typeof(strReturn) == 'undefined') return;
		with(getE("Categ"+nIndex)){
			r = options.length;
	       		for (var i=0; i<r; i++) {
	               		options.remove(options.length-1);
	       		}
		}
		PutCategoriesIdNameToSelect(strReturn, nIndex, false);
	}else{
		window.open("/Includes/PriceListSelectCatsOfProd.asp?TREE="+nTree+"&ProID="+nProID+"&DIS="+bAlsoDisabled+"&CatIDs="+saCatID+"&ADM="+nUserType+"&ProNM="+sProNM+"&nIndex="+nIndex,"okno","toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=470,height=450,left=0,top=0");
	}
	
}
function ClearCategories(nIndex) {

	while(document.PL['Categ'+nIndex].length>0) {
		document.PL['Categ'+nIndex].options[0] = null;	
		}
	
	document.PL['CatID' + nIndex].value = "";
	document.PL['Categ'+nIndex].style.display = "none";
	getE("ChooseCateg"+nIndex).style.display  = "inline";
}

// ##### PriceList END #####

var iTshLast;
iTshLast = 0;
var arrTsh = new Array();

function showTsh(iTsh, nTshCount, oTshOn) {

	if (iTsh == iTshLast) return;

	var sHidePar, sHideHod, sHideSes, sHideSpec;
	sHidePar = "none";
	sHideHod = "none";
	sHideSes = "none";
	sHideSpec = "none";
	if ("DetSpecifikace" == oTshOn) { sHideSpec = "inline"; }
	else if ("DetParametry" == oTshOn) { sHidePar = "inline"; }
	else if ("DetHodnoceni" == oTshOn) { sHideHod = "inline"; }
	else { sHideSes = "inline"; }

	if (getE('DetSpecifikace')!=null) getE('DetSpecifikace').style.display = sHideSpec;
	if (getE('DetParametry')!=null) getE('DetParametry').style.display = sHidePar;
	if (getE('DetHodnoceni')!=null) getE('DetHodnoceni').style.display = sHideHod;
	if (getE('DetSestava')!=null) getE('DetSestava').style.display = sHideSes;

	getE('tshImg' + (iTshLast * 2 + 1)).style.backgroundImage = 'url(/img/' + gsPlusPath + 'tshMidOff.gif)';
	getE('tshImg' + (iTsh * 2 + 1)).style.backgroundImage = 'url(/img/' + gsPlusPath + 'tshMidOn.gif)';
	getE('tshImg' + (iTshLast * 2 + 1)).className = 'DetTshOff';
	getE('tshImg' + (iTsh * 2 + 1)).className = 'DetTshOn';
	if (iTshLast == 0)
		getE('tshImg0').src = arrTsh[00].src;
	else {
		if (iTshLast!=iTsh+1)
			getE('tshImg' + (iTshLast*2)).src = arrTsh[20].src;
	}
	if (iTshLast == nTshCount - 1) {
		getE('tshImg' + (iTshLast*2+2)).src = arrTsh[30].src;
	} else {
		if (iTshLast!=iTsh-1)
			getE('tshImg' + (iTshLast*2+2)).src = arrTsh[20].src;
	}
	
	if (iTsh == 0)
		getE('tshImg0').src = arrTsh[01].src;
	else
		getE('tshImg' + (iTsh*2)).src = arrTsh[21].src;
	if (iTsh == nTshCount - 1)
		getE('tshImg' + (iTsh*2+2)).src = arrTsh[31].src;
	else
		getE('tshImg' + (iTsh*2+2)).src = arrTsh[22].src;

	iTshLast = iTsh;
}
// ##### Zalozky na detailu END #########################################################

function DisTshParamAndCompare(sImgDisCompareBegin, sImgDisCompareMid, sImgDisCompareEnd, sImgDisParamSearchEndOn) {
	var iTsh;
	iTsh = 0;
	while (getE('tshCompareMid'+iTsh)!=null) {
		if (aDisableTshAndCmp[iTsh]) {
			getE('tshCompareMid'+iTsh).innerHTML = 'Porovnej ceny';
			if (getE('tshParamSearchLR'+iTsh) != null) {
				getE('tshParamSearchLR'+iTsh).src = sImgDisParamSearchEndOn;
				getE('tshParamSearchMid'+iTsh).style.display = "none";
				getE('tshParamSearchEnd'+iTsh).style.display = "none";
			}
		}
		iTsh += 1;
	}
}

function ShowImage(sImgPath,imgSmall) {
		window.open("/ShowImage.asp?IMG=" + sImgPath+"&imgsmall="+imgSmall, "Foto","scrollbars=0,status=0,toolbar=0,location=0,directories=0,height=100,width=100,resizable=1");
}

function ShowHideSwitch(elementA,elementB) {
	var eA = getE( elementA );
	var eB = getE( elementB );
	
	if (eA.style.display=="none") { 
		eA.style.display = "" 
		eB.style.display = "none" 
	} else { 
		eA.style.display = "none" 
		eB.style.display = "" 
	};

}

//       STIFFOVY FCE
// ********************************* 



function ShowHide(element) {
	
	var e = getE( element );
	if (e.style.display=="none") { e.style.display = "" } else { e.style.display = "none" };
//	if (!Br.IE) this.blur(); //aby nam nezustaval v mozile oznacen klikaci text
}
function ShowHide2(element) {
	if (getE(element).className.indexOf('closed')>-1) {
		getE(element).className = getE(element).className.replace('closed','opened');
	} else {
		getE(element).className = getE(element).className.replace('opened','closed');
	}
}
function changeCross(element) {
		if (getE(element).className == 'crossClosed') {
			getE(element).className = 'crossOpened' 
		} else {
			getE(element).className = 'crossClosed';
		}
}

function styleChange(elementId,classNameStr) {
	var e = getE( elementId );
	e.className = classNameStr;
}

//---showRecDialog
function showRecDialog(eo,posX,posY) {
	var e = getE( eo );
	e.style.display = "inline";
	e.style.position = "absolute";

	e.style.top = topScroll()+(posY - 250)+'px';
	e.style.left = (posX-360 )+'px';

//	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -350)+'px';
	//e.style.left = (document.body.clientWidth/2 + 150)+'px';
	
}
function hideRecDialog(eo) {
	var e = getE( eo );
	e.style.display = "none";
}
//---------show Service Dialog----------------------
function showSerDialog(eo,posX,posY) { 
	var e = getE( eo );
	e.style.display = "inline";
	e.style.position = "absolute";

	e.style.top = topScroll()+(posY - 250)+'px';
	e.style.left = (posX-380 )+'px';

//	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -350)+'px';
	//e.style.left = (document.body.clientWidth/2 + 150)+'px';
	
}
function hideSerDialog(eo) {
	var e = getE( eo );
	e.style.display = "none";
}
//------------------------------------
// ShopConfirmBox - Count Dialog
function showCountDialog( formname, code, minCount, onlyMultiplied ) {
	var e = getE( "shopconfirmbox" );
	e.style.display = "";
	e.style.position = "absolute";
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 +150)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.shopconfirmform.elements.original_form.value = formname;
	document.forms.shopconfirmform.elements.code.value = code;
	document.forms.shopconfirmform.elements.minCountForOrder.value = minCount;
	document.forms.shopconfirmform.elements.onlyMultipliedCount.value = onlyMultiplied;
	document.forms.shopconfirmform.elements.count.value = minCount;
	document.forms.shopconfirmform.elements.count.focus();
}
function hideCountDialog() {
	var e = getE( "shopconfirmbox" );
	e.style.display = "none";
}
function submitCountDialog() {
	var orig_form;    orig_form    = document.forms["BuyForm"+document.forms.shopconfirmform.elements.original_form.value].elements;
	var shopbox_form; shopbox_form = document.forms.shopconfirmform.elements;

	if ( !((shopbox_form.count.value > 0) && (shopbox_form.count.value < 1000000000)) ) {
		hideCountDialog();
		return false;
	}
	
	if (!checkCount( shopbox_form.count.value, shopbox_form.minCountForOrder.value, shopbox_form.onlyMultipliedCount.value )) return false;
	
	orig_form.Count.value = shopbox_form.count.value;
	orig_form.submit();
}


// AvaibilityBox - Avaibility Dialog
function showAvaibilityDialog( code, posX, posY ) {
	var e = getE( "avaibilitybox" );
	e.style.display = "";
	e.style.position = "absolute";
//	e.style.top = (posY + 50)+'px';
//	e.style.left = (posX + 50)+'px';
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -200)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.avaibilityform.elements.code.value = code;
	document.frames.avaibilityFrame.document.location = "Avaibility.asp?sCode=" + code;
	document.forms.avaibilityform.elements.count.value = "Zjišťuje se...";
}
function hideAvaibilityDialog() {
	var e = getE( "avaibilitybox" );
	e.style.display = "none";
//	var e = getE( "avaibilitybox" );
//	e.style.display = "none";
}


function resizeHidingDialog(element,newHeight){
	getE('shopinfobox').style.height = newHeight;
	if (newHeight > 50) setTimeout("resizeHidingDialog('shopinfobox',"+(newHeight-50)+");", 0);
}

function showWaitingBox( str ) {
	var box = document.getElementById("hoverbox");
	box.style.left = document.documentElement.clientWidth / 2 - 350 + "px";
	box.style.top = topScroll() + document.documentElement.clientHeight / 2 - 10 + "px";
	box.className = "visible";
	box.innerHTML = "<p>"+str+"</p>"
}


/* positions */
function leftPosition(obj,ev){
	if (ev) {
		if ( obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent)) < ev.clientX )  {
			return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent))
		} else { // quli dvouradkovym elementum, tak aby se to nezobrazilo daleko od kurzoru na prvnim radku
			return ( ev.clientX );
		}
	} else { // kdyz volame rekurzivne, tak neni objekt ev k dispozici
		return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent));
	}
}
function topPosition(ev) {
	 return ( ev.clientY + topScroll() );
}
function topScroll() {
	if (window.innerHeight) {
		  return ( window.pageYOffset )
	} else if (document.documentElement && document.documentElement.scrollTop) {
		return ( document.documentElement.scrollTop )
	} else if (document.body) {
		  return ( document.body.scrollTop )
	}
}

function getParamItem(idForm){	
	var frm = getE(idForm)//.elements
	var strValue = "";
	//var frm = document.forms.idForm.elements;	
	var ParamItemElmnts = document.getElementsByName("ParamItemSelect");
	if(ParamItemElmnts!=null){	
	for(var i = 0 ;i < ParamItemElmnts.length;i++){
		var chr= String.fromCharCode(32 ,32 ,32, 32 ,32 )	
		strValue += ParamItemElmnts[i].value + chr + "  ";	
	}
	frm.ParamItem.value=strValue ;
	}
	
}

function setParamBox(idBox,lineObj,ii){
	var FlodText = getE("FlodText")
	var FlodTextChild = FlodText.childNodes
	var refObj=getE(idBox)
//-----------------------------	
	var y=0
	var FoldLine=getE("FoldLine")
	var FoldLineChild = FoldLine.childNodes
	arrStyle= new Array('FlodEx W1','FlodEx W2','FlodEx W3');
	
	for(var i=0 ;i < FoldLineChild.length ; i++){ 
		if(FoldLineChild[i].nodeName.toLowerCase()=="div"){							
			FoldLineChild[i].className=arrStyle[y];
			y++		
		}
		
	}	
	lineObj.className= arrStyle[ii]+" GR"

//--------------------------------	
	for(var i=0 ;i < FlodTextChild.length ; i++){ 
		if(FlodTextChild[i].nodeName.toLowerCase()=="div"){				
				FlodTextChild[i].style.display="none";							
		}		
	}
	refObj.style.display="";


}


/* /positions */

// specialitky

var fadeInOut;
function fadeInObject ( objID, speed, opacity ) { // fce necha plynule zobrazit libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
	window.clearTimeout(fadeInOut);
	var obj = getE(objID);
	if (!(opacity>0)) opacity = 0;
	if (!(speed>0)) speed = 5;
	opacity+=speed;
	if (Br.IE) {
		obj.style.filter = 'alpha(Opacity='+opacity+')';
		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.filter='' }
	} else if (Br.NS) {
		obj.style.MozOpacity = opacity/100;
		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.MozOpacity=1; }
	}
	if (obj.style.display=='none') obj.style.display='block';
}
function fadeOutObject ( objID, speed, opacity ) { // fce necha plynule zmiznout libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
	window.clearTimeout(fadeInOut);
	var obj = getE(objID);
	if (!(opacity>0)) opacity = 100;
	if (!(speed>0)) speed = 5;
	opacity-=speed;
	if (Br.IE) {
		obj.style.filter = 'alpha(Opacity='+opacity+')';
		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.filter=''; }
	} else if (Br.NS) {
		obj.style.MozOpacity = opacity/100;
		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.MozOpacity=1; }
	}
}


// AvaibilityBox - Avaibility Dialog
function showAvaibilityDialog( code, posX, posY ) {
	var e = getE( "avaibilitybox" );
	e.style.display = "";
	e.style.position = "absolute";
//	e.style.top = (posY + 50)+'px';
//	e.style.left = (posX + 50)+'px';
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -200)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.avaibilityform.elements.code.value = code;
	document.forms.avaibilityform.elements.count.value = "Zjišťuje se...";
	document.frames.avaibilityFrame.document.location = "Avaibility.asp?sCode=" + code;
}
function hideAvaibilityDialog() {
	var e = getE( "avaibilitybox" );
	e.style.display = "none";
//	var e = getE( "avaibilitybox" );
//	e.style.display = "none";
}

// ShopInfoBox

function showShopInfoDialog( code, name, variant, unit, count, price, priceSum ) {
	clearTimeout;
	if (Br.IE) {
		if (getE('variantSelector')) getE('variantSelector').style.visibility='hidden';
		if (getE('unitSelector')) getE('unitSelector').style.visibility='hidden';
		if (getE('sortingSelector')) getE('sortingSelector').style.visibility='hidden';
		if (getE('producerSelector')) getE('producerSelector').style.visibility='hidden';
	}
	var e = getE( "shopinfobox" );
	fadeInObject ( "shopinfobox", 0 );
	e.style.position = "absolute";
	e.style.top = topScroll() + 300+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	getE('shopinfoform_description').innerHTML = '<strong>' + name + '</strong><p><b>' + count + ' ' + unit + '</b>Množství:</p><p><b class="BA_Ex">'+priceSum+'</b>Cena celkem:</p>';
//	document.forms.shopinfoform.elements.code.value = code;
//	document.forms.shopinfoform.elements.name.value = name + (variant!='' ? ' / '+variant : '');
//	document.forms.shopinfoform.elements.count.value = count + ' ' + unit;
	setTimeout("hideShopInfoboxDialog();", 8000);
}

function hideShopInfoboxDialog() {
	var e = getE( "shopinfobox" );
	fadeOutObject ( "shopinfobox", 10 );
	clearTimeout;
	if (getE('itemsOnPageSelect')) { getE('itemsOnPageSelect').style.visibility='visible'; }
	if (getE('variantSelector')) getE('variantSelector').style.visibility='visible';
	if (getE('unitSelector')) getE('unitSelector').style.visibility='visible';
	if (getE('sortingSelector')) getE('sortingSelector').style.visibility='visible';
	if (getE('producerSelector')) getE('producerSelector').style.visibility='visible';

}

function showShopConfirmDialog() {
	clearTimeout;
	hideShopInfoboxDialog();
	if (Br.IE) {
		if (getE('sortingSelector')) getE('sortingSelector').style.visibility='hidden';
		if (getE('producerSelector')) getE('producerSelector').style.visibility='hidden';
	}
	var e = getE( "shopconfirmbox" );
	fadeInObject ( "shopconfirmbox", 0 );
	e.style.position = "absolute";
	e.style.top = topScroll() + 300+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	if (getE('boxformcount')) getE('boxformcount').focus();
}
function hideShopConfirmDialog() {
	if (getE('itemsOnPageSelect')) { getE('itemsOnPageSelect').style.visibility='visible'; }
	if (getE('sortingSelector')) getE('sortingSelector').style.visibility='visible';
	if (getE('producerSelector')) getE('producerSelector').style.visibility='visible';
	var e = getE( "shopconfirmbox" );
	fadeOutObject ( "shopconfirmbox", 10 );
}

function GetBuy(frm,sAction,sTarget) {
	frm.action = sAction;
	frm.target = sTarget;
	frm.elements.AUO.value = 'ok';
}


function changeSelectedBookmark( bkmrkNo, bkmrksCount ) { 
	for (var i=1; i<=bkmrksCount; i++) { 
		if (getE('bookmark_'+i)) getE('bookmark_'+i).className='bookmark';
		if (getE('bookmark_content_'+i)) getE('bookmark_content_'+i).className='bookmark_content';
	} 
	getE('bookmark_'+bkmrkNo).className='bookmark active';
	getE('bookmark_content_'+bkmrkNo).className='bookmark_content active';
} 

function changeCatProd( catprod, obj ) {
	if (catprod==1) {
		if (obj.checked) {getE('sb_categories').style.display='block';getE('sb_producers').style.display='none';InsertUserCookie('CP','C');}
	}else{
		if (obj.checked) {getE('sb_categories').style.display='none';getE('sb_producers').style.display='block';InsertUserCookie('CP','P');}
	}
}

/* hover images in commodity list */
var bHoverName = 0, bHoverImage = 0, nLastImageId = 0; // jestli mame mys nad nazvem a obrazkem
function hideHoverImage( hoverWhat, idImage ) {
	if (hoverWhat==1) bHoverName = 0;
	if (hoverWhat==2) bHoverImage = 0;
	setTimeout("if (bHoverName==0 & bHoverImage==0) getE('hover_"+idImage+"').style.display='none';", 500); //getE('hover_'+idImage).style.display='none';
}
function showHoverImage( hoverWhat, idImage ) {
	clearTimeout;
	if (idImage!=nLastImageId) { bHoverName = 0; bHoverImage = 0; if (getE('hover_'+nLastImageId)) getE('hover_'+nLastImageId).style.display='none'; }
	if (hoverWhat==1) bHoverName = 1;
	if (hoverWhat==2) bHoverImage = 1;
	nLastImageId = idImage;
	getE('hover_'+idImage).style.display='block';
}

function DeliverySelect(pkDel,isPickup){
	//gaDelivery - array from string 142$143$
	//gaDeliveryDPH - array from string 19$5$
	//gaPayment - array from string 41,43,$1,43,$
	//gaDefault - array from string 143,44  - defaultní ID dopravy a platby
	var oPTsel, sDeliveries, oPB, bPayOK;
	var bPaySelectedOK = false;
	var bPaySelected = false;

	oPT = getE('TransportPrice');
	
	if (oPT) {
		oPB = getE('DeliveryPrice_' + pkDel)
		if (oPB) {
			oPT.innerHTML = oPB.value;
			getE('DeliveryPrice').value = getE('DeliveryPrice_' + pkDel).value;
			getE('DeliveryName').value = getE('DeliveryName_' + pkDel).value;
			getE('DeliveryDPH').value = getE('DeliveryDPH_' + pkDel).value;
		}
	}
	getE("delivery"+pkDel).checked = true

		for (var j = 0; ; j++) {
				oPT = getE('DeliveryBlock'+ j);
				if (!oPT) break;
				for (var x=0 ;x< oPT.childNodes.length ; x++){			
					if (oPT.childNodes[x].type=="radio" ) {
						oPT.childNodes[x].disabled=true
						if(isPickup != 'true'){
							for (var y=0 ;y<  gaDelivery.length ; y++){								
								if(oPT.childNodes[x].value ==	gaDelivery[y] ){						
									oPT.childNodes[x].disabled=false;
									break;
								} 		
							}
						}else{
								oPT.childNodes[x].checked=false;
							
						}						
					}
				}		
		}
		
	if(isPickup == 'true'){
		
		return;
		
	}
	
	
// 	if( pkDel==null || pkDel==0 ){	
// 	
// 		for (var j = 0; ; j++) {
// 				oPT = getE('PaymentType' + j);
// 				if (!oPT) break;
// 				oPT.checked = false;			
// 		}
// 		for (var i=0; i<gaDelivery.length-1; i++) {
// 				oPT = getE('delivery' + gaDelivery[i]);
// 				if (!oPT) break;
// 				oPT.checked = false;			
// 		}
// 	alert('PaymentType' + gaDefault[1])
//  		getE("delivery"+gaDefault[0]).checked = true;
//  		getE('PaymentType' + gaDefault[1]).checked = true;
// 	return;
// 	}
	for (var i=0; i<gaDelivery.length-1; i++) {

		if (gaDelivery[i] == pkDel) {
			// provedu zobrazení/skrytí platebních metod podle vazby na dopravné
			for(var j = 0; ; j++) {
		
				oPT = getE('PaymentType' + j);
				if (!oPT) break;

				// nastavím bloku s typem platby modrou/šedou barvu
				oPB = getE('PaymentBlock' + j);
				sPayments = ',' + gaPayment[i];
				bPayOK = (sPayments.indexOf(',' + oPT.value + ',') != -1);
				if (oPT.checked)
					bPaySelectedOK = bPayOK; // je vybraná plat. met. stále možná i s nově zvoleným dopravným? existuje vazba?

				if (bPayOK) {
					if (!bPaySelected) {
						oPTsel = oPT;
						bPaySelected = true;
					}
					oPB.className = "PayDeliveryType";
				}
				else
					oPB.className = "PayDeliveryType payKO";
				oPT.disabled = !bPayOK;
				if (!bPaySelected) oPT.checked = true;
			}
			
			// pokud je vybrána platební metoda, kterou není možné provést s vybraným typem dopravy, změním to na první možnou volbu
			
			if (bPaySelected && !bPaySelectedOK)
			
				if (pkDel == gaDefault[0]) {
					for (var j = 0; ; j++) {
						oPT = getE('PaymentType' + j);
						if (!oPT) break;
						if (oPT.value == gaDefault[1]) oPT.checked = true;
					}
				}
				else oPTsel.checked = true;
			break;
		} else {
			for (var j = 0; ; j++) {
				oPT = getE('PaymentType' + j);
				if (!oPT) break;
				oPT.disabled = !(oPT.value == gaDefault[1]);
				if (oPT.value == gaDefault[1]) {
					oPT.checked = true;					
					getE('PaymentBlock' + j).className = "PayDeliveryType";
					}
				else {
					getE('PaymentBlock' + j).className = "PayDeliveryType payKO";
				}
				
				
			}
		}
	}
}

function setOtherCheck(idObj){


	var objs = document.getElementsByName("DeliveryType")
	
	for(var x=0 ; x<objs.length; x++){
		if (	objs[x].id!= idObj){
			objs[x].disabled=true
		}
	}


}
// function DeliverySelect(pkDel){
// 	//gaDelivery - array from string 142$143$
// 	//gaPayment - array from string 41,43,$1,43,$
// 	var oPTsel, sDeliveries, oPB, bPayOK;
// 	var bPaySelectedOK = false;
// 	var bPaySelected = false;
// 	for (var i=0; i<gaDelivery.length-1; i++){
// 		if (gaDelivery[i] == pkDel) {
// 			// provedu zobrazení/skrytí platebních metod podle vazby na dopravné
// 			sPayments = ',' + gaPayment[i]; // 41,43,
// 			for(var j = 0; ; j++) {
// 				oPT = getE('PaymentType' + j);
// 				if (!oPT) break;
// 
// 				// nastavím bloku s typem platby modrou/šedou barvu
// 				oPB = getE('PaymentBlock' + j);
// 				bPayOK = (sPayments.indexOf(',' + oPT.value + ',') != -1);
// 				if (oPT.checked)
// 					bPaySelectedOK = bPayOK; // je vybraná plat. met. stále možná i s nově zvoleným dopravným? existuje vazba?
// 
// 				if (bPayOK) {
// 					if (!bPaySelected) {
// 						oPTsel = oPT;
// 						bPaySelected = true;
// 					}
// 					oPB.className = "method-of-payment";
// 				}
// 				else
// 					oPB.className = "method-of-payment payKO";
// 				oPT.disabled = !bPayOK;
// 				if (!bPaySelected) oPT.checked = true;
// 			}
// 			// pokud je vybrána platební metoda, kterou není možné provést s vybraným typem dopravy, změním to na první možnou volbu
// 			if (bPaySelected && !bPaySelectedOK)
// 				oPTsel.checked = true;
// 			break;
// 		}
// 	}
// }

//--- funkce z tiketu 15849
// function isValidEmail(emailAddress) {
// 	var checkTLD=0;
//  	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
// 	var emailPat=/^(.+)@(.+)$/;
// 	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
// 	var validChars="\[^\\s" + specialChars + "\]";
// 	var quotedUser="(\"[^\"]*\")";
// 	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
// 	var atom=validChars + ´+´;
// 	var word="(" + atom + "|" + quotedUser + ")";
// 	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
// 	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
// 	var matchArray=emailAddress.match(emailPat);
// 	
// 	if (matchArray==null) { return false;}
//   var user=matchArray[1];
//   var domain=matchArray[2];
// 
//   for (i=0; i<user.length; i++) {
// 		if (user.charCodeAt(i)>127) {
// 			return false;
// 		}
//   }
// 	for (i=0; i<domain.length; i++) {
// 		if (domain.charCodeAt(i)>127) {
// 			return false;
// 		}
// 	}
// 	if (user.match(userPat)==null) {
// 		return false;
// 	}
//   var IPArray=domain.match(ipDomainPat);
//  	if (IPArray!=null) {
// 		for (var i=1;i<=4;i++) {
// 			if (IPArray[i]>255) {
// 		    return false;
// 			}
// 		}
// 		return true;
// 	}
// 	var atomPat=new RegExp("^" + atom + "$");
//   var domArr=domain.split(".");
//   var len=domArr.length;
//   for (i=0;i<len;i++) {
// 	  if (domArr[i].search(atomPat)==-1 || (i>=len-2 && domArr[i].length<1))
//     {
// 			return false;
// 		}
// 	}
//   if (checkTLD && domArr[domArr.length-1].length!=2 &&  domArr[domArr.length-1].search(knownDomsPat)==-1) {
// 	  return false;
//   }
// 	if (len<2) {
// 		return false;
// 	}
//   return true;
// 
// }
//---------------------------
function EmailControlRegExp(sEmail, bShowMsg)
 {
//   if (sEmail=='' || sEmail=='Váš@email.cz')
//   {
//     if (bShowMsg) alert('Nesprávný formát emailu');
// 		return false;
//   }
 										
  var regEx  = new RegExp("^[_a-zA-Z0-9\.\-]+@(([_a-zA-Z0-9\-]{1,}\.){1,})+\.[a-zA-Z]{2,}$");  									
  regEx.ignoreCase = true;  
  if (regEx.test(sEmail) == false)
  {
        if (bShowMsg) alert('Nesprávný formát emailu');
		return false;
  }
  return true;
} 


function ControlDataOrder(){
	if(getE('DeliveryType').value == "" ){alert("Vyberte způsob dopravy."); return false; }
	if(getE('PaymentType').value == "" ){alert("Vyberte způsob platby."); return false; }
	return true;
}

function ControlDataOrderStep2() {
	if(getE('DeliveryType').value == "" ){alert("Vyberte způsob dopravy."); return false; }
	if(getE('PaymentType').value == "" ){alert("Vyberte způsob platby."); return false; }
	return true;
}

function ControlDataOrderStep1() {
	var f = getF("frmOrder");
	if (f) {
		if (f.FirstName) {
		// Neni zalogovany
			if (trim(f.LastName.value)=="") { alert("Zadejte příjmení fakturační adresy."); f.LastName.focus(); return false; }
			if (trim(f.Street.value)=="") { alert("Zadejte ulici fakturační adresy."); f.Street.focus(); return false; }
			if (trim(f.City.value)=="") { alert("Zadejte město fakturační adresy."); f.City.focus(); return false; }
			if (trim(f.ZipCode.value)=="") { alert("Zadejte PSČ fakturační adresy."); f.ZipCode.focus(); return false; }
			if (trim(f.Phone.value)=="") { alert("Zadejte telefon fakturační adresy."); f.Phone.focus(); return false; }
		}
		else {
		// Je zalogovany

		}
	}

	return true;
}

function isMarketChecked(){ 
	if(getE('ChosenMarket')!=null){
		if(!parseInt(getE('ChosenMarket').value) > 0){
			alert('Vyberte prodejnu!');
			return false;		
		}else{
			return true ;
		}
	}		
}

function ControlDeliveryDataOrder(){
//	if(getE('OrderForm').ORDeliveryFirm.value == ""){alert("Zadejte firmu."); getE('OrderForm').ORDeliveryFirm.focus(); return false}
	if(getE('OrderForm').ORNameRecipient.value == ""){alert("Zadejte jméno."); getE('OrderForm').ORNameRecipient.focus(); return false}
	if(getE('OrderForm').ORDeliveryStreet.value == ""){alert("Zadejte ulici."); getE('OrderForm').ORDeliveryStreet.focus(); return false}
//	if(getE('OrderForm').ORStreetNum.value == ""){alert("Zadejte číslo."); getE('OrderForm').ORStreetNum.focus(); return false}
//	if(getE('OrderForm').ORPlace.value == ""){alert("Zadejte místo."); getE('OrderForm').ORPlace.focus(); return false}
//	if(getE('OrderForm').OROther.value == ""){alert("Zadejte ostaní."); getE('OrderForm').OROther.focus(); return false}
	if(getE('OrderForm').ORCity.value == ""){alert("Zadejte město."); getE('OrderForm').ORCity.focus(); return false}
	if(getE('OrderForm').ORZipCode.value == ""){alert("Zadejte PSČ."); getE('OrderForm').ORZipCode.focus(); return false}
	if (getE('OrderForm').ORDeliveryEmail.value != "" && !vfs_checkType_email(getE('OrderForm').ORDeliveryEmail.value)) { alert("E-mail má nesprávny formát."); getE('OrderForm').ORDeliveryEmail.focus(); return false; }
	if((getE('OrderForm').ORDeliveryPhone.value == "" && getE('OrderForm').ORDeliveryEmail.value == "")){alert("Zadejte telefon nebo e-mail."); getE('OrderForm').ORDeliveryPhone.focus(); return false}
//	if(getE('OrderForm').ORTerms.value == ""){alert("Zadejte podmínky."); getE('OrderForm').ORTerms.focus(); return false}
//	if(getE('OrderForm').ORDeliveryEmail.value == ""){alert("Zadejte E-mail."); getE('OrderForm').ORDeliveryEmail.focus(); return false}
//	if( !EmailControlRegExp(getE('OrderForm').ORDeliveryEmail.value,true) ){getE('OrderForm').ORDeliveryEmail.focus();return false}
//	if( isMarketChecked()==false ) {return false} ;
	return true;
}

function vfs_checkType_email(hodnota)
{
	var reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/
	if (reEmail.test(hodnota)) { return true; }
	return false;
}

function ControlPassword(NameOne,NameTwo){
	if (getE(NameOne).value != getE(NameTwo).value){
		alert("Špatně zadané heslo.");
		getE(NameOne).value = "";
		getE(NameTwo).value = "";
		getE(NameOne).focus();
		return false;
	}else{
		return true;
	}
}

function checkCount( myCount, minCount, sUnit, onlyMultiplied ) {
	myCount = parseInt(myCount.replace(",","."));
	minCount = parseInt(minCount.replace(",","."));
	//if ( myCount == 0 ) {alert('Zadejte množství.') ;return false;}
	if ( myCount == 0 ) {return true;}
	if ( myCount < minCount ) {
		alert('Toto zboží lze objednat v minimálním počtu '+minCount+' '+sUnit+'.'); return false;
	}
	if ( (onlyMultiplied==1) && ( (myCount*10) % (minCount*10) != 0) ) {
		alert('Toto zboží lze zakoupit pouze v násobcích '+minCount+' '+sUnit+'.'); return false;
	}
	return true;
}

function confirmEmptyBasket() {
	return confirm('"&GLS(190,"Přejete si zrušit objednávku a vyprázdnit košík?")&"');
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function ShowCalendar(oid,posX,posY,bAdmin)
 {
 
  var cal = document.getElementById('divcal');
  var calframe = document.getElementById('diviframcal');
  var tbox = document.getElementById(oid);
  var ssrc = '/Includes/Calendar_INC.asp?el=' + oid + '&selDate=' + tbox.value;  
  if(!bAdmin){
		cal.style.top = topScroll()+(posY - 250)+'px';
		cal.style.left = (posX-360 )+'px';
	}else{
		cal.style.top = tbox.offsetTop + tbox.offsetHeight;
  	cal.style.left = tbox.offsetLeft; 
	}
	
  
	 
  
	calframe.src = ssrc;
  cal.style.display = 'block';
 }

//------------- dodací adresy ---------------
var nClientAddress = 0
function changeSelectedClientAddress( actualSelected ) {
	if (nClientAddress == 0) nClientAddress = actualSelected;
	if (getE('AddressAdd'+actualSelected)) getE('AddressAdd'+actualSelected).style.display=(Br.IE ? 'block' : 'table');
}

function rowClientAddress(num, firm, street, city, zipcode) {
	var LineColor = 1
	if ((num % 2) == 0) LineColor = 2
	else LineColor = 1;
	var tbody = getE('tblRowCA');
	if (num <= tbody.rows.length) {
		tbody.deleteRow(num-1);
	}

//	if (num == 1 && tbody.rows.length == 1) {tbody.deleteRow(0);};

	var tRow = tbody.insertRow(num-1);
	tRow.id = "rowA_" + num;
	tRow.className = "tdRw" + LineColor;
	var tCell = tRow.insertCell(0);
	tCell.onclick = function() {changeSelectedClientAddress(num);};
	tCell.className = "cFN";
	tCell.innerHTML = firm;
	var tCell = tRow.insertCell(1);
	tCell.onclick = function() {changeSelectedClientAddress(num);};
	tCell.className = "TStreet";
	tCell.innerHTML = street;
	var tCell = tRow.insertCell(2);
	tCell.className = "TCity";
	tCell.innerHTML = city;
	var tCell = tRow.insertCell(3);
	tCell.className = "TzipCode";
	tCell.innerHTML = zipcode;
	var tCell = tRow.insertCell(4);
	tCell.className = "actn Tbtn";
	
	tCell.innerHTML = "<input type='image' class='btnBGs' src=\"/img/BTko.gif\" onclick='deleteClientAddress(" + num + "); return false;' title='Odstranit dodací adresu' />";
}

function CheckClientAddress(num,showAlert)	
{
	var pom2 = nClientAddressInTab;
	var pom = 1;
	if (num != 0) { pom = num; pom2 = num}
	for (i=pom; i< (pom2+1); i++ ) {
		if ( getE('delcaId_'+i).value == 0 ) {
		//	if (getE('caFirm_'+i).value == ""){showAlert ? alert("Vyplňte název firmy dodací adresy.") : "" ;getE('caFirm_'+i).focus();return false}
			if (getE('caStreet_'+i).value == ""){showAlert ? alert("Vyplňte ulici dodací adresy.") : "" ;getE('caStreet_'+i).focus();return false}
			if (getE('caCity_'+i).value == ""){showAlert ? alert("Vyplňte město dodací adresy.") : "" ;getE('caCity_'+i).focus();return false}
			if (getE('caZipCode_'+i).value == ""){showAlert ? alert("Vyplňte PSČ dodací adresy.") : "" ;getE('caZipCode_'+i).focus();return false}
		
			if (getE('caNameRecipient_'+i).value == ""){showAlert ? alert("Vyplňte jméno příjemce.") : "" ;getE('caNameRecipient_'+i).focus();return false}
			if (getE('caStreetNum_'+i).value == ""){showAlert ? alert("Vyplňte číslo.") : "" ;getE('caStreetNum_'+i).focus();return false}
			if(getE('CApkCountries_'+i)) {
				if (getE('CApkCountries_'+i).value == "0"){showAlert ? alert("Vyplňte stát.") : "" ;return false}
			}
			//if (getE('caZipCode_'+i).value == ""){showAlert ? alert("Vyplňte PSČ dodací adresy.") : "" ;getE('caZipCode_'+i).focus();return false}										
		}
	}
	return true;
}	

function saveClientAddress(num) {

	if (CheckClientAddress(num,true)) {
		rowClientAddress( num, '(#' + num + ') ' + getE('caFirm_' + num).value , getE('caStreet_' + num).value, getE('caCity_' + num).value, getE('caZipCode_' + num).value);
		getE('AddressAdd' + num).style.display='none';
	}
	return true;
}

function deleteClientAddress(num) {
	if (confirm('Přejete si skutečně smazat dodací adresu?')) {
		getE('delcaId_' + num).value='1';
		getE('AddressAdd' + num).style.display='none';
		getE('rowA_' + num).style.display='none';
	}
	return true;
}

var nClientAddressInTab = 0;
function addNewClientAddress(num) {
	if (nClientAddressInTab==0) { nClientAddressInTab = num + 1 } else { nClientAddressInTab++ };

	rowClientAddress(nClientAddressInTab, "(#" + nClientAddressInTab + ")" , "nová dodací adresa", "", "");

	getE('AddressAdd0').innerHTML += 
		'<input type="hidden" id="caId_'+nClientAddressInTab+'" name="caId" value="0" />' +
		'<input type="hidden" id="delcaId_'+nClientAddressInTab+'" name="delcaId" value="0" />' +
		'<table class="tblCD" cellpadding="0" cellspacing="0" id="AddressAdd' + nClientAddressInTab + '">' +
		'	<tr>' +
		'	 <td colspan="6" class="bClose"><span><img src="/img/BTClose.gif" alt="Zavřít" title="Zavřít" onclick="  if(!CheckClientAddress('+nClientAddressInTab+',false)){alert(\'Zapište údaje, nebo formulář odstraňte\')}else{ getE(\'AddressAdd' +  nClientAddressInTab + '\').style.display=\'none\';} " /></span><strong>Detail nové dodací adresy - #' + nClientAddressInTab + '</strong></td>' +
		'	</tr>' +		
		'		<tr>' +
		'			<td class="rNameEx">Firma:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caFirm_'+nClientAddressInTab+'" type="text" name="CAFirmDelivery" maxlength="100" tabindex="127" value="" /></td>' +
		'			<td class="rNameEx">Jméno příjemce:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caNameRecipient_'+nClientAddressInTab+'" type="text" name="CANameRecipient" maxlength="255" tabindex="128" value="" /><span class="decReg">&nbsp;</span></td>' +
		'		</tr>' + 	                       
		'		<tr>' +             
		'			<td class="rNameEx">Ulice:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caStreet_'+nClientAddressInTab+'" type="text" name="CAStreetDelivery" maxlength="255" tabindex="129" value="" /><span class="decReg">&nbsp;</span></td>' +
		'			<td class="rNameEx">Číslo:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caStreetNum_'+nClientAddressInTab+'" type="text" name="CAStreetNum" maxlength="100" tabindex="130" value="" /><span class="decReg">&nbsp;</span></td>' +
		'		</tr>' + 	                       
		'		<tr>' +             
		'			<td class="rNameEx">Místo:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caPlace_'+nClientAddressInTab+'" type="text" name="CAPlace" maxlength="100" tabindex="131" value="" /></td>' +
		'			<td class="rNameEx">Ostatní:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caOther_'+nClientAddressInTab+'" type="text" name="CAOther" maxlength="255" tabindex="132" value="" /></td>' +
		'		</tr>' +           
		'		<tr>' +             
		'			<td class="rNameEx">Město:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caCity_'+nClientAddressInTab+'" type="text" name="CACityDelivery" maxlength="100" tabindex="133" value="" /><span class="decReg">&nbsp;</span></td>' +
		'			<td class="rNameEx">PSČ:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caZipCode_'+nClientAddressInTab+'" type="text" name="CAZipCodeDelivery" maxlength="6" tabindex="134" value="" onblur="extractNumberEX(this,0,false);" onkeyup="extractNumberEX(this,0,false);" onkeypress="return blockNonNumbers(this, event, false, false);" /><span class="decReg">&nbsp;</span></td>' +
		'		</tr>' +
		'		<tr>' +
		'			<td class="rNameEx">Podmínky dodání:</td>' +
		'			<td class="rInsert"><input class="input_text INP" id="caTerms_'+nClientAddressInTab+'" type="text" name="CATerms" maxlength="255" tabindex="136" value="" /></td>' +
		'			<td class="rNameEx"> </td>' +
		'			<td class="rInsert"> </td>' +		
		'		</tr>' +			
		'		<tr>' +
		'			<td class="rNameEx">Stát:</td>' +
		'			<td class="rInsert"><div  id="countrySelect_'+nClientAddressInTab+'" style="width:95%;float:left"> </div><span class="decReg">&nbsp;</span></td>' +
		'			<td class="rNameEx"></td>' +
		'			<td class="rInsert"></td>' +
		'		</tr>' +	
		' <tr>' +
		'	 <td class="actn" colspan="6"><img src="/img/BTdelitem.gif" style="cursor:pointer" title="Odstranit dodací adresu" onclick="deleteClientAddress('+ nClientAddressInTab +'); return false;" />&nbsp;&nbsp;<img src="/img/BTsaveitem.gif" style="cursor:pointer" title="Uložit dodací adresu" onclick="saveClientAddress('+nClientAddressInTab+'); " title="Uložit dodací adresu osobu" /></td>' +
		' </tr>' +	
		'</table>' ;	
		getE( "countrySelect_"+ nClientAddressInTab).innerHTML=sCoutriesFn(nClientAddressInTab);
		
		
}

//------------- kontaktni osoby -------------
var nContactPerson = 0
function changeSelectedContactPerson( actualSelected ) {
	if (nContactPerson == 0) nContactPerson = actualSelected;
	if (getE('ContactAdd'+actualSelected)) getE('ContactAdd'+actualSelected).style.display=(Br.IE ? 'block' : 'table');
}

function rowContactPerson(num, login, jmeno, email, phone, news,role) {
	var LineColor = 1
	if ((num % 2) == 0) LineColor = 2
	else LineColor = 1;
	var tbody = getE('tblRowCP');
	if (num <= tbody.rows.length) {
		tbody.deleteRow(num-1);
	}
	
//	if (num == 1 && tbody.rows.length == 1) {tbody.deleteRow(0);};

	var tRow = tbody.insertRow(num-1);
	tRow.id = "rowC_" + num;
	tRow.className = "tdRw" + LineColor;
	
// 	var tCell = tRow.insertCell(0);
// 	tCell.innerHTML = login;
	var tCell = tRow.insertCell(0);
	tCell.onclick = function() {changeSelectedContactPerson(num);};
	tCell.className = "cFN" ;
	tCell.innerHTML = jmeno;
	var tCell = tRow.insertCell(1);
	tCell.innerHTML = email;
	var tCell = tRow.insertCell(2);
	tCell.innerHTML = phone;
	var tCell = tRow.insertCell(3);
	tCell.className = "actnC";
	tCell.innerHTML = news;
	var tCell = tRow.insertCell(4);
	tCell.className = "actn";
	tCell.innerHTML = role;
	var tCell = tRow.insertCell(5);
	tCell.className = "actn";
	tCell.innerHTML = "<input type='image' class='btnBGs' src=\"/img/BTko.gif\" onclick='deleteContactPerson(" + num + "); return false;' title='Odstranit kontaktni osobu' />";
}

function saveContactPerson(num) {


	if (CheckContactPersons(num,true)) {
// 		if (getE('cpNews_' + num).value == 1)
// 			var sNews = 'Ano';
// 		else
// 			var sNews = 'Ne';
		
		
		var cpId = getE('cpId_'+num).value;
		if(cpId == 0){		
			getE('saveClient_CC').src='/includes/SaveUserContact_INC.asp?SaveOK=1&cpId='+cpId+'&nCounter='+num+'&CPFirstName='+getE('cpFirstName_' + num).value+'&CPLastName='+getE('cpLastName_' + num).value+'&CPLogin='+getE('cpLogin_' + num).value+'&CPPassword='+getE('cpPassword_' + num).value+'&CPEmail='+getE('cpEmail_' + num).value+'&cpPhone='+getE('cpPhone_' + num).value+'&CPchangePassword='+getE('CPchangePassword_'+num).checked                   
		}
			
		if (getE('cpDisabledLogin_' + num).value == 1){
			var sDisabled = 'Ano';
		}else{
			var sDisabled = 'Ne';	
		}
		var cellA 
	
		if((getE('cpRolesHid_' + num).tagName).toLowerCase()=="select"){
			cellA = getE('cpRolesHid_' + num).options[getE('cpRolesHid_' + num).selectedIndex].text ;   //getE('cpLogin_' + num).value 
		}else{
			cellA = getE('RoleSelect_' + num).innerHTML;
		}	
		rowContactPerson( num, '' , '(#' + num + ')' +getE('cpFirstName_' + num).value + ' ' + getE('cpLastName_' + num).value, getE('cpEmail_' + num).value, getE('cpPhone_' + num).value, sDisabled, cellA);
		getE('ContactAdd' + num).style.display='none';
	}

	return true;
}
function changeDisabled(num,IdCheck,IdA,IdB){

	
//alert(IdA)	
var objA = getE(IdA)

var objB = getE(IdB)
var objCheck = getE(IdCheck)
//!!i v adminu
	if (objCheck==null) return ;

	if(objCheck.checked) {
	 	objA.readOnly=false;
	 	objB.readOnly=false;
	 	objA.className=objA.className.replace(' readonlyCss','')
		objB.className=objB.className.replace(' readonlyCss','') 		
	}else{
		objA.value="";
		objB.value="" ;	
		objA.className += ' readonlyCss'
		objB.className += ' readonlyCss' 		
		objA.readOnly=true;
	 	objB.readOnly=true;
	}
	disableInputSwitch(objCheck.checked,IdCheck)	
}

function disableInputSwitch(bChecked,idInp){
//disabled input aby se zmenil na hidden aby byl odesilan formularem
	var el = document.createElement("input")	
	 
		if(!bChecked){ // neni checked		
		//vytvorime hidden a dame mu jmeno a value a id originalu toto se odesle ve formu zatimco original je disabled
			var objInp = document.getElementById(idInp); 
			if(objInp !=null){						
			  el.type="hidden"
				el.value 			= "" ;
			  el.name 			= objInp.name ; 
			  el.id					= ""+idInp + "_hidden" ;				
				objInp.name="";				
			  objInp.parentNode.appendChild(el)	;	  
		  }	  
		}else{	// je checked
			var objInpA = document.getElementById(""+idInp + "_hidden");
			if(objInpA !=null){			
				var objOrigInp = document.getElementById(idInp);			
				if(objOrigInp != null){					
				  objOrigInp.name 			= objInpA.name ;				  
					objInpA.parentNode.removeChild(objInpA);											
				}	
			}	
		}	  
}


function deleteContactPerson(num) {
	if (confirm('Přejete si skutečně smazat kontaktní osobu?')) {
		getE('delcpId_' + num).value='1';
		getE('ContactAdd' + num).style.display='none';
		getE('rowC_' + num).style.display='none';
	}
	return true;
}

var nContactPersonInTab = 0;
function addNewContactPerson(num) {
	if (nContactPersonInTab==0) { nContactPersonInTab = num + 1 } else { nContactPersonInTab++ };
	
	rowContactPerson(nContactPersonInTab, "(#" + nContactPersonInTab + ")" , "nová kontaktní osoba", "", "", "","");

	getE('ContactAdd0').innerHTML += 
		'<input type="hidden" id="cpId_'+nContactPersonInTab+'" name="cpId" value="0" />' +
		'<input type="hidden" id="delcpId_'+nContactPersonInTab+'" name="delcpId" value="0" />' +
		'<table class="tblCD" cellpadding="0" cellspacing="0" id="ContactAdd' + nContactPersonInTab + '">' +
		'	<tr>' +
		'	 <td colspan="6" class="bClose"><span><img src="/img/BTClose.gif" alt="Zavřít" title="Zavřít" onclick=" if(!CheckContactPersons('+nContactPersonInTab+',false) ){alert(\'Zapište údaje, nebo formulář odstraňte\')}else{ getE(\'ContactAdd' +  nContactPersonInTab + '\').style.display=\'none\';} " /></span><strong>Detail nové kontaktní osoby - #' + nContactPersonInTab + '</strong></td>' +
		'	</tr>' +
		' <tr>' +
		'  <td class="rNameEx">Jméno:</td>' +
		'  <td class="rInsert"><input class="input_text INP" id="cpFirstName_'+ nContactPersonInTab + '" type="text" name="CPFirstName" maxlength="50" tabindex="5'+nContactPersonInTab+'1" value="" /><span class="decReg">&nbsp;</span></td>' +
		'  <td class="rNameEx">Příjmení:</td>' +
		'  <td class="rInsert"><input class="input_text INP" id="cpLastName_'+ nContactPersonInTab + '" type="text" name="CPLastName" maxlength="100" tabindex="5'+nContactPersonInTab+'2" value="" /><span class="decReg">&nbsp;</span></td>' +
		' </tr>' +
		' <tr>' +
		'  <td class="rNameEx">E-mail:</td>' +
		'  <td class="rInsert"><input class="input_text INP" id="cpEmail_'+ nContactPersonInTab + '" type="text" name="CPEmail" tabindex="5'+nContactPersonInTab+'3" maxlength="100" value="" onblur="if (this.value != \'\') if (!EmailControlRegExp(this.value,true)){this.value=\'\' ;this.focus();}" /><span class="decReg">&nbsp;</span></td>' +
		'  <td class="rNameEx">Zakázat přihlášení:</td>' +
		'  <td class="rInsert"><input id="cpibDisabledLogin_'+ nContactPersonInTab + '" type="checkbox" title="Zakázat přihlášení" class="input_check" tabindex="5'+nContactPersonInTab+'4" value="" name="CPiDisabledLogin" onclick="SetCPDisabledLogin(' + nContactPersonInTab + ');" /><input type="hidden" id="cpDisabledLogin_' + nContactPersonInTab + '" name="CPDisabledLogin" value="0" /></td>' +
		' </tr>' +
		'  <td class="rNameEx">Přístupové jméno:</td>'+
		'  <td class="rInsert"><input class="input_text INP" id="cpLogin_'+ nContactPersonInTab + '" type="text" tabindex="5'+nContactPersonInTab+'6" name="CPLogin" value="" /><span class="decReg">&nbsp;</span></td>'+
		'  <td class="rNameEx">Telefon:</td>' +
		'  <td class="rInsert"><input class="input_text INP" id="cpPhone_'+ nContactPersonInTab + '" type="text" name="CPPhone" value="" tabindex="5'+nContactPersonInTab+'7" onblur="extractNumberEX(this,0,false);" onkeyup="extractNumberEX(this,0,false);" onkeypress="return blockNonNumbers(this, event, false, false);" /><span class="decReg">&nbsp;</span></td>' +
		' </tr>' +
		'		<tr>'+
		'			<td class="rNameEx">&nbsp;</td>'+
		'			<td class="rInsert" colspan="3"><input type="checkbox" name ="CPchangePassword" id="CPchangePassword_'+ nContactPersonInTab +'" value="1" checked="checked" onclick="javascript:this.checked=true;alert(\'U nového kontaktu musíte vyplnit heslo.\')"/>&nbsp;Heslo se nezobrazuje. Pokud chcete heslo změnit, zaškrtněte příslušné políčko</td>'+
		'		</tr>'+
		
		
		' <tr>' +
		'  <td class="rNameEx">Heslo:</td>' +
		'  <td class="rInsert"><input class="input_text INP" id="cpPassword_'+ nContactPersonInTab + '" type="password" tabindex="5'+nContactPersonInTab+'8" name="CPPassword" title="min.5 znaků"  value="" /><span class="decReg">&nbsp;</span></td>' +
		'  <td class="rNameEx">Potvrzení hesla:</td>' +
		'  <td class="rInsert"><input class="input_text INP" id="cpPasswordCheck_'+ nContactPersonInTab + '" type="password" tabindex="5'+nContactPersonInTab+'9" name="CPPasswordCheck" title="min.5 znaků"  value="" /><span class="decReg">&nbsp;</span></td>' +
		' </tr>' +
		
		'		<tr>' +
		'			<td class="rNameEx">Skupina:</td>' +
		'			<td class="rInsert"><span id ="spanForHidenInp_'+nContactPersonInTab+'"></span><div id="RoleSelect_'+nContactPersonInTab+'" style="width:95%;float:left" ><input  id="cpRolesHid_'+nContactPersonInTab+'" type="hidden" name="CPpkRoles" value="" /></div></td>' +
		'			<td class="rNameEx" colspan="2"><img src="/img/selRole.gif" alt="Vybrat skupinu" title="Vybrat skupinu" style="cursor:pointer" onclick="sRoleFn('+nContactPersonInTab+');" /> </td>' +
		
		'		</tr>' +
		'		<tr>' +
		'			<td class="rNameEx" style="" colspan="4" id="tdSelContRole_'+nContactPersonInTab+'">' +
		'		<input type="hidden" name="MultiSelApproverSend" id="MultiSelApproverSend_'+nContactPersonInTab+'" value="" />'+
		'<div style="display:inline;" id="MultiSelMainBox_'+nContactPersonInTab+'">' +
		'	<div style="padding-left: 90px;">' +
		'		<div style="float:left;width:160px;"><div style="background:#aaaaaa;padding:2px 0 2px 2px"><b>Schvaluje objednávky od:</b></div>' +
		'			<select multiple="true" name="MultiSelApprover" id="MultiSelApprover_'+nContactPersonInTab+'" style="height:50px;width:160px">' +
		'			</select>' +
		'		</div>' +
		'		<div style="width: 100px; padding-left: 10px; padding-right: 10px; float:left;"><div>&nbsp;</div>' +
		'			<input type="button" value="přidat &lt;&lt;" onclick="set_APPROVER_Box('+nContactPersonInTab+')" style="width: 100px;" /><br />' +
		'			<input type="button" value="&gt;&gt; odebrat" onclick="del_APPROVER_Box('+nContactPersonInTab+')" style="width: 100px;" />' +
		'		</div>' +
		'		<div style="float:left;width:160px"><div style="background:#aaaaaa;padding:2px 0 2px 3px;"><b>Nepřiřazení:</b></div>' +
		'			<select multiple="true" name="MultiSelCreator" id="MultiSelCreator_'+nContactPersonInTab+'" style="height:50px;width:160px;float:left;">' +
		'			</select>' +
		'		</div>' +
		'	</div>' +
		'</div>' +	
		' 		</td>' +
		'		</tr>' +
		
		' <tr>' +
		'	 <td class="actn" colspan="6"><img src="/img/BTdelitem.gif" style="cursor:pointer" title="Odstranit kontaktni osobu" onclick="deleteContactPerson('+ nContactPersonInTab +');" />&nbsp;&nbsp;<img src="/img/BTsaveitem.gif" style="cursor:pointer" title="Uložit kontaktni osobu" onclick="saveContactPerson('+nContactPersonInTab+');" title="Uložit kontaktni osobu" /></td>' +
		' </tr>' +		
		'</table>';
		sRoleFn(nContactPersonInTab);
		//onChangeSelectElements()
		
}
function CheckContactPersons(num,showAlert)	
{
	var pom2 = nContactPersonInTab;
	var pom = 1;
	if (num != 0) { pom = num; pom2 = num}
	for (i=pom; i< (pom2+1); i++ ) {

		try{				
				if ( getE('delcpId_'+i).value == 0)  {
					if (getE('cpFirstName_'+i).value == ""){showAlert ? alert("Vyplňte jméno kontaktní osoby.") : "" ;getE('cpFirstName_'+i).focus();return false}
					if (getE('cpLastName_'+i).value == ""){showAlert ? alert("Vyplňte příjmení kontaktní osoby.") : ""; getE('cpLastName_'+i).focus();return false}
					if (getE('cpEmail_'+i).value == ""){showAlert ? alert("Vyplňte e-mail kontaktní osoby.") : "" ;getE('cpEmail_'+i).focus();return false}
					if (EmailControlRegExp(getE('cpEmail_'+i).value,false)==false) {getE('cpEmail_'+i).focus();return false;}
					if (getE('cpLogin_'+i).value == ""){showAlert ? alert("Vyplňte přihlašovací jméno kontaktní osoby.") : "";getE('cpLogin_'+i).focus();return false}
					if (getE('cpLogin_'+i).value.length < 5){showAlert ? alert("Přihlašovací jméno musí mít nejméně 5 znaků."):"";getE('cpLogin_'+i).focus();return false}
					if (getE('cpPhone_'+i).value == ""){showAlert ? alert("Vyplňte telefon kontaktní osoby.") : "";getE('cpPhone_'+i).focus();return false}
					
					if(getE('CPchangePassword_'+i) ==null || getE('CPchangePassword_'+i).checked ){
						if (getE('cpPassword_'+i).value == ""){showAlert ? alert("Vyplňte heslo kontaktní osoby.") : "";getE('cpPassword_'+i).focus();return false}
						if (getE('cpPassword_'+i).value.length < 5){showAlert ? alert("Heslo musí mít minimálně 5 znaků.") : "" ;getE('cpPassword_'+i).focus();return false}
						if(getE('cpPassword_'+i).value != getE('cpPasswordCheck_'+i).value){showAlert ? alert("Potvrzené heslo se neshoduje.") : "" ;getE('cpPasswordCheck_'+i).focus();return false}
					}
				}		
			
		}catch(e){			
			alert(e);
			return false;
		}
	}	
		
	
	return true;
}

function SetCPNews(Id) {
	getE('cpNews_'+Id).value = getE('cpiNews_'+Id).checked ? '1' : '0';
}
function SetCPDisabledLogin(Id) {

	getE('cpDisabledLogin_'+Id).value = getE('cpibDisabledLogin_'+Id).checked ? '1' : '0';
	
}

//-- special for GATC---
// Vse na strance do kose
function getOrderAllItem(){

	var BuyForms= document.getElementsByName("FormBuy");
	var y=0 ;
	var BuyFormsChild=null;
	var FormForAll = document.getElementById("FormForAll");
	//var temp=null;
	
	//projede vsechny formulare
	for(var i=0; i < BuyForms.length ;i++ ){
		BuyFormsChild = BuyForms[i].elements;
		var lng=BuyFormsChild.length ;
//parseInt(BuyForms[i].elements.count.value) > 0 &&
		if( BuyForms[i].elements.count.value!=BuyForms[i].elements.count.defaultValue){	
			for(y=0 ;y < BuyFormsChild.length;y++){						
				if(BuyFormsChild[y] ){		
					if(BuyFormsChild[y].nodeName.toLowerCase( )== "input" ){			
						if(BuyFormsChild[y].getAttribute("type").toLowerCase( )!="image"){
							//if(BuyFormsChild[y].getAttribute("type").toLowerCase( )=="text"){alert(	BuyFormsChild[y].setAttribute("type","hidden") )}
							
							FormForAll.appendChild(BuyFormsChild[y]);
							
							y--										
						}			
					}
				}
			}
		}			
	}
	//return
	if(FormForAll.childNodes.length>1){
	FormForAll.submit()
	}else{
	alert("Nemáte vybranou žádnou položku.")
	}
}
//---------------------
function selRowInBasket(){

	var arrpkCount = gnStrPkBasket.split("@|")
	var obj = null;
	var BuyForms= document.getElementsByName("FormBuy");
	
	for(var i =0 ;i< BuyForms.length;i++){
		for(var y =0 ;y < arrpkCount.length;y++){
			arrPkC = arrpkCount[y].split("@")
			var BuyFormsCurrentEl = BuyForms[i].elements	
			if(BuyFormsCurrentEl.nComID.value == arrPkC[0]){
				BuyFormsCurrentEl.count.value=arrPkC[1]
				BuyFormsCurrentEl.count.defaultValue=arrPkC[1]
				BuyFormsCurrentEl.count.style.cssText ="Xbackground:#f3f5f7;color:green";
				BuyFormsCurrentEl.count.style.border="2px solid green"//#fca202"
				BuyFormsCurrentEl.count.title="Tuto položku již máte v košíku.";										
			}		
		}		
	}
}
//---------------------


function selectOrderRow(obj){
// vola se na onblur v inputu count
	if(obj.value==obj.defaultValue) return ;
//	if(parseInt (obj.value)==0 ){return;}
	
	obj.style.color="red"
	obj.style.fontWeight="bold"	
	obj.style.border="solid 2px red"

	//if(bSetEventGb ==null ){
	//	setElementEvent();
	//}
	//bSetEventGb = 1 ;	
}



//**Filtr catAndProd****************
var objAllMRKChecked = true ;
function LoopObj(obj){
	var objChilds = obj.childNodes
	
//return
	for(var i=0;i < objChilds.length;i++){
	
		if(objChilds[i].type=='checkbox' && objChilds[i] != getE('AllMRK') ){			
				if(objChilds[i].checked==false){				
					objAllMRKChecked = false;
					return ;					
				}
		}		
		if(objChilds[i].hasChildNodes()){
			LoopObj(objChilds[i]);
		}		
	}
}
function checkbAllChecked (obj){
	LoopObj(obj)
	getE('AllMRK').checked=false;
	
	if( objAllMRKChecked ){  getE('AllMRK').checked=true;}
}

function setAllCheckEX(obj) {
	//getE('fillterProdIn')	
	var objChilds = obj.childNodes	 
	for(var i=0;i < objChilds.length;i++){
		if(objChilds[i].type=='checkbox'){			
				objChilds[i].checked=true;
		}		
		if(objChilds[i].hasChildNodes()){
			setAllCheckEX(objChilds[i]);
		}else{		
		
		}			
	}		 
}

function setAllNoCheckEX(obj) {
	//getE('fillterProdIn')	
	var objChilds = obj.childNodes	 
	for(var i=0;i < objChilds.length;i++){
		if(objChilds[i].type=='checkbox'){			
				objChilds[i].checked=false;
		}
		
		if(objChilds[i].hasChildNodes()){
			setAllNoCheckEX(objChilds[i]);
		}else{		
			//return false ;
		}			
	}		 
}
//**Filtr catAndProd****************
//**********************************
//==========================================
//==== Editace roli pro kontaktni osoby=====
function onChangeSelectElements(){
	var obj = document.getElementsByName("CPpkRoles")
	var id="";
	var objIn = null;
	var objLength = obj.length
	//alert(obj.length)
	for(var i=0; i < objLength ;i++){
	
		objIn = obj[i] 
		if (objIn.tagName.toLowerCase( )=="input"){
			id= objIn.id.replace("cpRolesHid_","")
		//alert(objIn.id+'|'+id)
			changeSelRoleBox(id,objIn.value)	
		}else{			
			id=objIn.id.replace("cpRolesHid_","")			
			changeSelRoleBox(id,objIn.options[objIn.selectedIndex].value)
		}
		
	}
}

function setCreatorToRoleBox(){
//--nastavi CREATOR box na aktualni kreatory

	
	var obj = document.getElementsByName("CPpkRoles")
	var objMultiSelCreatorBox = 	document.getElementsByName("MultiSelCreator")
	var objApprover = document.getElementsByName("MultiSelApprover")
	var bExist=false
		
	delete_CREATOR_MultiOption();			//smazne vsechny CREATOR Boxy  
		
	for(var i=0; i < obj.length;i++){ //najde creatora a do vsech CREATOR boxu ho Zapise pokud jiz neni v APPROVER
		var cpId = obj[i].id.replace("cpRolesHid_","")
		if(obj[i].value=="CREATOR" &&  getE("cpId_"+cpId).value!=0 ){
				
			var strName = obj[i].id.replace("cpRolesHid_","cpFirstName_");
			var strText = getE(strName).value;					
		
			var sValue = getE("cpId_"+cpId).value ;
			var nameElement = "optionCpId_"+cpId  //+"_"+sValue+"_"+strText ;
			
			for(var x = objApprover.length-1 ;x>=0; x--){	//vsechny okna APPROVER
				var objApproverItem = objApprover[x]
				var selIndex = objApproverItem.options.length;	
				if (selIndex != -1) {
			    for(xx=objApproverItem.length-1; xx>=0; xx--){
					//alert(objApproverItem.options[xx].id+'|'+ nameElement) 					 
						if (objApproverItem.options[xx].id == nameElement ){						
							//alert(objApproverItem.options[xx].id + ' je již přidělen !')	
							bExist =true;
							//break ;						
						}						 
			    }
			  }						
			}
		
			if (!bExist) {
				for(var y=0 ;y < objMultiSelCreatorBox.length;y++){	
					id = objMultiSelCreatorBox[y].id.replace("MultiSelCreator_","")			
					add_CREATOR_MultiOption(id,nameElement,sValue,strText)
				}	
			}
			bExist =false						
		}
	}		
}

function set_APPROVER_Box(id){
//onclick na tlacitko <<
//presune z boxu CREATOR do boxu APPROVE 
//	delete_APPROVER_MultiOption()


	var obj = getE("MultiSelCreator_"+id) ;		
	var selIndex = obj.options.length;	
	if (selIndex != -1) {
    for(i=obj.length-1; i>=0; i--){   
			if (obj.options[i].selected){		
			
				add_APPROVER_MultiOption(id,obj.options[i])
				
			}		    
    }
  }
  check_APPROVER_Exists(id) // zjisti jestli existuje v APPROVER boxu nejaky CREATOR
	setCreatorToRoleBox()  
}

function del_APPROVER_Box(id){
//onclick na tlacitko >>
//presune z boxu APPROVER  do boxu CREATOR respektive smaze z APPROVER

	var obj = getE("MultiSelApprover_"+id) ;		
	var selIndex = obj.options.length;	
	if (selIndex != -1) {
    for(i=obj.length-1; i>=0; i--){   
			if (obj.options[i].selected){					
				obj.options[i] = null;
				 
			}		    
    }
  }
  check_APPROVER_Exists(id)
	setCreatorToRoleBox()
	 
}

function changeSelRoleBox(id,sValue){
//na onchange selectu	
//alert(id)
//alert(getE("cpId_"+id).value)
	//var cpId = id //getE("cpId_"+id).value ;
	
	switch (sValue) {
		case "VIEW_ONLY":
			getE("MultiSelMainBox_"+id).style.display="none"
			delete_APPROVER_MultiOptionItem(id)		//smaze APPROVER box kde se nachazi tento kontakt (nadrazeneho schvalovace)
			delete_APPROVER_MultiOption(id);			//delete (vlastniho) celeho APPROVER boxu
						
			break ;	
		case "CREATOR":		
			getE("MultiSelMainBox_"+id).style.display="none"
			
		//	delete_APPROVER_MultiOption(id); 			//delete (vlastniho) celeho APPROVER boxu	
					
			break ;
		case "APPROVER_ONLY":
		
			getE("MultiSelMainBox_"+id).style.display=""

// 			var objOptionContact = document.getElementsByName("optionCpId_"+id) 
// 			alert(objOptionContact.length)
			delete_APPROVER_MultiOptionItem(id)		//smaze APPROVER box kde se nachazi tento kontakt (nadrazeneho schvalovace)
			
			break ;
		case "APPROVER_CREATOR":
			getE("MultiSelMainBox_"+id).style.display=""
			
			delete_APPROVER_MultiOptionItem(id)		//smaze APPROVER box kde se nachazi tento kontakt (nadrazeneho schvalovace)
			break
			
		default :
		getE("MultiSelMainBox_"+id).style.display=""
		getE("RoleSelect_"+id).innerHTML=sRoleFn(id);"" 
	}
	setCreatorToRoleBox();
	
	
}
function check_APPROVER_Exists(id){

	var objAllBox = document.getElementById("MultiSelApprover_"+id)
	var selIndex = objAllBox.options.length;
	if (selIndex != -1) {
	
		if(objAllBox.length > 0){		
			getE("cpRolesHid_"+id).disabled=true;	//protoze je to disabled musime oddisablovat aby se odeslal s formem(viz  selectAllApprover())
			if (getE("cpRolesHid_"+id).tagName.toLowerCase( )=="input"){
				val = getE("cpRolesHid_"+id).value 
			}else if(getE("cpRolesHid_"+id).tagName.toLowerCase( )=="select") {
				var selIndexA = getE("cpRolesHid_"+id).selectedIndex				
				val= getE("cpRolesHid_"+id).options[selIndexA].value		
			}
		 		
		}else{
			getE("cpRolesHid_"+id).disabled=false;
			//getE("cpRolesHid_"+id).name='CPpkRoles'
			getE("spanForHidenInp_"+id).innerHTML=""
		}		
	}
	
	
	
}

function delete_APPROVER_MultiOptionItem(id){
//	return;
	var objAllBox = document.getElementsByName("MultiSelApprover")
	for(var y=0 ;y < objAllBox.length;y++){	
		 
		var obj =objAllBox[y]
		var selIndex = obj.options.length; 
		if (selIndex != -1) {
	    for(i=obj.length-1; i>=0; i--){ 
	    	if(obj.options[i].id == "optionCpId_"+id ){
	        obj.options[i] = null;				     
	      } 
	    }	    
	  }	  
	  var num = objAllBox[y].id.replace("MultiSelApprover_","")	
		check_APPROVER_Exists(num)		
	}
	
} 


function delete_CREATOR_MultiOption(){
//smaze vse ze vsech  CREATOR boxu

	var objAllBox = document.getElementsByName("MultiSelCreator")
//	alert(objAllBox.length)
	for(var y=0 ;y < objAllBox.length;y++){	
		var obj =objAllBox[y]// getE("MultiSelCreator") ;
		var selIndex = obj.options.length; 
		if (selIndex != -1) {
	    for(i=obj.length-1; i>=0; i--)
	    { 
	        obj.options[i] = null;     
	    }
	  }	
	}  
}

function delete_APPROVER_MultiOption(id){
//delete celeho APPROVER boxu
	var obj = getE("MultiSelApprover_"+id) ;
	var selIndex = obj.options.length; 
	if (selIndex != -1) {
    for(i=obj.length-1; i>=0; i--)
    { 
        obj.options[i] = null;     
    }
  }
}

function add_CREATOR_MultiOption(id,nameElement,sValue,sText){

	var el =  new Option();// document.createElement("OPTION")
	    el.value = sValue;		
			//el.text=sText;
			el.name = nameElement;
			el.text=sText ;   //+"|"+nameElement ;	
			getE("MultiSelCreator_"+id).options.add(el)
}

function add_APPROVER_MultiOption(id,el){ 
 		
 	var obj = getE("MultiSelApprover_"+id) ;		
 	var selIndex = obj.options.length ;	
	var bIsSameElement = false;	
	if( selIndex > 0 ) {
    for(var i=(obj.length)-1; i>=0; i--){    
			if (el ==  obj.options[i] ){  //obj.options[i].value==sValue && obj.options[i].text==sText) {					
				bIsSameElement =true
				return;				
			}			
		}
   }
	
	 if(!bIsSameElement){
	 		var eel = document.createElement("OPTION")
 	    eel.value = el.value;		
 			eel.text=el.text;
			eel.id=el.name;
				
			getE("MultiSelApprover_"+id).options.add(eel)	 
	 }
}
function selectAllApprover(){
//pri odesilani formu
	var objAllBox = document.getElementsByName("MultiSelApprover")
	for(var y=0 ;y < objAllBox.length;y++){	
		
		var obj =objAllBox[y]
		var id=obj.id.replace("MultiSelApprover_","")		
		getE("cpRolesHid_"+id).disabled=false; // nektere jsou disabled , aby se to odeslalo musime oddisablovat 
		var selIndex = obj.options.length; 
		if (selIndex != -1) {
	    for(i=obj.length-1; i>=0; i--){ 
	    //alert(obj[i].value)
	    	getE("MultiSelApproverSend_"+id).value += obj[i].value+'||';	    	
			}
		}else{
		
		
		}
	}
	return true//false
}
//===========================================
//==========================================
function fnChangeBtnMultiOrder(){
	getE("btn_ACTUAL_SendOrder").style.display=""; 
 	getE("btn_SEND_SendOrder").innerHTML=""; // input musi uplne zmizet aby neslo odeslat form pres enter (mozilla)
	


}

function fnChangeBtn(){
//casovac na order. po uplynuti nastavene doby se zmeni tlacitka aby si klient aktualizoval ceny

	getE("btn_ACTUAL_SendOrder").style.display=""; 
 	getE("btn_SEND_SendOrder").innerHTML=""; // input musi uplne zmizet aby neslo odeslat form pres enter (mozilla)


	var objForm = getE("OrderForm")

	if(getE("order_do") != null ){
		//u neregistrovanych musime nechat zmizet aby se nepridal klient do tbl
		var order_do 			= getE("order_do");
		//var order_Firm		= getE("order_Firm");
		var order_NoRgUsr = getE("order_NoRgUsr");
		order_do.value="" ;
		//order_Firm.value=""  ;
		//order_NoRgUsr.value = "0";
	}
	getE("btn_ACTUAL_TOP_SendOrder").style.display =""
	objForm.elements.Step.value="0" ;

}

//===========================================
//===========================================

function getLabelSelected(){
	var e ;
	try{
		var obj = document.getElementsByTagName ("label")
		for (var i=0;i<obj.length;i++){		
			var ido = obj[i].attributes['for'].value
			if(getE(ido)!=null){
			
				if(getE(ido).checked ){
					obj[i].style.cssText += "cursor:pointer;font-weight:bold" //font.weight="bold" //color="red"			
				}else{
					obj[i].style.cssText = "cursor:pointer;font-weight:normal"
				}	
			}	
		}
	}catch(e){
	//alert(e)
	}
	
}
//  function zprava(en)
// {
// // identifikace prohlížeče
// var ver = parseInt(navigator.appVersion);
// var browser = navigator.appName;
// //blok příkazů pro NN
// if (ver >= 4 & browser == "Netscape") {var tlacitko = en} ;
// // blok příkazů pro IE
// if (ver >= 4 & browser == "Microsoft Internet Explorer") {
// var tlacitko = event.button
// //převedení získaných hodnot tak, aby byly kompatibilní s NN
// if (tlacitko ==2) {tlacitko = 3};
// if (tlacitko ==4) {tlacitko = 2};
// }
// if (tlacitko == 1) {alert ("Klikli jste na levé tlačítko myši")};
// if (tlacitko == 2) {alert ("Klikli jste na prostřední tlačítko myši")};
// if (tlacitko == 3) {alert ("Klikli jste na pravé tlačítko myši")};
// return false;
// } 
//  function onunload_checkSelRow(){
// return confirm(0)
// 
// }
// bSetEventGb = null
//  
// 	function setElementEvent(){
// 	
// 		var obj = document.getElementsByTagName("a")
// 		for(var i=0 ; i < obj.length;i++){
// 			addEvent(obj[i])
// 		}		
// 		obj = document.getElementsByTagName("input")
// 		for(var i=0 ; i < obj.length;i++){
// 		
// 			if(obj[i].type=="checkbox"){
// 			
// 				addEvent(obj[i])
// 			}
// 		}	
// 	}
// 	
// 	function addEvent(target){
// 	  
//   	if(document.all && !document.addEventListener){
// 		//	eval('target.onclick=fnA()');
// 			target.attachEvent("onclick", checkEvent);
// 		}else{
// 	
// 			target.addEventListener('click',checkEvent,false);
// 		} 
// 	}
// 	var gb = null
// 	function checkEvent(event){
// 	
// 
// 	
// 		if( document.all ){
// 	
// 		//	if(event.srcElement != event.target) return ; 
// 			if(!confirm("ieieie",'kkk')) {						
// 				event.cancelBubble =true;return false;
// 				
// 			}
// 			
// 		}else{
// 				if(event.target!=event.currentTarget ) return ; // v mozila se zastavuje i na parentovych elementech
// // 			if(gb!=null) return;
// // 			gb=1 
// 			if(!confirm("ffff",'kkk')){
// 	 			event.stopPropagation();
// 				event.preventDefault();
// 				
// 			}else{
// 				//alert(event.relatedTarget  )
// 			
// 			}	
// 		}	
// 	}

//END special for GATC










