
// 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 InsertCookiesCategory(intId){
	alert(intId);
	document.cookie="ActiveCat="+intId + ";";
	document.cookie="ActiveCat="+intId + ";";
	document.cookie="ActiveCat="+intId + ";";
	document.cookie="ActiveCat="+intId + ";";
	document.cookie="ActiveCat="+intId + ";";
}

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()+";";
	}
	
	//window.location.reload();
	//if (getE('RedirOnListCagChange')!=null) window.location.href=sURL;
}


// ###   FCE PRO BOXIKY SE SUBKATEGORIEMI   ###

var IdTimeToHideCategoryBox;
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 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";	
}

// ###   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;
}

// ###   FCE PRO PriceList ###

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 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 x = strName + '=' + strData + '; path=/';


	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() - 365);
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+";";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie= x;
}

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 ShowSearchMenu(x){
    if (x == 1){
        getE('Searchtable').style.display='';
    }else{
        getE('Searchtable').style.display='none';
    }
}


function ControlSendEmailToFriend()
{
    var obj1 = document.getElementById('SendToEmail');
    var obj2 = document.getElementById('SendFromEmail'); 
	
	if(obj1.value == ""){alert("Vyplňte email");obj1.focus();return false;}
	if(obj2.value == ""){alert("Vyplňte email");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 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 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-';
				getE('Categ0').options.add(el);
			}
		} else
		    getE('Categ0').options.add(el);
	}
		
	getE('CatID0').value = saCatID.substr(0,saCatID.length - 1);
	if (saCatIdName == "") {
		getE('Categ0').style.display = "none";
		getE("ChooseCateg0").style.display  = "inline";
	} else {
		getE('Categ0').style.display = "inline";
		getE("ChooseCateg0").style.display  = "none";
	}
}

function GetCategoriesIdNameForSelect(nTree,bAlsoDisabled,nIndex,nUserType) {
	var saCatID,nProID,sProNM;
	var r;
	
	nProID = 0;
	
	saCatID = getE('CatID0').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();

// ##### 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") { 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;
}

function checkCount( myCount, minCount, onlyMultiplied ) {
	if ( myCount == 0 ) return true;
	if ( myCount < minCount ) {
		alert('Všechny kategorie '+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 fnCheckParamCommodityUse(objForm) {
	if (objForm.bParamUsed.value=='0') 
		return true;
	else 
		return confirm('Tento parametr je použit u zboží, opravdu jej chcete smazat?');
}




function ZavriKosik(bHideCB)
{
	getE("StateInfo1").style.display="none";
}

function SearchExt_ShowHide()
{
    var objDiv = document.getElementById("SearchExt");
   
    if (objDiv.style.display == "none")
            objDiv.style.display = "block";
    else         
            objDiv.style.display = "none"; 
}

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 ChangeFilters(bState, sCookieName)
{
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);
	var sCookie  = sCookieName + '=' + (bState==true ? '1' : '0') + ';';

    document.cookie = sCookie;
}

function LogOff_User()
{
	if(confirm('Odhlásit?')){;document.forms.LogOff.submit();}
}




//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 == '' || sValue == 'Zadej text...')
	{
		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 openclosearchiv(partId)
{

    var sOpenOrClose = getE(partId).style.display;
    
    if (sOpenOrClose=="none")
    {
        getE(partId).style.display = 'block';
    }
    else
    {
        getE(partId).style.display = 'none';
    }
}

