// 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.IE  = (this.IE4 || this.IE5 || this.IE6);

 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 getFEx(formName, oDocument) {
	return oDocument.forms[formName];
}

function getEEx(objectID, oDocument) {
	return oDocument.getElementById(objectID);
}

function SetDSP2(nType, sURL) 
{
	var vyprs=new Date();	
	vyprs.setDate(vyprs.getDate() + 14);
	window.location.href=sURL + '&DSP=' + nType;
}

function SetDSP(nDSP, sURL) {
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);

	if (nDSP==1) {
		document.cookie="DSP=1; expires="+vyprs.toGMTString()+";";
	} else {
		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;
}

// ###   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';
}

function BuyOrSetVariableParams(sFormSuffix,sFormIndex, bType,x, y) 
{
		var sSelects, nWindowHeight;
	    gsFormIndex = sFormIndex;
	    gsFormSuffix = sFormSuffix;
	    var e = getE('BuyItem' + sFormIndex);
				
		if (bType != 2)       				
			x= 235;
		else
			x= 120;

		if (bType != 0)      
			y = y + topScroll() - 320;
	   else
			y= 70;
		
		getE("StateInfo1").style.left = x + 'px';
		getE("StateInfo1").style.top = y + 'px';
		
        sSelects = "FormBuy" + sFormSuffix; // + sFormIndex;

		document.forms[sSelects].submit();
}

function findPosX2(Obj)
// nalezne absolutni souradnice objektu
{
  var x= -Obj.offsetLeft; 
  var y= -Obj.offsetTop; 
  var temp;
  
  if (Obj.offsetParent) {
    temp = Obj;
    while (temp.offsetParent) {
      temp = temp.offsetParent;
      x += temp.offsetLeft;
      y += temp.offsetTop;
    }
  }
  
  x += Obj.offsetLeft;
  y += Obj.offsetTop;
  
  return x; 
}
function findPosX(obj)
{
var curleft = 0;
var x = obj;
while (x.parentNode && x.tagName != 'BODY' )
{
    x = x.parentNode;
   curleft += x.offsetLeft ;
   alert(x.tagName + ".." + x.offsetLeft); 
}
	
//	if (obj.offsetParent)
//	{
//		while (obj.offsetParent && obj.tagName != 'body')// obj.id != '')
//		{
//			curleft += obj.offsetLeft
//
//			obj = obj.offsetParent;
//		}
//	}
//	else if (obj.x)
//	{
//	aleret("X");
//		curleft += obj.x;
//	}
	//curleft = curleft -1650
	alert(curleft);

	return curleft;
}


function findPosY2(Obj)
// nalezne absolutni souradnice objektu
{
  var x= -Obj.offsetLeft; 
  var y= -Obj.offsetTop; 
  var temp;
  
  if (Obj.offsetParent) {
    temp = Obj;
    while (temp.offsetParent) {
      temp = temp.offsetParent;
      x += temp.offsetLeft;
      y += temp.offsetTop;
    }
  }
  
  x += Obj.offsetLeft;
  y += Obj.offsetTop;
  
  return y; 
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent && obj.id != 'containerBody')
		{
		    //alert(obj.offsetTop + '---' + obj.tagName);
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	curtop  = curtop  -135;
	return curtop;
}

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.parentElement;
	}
	return null;
}

function outlineCat() {
	var open = event.srcElement;
	var el = checkParent(open, "TD");
	if (null!=el) {
		var pos = 0;
		for (var pos=0; pos<el.children.length; pos++) {
			if ("TABLE"==el.children[pos].tagName) {
				if (el.children[0].src.indexOf("/img/catTree/plus.gif")>0) {
					el.children[0].src = "/img/catTree/minus.gif";
				}else{
					el.children[0].src = "/img/catTree/plus.gif";
				}
				break;
			}
		}
	    if (pos==el.children.length) return;
	} else return;
	el = el.children[pos];
	if ("TABLE"==el.tagName) {
		if (""==el.style.display) {
			el.style.display = "none";
		} else {
			el.style.display = "";
		}
	}
	event.cancelBubble = true;
}

// ###   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=330,width=350,left=10,top=10");
	objWnd.focus();
}
function OpenWndForPrint(strURL){
    //window.print();
	var objWnd = window.open(strURL,"Tisk","scrollbars=no,height=500,width=800left=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";
	}
}
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(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 (((event.keyCode <48) || (event.keyCode >57)) && (event.keyCode!=13)) event.returnValue = false;
}
function ControlPhone() {
    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 (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32))
		event.returnValue = false;
}
function ControlDate() {
     if (((event.keyCode <48) || (event.keyCode >57)) && (event.keyCode!=46)) 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;
	}
}

function ControlSendEmailToFriend()
{

    var obj1 = document.getElementById('SendToEmail');
    var obj2 = document.getElementById('SendFromEmail'); 
	
	if(obj1.value == ""){alert("Vyplňte e-mail.");obj1.focus();return false;}
	if(obj2.value == ""){alert("Vyplňte e-mail.");obj2.focus();return false;}
	
	if (EmailControl(obj1.value)==false) {obj1.focus();return false;}
	if (EmailControl(obj2.value)==false) {obj2.focus();return false;}
	
	return true;
}


