// 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;
}

// ###   FCE PRO zaskrtnutí a odeslání pk zboží pro Compare.asp   ###

// ###   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;
}

// SELECT on/off
function SelectExcept(o){
	return !( (o.id == "AMenu1")||(o.id == "TabMenu1")||(o.id == "TabMenu5")||(o.id == "TabMenu6")||(o.id == "CellMenu1")||(o.id == "CellMenu2")||(o.id == "/imgMenu1")); 
}

function SelectHide(sStyle){
	SelectHideEx(sStyle,document);
	for (var i=0;i<window.frames.length;i++){
		SelectHideEx(sStyle,window.frames[i].document);
	}
}

function SelectHideEx(sStyle,odocument){	
	var o;
	o = odocument.getElementsByTagName("select");
	if (o !=null ){
		if (o.tagName == 'SELECT') {
			if (SelectExcept(o)) o.style.visibility=sStyle;
		} else {
			for(var i=0;i<o.length;i++){
				if (SelectExcept(o[i])) o[i].style.visibility=sStyle;
			}
		}
	}
}

// ##########

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){    
        window.alert(gsGLS[498] + 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 #######################################################


// ##### PriceList END #####

// ##### Zalozky na detailu END #########################################################

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") {
		if (!Br.OP) SelectHide('hidden');
		e.style.display = "" }
	else {
		if (!Br.OP) SelectHide('visible');
		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

// AvaibilityBox - Avaibility Dialog
function showAvaibilityDialog( code, posX, posY ) {
	var e = getE( "avaibilitybox" );
	e.style.display = "";
	e.style.position = "absolute";
//	e.style.top = (posY + 50)+'px';
//	e.style.left = (posX + 50)+'px';
	e.style.top = (document.body.scrollTop + document.body.clientHeight/2 -200)+'px';
	e.style.left = (document.body.clientWidth/2 - 100)+'px';
	document.forms.avaibilityform.elements.code.value = code;
	document.frames.avaibilityFrame.document.location = "Avaibility.asp?sCode=" + code;
	document.forms.avaibilityform.elements.count.value = "Zjišťuje se...";
}
function hideAvaibilityDialog() {
	var e = getE( "avaibilitybox" );
	e.style.display = "none";
//	var e = getE( "avaibilitybox" );
//	e.style.display = "none";
}


function resizeHidingDialog(element,newHeight){
	getE('shopinfobox').style.height = newHeight;
	if (newHeight > 50) setTimeout("resizeHidingDialog('shopinfobox',"+(newHeight-50)+");", 0);
}

function showWaitingBox( str ) {
	var box = document.getElementById("hoverbox");
	box.style.left = document.documentElement.clientWidth / 2 - 350 + "px";
	box.style.top = topScroll() + document.documentElement.clientHeight / 2 - 10 + "px";
	box.className = "visible";
	box.innerHTML = "<p>"+str+"</p>"
}


/* positions */
function leftPosition(obj,ev){
	if (ev) {
		if ( obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent)) < ev.clientX )  {
			return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent))
		} else { // quli dvouradkovym elementum, tak aby se to nezobrazilo daleko od kurzoru na prvnim radku
			return ( ev.clientX );
		}
	} else { // kdyz volame rekurzivne, tak neni objekt ev k dispozici
		return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent));
	}
}
function topPosition(ev) {
	 return ( ev.clientY + topScroll() );
}
function topScroll() {
	if (window.innerHeight) {
		  return ( window.pageYOffset )
	} else if (document.documentElement && document.documentElement.scrollTop) {
		return ( document.documentElement.scrollTop )
	} else if (document.body) {
		  return ( document.body.scrollTop )
	}
}
/* /positions */

// specialitky


// ShopInfoBox

