// KOMPATIBILITA

var Br = new BrCheck()

function BrCheck()
{
	this.VER	= navigator.appVersion;
	this.AGENT	= navigator.userAgent.replace(/[\/]/g,' ');
	this.DOM	= document.getElementById ? true:false;

	this.OP5	= this.AGENT.indexOf("Opera 5")>-1							?true:false;
	this.OP6	= this.AGENT.indexOf("Opera 6")>-1							?true:false;
	this.OP7	= this.AGENT.indexOf("Opera 7")>-1							?true:false;
	this.OP8	= this.AGENT.indexOf("Opera 8")>-1							?true:false;
	this.OP		= (this.OP5 || this.OP6 || this.OP7 || this.OP8);

	this.IE4	= (document.all && !this.DOM && !this.OP)					?true:false;
	this.IE5	= (this.VER.indexOf("MSIE 5")>-1 && this.DOM && !this.OP)	?true:false; 
	this.IE6	= (this.VER.indexOf("MSIE 6")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE7	= (this.VER.indexOf("MSIE 7")>-1 && this.DOM && !this.OP)	?true:false;
	this.IE		= (this.IE4 || this.IE5 || this.IE6 || this.IE7);

	this.NS4	= (document.layers && !this.DOM)							?true:false;
	this.NS7	= (this.DOM && parseInt(this.VER) >= 5 && this.AGENT.lastIndexOf('Netscape')<this.AGENT.lastIndexOf('7'))?true:false;
	this.NS6	= (this.DOM && parseInt(this.VER) >= 5 && !this.NS7)		?true:false;
	this.NS		= (this.NS4 || this.NS6 || this.NS7);

	return this;
}

function getFirstAvailableDateAfter(dDate) {

	var dDatumVelikonoc = getDatumVelikonoc(dDate.getYear());
	var sHolidays = gsHolidays + dDatumVelikonoc.getDate() + "." + (dDatumVelikonoc.getMonth() + 1) + ".;";

 	var dayNumber = dDate.getDay();

 	while (dayNumber == 0 || dayNumber == 6 || sHolidays.indexOf(";" + dDate.getDate() + "." + (dDate.getMonth() + 1) + ".;") > -1) {
 		dDate = new Date(dDate.getTime() + 86400000);
 		var dayNumber = dDate.getDay();
 	}

	return dDate;
}

/*------------------------------------------------------------------------------
 * Vrati XMLHttpRequest objekt
 */ 
function getNewHttpObject() {
	var objType = false;
	try {
		objType = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e) {
		try {
			objType = new ActiveXObject('Microsoft.XMLHTTP');
    }
		catch(e) {
			objType = new XMLHttpRequest();
		}
	}

	return objType;
}

function showWaitMiscBox() {
	getE("miscInfoBox").innerHTML = "<div style='padding: 20px; text-align: center;'>Strpení ...</div>";
	showMiscInfoBox();
}

function showVisibleStoresAvailability(sCommCode, nType) {
	window.setTimeout("showVisibleStoresAvailabilityCore('" + sCommCode + "', " + nType + ")", 100);
}

function showVisibleStoresAvailabilityCore(sCommCode, nType) {

	//
	// Vytvorime, nastavime a spustime ajax
	//
	var theHttpRequest = getNewHttpObject();
	theHttpRequest.onreadystatechange = function() { processAJAX(); };
	theHttpRequest.open("get", "/includes/ajax_Availability.asp?code=" + sCommCode + "&type=" + nType);
	theHttpRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	theHttpRequest.send(null);

	function processAJAX() {
		if (theHttpRequest.readyState == 4) {
			var responseTxt = theHttpRequest.responseText;

			getE("miscInfoBox").innerHTML = theHttpRequest.responseText;
			
		}
	}

}

function getDatumVelikonoc(nRok) {
	var a = nRok % 19;
	var b = nRok % 4;
	var c = nRok % 7;
	var d = ((19 * a) + 24) % 30;
	var e = (5 + (2 * b) + (4 * c) + (6 * d)) % 7;

	var nNedele = 22 + d + e;
	var nMesic = 3;
	if (nNedele > 31) {
		nNedele = ((d + e - 9) > 25) ? d + e - 16 : d + e - 9;
		nMesic = 4
	}

	return new Date(nRok, nMesic - 1, nNedele + 1);
}

function sendTransfer() {

	var form = getF("frmTransfer");
	if (form.StoreToID.value == "") {
		alert("Zvolte sklad, kam se má zboží převést.");
		return;
	}

	form.step.value = 1;
	form.submit();
}

function sendSale() {

	var form = getF("frmSale");
	if (form.CustomerID.value == "") {
		alert("Zvolte zákazníka, kterému se prodává.");
		return;
	}

	form.step.value = 1;
	form.submit();
}

function sendIssue() {

	var form = getF("frmIssue");
	form.step.value = 1;
	form.submit();
}

/*------------------------------------------------------------------------------
 * Vrati x pozici scroll
 */ 
function getViewportScrollX() {
	var scrollX = 0;
	if( document.documentElement && document.documentElement.scrollLeft ) {
		scrollX = document.documentElement.scrollLeft;
	}
	else if( document.body && document.body.scrollLeft ) {
		scrollX = document.body.scrollLeft;
	}
	else if( window.pageXOffset ) {
		scrollX = window.pageXOffset;
	}
	else if( window.scrollX ) {
		scrollX = window.scrollX;
	}
	return scrollX;
}

/*------------------------------------------------------------------------------
 * Vrati y pozici scroll
 */ 
function getViewportScrollY() {
	var scrollY = 0;
	if(document.documentElement && document.documentElement.scrollTop) {
		scrollY = document.documentElement.scrollTop;
	}
	else if(document.body && document.body.scrollTop) {
		scrollY = document.body.scrollTop;
	}
	else if(window.pageYOffset) {
		scrollY = window.pageYOffset;
	}
	else if(window.scrollY) {
		scrollY = window.scrollY;
	}
	return scrollY;
}

/*------------------------------------------------------------------------------
 * Vycentruje element
 */ 
function centerElement(el) {
	var nScrollLeft = (isNaN(getViewportScrollY())) ? 0 : getViewportScrollX();
	var nScrollTop = (isNaN(getViewportScrollY())) ? 0 : getViewportScrollY();
	var nWidth = getWindowWidth();
	var nHeight = getWindowHeight();
	var nLeft = ((nWidth - el.offsetWidth) / 2) + nScrollLeft;
	var nTop = ((nHeight - el.offsetHeight) / 2) + nScrollTop;

	el.style.left = nLeft.toString() + "px";
	el.style.top = nTop.toString() + "px";
}

/*------------------------------------------------------------------------------
 * Vrati sirku okna
 */ 
function getWindowWidth() {
	return (typeof(window.innerWidth) == 'number') ? window.innerWidth : document.documentElement.clientWidth;
}

/*------------------------------------------------------------------------------
 * Vrati vysku okna
 */
function getWindowHeight() {
	return (typeof(window.innerHeight) == 'number') ? window.innerHeight : document.documentElement.clientHeight;
}

function checkFastOrderItem(form) {

	if (form.Code.value == "" && form.Name.value == "") { alert("Zadejte kód nebo název položky."); form.Code.focus(); return false; }

	return true;
}

function getE(objectID) {
	return document.getElementById(objectID); 
}

function getF(formName) {
	return document.forms[formName];
}

var gsLastTypedDate;
function txtCalendarOnFocus(txtEl) {
	gsLastTypedDate = txtEl.value;
	txtEl.value = "";
}

function checkTypedDate(txtEl, sMinDate, nUseWeekends) {

	if (txtEl.value == '') {
		txtEl.value = gsLastTypedDate;
		return true;
	}

	if (!isDate(txtEl.value)) {
		alert("Zadejte datum ve formátu 'd.m.yyyy'");
		txtEl.value = gsLastTypedDate;
		return false;
	}

	var dDate = parseDate(txtEl.value);
	var dMinDate = parseDate(sMinDate);

	if (dMinDate > dDate) {
		alert("Datum musí být minimálně " + sMinDate + ".");
		txtEl.value = gsLastTypedDate;
		return false;
	}

	if (nUseWeekends == 0 ) {
		if(dDate != getFirstAvailableDateAfter(dDate)) {
			alert("Datum nesmí být víkend ani svátek.");
			txtEl.value = gsLastTypedDate;
			return false;
		}
	}

	txtEl.value = dDate.getDate() + '.' + (dDate.getMonth() + 1) + '.' + dDate.getFullYear();
	return true;
}

function isDate(dateStr) {
	var aNums = dateStr.split(".");

	if (aNums.length < 3) return false;
	if (isNaN(parseInt(aNums[0], 10)) || isNaN(parseInt(aNums[1], 10)) || isNaN(parseInt(aNums[2], 10))) return false;

	day = parseInt(aNums[0], 10);
	month = parseInt(aNums[1], 10); // p@rse date into variables
	year = parseInt(aNums[2], 10);
	if (year < 100) year += 2000;

	if (month < 1 || month > 12) { // check month range
		return false;
	}

	if (day < 1 || day > 31) {
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			return false;
		}
	}

	return true;
}