function ControlUserDataSubmit(bIsAdmin)
{
	
	
	if(document.forms['UserDataForm'].Firm.value == "" ){alert("Vyplňte firmu.");document.forms['UserDataForm'].Firm.focus();return false}

	if(getF('UserDataForm').Street.value == ""){alert("Vyplňte ulici.");getF('UserDataForm').Street.focus();return false}
	if(getF('UserDataForm').City.value == ""){alert("Vyplňte město.");getF('UserDataForm').City.focus();return false}
	if(getF('UserDataForm').ZipCode.value == ""){alert("Vyplňte PSČ.");getF('UserDataForm').ZipCode.focus();return false}

	if(getF('UserDataForm').ICO.value == ""){alert("Vyplňte IČO.");getF('UserDataForm').ICO.focus();return false}
	
	if (getE("MarketList").readonly == false || getE("MarketList").value=='0') 
		if ( getE("MarketList").options[ getE("MarketList").selectedIndex ].value == '0' ) {alert("Vyberte odběrné místo.");getE('MarketList').focus();return false}


	
	//##### pouze pro gli=1, 2
	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};
	
  return CheckContactPersons(bIsAdmin)	
  
}
function ControlDataOrder(bCheckAddress)
{
	var nPriceSum = parseFloat( getE('PriceSum').value.replace(',','.') );
	var nMinSumFordiscountDelivery = parseFloat( getE('nMinSumFordiscountDelivery').value );

	if (nPriceSum <= nMinSumFordiscountDelivery) 	
	{
		// zpusob platby 
		if (document.forms['OrderForm'].OrderType.value == 'standart' )		// obj standard
		{
			 	if(document.forms['OrderForm'].DeliveryType.value == "-")
				{
					alert("Vyberte způsob dopravy."); 
					document.forms['OrderForm'].DeliveryType.focus(); 
					return false;
				}
				if (document.forms['OrderForm'].PaymentType.value == "-") {alert("Vyberte způsob platby."); document.forms['OrderForm'].PaymentType.focus(); return false; }
		}
	}
	if (document.forms['OrderForm'].OrderType.value != 'standart' )		// obj obj pick up
	{
			if (document.forms['OrderForm'].IdMarket.value == "0" || document.forms['OrderForm'].IdMarket.value == "" ) {alert("Vyberte prodejnu."); return false; }
	}
	
		
	if (bCheckAddress == true)              // user not logged = vaklidate address & contact person data
	{
	    if (document.forms['OrderForm'].DeliveryFirm.value == "")				 {alert("Vyplňte název firmy.");document.forms['OrderForm'].DeliveryFirm.focus();return false;}
	    if (document.forms['OrderForm'].DeliveryStreet.value == "")            {alert("Vyplňte ulici.");document.forms['OrderForm'].DeliveryStreet.focus();return false;}
	    if (document.forms['OrderForm'].DeliveryCity.value == "")                {alert("Vyplňte město.");document.forms['OrderForm'].DeliveryCity.focus();return false;}
	    if (document.forms['OrderForm'].DeliveryZipCode.value == "")       {alert("Vyplňte PSČ.");document.forms['OrderForm'].DeliveryZipCode.focus();return false;}
	    
	    if (document.forms['OrderForm'].sEmail.value == "")								  {alert("Vyplňte e-mail.");document.forms['OrderForm'].sEmail.focus();return false;}
	   	if ( EmailControl( document.forms['OrderForm'].sEmail.value  ) == false)   {document.forms['OrderForm'].sEmail.focus();return false;}
	    
	    if (document.forms['OrderForm'].Phone.value  == "") {alert("Vyplňte telefon.");document.forms['OrderForm'].Phone.focus();return false;}
	}
	
    //document.forms['OrderForm'].submit();
	return true;
}
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 EmailControl(f)
{
    
    return EmailControlRegExp(f, true);
    
	if ((f=='' || f=='Váš@email.cz') ||(f.indexOf('@') < 1 || f.indexOf('@') != f.lastIndexOf('@') || f.lastIndexOf('.') < f.lastIndexOf('@')+2  || f.lastIndexOf('.') > (f.length-3) || f.lastIndexOf('.') < (f.length-4))){
		alert('Nesprávný formát e-mailu');
		return false;
		}
    if (f.indexOf('"') != -1 || f.indexOf("'") !=  -1 || f.indexOf(';') !=  -1 || f.indexOf(',') !=  -1) 	
	{
	   alert('E-mail obsahuje nepovolený znak.');
	   return false; 
	}

	return true;
}

function EmailControlRegExp(sEmail, bShowMsg)
 {

   if (sEmail=='' || sEmail=='Váš@email.cz')
   {
        if (bShowMsg) alert('Nesprávný formát e-mailu');
		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 e-mailu');
		return false;
  }
  		
  		
  return true;
}  
 
// ##### 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 = 0;// 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=550px;dialogHeight=400px");
		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=450,height=400,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 ShowHideX(element,sElName) {
	var e                               = getE( element );
	var sCurrClassName = document.getElementById(sElName).className;

	if (e.style.display=="none") 
	{ 
	    e.style.display = "block"; 
	    document.getElementById(sElName).className = sCurrClassName + 'Sel';
	} 
	else 
	{ 
	    e.style.display = "none";
	    document.getElementById(sElName).className = sCurrClassName.slice(0, -3); 
    }
//	if (!Br.IE) this.blur(); //aby nam nezustaval v mozile oznacen klikaci text
}

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 checkCount( myCount, minCount, onlyMultiplied ) {
	if ( myCount == 0 ) return true;
	if ( myCount < minCount ) {
		alert('Toto zboží lze objednat v minimálním počtu '+minCount+' ks.'); return false;
	}
	if ( (onlyMultiplied==1) && ( (myCount % minCount) != 0) ) {
		alert('Toto zboží lze zakoupit pouze v násobcích '+minCount+' ks.'); return false;
	}
	return true;
}