function showShopInfoDialog() {
	clearTimeout;
	if (!Br.OP) SelectHide('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 - 100)+'px';
	setTimeout("hideShopInfoboxDialog();", 20000);
}

function hideShopInfoboxDialog() {
	var e = getE( "shopinfobox" );
	fadeOutObject ( "shopinfobox", 10 );
	clearTimeout;
	if (!Br.OP) SelectHide('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';
}


/* 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('DeliveryPrice');
	
	
	if (oPT) {
		oPB = getE('DeliveryPrice_' + pkDel)
		//alert (oPB);
		if (oPB) {
			oPT.value = oPB.value;
			getE('DeliveryPrice').value = getE('DeliveryPrice_' + pkDel).value;
			getE('DeliveryName').value = getE('DeliveryName_' + pkDel).value;
			getE('DeliveryDPH').value = getE('DeliveryDPH_' + pkDel).value;
			//alert(getE('DeliveryPrice').value);
		}
	}
	
	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\-]{1,}\.){1,})+\.[a-zA-Z]{2,}$"); 
	
	regEx.ignoreCase = true;
		
	if (regEx.test(sEmail) == false)	{
		alert(gsGLS[499]);
		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(gsGLS[500]);getE('caFirm_'+i).focus();return false}
			if (getE('caStreet_'+i).value == ""){alert(gsGLS[501]);getE('caStreet_'+i).focus();return false}
			if (getE('caCity_'+i).value == ""){alert(gsGLS[502]);getE('caCity_'+i).focus();return false}
			if (getE('caZipCode_'+i).value == ""){alert(gsGLS[503]);getE('caZipCode_'+i).focus();return false}
		}
	}
	return true;
}	

function ControlUserDataSubmit(){

	if(getF('UserDataForm').Firm.value == ""){alert(gsGLS[497]);getF('UserDataForm').Firm.focus();return false}
	if(getF('UserDataForm').Street.value == ""){alert(gsGLS[504]);getF('UserDataForm').Street.focus();return false}
	if(getF('UserDataForm').City.value == ""){alert(gsGLS[505]);getF('UserDataForm').City.focus();return false}
	if(getF('UserDataForm').ZipCode.value == ""){alert(gsGLS[506]);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').Firm2.value == ""){alert("Vyplňte jméno a příjmení.");getF('UserDataForm').Firm2.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(gsGLS[262]);getF('UserDataForm').Email.focus();return false}
	if(getF('UserDataForm').Phone.value + getF('UserDataForm').Mobil.value == ""){alert(gsGLS[507]);getF('UserDataForm').Phone.focus();return false}

	if(getF('UserDataForm').Login.value == ""){alert(gsGLS[508]);getF('UserDataForm').Login.focus();return false}
	if(getF('UserDataForm').Login.value.length < 5){alert(gsGLS[509]);getF('UserDataForm').Login.focus();return false}
	if(getF('UserDataForm').Password.value == ""){alert(gsGLS[510]);getF('UserDataForm').Password.focus();return false}
	if(getF('UserDataForm').Password.value.length < 5){alert(gsGLS[224]);getF('UserDataForm').Password.focus();return false}
	if(getF('UserDataForm').Password.value != getF('UserDataForm').PasswordCheck.value){alert(gsGLS[511]);getF('UserDataForm').Password.focus();return false}
  
  if(getF('UserDataForm').agree.checked != true) {alert(gsGLS[512]);getF('UserDataForm').agree.focus();return false}


	//return (CheckContactPersons(0) && CheckClientAddress(0));
}

function ControlDataOrder(){
	var isCheck = false;
	if (typeof(getF('OrderForm').DeliveryType.length) == 'number')
	{
    for (var i=0; i < getF('OrderForm').DeliveryType.length; i++) {
      if (getF('OrderForm').DeliveryType[i].checked) isCheck = true;
  	}
	}
	else
	{
    if (getF('OrderForm').DeliveryType.checked) isCheck = true;
  }
	
  if (!isCheck) {alert(gsGLS[513]); return false}
}

function ControlPassword(NameOne,NameTwo){
	if (getE(NameOne).value != getE(NameTwo).value){
		alert(gsGLS[514]);
		getE(NameOne).value = "";
		getE(NameTwo).value = "";
		getE(NameOne).focus();
		return false;
	}else{
		return true;
	}
}

//------------- dodací adresy ---------------
var nClientAddress = 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(gsGLS[94]);
}

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';
 }
 
function ShowCalendarFE(oid,lang)
 {
  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+'&LANG='+lang;

  cal.style.top = tbox.offsetTop + tbox.offsetHeight;
  cal.style.left = tbox.offsetLeft;

  calframe.src = ssrc;
  cal.style.display = 'block';
 }
 
function Bookmark(url,title){
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}
	else if( document.all){
		window.external.AddFavorite(url, title);
	}
	else{
		return true;
	}
}
 
function checkChildrens(obj,i)
{
var i, objvalue

objvalue=obj.checked;

//alert("cc"+(i+1));
if (obj=document.getElementById("cc"+(i+1)))
{
//obj.style.background="green";
inputs=obj.getElementsByTagName("INPUT");

for (i=0; i < inputs.length; i++) {
    inputs[i].checked=objvalue;
    }
//recurseChildrens(obj,objvalue);
}
}

function recurseChildrens(obj,objvalue)
{
alert (obj.tagName);
if (obj.tagName=="UL")
{
for (i=0;obj.childNodes[i];i++)
  {
    alert(obj.childNodes[i].tagName+i);
    alert(obj.childNodes[i].id);
    if (obj.childNodes[i].tagName=="LI")
      {
      obj.childNodes[i].style.background="blue";
      if(obj.childNodes[i].childNodes[0].tagName=="INPUT")
        {
        obj.childNodes[i].childNodes[0].checked=objvalue;
        }
      }
    // recurseChildrens(obj.childNodes[i],objvalue);
  }
}
}

//pro vybrani dodaci adresy v objednavce
function FlushSelectedCountry(obj)
{
  var adata;
  adata=obj.value.split("#");
 
  for (i=0;i<5;i++)
  { 
    document.getElementById('deliveryaddress').getElementsByTagName('input')[i].value=adata[i];
  }
  document.getElementById('deliveryaddress').getElementsByTagName('select')[1].value=adata[5];
}