function parseDate(sDate) {
	var aNums = sDate.split(".");

	day = parseInt(aNums[0], 10);
	month = parseInt(aNums[1], 10); // p@rse date into variables
	year = parseInt(aNums[2], 10);
	if (year < 100) year += 2000;

	return new Date(year, month - 1, day);
}

function showCalendarEx(oid, x, y, gli, dMinDate, nUseWeekends)
{
	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 + "&gli=" + gli + "&minDate=" + dMinDate + "&useWeekends=" + nUseWeekends;  
	cal.style.position = "absolute";	
	cal.style.top = (getPosY(tbox) + 18) + 'px';
	cal.style.left = (getPosX(tbox)) + 'px'; 
	calframe.src = ssrc;
	cal.style.display = 'block';
}

function getPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function getPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

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;
}

// ###   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 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 || keynum == 13 || (Br.NS && e.charCode == 0)
}

function ControlFloat(){
	if (!Br.IE) return;
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode !=46)) event.returnValue = false;
}

function ControlPhone() {
	if (!Br.IE) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32)  && (event.keyCode!=40) && (event.keyCode!=41) && (event.keyCode!=43))
		event.returnValue = false;
}
function ControlPSC() {
	if (!Br.IE) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32))
		event.returnValue = false;
}
//----------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");
}