// AvaibilityBox - Avaibility Dialog
// nType=0 ..detail, =1 .. katalog
function showAvaibilityDialog( code, posX, posY , nType) {

	var e = getE( "avaibilitybox" );

	if (nType==0)									  //detail
	{
		e.style.top = '135px';
		e.style.left = '235px';
	}	
	if (nType==1)									  //katalog
	{
		posY = posY + topScroll() - 330;
		e.style.top =  posY + 'px';
		e.style.left = '110px';
	}
	if (nType==2)									  //seznam
	{
		posY = posY + topScroll() - 230;
		e.style.top =  posY + 'px';
		e.style.left = '200px';
	}
	getE('CodeAvail').value = code;
	e.style.display = "";
//	document.frames.avaibilityFrame.document.location = "Avaibility.asp?sCode=" + code;
}
function hideAvaibilityDialog() {
	var e = getE( "avaibilitybox" );
	e.style.display = "none";
}

// ShopInfoBox

function showShopInfoDialog( code, name, count, price ) {
	var e = getE( "shopinfobox" );
	e.style.display = "";
	e.style.position = "absolute";
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -100)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.shopinfoform.elements.code.value = code;
	document.forms.shopinfoform.elements.name.value = name;
	document.forms.shopinfoform.elements.count.value = count + ' ks';
	setTimeout("hideShopInfoboxDialog();", 10000);
}
function hideShopInfoboxDialog() {
	var e = getE( "shopinfobox" );
	e.style.display = "none";
}



/* pretahnuti polozek z jednoho slectu do druheho */
	  function move(odkud,kam,cislo){
	          if (document.all[odkud].selectedIndex < 0){alert('Nebylo nic vybráno!');return}
	          var strValue = document.all[odkud].value;
	          var strText = document.all[odkud].options[document.all[odkud].selectedIndex].text;
	          var intIndex = parseFloat(document.all[odkud].selectedIndex)
	          if (strValue != ""){
                 var el = document.createElement("OPTION")
                 el.text = strText;
                 el.value = strValue;
                 document.all[kam].options.add(el);
              }
              var x = "";
              x = "but"+odkud;
              document.all[odkud].options.remove(intIndex);
              if (parseFloat(document.all[odkud].options.length)== 0){
                  document.all[x].disabled = true;
              }
              x = "but"+kam;
              if (parseFloat(document.all[kam].options.length)> 0){
                  document.all[x].disabled = false;
              }
               document.all["total"+cislo].value = ""; 
			   for(var i = 0; i < document.all["SelectMenu"+cislo].length; i++){
			   document.all["total"+cislo].value += "&nbsp;"+(i+1)+"."+document.all["SelectMenu"+cislo].options[i].value+" &nbsp;";
			  }
          } 
		  
function GaleryPicture(FormName, ImageSrc, InputUrl, InputWidth, InputHeight, IgnoreImage, StartingPath, GaleryTitle)
{	
	window.open('/Administration/ImageGalery/ImageGalery.asp?fF='+FormName+'&fSRC='+ImageSrc+'&fURL='+InputUrl+'&fW='+InputWidth+'&fH='+InputHeight+'&II='+IgnoreImage+'&Path='+StartingPath+'&Title='+GaleryTitle, 'GaleryPicture', 'toolbar=yes,location=yes,directories=yes,menubar=yes,scrollbars=yes,resizable=yes,status=yes');	
}

function ControlBookofWishSubmit(){

  if(document.wishform.Jmeno.value == ""){alert("Vyplňte jméno.");return false}
  if(document.wishform.Email.value == ""){alert("Vyplňte e-mail.");return false}
  if(document.wishform.Nadpis.value == ""){alert("Vyplňte předmět.");return false}
  if(document.wishform.text.value == ""){alert("Vyplňte zprávu.");return false}
  
  return true
}


function fnCheckParamCommodityUse(objForm) {
	if (objForm.bParamUsed.value=='0') 
		return true;
	else 
		return confirm('Tento parametr je použit u zboží, opravdu jej chcete smazat?');
}

function CheckPaymentCS()
{
	var nIndex = 0;
													
	if (getE('PaymentType'))
	{
		nIndex = getE('PaymentType').selectedIndex;
		
		if (nIndex>0)
		{		
			var sSelValue = getE('PaymentType').options[ nIndex ].value;	

			if (sSelValue.toLowerCase() == 'csp')
				getE('trCS').style.display='';
			else
				getE('trCS').style.display='none';
		}
	}
			
}

//idecko nahrazeno kodem - CPA
function VazbySelect(s1,s2,pkDel){
																 
//$$$$41||Dobírkou##43||Hotove##46||Predem (eBanka)##$$$$43||Hotove##46||Predem (eBanka)##$$$$
//0$$$$142$$$$143$$$$
	var s1pole,s2pole,s1pom,s1p,pkP,NazevP,iHtml;
//	alert(s1+'\n'+s2 +'\n ' +pkDel);
//	return true;//**************************************************************************************************
	iHtml = '<select tabindex="213" id="i213" size="1" name="PaymentType" class="INP RSEL"  style="width:188px" onchange="javascript:CheckPaymentCS();">';
	s1pole = s1.split('$$$$');
	s2pole = s2.split('$$$$');
	for (i=0;i<s2pole.length-1; i++){
	
		if (s2pole[i] == pkDel){
			s1pom = s1pole[i].split('##');
				for(j=0;j<s1pom.length-1;j++){
				s1p = s1pom[j].split('||');
				pkP = s1p[0];
				NazevP = s1p[1];
				iHtml += '<option value="' + pkP + '">' + NazevP + '</option>';
				  
			}
		}
	}
	iHtml +='</select>';
	getE('DivForVazby').innerHTML = iHtml;
	
	CheckPaymentCS();

//    alert(iHtml);	
}

