// 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.IE8	= (this.VER.indexOf("MSIE 8")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE		= (this.IE4 || this.IE5 || this.IE6 || this.IE7 || this.IE8);

	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 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()+";";
	}
	if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
}

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;
}

function addBookmark() {
	var sTitle, sUrl;
	
	sTitle = document.title;
  sUrl  = document.location.href;
  
	if (window.sidebar) {
		window.sidebar.addPanel(sTitle, sUrl,"");
	} 
	else if ( document.all ) {
		window.external.AddFavorite( sUrl, sTitle);
	} 
	else if ( window.opera && window.print )
		{
			return true;
		}
}

// ###   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;
}



/* 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 controlMaxNumber(value,nMax){
		if(value > nMax && value >= 1){    
        alert("Číslo stránky musí být v rozmezí od 1 - " + nMax);
        return false;
    }else{    
        return true;
    }
}
function ControlFloat(){
	if (!Br.IE) return;
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode !=46)) event.returnValue = false;
}

function ControlNumber(e){
	var keynum
	var keychar
	var numcheck
	if(window.event){
		keynum = e.keyCode
	}
	else if(e.which){
		keynum = e.which
	}
	return ((keynum >= 48) && (keynum <= 57)) || keynum == 8
}

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;
}
//----------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) {
		window.open('/ShowImage.asp?IMG=' + sImgPath, "Foto","scrollbars=0,status=0,toolbar=0,location=0,directories=0,height=100,width=100,resizable=1");
}


//       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;
}


// 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();
}


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 )
	}
}
/* /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 ) {
	var e = getE("avaibilitybox");
	e.style.display = "";
	e.style.position = "absolute";
	e.style.top = topScroll() + 200+'px';
	e.style.left = (document.body.clientWidth/2 - 200)+'px';
	document.forms.avaibilityform.elements.code.value = code;
	document.forms.avaibilityform.elements.count.value = "Zjišťuje se...";
	window.frames.avaibilityFrame.document.location = "Avaibility.asp?sCode=" + code;
}

function hideAvaibilityDialog() {
	var e = getE( "avaibilitybox" );
	e.style.display = "none";
}


// ShopInfoBox
function showShopInfoDialog() {
	clearTimeout;
	if (Br.IE) {
		if (getE('itemsOnPageSelect')) getE('itemsOnPageSelect').style.visibility='hidden';
		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() + 200+'px';
	e.style.left = (document.body.clientWidth/2 - 200)+'px';
	setTimeout("hideShopInfoboxDialog();", 20000);
}

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){
	//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 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 EmailControl(sEmail){
	var regEx  = new RegExp("^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$"); 
	
	regEx.ignoreCase = true;
		
	if (regEx.test(sEmail) == false)	{
		alert('Nesprávný formát emailu');
		return false;
	}
	//alert('NEJSI KOKOT');
	return true;
}

function EmailControlRegExp(f, bShowMsg)
 {
//   if (sEmail=='' || sEmail=='Váš@email.cz')
//   {
//     if (bShowMsg) alert('Nesprávný formát emailu');
// 		return false;
//   }
 
if(f.replace(/^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/,"")=="") {

		return true
	} else {
		if (bShowMsg) alert('Nesprávný formát emailu');
		return false;
	}
									
  return true;
} 

function CheckContactPersons(num)	
{
	var pom2 = nContactPersonInTab;
	var pom = 1;
	if (num != 0) { pom = num; pom2 = num}
	for (i=pom; i< (pom2+1); i++ ) {
		if ( getE('delcpId_'+i).value == 0)  {
			if (getE('cpFirstName_'+i).value == ""){alert("Vyplňte jméno kontaktní osoby.");getE('cpFirstName_'+i).focus();return false}
			if (getE('cpLastName_'+i).value == ""){alert("Vyplňte příjmení kontaktní osoby.");getE('cpLastName_'+i).focus();return false}
			if (getE('cpEmail_'+i).value == ""){alert("Vyplňte e-mail kontaktní osoby.");getE('cpEmail_'+i).focus();return false}
			if (EmailControl(getE('cpEmail_'+i).value)==false) {getE('cpEmail_'+i).focus();return false;}
			if (getE('cpLogin_'+i).value == ""){alert("Vyplňte přihlašovací jméno kontaktní osoby.");getE('cpLogin_'+i).focus();return false}
			if (getE('cpLogin_'+i).value.length < 5){alert("Přihlašovací jméno musí mít nejméně 5 znaků.");getE('cpLogin_'+i).focus();return false}
			if (getE('cpPhone_'+i).value == ""){alert("Vyplňte telefon kontaktní osoby.");getE('cpPhone_'+i).focus();return false}
			if (getE('cpPassword_'+i).value == ""){alert("Vyplňte heslo kontaktní osoby.");getE('cpPassword_'+i).focus();return false}
			if (getE('cpPassword_'+i).value.length < 5){alert("Heslo musí mít minimálně 5 znaků.");getE('cpPassword_'+i).focus();return false}
			if(getE('cpPassword_'+i).value != getE('cpPasswordCheck_'+i).value){alert("Potvrzené heslo se neshoduje.");getE('cpPasswordCheck_'+i).focus();return false}
		}
	}
	return true;
}	

function CheckClientAddress(num)	
{
	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 == ""){alert("Vyplňte název firmy doručovací adresy.");getE('caFirm_'+i).focus();return false}
			if (getE('caStreet_'+i).value == ""){alert("Vyplňte ulici doručovací adresy.");getE('caStreet_'+i).focus();return false}
			if (getE('caCity_'+i).value == ""){alert("Vyplňte město doručovací adresy.");getE('caCity_'+i).focus();return false}
			if (getE('caZipCode_'+i).value == ""){alert("Vyplňte PSČ doručovací adresy.");getE('caZipCode_'+i).focus();return false}
		}
	}
	return true;
}	

function ControlUserDataSubmit(){

	if(getF('UserDataForm').Firm.value == ""){alert("Vyplňte název firmy.");getF('UserDataForm').Firm.focus();return false}
	if(getF('UserDataForm').Street.value == ""){alert("Vyplňte ulici fakturační adresy.");getF('UserDataForm').Street.focus();return false}
	if(getF('UserDataForm').City.value == ""){alert("Vyplňte město fakturační adresy.");getF('UserDataForm').City.focus();return false}
	if(getF('UserDataForm').ZipCode.value == ""){alert("Vyplňte PSČ fakturační adresy.");getF('UserDataForm').ZipCode.focus();return false}
	
	if(getF('UserDataForm').ICO.value == ""){alert("Vyplňte IČO.");getF('UserDataForm').ICO.focus();return false}
	if(!ValidateAccount(getF('UserDataForm').BankAccount.value)){alert("Bankovní účet není platný, zkuste jej zadat znovu, nebo pole nevyplňujte.");getF('UserDataForm').BankAccount.focus();return false};

//	if(getF('UserDataForm').FirstName.value == ""){alert("Vyplňte jméno.");getF('UserDataForm').FirstName.focus();return false}
//	if(getF('UserDataForm').LastName.value == ""){alert("Vyplňte příjmení.");getF('UserDataForm').LastName.focus();return false}
//	if(getF('UserDataForm').Email.value == ""){alert("Vyplňte email.");getF('UserDataForm').Email.focus();return false}
	if(getF('UserDataForm').Phone.value  == ""){alert("Vyplňte telefon!.");getF('UserDataForm').Phone.focus();return false}

//	if(getF('UserDataForm').Login.value == ""){alert("Vyplňte přihlašovací jméno.");getF('UserDataForm').Login.focus();return false}
//	if(getF('UserDataForm').Login.value.length < 5){alert("Přihlašovací jméno musí mít nejméně 5 znaků.");getF('UserDataForm').Login.focus();return false}
//	if(getF('UserDataForm').Password.value == ""){alert("Vyplňte heslo.");getF('UserDataForm').Password.focus();return false}
//	if(getF('UserDataForm').Password.value.length < 5){alert("Heslo musí mít minimálně 5 znaků.");getF('UserDataForm').Password.focus();return false}
//	if(getF('UserDataForm').Password.value != getF('UserDataForm').PasswordCheck.value){alert("Potvrzené heslo není správně.");getF('UserDataForm').Password.focus();return false}

	return true;
}

function ControlUserDataSubmitWithPerson(){
	if(getF('UserDataForm').Firm.value == ""){alert("Vyplňte název firmy.");getF('UserDataForm').Firm.focus();return false}
	if(getF('UserDataForm').Street.value == ""){alert("Vyplňte ulici fakturační adresy.");getF('UserDataForm').Street.focus();return false}
	if(getF('UserDataForm').City.value == ""){alert("Vyplňte město fakturační adresy.");getF('UserDataForm').City.focus();return false}
	if(getF('UserDataForm').ZipCode.value == ""){alert("Vyplňte PSČ fakturační adresy.");getF('UserDataForm').ZipCode.focus();return false}
	if(getF('UserDataForm').Phone.value == ""){alert("Vyplňte telefon.");getF('UserDataForm').Phone.focus();return false}
	
	if(getF('UserDataForm').ICO.value == ""){alert("Vyplňte IČO.");getF('UserDataForm').ICO.focus();return false}
	if(!ValidateAccount(getF('UserDataForm').BankAccount.value)){alert("Bankovní účet není platný, zkuste jej zadat znovu, nebo pole nevyplňujte.");getF('UserDataForm').BankAccount.focus();return false};


	if(getF('UserDataForm').CPLogin.value == ""){alert("Vyplňte přihlašovací jméno ( email ).");getF('UserDataForm').CPLogin.focus();return false}
	if(!EmailControlRegExp(getF('UserDataForm').CPLogin.value,true)){getF('UserDataForm').CPLogin.focus();return false;}
	if(getF('UserDataForm').CPPassword.value == ""){alert("Vyplňte heslo.");getF('UserDataForm').CPPassword.focus();return false}
	if(getF('UserDataForm').CPPassword.value.length < 5){alert("Heslo musí mít minimálně 5 znaků.");getF('UserDataForm').CPPassword.focus();return false}
	if(getF('UserDataForm').CPPassword.value != getF('UserDataForm').CPPasswordCheck.value){alert("Potvrzené heslo není správně.");getF('UserDataForm').CPPassword.focus();return false}
	if(getF('UserDataForm').CPFirstName.value == ""){alert("Vyplňte jméno.");getF('UserDataForm').CPFirstName.focus();return false}
	if(getF('UserDataForm').CPLastName.value == ""){alert("Vyplňte příjmení.");getF('UserDataForm').CPLastName.focus();return false}
	if(getF('UserDataForm').CPMobil.value == ""){alert("Vyplňtemobil.");getF('UserDataForm').CPMobil.focus();return false}

	
}

function ControlUserDataSubmitPerson(){
//ICO
	if(getF('UserDataForm').Firm){
		if(getF('UserDataForm').Firm.value == ""){alert("Vyplňte název firmy.");getF('UserDataForm').Firm.focus();return false}
		}
	if(getF('UserDataForm').ICO){
		if(getF('UserDataForm').ICO.value == ""){alert("Vyplňte IČO.");getF('UserDataForm').ICO.focus();return false}
		}
	if(getF('UserDataForm').Login.value == ""){alert("Vyplňte přihlašovací jméno ( email ).");getF('UserDataForm').Login.focus();return false}
//	if(!EmailControlRegExp(getF('UserDataForm').Email.value,true)){getF('UserDataForm').Email.focus();return false;}
	if(!EmailControlRegExp(getF('UserDataForm').Login.value,true)){alert("Špatný formát emailu ( loginu ) ");getF('UserDataForm').Login.focus();return false;}
	if(getF('UserDataForm').Password.value == ""){alert("Vyplňte heslo.");getF('UserDataForm').Password.focus();return false}
	if(getF('UserDataForm').Password.value.length < 5){alert("Heslo musí mít minimálně 5 znaků.");getF('UserDataForm').Password.focus();return false}
	if(getF('UserDataForm').Password.value != getF('UserDataForm').PasswordCheck.value){alert("Potvrzené heslo není správně.");getF('UserDataForm').Password.focus();return false}
	if(getF('UserDataForm').FirstName.value == ""){alert("Vyplňte jméno.");getF('UserDataForm').FirstName.focus();return false}
	if(getF('UserDataForm').LastName.value == ""){alert("Vyplňte příjmení.");getF('UserDataForm').LastName.focus();return false}
	if(getF('UserDataForm').Mobil.value == ""){alert("Vyplňte mobil.");getF('UserDataForm').Mobil.focus();return false}
	return true;
}

function ControlDataOrder(){
	var isCheck = false;
	for (var i=0; i < getF('OrderForm').DeliveryType.length; i++) {
		if (getF('OrderForm').DeliveryType[i].checked) isCheck = true;
	}
	if (!isCheck) {alert("Vyberte způsob dopravy."); return false}

	isCheck = false;
	for (var i=0; i < getF('OrderForm').PaymentType.length; i++) {
		if (getF('OrderForm').PaymentType[i].checked) isCheck = true;
	}
	if (!isCheck) {alert("Vyberte způsob platby.");	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;
	}
}

//------------- 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.innerHTML = street;
	var tCell = tRow.insertCell(2);
	tCell.innerHTML = city;
	var tCell = tRow.insertCell(3);
	tCell.innerHTML = zipcode;
	var tCell = tRow.insertCell(4);
	tCell.className = "actn";
	tCell.innerHTML = "<input type='image' class='btnBGs' src=\"/img/BTko.gif\" onclick='deleteClientAddress(" + num + "); return false;' title='Odstranit dodací adresu' />";
}

function saveClientAddress(num) {
	if (CheckClientAddress(num)) {
		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/BTko.gif" alt="Zavřít" title="Zavřít" onclick="getE(\'AddressAdd' +  nClientAddressInTab + '\').style.display=\'none\'; " /></span><strong>Detail nové dodací adresy - #' + nClientAddressInTab + '</strong></td>' +
		'	</tr>' +
		' <tr>' +
		'  <td class="RName">Firma:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="caFirm_'+ nClientAddressInTab + '" type="text" name="CAFirmDelivery" maxlength="100" tabindex="127" value="" /><span class="decReg">!</span></td>' +
		'  <td class="RName">Ulice:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="caStreet_'+ nClientAddressInTab + '" type="text" name="CAStreetDelivery" maxlength="255" tabindex="128" value="" /><span class="decReg">!</span></td>' +
		' </tr>' +
		' <tr>' +
		'  <td class="RName">Město:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="caCity_'+ nClientAddressInTab + '" type="text" name="CACityDelivery" tabindex="129" maxlength="100" value="" /><span class="decReg">!</span></td>' +
		'  <td class="RName">PSČ:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="caZipCode_'+ nClientAddressInTab + '" type="text" name="CAZipCodeDelivery" value="" maxlength="6" tabindex="130" onkeypress="return ControlPSC();" /><span class="decReg">!</span></td>' +
		' </tr>' +
		' <tr>' +
		'	 <td class="actn" colspan="6"><input type="image" src="/img/BTdelitem.gif" title="Odstranit dodací adresu onclick="deleteClientAddress('+ nClientAddressInTab +'); return false;" />&nbsp;&nbsp;<input type="image" src="/img/BTsaveitem.gif" title="Uložit dodací adresu" onclick="saveClientAddress('+nClientAddressInTab+'); return false;" title="Uložit dodací adresu osobu" /></td>' +
		' </tr>' +
		'</table>';
}

//------------- 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) {
	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(1);
	tCell.onclick = function() {changeSelectedContactPerson(num);};
	tCell.className = "cFN" ;
	tCell.innerHTML = jmeno;
	var tCell = tRow.insertCell(2);
	tCell.innerHTML = email;
	var tCell = tRow.insertCell(3);
	tCell.innerHTML = phone;
	var tCell = tRow.insertCell(4);
	tCell.className = "actn";
	tCell.innerHTML = news;
	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)) {
		if (getE('cpNews_' + num).value == 1)
			var sNews = 'Ano';
		else
			var sNews = 'Ne';
		rowContactPerson( num, '(#' + num + ') ' + getE('cpLogin_' + num).value, getE('cpFirstName_' + num).value + ' ' + getE('cpLastName_' + num).value, getE('cpEmail_' + num).value, getE('cpPhone_' + num).value, sNews);
		getE('ContactAdd' + num).style.display='none';
	}
	return true;
}

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/BTko.gif" alt="Zavřít" title="Zavřít" onclick="getE(\'ContactAdd' +  nContactPersonInTab + '\').style.display=\'none\'; " /></span><strong>Detail nové kontaktní osoby - #' + nContactPersonInTab + '</strong></td>' +
		'	</tr>' +
		' <tr>' +
		'  <td class="RName">Jméno:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="cpFirstName_'+ nContactPersonInTab + '" type="text" name="CPFirstName" maxlength="50" tabindex="119" value="" /><span class="decReg">!</span></td>' +
		'  <td class="RName">Příjmení:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="cpLastName_'+ nContactPersonInTab + '" type="text" name="CPLastName" maxlength="100" tabindex="120" value="" /><span class="decReg">!</span></td>' +
		' </tr>' +
		' <tr>' +
		'  <td class="RName">E-mail:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="cpEmail_'+ nContactPersonInTab + '" type="text" name="CPEmail" tabindex="121" maxlength="100" value="" onblur="if (this.value != \'\') if (!EmailControl(this.value)) this.value=\'\';" /><span class="decReg">!</span></td>' +
		'  <td class="RName">Odběr novinek:</td>' +
		'  <td class="RInsert"><input id="cpiNews_'+ nContactPersonInTab + '" type="checkbox" title="Odběr novinek a akčního zboží" class="input_check" tabindex="122" value="" name="CPiNews" onclick="SetCPNews(' + nContactPersonInTab + ');" /><input type="hidden" id="cpNews_' + nContactPersonInTab + '" name="CPNews" value="0" /></td>' +
		' </tr>' +
		'  <td class="RName">Login:</td>'+
		'  <td class="RInsert"><input class="input_text INP" id="cpLogin_'+ nContactPersonInTab + '" type="text" tabindex="124" name="CPLogin" value="" /><span class="decReg">!</span></td>'+
		'  <td class="RName">Telefon:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="cpPhone_'+ nContactPersonInTab + '" type="text" name="CPPhone" value="" tabindex="123" onkeypress="return ControlPhone();" /><span class="decReg">!</span></td>' +
		' </tr>' +
		' <tr>' +
		'  <td class="RName">Heslo:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="cpPassword_'+ nContactPersonInTab + '" type="password" tabindex="125" name="CPPassword" title="min.5 znaků"  value="" /><span class="decReg">!</span></td>' +
		'  <td class="RName">Potvrzení hesla:</td>' +
		'  <td class="RInsert"><input class="input_text INP" id="cpPasswordCheck_'+ nContactPersonInTab + '" type="password" tabindex="126" name="CPPasswordCheck" title="min.5 znaků"  value="" /><span class="decReg">!</span></td>' +
		' </tr>' +
		' <tr>' +
		'	 <td class="actn" colspan="6"><input type="image" src="/img/BTdelitem.gif" title="Odstranit kontaktni osobu" onclick="deleteContactPerson('+ nContactPersonInTab +'); return false;" />&nbsp;&nbsp;<input type="image" src="/img/BTsaveitem.gif" title="Uložit kontaktni osobu" onclick="saveContactPerson('+nContactPersonInTab+'); return false;" title="Uložit kontaktni osobu" /></td>' +
		' </tr>' +
		'</table>';
}

function SetCPNews(Id) {
	getE('cpNews_'+Id).value = getE('cpiNews_'+Id).checked ? '1' : '0';
}

function checkCount( myCount, minCount, sUnit, onlyMultiplied ) {
	myCount = parseInt(myCount.replace(",","."));
	minCount = parseInt(minCount.replace(",","."));
	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 GoToPage(nPage, sParam) {
	document.location.href = '?pgID=' + nPage + sParam;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function ShowCalendar(oid)
 {
  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;
  
  cal.style.top = tbox.offsetTop + tbox.offsetHeight;
  cal.style.left = tbox.offsetLeft;
  
  calframe.src = ssrc;
  cal.style.display = 'block';
 }