function CheckBeforeReceive() {
	var f = getF("frmReceive");

	if (!f) return false;
	if (!f.OrderItemID) return false;

	if (f.OrderItemID.length) {
		for (var i = 0; i < f.OrderItemID.length; i++) {
			if (isNaN(parseInt(f.Count[i].value))) {
				alert(f.CommodityID[i].value + " - Neplatné množství k příjmu");
				f.Count[i].focus
				return false;
			}

			if (parseInt(f.CountToReceive[i].value) < parseInt(f.Count[i].value)) {
				alert(f.CommodityID[i].value + " - Nelze přijmout více, než je k příjmu");
				f.Count[i].focus
				return false;
			}
		}
	}
	else {
		if (isNaN(parseInt(f.Count.value))) {
			alert(f.CommodityID.value + " - neplatný počet pro příjem");
			f.Count.focus
			return false;
		}

		if (parseInt(f.CountToReceive.value) < parseInt(f.Count.value)) {
			alert(f.CommodityID.value + " - nelze přijmout více, než je k příjmu");
			f.Count.focus
			return false;
		}
	}

	return true;
}

//       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();

	return true;
}


// 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>"

	return true;
}

function showMiscInfoBox() {
  if (Br.IE) hideSelects();
	getE("miscInfoBox").style.display = "block";
	fadeInObject("miscInfoBox", 0);
	centerElement(getE("miscInfoBox"));
}

function hideMiscInfoBox() {
	getE("miscInfoBox").style.display = "none";
	fadeOutObject("miscInfoBox", 10);
	if (Br.IE) showSelects();
	clearTimeout;
}