function VazbySelectRegistration(s1,s2,s3,s4)
{

	var pkDel;

//	if (getE('OrderType').value != 'standard')	
//	{
//		s1 = s3; 
//		s2 = s4;
//		pkDel = getE('DeliveryTypePickUp').options[getE('DeliveryTypePickUp').selectedIndex].value;
//	}
//	else
//	{

		pkDel=0;
		
		if (getE('DeliveryTypeStandart').options.length>0)			pkDel = getE('DeliveryTypeStandart').options[getE('DeliveryTypeStandart').selectedIndex].value;
//	}

	var s1pole,s2pole,s1pom,s1p,pkP,NazevP,iHtml,sSelect;
//	alert(s1+'\n'+s2 +'\n ' +pkDel);
//	return true;//**************************************************************************************************
	iHtml = '<select tabindex="213"  size="1" name="PaymentType" class="INP RSEL" >';
	s1pole = s1.split('$$$$');
	s2pole = s2.split('$$$$');
	
	for (i=0;i<s2pole.length-1; i++){
	
		if (s2pole[i] == pkDel){
			s1pom = s1pole[i].split('##');
				for(j=0;j<s1pom.length-1;j++){
				s1p = s1pom[j].split('||');
				pkP = s1p[0];
 				NazevP = s1p[1];
				 sSelect='';
				if (gb_IdPayment == pkP)	sSelect = ' selected ';
				iHtml += '<option value="' + pkP + '" ' + sSelect + '>' + NazevP + '</option>'; 
			}
		}
	}
	
	iHtml +='</select>';
	//alert(s1+'....'+s2+'....'+pkDel);

	getE('DivForVazby').innerHTML =iHtml;

//    alert(iHtml);	
}


function ZavriKosik(bHideCB)
{
	getE("StateInfo1").style.display="none";
	
	//if (bHideCB == 1)  //potreba skryti/obrazeni elementu select
	//{
	//    window.parent.document.getElementById('PN').style.display = "";
	//}
}

function SearchExt_ShowHide()
{
    var objDiv = document.getElementById("SearchExt");
   
    if (objDiv.style.display == "none")
            objDiv.style.display = "block";
    else         
            objDiv.style.display = "none"; 
}





/////////////////////////////////////////////////////

//onmouseover=""showStoreBox('" & FcenSkladem(nSkladem) & "','"&sCode&"',event.clientY,event.clientX);""  onmouseout=""hideStoreBox();""

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 showStoreBox( pcs,code, posY, posX) {
	var e = getE( "StoreBox" );
	e.style.display = "";
	e.style.position = "absolute";

	e.style.top  =topScroll()+(posY-80)+'px'
	e.style.left =(posX-210)+'px'

	getE("pcsCode").innerHTML=code
	getE("pcsOnStore").innerHTML=pcs;
}

function hideStoreBox() {

	var e = getE( "StoreBox" );
	e.style.display = "none";
}

function ChangeFilters(bState, sCookieName)
{
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);
	var sCookie  = sCookieName + '=' + (bState==true ? '1' : '0') + ';';

    document.cookie = sCookie;
}


function SetVariImage(nItem, nPosition)
{
        var sClassPrev, sClassNext, sActionPrev, sActionNext;
        var  arrImgDataAll = getE("varimgH").value.split('|||');
       //alert(getE("varimgH").value)
        
        var  nImgLength = arrImgDataAll.length;
        var  vyprs=new Date();
	    var  nPos = nPosition + nItem;
	    var  sHtmlPrev, sHtmlNext, sHtml;  
	   
        if (nPos<0 || isNaN(nPos) == true) nPos = 0; 
        if (nPos+1 > (nImgLength-1)) nPos = nImgLength-2;
        
        var arrItem  = arrImgDataAll[nPos].split("~");
        
       
        
        sHtml = "<img src='" + arrItem[0] + "' title='" + arrItem[2] + "'/>";
        if (arrItem[1] != null && arrItem[1] != '' )
                sHtml = "<a class='Vari' href='/detailPage.asp?" + arrItem[1] + "&amp;Pos=" + nPos + "' title='" + arrItem[2] + "' >" + sHtml + "</a>";
        else
                sHtml = "<span>" + sHtml + "</span>";
        if (nPos+1 < (nImgLength-1) || nPos+1 == (nImgLength-1))
        {
            arrItem  = arrImgDataAll[nPos+1].split("~");

            if (arrItem[1] != null && arrItem[1] != '' )         
                sHtml = sHtml +  "<a class='Vari' href='/detailPage.asp?" + arrItem[1] + "&amp;Pos=" + nPos + "' title='" + arrItem[2] + "' >";
            else
                sHtml = sHtml + "<span>";

            sHtml = sHtml +  "<img src='" + arrItem[0] + "' title='" + arrItem[2] + "'/>";
            //sHtml = sHtml +  "<img src='" + arrItem[0] + "' title='" + arrItem[2] + "'/>";

            if (arrItem[1] != null && arrItem[1] != '' )         
                    sHtml = sHtml +  "</a>";
            else
                sHtml = sHtml + "</span>";
        } 

        sClassPrev = 'DarrowL';
        sClassNext = 'DarrowR';
        sActionPrev = "javascript:SetVariImage(-1, " + nPos + ");";
        sActionNext = "javascript:SetVariImage(1, " + nPos + ");";
        
       if (nPos == 0)  {sClassPrev= 'DarrowLEnd'; sActionPrev = "javascript:alert(\"Jste na začátku seznamu.\");";}
       if (nPos+1 == (nImgLength-1))  {sClassNext= 'DarrowREnd';sActionNext = "javascript:alert(\"Jste na konci seznamu.\");";}
        
        sHtmlPrev = "   <a class='" + sClassPrev + "' href='" + sActionPrev + "' title='předchozí obrázek'></a>" 
        sHtmlNext = "   <a class='" + sClassNext + "' href='" + sActionNext + "' title='následující obrázek'></a>" 
    
        getE('divVari').innerHTML = sHtmlPrev +sHtml + sHtmlNext;
}
/* registrace / oprava osobnich udaju - Neumax*/

function DelContactRow(nIndex)
{	
	getE("tabContacts").deleteRow(getE("tr"+nIndex + "_0").rowIndex);
	getE("tabContacts").deleteRow(getE("tr"+nIndex + "_1").rowIndex);
	
}
function AddContactRow(nIndex)
{	
	var ntabindex = 50+ (nIndex*10);
	var sRow  = "";	
	var nRowIndex = getE("tr"+nIndex + "_1").rowIndex+1;
	var objNewTR0 = getE("tabContacts").insertRow(nRowIndex);
	
	objNewTR0.setAttribute("id","tr" + (nIndex+1) + "_0"); 
	
	//var objNewTD0_0 = objNewTR0.insertCell(-1);
	var objNewTD0_1 = objNewTR0.insertCell(-1);
	var objNewTD0_2 = objNewTR0.insertCell(-1);
	var objNewTD0_3 = objNewTR0.insertCell(-1);
	
	
	
	//sRow = '<input class=\'INP C\' type=\'text\' tabindex=\'' + ntabindex + '\' title=\'jméno\' name=\'Cname\' value=\'Jméno\' onfocus="if (this.value==\'Jméno\'){this.value=\'\';}\" onblur=\"if (this.value==\'\'){this.value=\'Jméno\';}" />';
	// objNewTD0_0.innerHTML = sRow;
	// ntabindex= ntabindex+1;
	sRow = '<input class=\'INP C\' type=\'text\' tabindex=\'' + ntabindex + '\' title=\'jméno a příjmení\' name=\'Cprijmeni\' value=\'Jméno a příjmení\' onfocus="if (this.value==\'Jméno a příjmení\'){this.value=\'\';}\" onblur=\"if (this.value==\'\'){this.value=\'Jméno a příjmení\';}" />';
	 objNewTD0_1.innerHTML = sRow;
	 ntabindex= ntabindex+1;
	sRow = '<input class=\'INP C\' type=\'text\' tabindex=\'' + ntabindex + '\' title=\'email\' name=\'Cemail\' value=\'E-mail\' onfocus="if (this.value==\'E-mail\'){this.value=\'\';}\" onblur=\"if (this.value==\'\'){this.value=\'E-mail\';}" />';
	 objNewTD0_2.innerHTML = sRow;
	 ntabindex= ntabindex+1;
	sRow = '<input class=\'INP C\' type=\'text\' tabindex=\'' + ntabindex + '\' name=\'Ctelefon\' value=\'Telefon\' title=\'telefon\' onfocus="if (this.value==\'Telefon\'){this.value=\'\';}\" onblur=\"if (this.value==\'\'){this.value=\'Telefon\';}" />';
	 objNewTD0_3.innerHTML = sRow;
	 ntabindex= ntabindex+1;

	
	nRowIndex++;
	var objNewTR1 = getE("tabContacts").insertRow(nRowIndex);
	objNewTR1.setAttribute("id","tr" + (nIndex+1) + "_1");
	var objNewTD1 = objNewTR1.insertCell(0);
	objNewTD1.setAttribute("colSpan",4);

	sRow = '<input class=\'INP R\' type=\'text\' tabindex=\'' + ntabindex + '\' style=\'width:438px\' name=\'Cpoznamka\' title=\'poznámka\' value=\'Poznámka\' onfocus="if (this.value==\'Poznámka\'){this.value=\'\';}\" onblur=\"if (this.value==\'\'){this.value=\'Poznámka\';}" />&nbsp;<img src=\'/img/ClientDel.gif\'  class=\'B\' onclick=\'DelContactRow(' + (nIndex+1) + ');\' title=\'smazat kontaktní osobu\' />&nbsp;<img class=\'B\' src=\'/img/BTarrowDSelect.gif\' title=\'zadat další kontaktní osobu\' onclick=\'AddContactRow(' + (nIndex+1) + ');\' />';
	  objNewTD1.innerHTML = sRow;
	
	
	
}

function LogOff_User()
{
	if(confirm('Odhlásit?')){;document.forms.LogOff.submit();}
}


function xx(evn)
{

    if (Br.IE)
        alert("IE");
      else
     { 
       alert( window.event.keycode );
           
     } 
}
function PopupOOU(x, y)
{
    getE('PopUp').style.left = x + "px";
    getE('PopUp').style.top=y+ "px"; 
    getE('PopUp').style.display='block';
}

function PopupOOU2(x, y)
{
    getE('PopUp').style.left = x + "px";
    getE('PopUp').style.top=y+ topScroll() - 370 + "px"; 
    getE('PopUp').style.display='block';
}
function HidePopupOOU()
{
    getE('PopUp').style.display='none';
}