/* 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 = 40;
	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 = 40;
	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; }
	}
}

// ShopInfoBox

function showShopInfoDialog(sContent) {
  hideSelects();
	clearTimeout;

	var e = getE("shopinfobox");
	fadeInObject("shopinfobox", 0);
	e.style.position = "absolute";
	e.style.top = topScroll() + 300 + 'px';
	e.style.left = (document.body.clientWidth / 2 - 100) + 'px';

	getE('shopinfoform_content').innerHTML = sContent;

	setTimeout("hideShopInfoboxDialog();", 2000);
}

function hideShopInfoboxDialog() {
	var e = getE("shopinfobox");
	e.style.display = "none";
	
	/*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';
  showSelects();
}

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';
  if (Br.IE) showSelects();
}
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;
  if (Br.IE) hideSelects();
	getE('hover_'+idImage).style.display='block';
}


function EmailControl(sEmail) {
	var regEx  = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/i; 

	return (regEx.test(sEmail))
}

function ControlPassword(NameOne,NameTwo){
	if (getE(NameOne).value != getE(NameTwo).value){
		alert("Špatně zadané heslo.");
		getE(NameOne).value = "";
		getE(NameTwo).value = "";
		getE(NameOne).focus();
		return false;
	}else{
		return true;
	}
}

function checkCount(frm, checkOnStore) {

	var count = 0;

	if (frm.Count.value == "") {
		count = 1;
	}
	else {
		count = parseInt(frm.Count.value);
	}

	if (isNaN(count)) {
		alert("Zadejte platné množství pro přidání.");
		frm.Count.value = frm.Count.defaultValue;
		return false;
	}

	if (count < 0) {
		alert("Zadejte platné množství pro přidání.");
		frm.Count.value = frmCount.defaultValue;
		return false;
	}

	if (frm.OnStore && checkOnStore) {
		var countOnStore = parseInt(frm.OnStore.value);
		if (isNaN(countOnStore)) {
			countOnStore = 0;
		}

		if (countOnStore < count) {
			alert("Skladem máte " + countOnStore + " " + frm.Unit.value + ".\n\nNelze přidat větší množství, než je skladem.");
			frm.Count.value = frm.Count.defaultValue;
			return false
		}
	}

	return true;
}

function confirmEmptyBasket() {
	return confirm('Přejete si zrušit objednávku a vyprázdnit košík?');
}


var lastAddressSelected = 0;
function changeDeliveryAddressSelected( firstSelected, actualAddressSelected ) {
	if (lastAddressSelected == 0) lastAddressSelected = firstSelected;
	if (document.getElementById('deliveryAdd'+lastAddressSelected)) document.getElementById('deliveryAdd'+lastAddressSelected).style.display='none';
	if (document.getElementById('deliveryAdd'+actualAddressSelected)) document.getElementById('deliveryAdd'+actualAddressSelected).style.display=(Br.IE ? 'block' : 'table');
	lastAddressSelected = actualAddressSelected;
}

var DeliveryAddressesInSelect = 0, maximumDeliveryAddresses = 20;
function addNewDeliveryAddress(num) {
	if (DeliveryAddressesInSelect==0) { DeliveryAddressesInSelect = num + 1 } else { DeliveryAddressesInSelect++ };
	if (DeliveryAddressesInSelect>maximumDeliveryAddresses) { alert('Maximální počet doručovacích adres je '+maximumDeliveryAddresses+'.'); return; }
	var Sel = getE('deliveryAddressSelector');
	Sel.options[Sel.options.length] = new Option("#"+DeliveryAddressesInSelect+" - Nová adresa",DeliveryAddressesInSelect);
	Sel.selectedIndex=DeliveryAddressesInSelect-1;

	getE('placeForNewAddresses').innerHTML +=
			"<input type='hidden' name='pkTblCommodityClientAddress' value='' />" +
			"<input type='hidden' name='sDeliveryAddressCode' value='' />" +
			"<table id='deliveryAdd"+DeliveryAddressesInSelect+"'>"+
			"<tr><td colspan='4'><h5>Adresa #"+DeliveryAddressesInSelect+":</h5></td></tr>" +
			"<tr>" +
			"<td class='rName' rowspan='2'><label>Firma :</label></td>" +
			"<td class='rInput'><input type='text' tabindex='131' class='input_text ' maxlength='30' name='Delivery_Firm' value='' /></td>" +
			"<td class='rName1'><label>Ulice :</label></td>" +
			"<td class='rInput1'><input type='text' tabindex='138' class='input_text' maxlength='50' name='Delivery_Street' value='' /></td>" +
			"</tr>" +
			"<tr>" +
			"<td class='rInput'><input type='text' tabindex='132' class='input_text ' maxlength='30' name='Delivery_Firm2' value='' /></td>" +
			"<td class='rName1'><label>Upřesnění adresy :</label></td>" +
			"<td class='rInput1'><input type='text' tabindex='139' class='input_text' maxlength='50' name='Delivery_District' value='' /></td>" +
			"</tr>" +
			"<tr>" +
			"<td class='rName'><label>Kontakt :</label></td>" +
			"<td class='rInput'><input type='text' tabindex='133' class='input_text' maxlength='30' name='Delivery_LastName' value='' /></td>" +
			"<td class='rName1'><label>Město :</label></td>" +
			"<td class='rInput1'><input type='text' tabindex='140' class='input_text' maxlength='50' name='Delivery_City' value='' /></td>" +
			"</tr>" +
			"<tr>" +
			"<td class='rName'><label>Telefon :</label></td>" +
			"<td class='rInput'><input type='text' tabindex='134' maxlength='40' class='input_text' name='Delivery_Phone' value='' onkeypress='return ControlPhone();' /></td>" +
			"<td class='rName1'><label>PSČ :</label></td>" + 
			"<td class='rInput1'><input type='text' tabindex='141' class='input_text itEx1' maxlength='6' name='Delivery_ZipCode' onkeypress='return ControlPSC()' value='' /></td>" +
			"</tr>" +
			"<tr>" +
			"<td class='rName'><label>Mobil :</label></td>" +
			"<td class='rInput'><input type='text' tabindex='135' maxlength='40' class='input_text' name='Delivery_Mobil' value='' onkeypress='return ControlPhone();' /></td>" +
			"<td class='rName1'>&nbsp;</td>" +
			"<td class='rInput1'>&nbsp;</td>" +
			"</tr>" +
			"<tr>" +
			"<td class='rName'><label>Fax :</label></td>" +
			"<td class='rInput'><input type='text' tabindex='136' maxlength='40' class='input_text' name='Delivery_Fax' value='' /></td>" +
			"<td class='rName1'>&nbsp;</td>" +
			"<td class='rInput1'>&nbsp;</td>" +
			"</tr>" +
			"<tr>" +
			"<td class='rName'><label>E-mail :</label></td>" +
			"<td class='rInput'><input type='text' tabindex='137' maxlength='40' class='input_text' name='Delivery_Email' value='' /></td>" +
			"<td class='rName1'>&nbsp;</td>" +
			"<td class='rInput1'>&nbsp;</td>" +
			"</tr>" +
			"<tr>" +
			"<td colspan='4'>&nbsp;</td>" +
			"</tr>" +
			"</table>"

	changeDeliveryAddressSelected((num>0?1:0),DeliveryAddressesInSelect);
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
	function hideSelects() {
		var els = document.getElementsByTagName('select'); for (var i=0;i<els.length;i++) { els[i].style.visibility='hidden'; }
	}
	function showSelects() {
		var els = document.getElementsByTagName('select'); for (var i=0;i<els.length;i++) { els[i].style.visibility='visible'; }
	}

 function ShowCalendar(oid)
 {
  var cal = document.getElementById('divcal');
  var calframe = document.getElementById('diviframcal');
  var tbox = document.getElementById(oid);
  var ssrc = '/administration/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 GoToPage(nPage, sParam) {
	document.location.href = '?pgID=' + nPage + sParam;
}
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 AddClientStock(){
	var el = getE('stockBox')
	el.innerHTML = el.innerHTML +"<table><tr><td><input type='hidden' name='stockID' value='' /><input type='text' value='' name='StockIdentifier' /></td><td><nobr><input type='text' value='' name='StockName' /></nobr></td></tr></table>" ;
}

function AddStockMan(){
	var el = getE('stockManBox')
	el.innerHTML = el.innerHTML +"<table><tr><td><input type='hidden' name='ClientID' value='0' /><input type='text' value='' name='Firm' /><input type='text' value='' name='Login' /></td><td><nobr><input type='text' value='' name='Password'/></nobr></td><td>"+getE('stockManBoxMemo').innerHTML+"</td></tr></table>" ;
}