//------------- dodaci adresy -------------
var nDodAdr = 1;
var sCountryTemplate = '';
function AddDodaciAdresa(idRow)
{
	getE('NaviRowAdr').style.display='none'; //navigacni radek s tlackem pro pridani adresy je zobrazen pouze tehdy pokud neni zadna adresa

	var sHTML	  = ''
	var sRowId    = '';										
	var nRowIndex = getE(idRow).rowIndex+1;
	var objNewTR0 = getE("tabaddress").insertRow(nRowIndex);
	
	nDodAdr++;
	sRowId = 'rowAdr_' + nDodAdr;
	objNewTR0.setAttribute("id",sRowId); 
	
	objNewTR0.className ='TRCP'; 
	
	var objNewTD0_1 = objNewTR0.insertCell(-1);
	
	var sHTML = '';
	var sSelTemplate = sCountryTemplate; //getE('countrytemplate').value;
	
	
	sHTML = sHTML + '<div id="block_' + nDodAdr + '"  class="xDelAdr" >';
	sHTML = sHTML + ' <table cellpadding="0" cellspacing="0">';
	sHTML = sHTML + ' <tr>';
	sHTML = sHTML + '  <td class="inicialy"><label>Firma:</label></td>';
	sHTML = sHTML + '  <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="text"  tabindex="' + parseInt(300+(nDodAdr*10)) + '" id="DeliveryFirm_' + nDodAdr + '" name="DeliveryFirm" value="" /></p></td>';
	sHTML = sHTML + '   <td class="inicialy"><label>Město:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="text" tabindex="' + parseInt(302+(nDodAdr*10)) + '" id="DeliveryCity_' + nDodAdr + '" name="DeliveryCity" value=""  /></p></td>';
	sHTML = sHTML + '  </tr>';
	sHTML = sHTML + '  <tr>';
	sHTML = sHTML + '   <td class="inicialy"><label>Ulice:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="text" tabindex="' + parseInt(301+(nDodAdr*10)) + '" id="DeliveryStreet_' + nDodAdr + '" name="DeliveryStreet" value="" /></p></td>';
	sHTML = sHTML + '  <td class="inicialy"><label>PSČ:</label></td>';
	sHTML = sHTML + '  <td class="inicialy1"><p class="INP LG1"><input maxlength="5" class="SER_N LG2" type="text" tabindex="' + parseInt(303+(nDodAdr*10)) + '" id="DeliveryZipCode_' + nDodAdr + '" name="DeliveryZipCode" onkeypress="return ControlPSC()" value=""  /></p></td>';
	sHTML = sHTML + '  </tr>';
	sHTML = sHTML + '  <tr>';
	sHTML = sHTML + '   <td class="inicialy"><img src="/img/BTDelAdr_1.gif"  onclick="DelDodaciAdresa('+nDodAdr+')"/></td>';
	sHTML = sHTML + '   <td class="inicialy1"><img src="/img/BTNewAdr_1.gif"  onclick="AddDodaciAdresa(\'' + sRowId + '\')"/></td>';
	sHTML = sHTML + '   <td class="inicialy"><label>Stát:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><select class="INP RSEL" tabindex="' + parseInt(304+(nDodAdr*10)) + '" id="DeliveryCountry_' + nDodAdr + '" name="DeliveryCountry">' +  sSelTemplate + ' </select></p></td>';
	sHTML = sHTML + '  </tr>';
	sHTML = sHTML + ' </table>';
	sHTML = sHTML + '</div>';

	objNewTD0_1.innerHTML = sHTML;
	
	return false;
	
}

function DelDodaciAdresa(Id)
{
	if ( getE('rowAdr_'+Id) )	getE("tabaddress").deleteRow( getE('rowAdr_'+Id).rowIndex );
	if ( getE("tabaddress").rows.length == 1 )	getE('NaviRowAdr').style.display='';
		
}
//------------- kontaktni osoby -------------
var nContactPerson = 1

function  AddContactPerson(idRow)
{
	getE('NaviRow').style.display='none'; //navigacni radek s tlackem pro pridani osoby je zobrazen pouze tehdy pokud vsechny osoby jsou zruseny

	var sHTML	  = ''
	var sRowId    = '';										
	var nRowIndex = getE(idRow).rowIndex+1;
	var objNewTR0 = getE("tabcontact").insertRow(nRowIndex);
	
	nContactPerson++;
	sRowId = 'row_' + nContactPerson;
	objNewTR0.setAttribute("id",sRowId); 
	
	objNewTR0.className ='TRCP'; 
	
	var objNewTD0_1 = objNewTR0.insertCell(-1);
	
	sHTML = sHTML + '<div id="blockCP_' + nContactPerson + '"  class="xDelAdr" >';
	sHTML = sHTML + ' <input type="hidden" id="cpId_'+nContactPerson+'" name="cpId" value="0" />';
	sHTML = sHTML + ' <table cellpadding="0" cellspacing="0">';
	sHTML = sHTML + '  <tr>';
	sHTML = sHTML + '   <td class="inicialy"><label>Jméno a příjmení:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="text" id="cpName_'+nContactPerson+'" name="cpName"  tabindex="' + parseInt(50+(nContactPerson*10)) + '" value="" /></p><span>&nbsp;</span></td>';
	sHTML = sHTML + '   <td class="inicialy"><label>Telefon:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="text" id="cpTel_'+nContactPerson+'" name="cpTel" value="" tabindex="' + parseInt(52+(nContactPerson*10)) + '" onkeypress="return ControlPhone();" /></p><span>&nbsp;</span></td>';
	sHTML = sHTML + '  </tr>';
	sHTML = sHTML + '  <tr>';
	sHTML = sHTML + '   <td class="inicialy"><label>E-mail:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="text" id="cpEmail_'+nContactPerson+'" name="cpEmail"   tabindex="' + parseInt(51+(nContactPerson*10)) + '" value="" /></p><span>&nbsp;</span></td>';
	sHTML = sHTML + '   <td class="inicialy"><label for="idnews" class="labelRadio">Odběr novinek:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1" style="vertical-align:middle;"><input type="CheckBox"  title="Odběr novinek a akčního zboží" class="RCheck"  tabindex="' + parseInt(53+(nContactPerson*10)) + '" value="" id="cpNews_'+nContactPerson+'" name="cpNews"  onclick="SetCPNews('+nContactPerson+');" /><input type="hidden" id="cpiNews_'+nContactPerson+'" name="cpiNews" value="0" /></td>';
	sHTML = sHTML + '  </tr>';
	sHTML = sHTML + '  <tr>';
	sHTML = sHTML + '   <td class="inicialy"><label>Přístupové jméno:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="text" id="cpLogin_'+nContactPerson+'" tabindex="' + parseInt(54+(nContactPerson*10)) + '" name="cpLogin" value="" /></p><span>&nbsp;</span></td>';
	sHTML = sHTML + '   <td class="inicialy"><label>Heslo:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="password" id="cpPassword_'+nContactPerson+'" tabindex="' + parseInt(55+(nContactPerson*10)) + '" name="cpPassword" title="min.5 znaků"  value="" /></p><span>&nbsp;</span></td>';
	sHTML = sHTML + '  </tr>';
	sHTML = sHTML + '  <tr>';
	sHTML = sHTML + '   <td class="inicialy"><img src="/img/BTDelAdr_1.gif"  onclick="DelContactPerson('+nContactPerson+')"/></td>';
	sHTML = sHTML + '   <td class="inicialy1"><img src="/img/BTNewCp_1.gif"  onclick="AddContactPerson(\'' + sRowId + '\')" /></td>';
	sHTML = sHTML + '   <td class="inicialy"><label>Kontrola hesla:</label></td>';
	sHTML = sHTML + '   <td class="inicialy1"><p class="INP LG1"><input class="SER_N LG2" type="password" id="cpPasswordCheck_'+nContactPerson+'" tabindex="' + parseInt(56+(nContactPerson*10)) + '" name="cpPasswordCheck" title="min.5 znaků"  value="" /></p><span>&nbsp;</span></td>';
	sHTML = sHTML + '  </tr>';
	sHTML = sHTML + '</table>';
	sHTML = sHTML + '</div>';
	
	objNewTD0_1.innerHTML = sHTML;
	return false;
}

function DelContactPerson(Id)
{
	if ( getE('row_'+Id) )	getE("tabcontact").deleteRow( getE('row_'+Id).rowIndex );
	
	if	( getE("tabcontact").rows.length == 1  )	   
		getE('NaviRow').style.display=''; //navigacni radek s tlackem pro pridani osoby je zobrazen pouze tehdy pokud vsechny osoby jsou zruseny
}

function SetCPNews(Id)
{
	getE('cpiNews_'+Id).value = (getE('cpNews_'+Id).checked ? '1' : '0');
}

function CheckContactPersons(bIsAdmin)	
{
	// ucet admin
	if (bIsAdmin == 1)
	{
		if (getE('AdminName').value == ""){alert("Vyplňte jméno a příjmení.");getE('AdminName').focus();return false}
		if (getE('AdminTel').value == ""){alert("Vyplňte telefon.");getE('AdminTel').focus();return false}
		
		if (getE('AdminEmail').value == ""){alert("Vyplňte e-mail.");getE('AdminEmail').focus();return false}
		if(EmailControl(getE('AdminEmail').value)==false) {getE('AdminEmail').focus();return false;}
		
		if(getE('AdminLogin').value == ""){alert("Vyplňte přihlašovací jméno.");getE('AdminLogin').focus();return false}
		if(getE('AdminLogin').value.length < 5){alert("Přihlašovací jméno musí mít nejméně 5 znaků.");getE('AdminLogin').focus();return false}
		
		if(getE('AdminPassword').value == ""){alert("Vyplňte heslo.");getE('AdminPassword').focus();return false}
		if(getE('AdminPassword').value.length < 5){alert("Heslo musí mít minimálně 5 znaků.");getE('AdminPassword').focus();return false}
		
		if(getE('AdminPasswordCheck').value == ""){alert("Vyplňte kontrolu hesla.");getE('AdminPasswordCheck').focus();return false}
		if(getE('AdminPassword').value != getE('AdminPasswordCheck').value){alert("Zadaná hesla se neshodují.");getE('AdminPasswordCheck').focus();return false}	
	}
	
	var i = 0;
	for (i=0; i< (nContactPerson+1); i++ )
	{
		if ( getE('cpNews_'+i) && !getE('cpNews_'+i).disabled  )
		{
			if (getE('cpName_'+i).value == ""){alert("Vyplňte jméno a příjmení.");getE('cpName_'+i).focus();return false}
			if (getE('cpTel_'+i).value == ""){alert("Vyplňte telefon.");getE('cpTel_'+i).focus();return false}
			
			if (getE('cpEmail_'+i).value == ""){alert("Vyplňte e-mail.");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.");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('cpPassword_'+i).value == ""){alert("Vyplňte heslo.");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('cpPasswordCheck_'+i).value == ""){alert("Vyplňte kontrolu hesla.");getE('cpPasswordCheck_'+i).focus();return false}
			if(getE('cpPassword_'+i).value != getE('cpPasswordCheck_'+i).value){alert("Zadaná hesla se neshodují.");getE('cpPasswordCheck_'+i).focus();return false}
		}
	}
	return true;
}	

//	objednavka - prace s delivery address
function SetNewDeliveryAddress()
{
	getE('IdDelAdr').value = '0';
	
	getE('DeliveryFirm').value = '';
	getE('DeliveryZipCode').value = '';
	getE('DeliveryStreet').value = '';
	getE('DeliveryCity').value = '';
	
	
	getE('DeliveryFirm').disabled		= false;
	getE('DeliveryStreet').disabled		= false;
	getE('DeliveryZipCode').disabled	= false;
	getE('DeliveryCity').disabled		= false;
	getE('DeliveryCountry').disabled	= false;
}

function OnChangeDeliveryAddress()
{
	var sSelValue = getE('DeliveryCountryx').options[ getE('DeliveryCountryx').selectedIndex ].value;	
	var bDisabled = true;	
	if (sSelValue == '0')
	{
		getE('IdDelAdr').value					= '0';
		getE('DeliveryFirm').value			= '';
		getE('DeliveryStreet').value		= '';
		getE('DeliveryZipCode').value	= '';
		getE('DeliveryCity').value			= '';
		bDisabled = false;
	}
	else
	{
		var arrValue  = sSelValue.split('|||');	
		
		getE('IdDelAdr').value			= arrValue[0];
		getE('DeliveryFirm').value		= arrValue[1];
		getE('DeliveryStreet').value	= arrValue[2];
		getE('DeliveryZipCode').value	= arrValue[3];
		getE('DeliveryCity').value		= arrValue[4];
		var nIdCountry					= arrValue[5];
		

		for (i=0; i<getE('DeliveryCountry').options.length;i++)
		{
		
			if ( getE('DeliveryCountry').options[i].value==nIdCountry )
			{
			//alert( getE('DeliveryCountry').selectedIndex + '....' + i);
				getE('DeliveryCountry').selectedIndex = i;
			}
		}
	}	
	getE('DeliveryFirm').disabled		= bDisabled;
	getE('DeliveryStreet').disabled		= bDisabled;
	getE('DeliveryZipCode').disabled	= bDisabled;
	getE('DeliveryCity').disabled			= bDisabled;
	getE('DeliveryCountry').disabled	= bDisabled;
}

//nType = 0 iframe, 1 order_inc
var gb_nIframeMarketCount;
function SetMarketIFrameCount(nCount)
{
	gb_nIframeMarketCount=nCount;
}
function SetMarketIDOrder( nIdMarket)
{

		window.parent.document.getElementById('IdMarket').value = nIdMarket;
	
}



// -- kontrola search string
function CheckSearchString()
{
	var sValue = document.forms['fmrsearch'].EXPS.value;
	
	if (sValue == '' )
	{
		alert('Není zadán výraz pro hledání.'); 
		return false;
	}
	
	sValue = sValue.replace(/^\s*|\s*$/g,"");
	
	if (sValue.length < 3 ) 
	{
		alert('Hledaný výraz musí obsahovat min 3 znaky.'); 
		return false;
	}
	return true;
}

function ShowHidePickUp()
{

	if (getE('OrderType').value=='standard')
	{
		getE('MarketList').disabled = true;
		getE('pickup').style.display='none';
		
		getE('DeliveryTypeStandart').disabled = false;
		getE('DeliveryTypePickUp').disabled = true;
		getE('DeliveryTypeStandart').style.display='';
		getE('DeliveryTypePickUp').style.display='none';
	}
	else
	{
		getE('MarketList').disabled = false;
		getE('pickup').style.display='';
		
		getE('DeliveryTypeStandart').disabled = true;
		getE('DeliveryTypePickUp').disabled = false;
		getE('DeliveryTypeStandart').style.display='none';
		getE('DeliveryTypePickUp').style.display='';
	}
	VazbySelectRegistration(gvsOutput1, gvsOutput2,gvsOutput3, gvsOutput4);
	
}

function VazbySelectRegistrationAdmin(s1,s2,s3,s4)
{
 	var pkDel;

	if ( document.getElementById('DeliveryTypeStandart').options.length==0 ) return false;
	
	pkDel = document.getElementById('DeliveryTypeStandart').options[document.getElementById('DeliveryTypeStandart').selectedIndex].value;

	var s1pole,s2pole,s1pom,s1p,pkP,NazevP,iHtml,sSelect;
//	alert(s1+'\n'+s2 +'\n ' +pkDel);
//	return true;//**************************************************************************************************
	iHtml = '<select tabindex="213"  size="1" name="PaymentType" style="width:146px" >';
	s1pole = s1.split('$$$$');
	s2pole = s2.split('$$$$');
	
	for (i=0;i<s2pole.length-1; i++)
	{
		if (s2pole[i] == pkDel){
			s1pom = s1pole[i].split('##');
				for(j=0;j<s1pom.length-1;j++)
				{
				
				s1p = s1pom[j].split('||');
				pkP = s1p[0];
 				NazevP = s1p[1];
 				sSelect='';
 				if (gb_idpayment == pkP)	sSelect = ' selected ';
				iHtml += '<option value="' + pkP + '" ' + sSelect + '>' + NazevP + '</option>';
				  
			}
		}
	}
	
	iHtml +='</select>';
	//alert(iHtml);

	document.getElementById('DivForVazby').innerHTML =iHtml;

//    alert(iHtml);	
}	
