// globalni promenna------------------
var strContentElBarto = "";
var gb_nCurrentPrice        = 0 //0...nas cena  1..ekonomicka cena

var Br = new BrCheck()

function BrCheck()
{
	this.VER	= navigator.appVersion;
	this.AGENT	= navigator.userAgent;
	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.OP		= (this.OP5 || this.OP6 || this.OP7);

	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 AddNameParameter(){

  var strReturn = showModalDialog("QueryPage.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=200pt;dialogHeight=100pt");

		  if (strReturn == null) return;
          if (strReturn == ""){alert('Nebyl zadán žádný text.');return}
          var strValue = strReturn;
          var strText = strReturn;
          var el;
        if(typeof(document.all.VALUEPARAM.length) == "number"){
                for (var i=0; i<document.all.PARAMETERNAME.length; i++) {
                        el = document.createElement("OPTION")
                        el.text = strText;
                        el.value = strValue;
                          document.all.PARAMETERNAME[i].options.add(el);
                  }
        }else{
                el = document.createElement("OPTION")
                el.text = strText;
                el.value = strValue;
                document.all.PARAMETERNAME.options.add(el);
        }

}

//------------------------------------
function SelectKomodita() {
    Client.style.display = 'none';
    Komodita.style.display = 'inline';
    Price.style.display = 'none';
}
function SelectCeny() {
    Client.style.display = 'none';
    Komodita.style.display = 'none';
    Price.style.display = 'inline';
}
function SelectClient() {
	Client.style.display = 'inline';
	Komodita.style.display = 'none';
	Price.style.display = 'none';
}

function CenyRad() {
	Price.style.display = 'inline';
	Client.style.display = 'none';
	Komodita.style.display = 'none';
}

function FormControl(f, p)
{
  var ret  = true;
  var ret1 = true;
  var msg = "";
	if ((f=='' || f=='Váš E-mail.. ') || (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)))
  {
	 msg = 'Nesprávný formát emailu !\n\n';
	 ret = false;
	}
	
	if(!processNumber(p) && !ret)
	{
	 msg+= 'Telefon musí mít jen číslice !\n\n';
	 ret1 = false;
  }

  if(!ret && !ret1)
  {
    alert(msg + '\nStačí vložit platný e-mail nebo telefonní číslo.');
    return false;
  } 
	return true;
}

function processNumber(p)
{
    var check = true;
    if(p.length < 1){return false;}
    var value = p;
    for(var i=0;i < p.length; ++i)
    {
       var new_key = value.charAt(i); 
       if(((new_key < "0") || (new_key > "9")) && 
            !(new_key == ""))
       {
            check = false;
            break;
       }
    }
    return check;
}

function EmailControl(f){

//  alert(Br)+'1';
	if ((f=='' || f=='Váš E-mail.. ') || (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 emailu');
		  return false;
		}
	return true;
	
}

function ShowDate(strItem) {
     var strReturn = showModalDialog("/Administration/SelectDate.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=250pt;dialogHeight=200pt");
     if (strReturn == undefined){return;}
     strItem.value = strReturn;
}

function ChangeStateOrder(intState){
	var Childstate, lengthItem;

	if (intState == 0){
		Childstate = 0
	}else if(intState == 3){
		Childstate = 2
	}else if(intState == 4){
		Childstate = 4
	}else{
		Childstate = 1
	}

    if(typeof (document.EditOrder.IdItem[1]) == "object"){
		lengthItem = document.EditOrder.IdItem.length;
		for(var i = 0; i < lengthItem; i++){
			document.EditOrder.StateItem[i].value = Childstate;
		}
	}else{
		document.EditOrder.StateItem.value = Childstate;
	}
}

function ShowOffers(intId) {
	if (document.getElementById(intId).style.display == "none"){
		document.getElementById(intId).style.display = "";
	}else{
		document.getElementById(intId).style.display = "none";
	}
}


function FrameLocation(strURL) {
	/*alert(strURL);*/
	window.frames['ActionFrame'].location.href = strURL;
}

function WriteNameAction(strName) {
	if (strName != "") strName = "Administrace katalogu";
	if (window.parent) if (window.parent.document.all.NameAction) window.parent.document.all.NameAction.innerHTML = strName;
}
function ChangeCategory(strString){
	var arrData;//3##Kapky##0##imgCat##imgCatForPrint##False'
	arrData = strString.split("##");
	document.forms.EditCategory.elements.IDCategory.value = arrData[0];
	document.forms.EditCategory.elements.NameCategory.value = arrData[1];
	document.forms.EditCategory.elements.ParentSelect.value = arrData[2];
	document.forms.EditCategory.elements.ImageCat.value = arrData[3];
	document.getElementById('ImgCat1').src = '/Foto/ImgCategory/'+arrData[3];
	
//	document.forms.EditCategory.elements.ImageCatPrint.value = arrData[4];
//	document.forms.EditCategory.elements.DeliveryPrice.value = arrData[6];
//	document.forms.EditCategory.elements.PackageDescription.value = arrData[7];
	document.forms.EditCategory.elements.OrderNo.value = arrData[5];
	
//	document.getElementById('ImgCat1').src = '/Foto/ImgCategory/'+arrData[3];
//	document.getElementById('ImgCat2').src = '/Foto/ImgCategory/Over/'+arrData[3];
//	document.getElementById('ImgCatPrint').src = '/Foto/ImgCategory/'+arrData[4];
	window.frames.FrameDescription.location.href='BlankWhite.htm';
	
	if (document.forms.EditCategory.elements.sMETATitle)	document.forms.EditCategory.elements.sMETATitle.value = arrData[7];
	if (document.forms.EditCategory.elements.sMETAKeyWords) document.forms.EditCategory.elements.sMETAKeyWords.value = arrData[8];
	if (document.forms.EditCategory.elements.sMETADescription) document.forms.EditCategory.elements.sMETADescription.value = arrData[9];
//	alert(arrData[4].toString())
	if(arrData[4].toString() == "True"){
		document.EditCategory.bDisabled.checked = "True";
	}else{
		document.EditCategory.bDisabled.checked = "" ;
	}

	if(arrData[10].toString() == "True"){
		document.EditCategory.ForXML.checked = "True";
	}else{
		document.EditCategory.ForXML.checked = "" ;
	}
	
	if(arrData[11].toString() == "True"){
		document.EditCategory.OnlyInfo.checked = "True";
	}else{
		document.EditCategory.OnlyInfo.checked = "" ;
	}
  
	// fkceditor
	//var oEditor = FCKeditorAPI.GetInstance('FCKeditor1')
	//oEditor.Value = arrData[9];
	
	
}
function ControlParent(idCat) {
	if(idCat == document.EditCategory.IDCategory.value){
		alert("Kategorie nemůže být nadřazená sama sobě.");
		document.EditCategory.ParentSelect.value = 0;
	}
}
function EmptyCategory() {
	document.EditCategory.NameCategory.value = "";
	document.EditCategory.IDCategory.value = 0;
	document.EditCategory.ParentSelect.value = 0;
	document.EditCategory.ImageCat.value = "";
//	document.EditCategory.ImageCatPrint.value = "";
	document.images.ImgCat1.src = "";
	document.images.ImgCat2.src = "";
//	document.images.ImgCatPrint.src = "";
	
}

function SearchParameterString(sParamName, sParamValue, sRowName){
	var strReturn = showModalDialog("/administration/ListOfParamsValues.asp?sParamName=" + sParamName + "&sParamValue=" + sParamValue,"","status:no; center:yes; help:no; minimize:no;dialogWidth=200pt;dialogHeight=100pt");

	if (strReturn == ""){alert('Nebyl zadán žádný text.');return};
    if (strReturn == undefined){return;};
    var strValue = strReturn;
    var strText = strReturn;

	sRowName.value = strText;
}
function InsertImage(Action){
	var strReturn = showModalDialog("ListImage.asp?STAT="+Action,"","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt;");
	if (strReturn == undefined){return;};
	document.all.ImageItem.value = strReturn;
	ChangeImage();
}
function PictureManager(strRootDir)
{
	var strReturn = showModalDialog("/administration/picturemanager.asp?rootDir=" + strRootDir,"PictureManager","status:no; center:yes; help:no; minimize:no;dialogWidth=800pt;dialogHeight=600pt;");
	if (strReturn == undefined){return;};
	document.all.ImageItem.value = strReturn;
	ChangeImage();
}
function InsertAddRelated(intNoInput){

	var strReturn = showModalDialog("ListRelated.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");

	if (typeof(strReturn) == 'undefined'){return;}
	var arrString;
	arrString = strReturn.split("|"); 
	if(typeof(document.all.RelatedCode.length) == "number"){
		document.all.IdCommodityRelated[intNoInput].value = arrString[0];
		document.all.RelatedCode[intNoInput].value = arrString[1];
		document.all.RelatedName[intNoInput].value = arrString[2];
	}else{
		document.all.IdCommodityRelated.value = arrString[0];
		document.all.RelatedCode.value = arrString[1];
		document.all.RelatedName.value = arrString[2];
	}
}
function InsertAddAlternative(intNoInput){

	var strReturn = showModalDialog("ListAlternative.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");

	if (typeof(strReturn) == 'undefined'){return;};
	var arrString;
	arrString = strReturn.split("|"); 
	if(typeof(document.all.AlternativeCode.length) == "number"){
		document.all.IdCommodityAlternative[intNoInput].value = arrString[0];
		document.all.AlternativeCode[intNoInput].value = arrString[1];
		document.all.AlternativeName[intNoInput].value = arrString[2];
	}else{
		document.all.IdCommodityAlternative.value = arrString[0];
		document.all.AlternativeCode.value = arrString[1];
		document.all.AlternativeName.value = arrString[2];
	}
}
function UploadFile(sPath){
         var strReturn = showModalDialog("/administration/UploadFileModal.asp?path=" + sPath,"","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");

         if (strReturn == undefined){return;};
}
function InsertAddImage(intNoInput){
	
	var strReturn = showModalDialog("ListAddImage.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");

	if (strReturn == undefined){return;};
	if(typeof(document.all.ImageAddItem.length) == "number"){
	       document.all.ImageAddItem[intNoInput].value = strReturn;
	}else{
	       document.all.ImageAddItem.value = strReturn;
	}
}
function InsertImageAdvertising(objForm){

	var strReturn = showModalDialog("/ElBarto/ListImg.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");

	if (strReturn == undefined){return;}
	if(strReturn.substring(strReturn.length-3) == "swf"){
	    objForm.Body.value = "<embed width='468px' height='60px' src='/ImgGalery/"+strReturn+"' />";
	}else{
	    var strUrl = prompt("Zadejte URL na kterou má obrázek odkazovat.","http://");
//		alert("<a href='"+strUrl+"' target='blank'><img src='/ImgGalery/"+strReturn+"' /></a>");
	    objForm.Body.value = "<a href='"+strUrl+"' target='blank'><img src='/ImgGalery/"+strReturn+"' alt='' /></a>";
	}
}
function InsertAddFile(intNoInput){	

	var strReturn = showModalDialog("ListAddFiles.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
	if (strReturn == undefined){return;};
		if(typeof(document.all.FileAddName.length) == "number"){
		      document.all.FileAddPath[intNoInput].value = strReturn;
		}else{
		      document.all.FileAddPath.value = strReturn;
		}
}

function InsertImageCat(Action){
	var strReturn = showModalDialog("ListImageCat.asp?STAT="+Action,"","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
	if (strReturn == undefined){return;}
	document.all.ImageCat.value = strReturn;
	document.all.ImgCat1.src = '/Foto/ImgCategory/'+strReturn;
}

function InsertImageProducer(Action){
	var strReturn = showModalDialog("ListImageproducer.asp?STAT="+Action,"","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
	if (strReturn == undefined){return;}
	document.all.ImageProd.value = strReturn;
	document.all.ImgProd.src = '/Foto/ImgProducer/'+strReturn;
}


function InsertImageBanner(Banner){
	var strReturn = showModalDialog("ListImageBanner.asp?STAT="+Banner,"","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
	if (strReturn == undefined){return;}
	document.all.ImageBanner.value = strReturn;
	
}

function InsertImageSecondBanner(Banner){
	var strReturn = showModalDialog("ListImageBanner.asp?STAT="+Banner,"","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
	if (strReturn == undefined){return;}
	document.all.ImageSecondBanner.value = strReturn;
	
}




function InsertImageCatPrint(Action){
      var strReturn = showModalDialog("ListImageCat.asp?NUM=1&STAT="+Action,"","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
      if (strReturn == undefined){return;}
      document.all.ImageCatPrint.value = strReturn;
      document.all.ImgCatPrint.src = '/Foto/ImgCategory/'+strReturn;
}

function PrintOrder(strPkOrder){
	var msg = window.open('OrderPrintAdmin.asp?ID='+strPkOrder,'okno','toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=700,height=500,left=20,top=20');
	msg.focus();
}

function DeleteOrder(strPkOrder){
	if (confirm("Opravdu chcete objednávku č.: "+strPkOrder+" smazat?")){
		return true;
	}else{
		return false;
	}
}

function InsertTemplate(){
	var arrReturn
	var strReturn = showModalDialog("ListTemplate.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
	if(strReturn != undefined){
		arrReturn = strReturn.split("&");
		if(arrReturn[0] == "Param"){window.location.href=window.location.pathname+"?IdItem="+document.all.IdItem.value+"&PRM="+arrReturn[1]}
//		if(arrReturn[0] == "All"){window.location.href="EditCommodityItem.asp?TMP="+arrReturn[1]}
		if(arrReturn[0] == "All"){window.location.href=window.location.pathname+"?TMP="+arrReturn[1]}
	}
}

function ControlNumber(){
	if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}

function ControlFloat(){
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode !=46)) event.returnValue = false;
}

function AddCategory(intTree){
	var arrData,arrSubData,apkTblCommodityCategory;
	var strReturn = showModalDialog("SelectCategory.asp?TREE="+intTree+"&CAT="+document.all.IdItem.value,"Info","status:no; center:yes; help:no; minimize:no;dialogWidth=350pt;dialogHeight=300pt");

	if (strReturn == 'undefined'){alert('Nebylo nic vybráno.');return}
	var el,r;
	with(document.all['strCategory'+intTree]){
		r = options.length;
		for (var i=0; i<r; i++) {
			options.remove(options.length-1);
		}
	}
	arrData = strReturn.split("*");
	apkTblCommodityCategory = new Array();
	for (var i=0; i<arrData.length-1; i++) {
		arrSubData = arrData[i].split("/");

//		[Sel.options.length] = new Option("#"+DeliveryAddressesInSelect+" - Nová adresa",DeliveryAddressesInSelect);

		el = document.createElement("OPTION");
		el.value = arrSubData[0];
		el.text = arrSubData[1];
		document.all['strCategory'+intTree].options.add(el);	
		apkTblCommodityCategory[i] = arrSubData[0];
	}
//	ComParamAddUpdFromCategories(apkTblCommodityCategory);
}

function SendBulkMail(bNews,bCustomer,intID){
	if(bNews){
		bNews = 1;
	}else{
		bNews = 0;
	}
	if(bCustomer){
		bCustomer = 1;
	}else{
		bCustomer = 0;
	}
	var msg = window.open('SendBulkMail.asp?TypeMail=Client&NWS='+bNews+'&CST='+bCustomer+'&GRP='+intID,'okno','toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=870,height=740,left=20,top=20');
	msg.focus();
}
function SendMail(strAddress){
	var msg = window.open(strAddress,'win','toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=700,height=500,left=20,top=20');
	msg.focus();
}
function InsertElBarto(strContent){
	strContentElBarto = strContent;
	var msg = window.open('ShowOneElBarto.asp','EditWindow','toobar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width=700,height=550,left=20,top=20');
	msg.focus();
}

// 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<document.frames.length;i++){
		SelectHideEx(sStyle,document.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 SelectClanek(strItemPk, strItemTitle) {
	var strReturn = showModalDialog("/Administration/Competition/SelectArticle.htm","","status:no; center:yes; help:no; minimize:no;dialogWidth=400px;dialogHeight=250px");
	var arrPkAndTitle;
	if (strReturn == undefined){return;}
	arrPkAndTitle = strReturn.split("##");
	strItemPk.value = arrPkAndTitle[0];
	strItemTitle.value = arrPkAndTitle[1];
}


function ChangePrice(sOurPrice, sMena, sEcoPrice, sEcoDesc, nPriceForHidden, nPriceEcoForHidden)
{
	var objPriceName		= document.getElementById('priceName');
	var objPriceValue		= document.getElementById('priceValue');
	var objPriceButton		= document.getElementById('priceBT') ;
	var objConf				= document.getElementById('confBT');
	var objHiddenPrice		= document.getElementById('Price');
	var objHiddenPriceWDPH  = document.getElementById('PriceWDPH');
	
	if (gb_nCurrentPrice == 0)
	{
		objPriceName.innerHTML = 'Ekonomická cena:';
		objPriceValue.innerHTML = sEcoPrice + ' ' + sMena;
		objPriceValue.title='Ekonomická cena včetně DPH'
		
		// tlacitko ceny
		objPriceButton.title     = 'Naše cena';
		objPriceButton.className = 'willOurPriceBT';
		
		// konfigurator
		objConf.title = 'Konfigurátor není dostupný';
		objConf.className = 'configurationDisabledBT';
	
		objHiddenPrice.value	 = nPriceEcoForHidden;
		objHiddenPriceWDPH.value = sEcoPrice;
		
		
	}
	else
	{
		objPriceName.innerHTML = 'Naše cena:';
		objPriceValue.innerHTML = sOurPrice + ' ' + sMena;
		objPriceValue.title='Naše cena včetně DPH'
		
		// tlacitko ceny
		objPriceButton.title     = sEcoDesc;
		objPriceButton.className = 'willBetterPriceBT';
		
		// konfigurator
		objConf.title = 'Konfigurátor';
		objConf.className = 'configurationBT';
		
		objHiddenPrice.value	 = nPriceForHidden;
		objHiddenPriceWDPH.value = sOurPrice;
	}
	gb_nCurrentPrice = !gb_nCurrentPrice;
} 

function OnClickKonfiguratorBT(nIDCommodity)
{
    if (gb_nCurrentPrice == 1)
    {
            alert("Konfigurátor není dostupný, klikněte na tlačítko 'NAŠE CENA'.");
            return false;           
    } 
    else
   {
        document.location.href = '/Configuration.asp?CFG=1&ID=' +nIDCommodity;
   }  
 
}

var g_arrChangedComponents = new Array();

function OnChangeComponent(objRadio, idZarazeni, nCommodityPrice, sNameField, nPriceNoDPH, nValueDph, nIdCommodity)
{

	var nIdCommodity = objRadio.value;
	var objOldRadio	 = document.getElementById('radio' + document.getElementById('ProdSel'+idZarazeni).value);
	objOldRadio.checked = false;
	objRadio.checked	= true;
	
	document.getElementById('ProdSel'+idZarazeni).value = nIdCommodity;
	
	// nacteni a vypocet cen / cenovych rozilu
	var nOurPrice  = parseFloat(BarterComma(document.getElementById('ourprice').value));
	var nCurrPrice = parseFloat(BarterComma(document.getElementById('currentprice').value));
	var nDflPrice  = parseFloat(BarterComma(document.getElementById('ProdPriceWDPH'+idZarazeni).value));
	var nPrice     = nCurrPrice - nDflPrice + parseFloat(nCommodityPrice);
	var nPriceDiff = Math.abs(nPrice - nOurPrice);
	
	//alert (nCurrPrice +  ' - ' + nDflPrice + ' - ' +nCommodityPrice);
	var sMenaCode = document.getElementById('mena').value;
	
	document.getElementById('currentprice').value     = FormatFloat(nPrice,2).replace('.',','); 
	document.getElementById('price_forall').innerHTML = FormatCurrency(nPrice,2) + " " + sMenaCode;
	
	if (nPrice > nOurPrice)
		document.getElementById('price_forallDiff').innerHTML = '+' + FormatCurrency(nPriceDiff,2) + " " + sMenaCode;	
	if (nPrice < nOurPrice)
		document.getElementById('price_forallDiff').innerHTML = '-' + FormatCurrency(nPriceDiff,2) + " " + sMenaCode;	
	if (nPriceDiff == parseFloat(0))	
		document.getElementById('price_forallDiff').innerHTML = "0 " + sMenaCode;	
	
	document.getElementById('ProdPrice'+idZarazeni).value     = nPriceNoDPH;
	document.getElementById('ProdDPH'+idZarazeni).value       = nValueDph;
	document.getElementById('ProdSel'+idZarazeni).value       = nIdCommodity;
	document.getElementById('ProdPriceWDPH'+idZarazeni).value = nCommodityPrice;
	document.getElementById('NameDfl'+idZarazeni).innerHTML   = sNameField;
	document.getElementById('NameDfl'+idZarazeni).title       = 'Vybraná položka - ' + sNameField;
	
	document.getElementById('PriceDfl'+idZarazeni).innerHTML  = FormatCurrency(nCommodityPrice,2) + " " + sMenaCode;
	
	SaveChangedComponents(idZarazeni);
}

// zaznamenani operaci s konfiguratorem - pouzito pri ukladani do db/kosiku
function SaveChangedComponents(idZarazeni)
{
	var sValue	   	    = "";
	var nPoradi         = document.getElementById('PozZarazeni'		 + idZarazeni).value;
	var nCount          = document.getElementById('ProdCount'		 + idZarazeni).value;
	var nIdProdDfl      = document.getElementById('ProdSelDfl'		 + idZarazeni).value;
	var nIdProdSel      = document.getElementById('ProdSel'			 + idZarazeni).value;
	var nPriceWDPHDfl   = document.getElementById('ProdPriceWDPHDfl' + idZarazeni).value;
    var nPriceWDPHSel   = document.getElementById('ProdPriceWDPH'	 + idZarazeni).value;
    var nPriceDfl       = document.getElementById('ProdPriceDfl'     + idZarazeni).value;
    var nPriceSel       = document.getElementById('ProdPrice'	     + idZarazeni).value;
    var nDPHDfl	        = document.getElementById('ProdDPHDfl'       + idZarazeni).value;
    var nDPHSel         = document.getElementById('ProdDPH'	         + idZarazeni).value;
    
    // id ||| cena bez dph ||| dph ||| cena s dph ||| mnozstvi |~| aktualni zbozi
    if (nIdProdDfl != nIdProdSel)
          sValue = nIdProdDfl + "|||" + nPriceDfl + "|||" + nDPHDfl + "|||" + nPriceWDPHDfl + "|||-" + nCount + 
                   "|~|" + nIdProdSel + "|||" + nPriceSel + "|||" + nDPHSel + "|||" + nPriceWDPHSel + "|||" + nCount
    
	g_arrChangedComponents[nPoradi] = sValue;
}

// priprava dat pro volani procedur

function SetDataForSaveConfig()
{
	var sValueArr  = "";
	var sResultArr = "";
	var sDelimiter = ""
	
	for (i=0;i<g_arrChangedComponents.length;i++)
	{
		sValueArr  = g_arrChangedComponents[i];
		sDelimiter = "~~~";
		
   		if (sValueArr != "" && sValueArr != undefined)	
		{
			    if (sResultArr == "") {sDelimiter = "";}
			    sResultArr = sResultArr + sDelimiter  + sValueArr;
		}
	}
	document.getElementById('ResultConfig').value = sResultArr;
	//alert("-- " + document.getElementById("ResultConfig").value);
}

function ObsahCookies(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 "";
        }
}
function WriteCookiesRemember(nID,name,nIDShop,nShopGRP) { 
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() + 14);
        vyprseni = vyprs.toGMTString();
	
        var sTemp;
        var apkTblCommodity,aLen;
	var sValue = ObsahCookies(name);
	if ((sValue=='none')||(sValue=='')) {
	        sValue = nIDShop + "$" + nID + "/" + nShopGRP + "#";
                document.cookie=name + "=" + sValue + ";expires="+vyprseni;
                alert("Položka byla přidána do pamatováčku!!");
        	return;
	}
        sTemp = "#" + sValue;
       	if (sTemp.indexOf("#" + nIDShop + "$" + nID + "/" )!=-1) {
                alert("Produkt již je v pamatováčku!!");
                return;
        } else {
                alert("Položka byla přidána do pamatováčku!!");
                sValue += nIDShop + "$" + nID + "/" + nShopGRP + "#";
                document.cookie=name + "=" + sValue + ";expires="+vyprseni;
                return;
        }
}

//-------------------------------------- Z DetailPage_INC.asp -----------------------------------------------------

function addParametersAsCommodities()
{
	var re=/ /g;
	
	if(document.dform.MCode.value.replace(re,"")!="")
	{
		if(document.dform.MCode.value.replace(re,"")==document.dform.MCodeMem.value.replace(re,""))
		{
			document.dform.MCode.value="";
		}
	}

	if(document.dform.MoCode.value.replace(re,"")!="")
	{
		if(document.dform.MoCode.value.replace(re,"")==document.dform.MoCodeMem.value.replace(re,""))
		{
			document.dform.MoCode.value="";
		}
	}

	if(document.dform.PoCode.value.replace(re,"")!="")
	{
		if(document.dform.PoCode.value.replace(re,"")==document.dform.PoCodeMem.value.replace(re,""))
		{
			document.dform.PoCode.value="";
		}
	}

	if(document.dform.CCode.value.replace(re,"")!="")
	{
		if(document.dform.CCode.value.replace(re,"")==document.dform.CCodeMem.value.replace(re,""))
		{
			document.dform.CCode.value="";
		}
	}
	if(document.dform.PCode.value.replace(re,"")!="")
	{
		if(document.dform.PCode.value.replace(re,"")==document.dform.PCodeMem.value.replace(re,""))
		{
			document.dform.PCode.value="";
		}
	}

	if(document.dform.KCode.value.replace(re,"")!="")
	{
		if(document.dform.KCode.value.replace(re,"")==document.dform.KCodeMem.value.replace(re,""))
		{
			document.dform.KCode.value="";
		}
	}
}
//---------------------------------------------------------------------------------------------------
function openWndImage(sImage,sParams)
{
	var obj=window.open('/viewImage.asp?img=' + sImage,'',sParams);
	obj.focus();
}
//---------------------------------------------------------------------------------------------------
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 CheckFlag()
{
    //debugger;
    var name;
    var el;
    for(a=1; a<2; a++)
    {
        name = 'valNameParameter_'
        el = document.getElementById(name + a);
        //if(el && el.value != '')
        //{
            //debugger;
            alert('value ('+name + a+'): '+el.value);
            //return;
        //}
    }
}
//---------------------------------------------------------------------------------------------------
function CheckParam(nParam, memID, sValue, memClass, idTD, pkTblCommodity, step, status, x)
{

    //if(sValue == 'Komfort'){debugger;}
    //debugger;
    if(document.getElementById(memID))
        document.getElementById(memID).value = sValue;

    var valMemId = document.getElementById(memClass).value;
    if(valMemId != '')
    {
        if(document.getElementById(valMemId))
            document.getElementById(valMemId).className = 'valParam';
    }

    if(document.getElementById(memClass))
        document.getElementById(memClass).value = idTD;

    //-- tvorba urlparams z hidden inputu
    var p = 1;
    var labels = '';
    var value;
    var params = '';
    var parameters = '';
    while(document.getElementById('valNameParameter_'+p))
    {
        value = document.getElementById('valNameParameter_'+p).value
        if(value != '')
        {
            //debugger;
            labels += (document.getElementById('sLabelParameter_'+p) ? document.getElementById('sLabelParameter_'+p).innerHTML + '=' + value + '; ' : '' );
            parameters+=value+',';
            if ( status == 1 && (p == nParam || 1==1) )
                params+= '&valNameParameter_'+p+'='+value;
        }
        
        value = document.getElementById('valMemClass_'+p).value
        if(value != '')
        {
            if (status == 1 && (p == nParam || 1==1) )
                params+= '&valMemClass_'+p+'='+value;
        }
        p++;
    }
    if(parameters!='')
    {
        parameters = '&parameters=' + parameters.substr(0, parameters.length-1);
    }
    document.getElementById('Comment').value = '';
    if(labels!='')
    {
        document.getElementById('Comment').value = labels.substr(0, labels.length-1)
        comments = '&comment=' + labels.substr(0, labels.length-1).replace('.jpg', '');
    }
    params+='&status='+status;
    params+='&p='+(p-1);

    var url = '/ajaxCommodityParams.asp?id=' + pkTblCommodity + '&param=' + sValue + '&step=' + step + params + parameters;// + comments;
    
    ajxParams(url, 'work');
}
//---------------------------------------------------------------------------------------------------
function OverParams(sID, sClass, memID, sValue, memClass, status, x )
{

    //if(sValue == 'Molitan' && status == 0){debugger;}
    if(sClass.indexOf('On') == -1)
      document.getElementById('paramchecked'+x).className = 'paramchecked';
    
    var valMemId = '';
    if(document.getElementById(memClass))
    {
        valMemId = document.getElementById(memClass).value;
        if(valMemId != '')
        {
            if(valMemId != '' && document.getElementById(valMemId) && status == 1)
            {
                document.getElementById(valMemId).className = 'valParamOn';
                
            }
        }

    }

        if(sClass.indexOf('On') > 0)
          document.getElementById('paramchecked'+x).className = 'paramcheckedOn';
          
    var el = document.getElementById(sID);
    if(el && valMemId != sID && (status == 1||1==1))
    {
        el.className = sClass;

    }
}
//---------------------------------------------------------------------------------------------------
function ItemToForm(pktblcommodity, sCode, nPrice, sName, sAvail)
{
    var elID    = document.getElementById('CommID');
    if(elID)
    {
        elID.value = pktblcommodity;
    }
    var elCode  = document.getElementById('Code');
    if(elCode)
    {
        elCode.value = sCode;
    }
    var elCode  = document.getElementById('strCode');
    if(elCode)
    {
        elCode.innerHTML = sCode;
    }
    var elPrice = document.getElementById('Price');
    if(elPrice)
    {
        elPrice.value = nPrice;
    }
    var elPrice = document.getElementById('intPrice');
    if(elPrice)
    {
        elPrice.innerHTML = nPrice + '<small> Kč</small>';
    }
    var elName  = document.getElementById('NameItem');
    if(elName)
    {
        elName.value = sName;
    }
    var elHName = document.getElementById('HName');
    if(elHName)
    {
        elHName.innerHTML = sName;
    }
    var elTR = document.getElementById('bMaster1');
    if(elTR)
    {
        elTR.style.display = '';
    }
    var elTR = document.getElementById('bMaster2');
    if(elTR)
    {
        elTR.style.display = '';
    }
    var elTR = document.getElementById('TRSale');
    if(elTR)
    {
        elTR.style.display = 'none';
    }
    var elTR = document.getElementById('TRRecommend');
    if(elTR)
    {
        elTR.style.display = 'none';
    }
    var elTR = document.getElementById('TRAvail');
    if(elTR)
    {
        elTR.innerHTML = sAvail;
    }
    
    var el = document.getElementById('choiceparam');
    el.style.display = 'none';
    
    var el = document.getElementById('DetailDiv');
    var el1 = document.getElementById('DetailDiv1');
    var sHTML = el.innerHTML;
    
    //el1.innerHTML = sHTML;
    //el1.style.display = '';
    
    location.href = '#topdetail';
    getE('frmOrderContentIframe').submit();
    
}
//---------------------------------------------------------------------------------------------------
var gHTML   = '';
var gTarget = '';
var gParam  = 0;
var gCode   = '';
//---------------------------------------------------------------------------------------------------
function ajxParams(url, sTarget)
{
    gTarget = sTarget;
    var ajax = new Ajax(url,'get', cbfContent);
    ajax.sendRQ(null, true);
}
//---------------------------------------------------------------------------------------------------
function cbfContent(sHTML)
{
  gHTML = sHTML;
  var el = document.getElementById(gTarget);
  if(!document.all)
  {
    el.innerHTML = sHTML;
  }else{
    //debugger;
    el.innerHTML = "";
    var newdiv = document.createElement("div");
    newdiv.innerHTML = sHTML;
    el.appendChild(newdiv);
  }

}
//---------------------------------------------------------------------------------------------------

function divStoreHide(sID)
{
  getE('sSubItemsDIV_'+sID).style.display='none';
}


function getE(objectID) {
	return document.getElementById(objectID);
}

function getF(formName) {
	return document.forms[formName];
}

// status, args nechany z duvodu kompatibility
function showMyModalDialog(url,title,sizeX,sizeY,status,args,top) //top znaci jak daleko od vrchu okna
{
   var wo = document;
   var frameID = '';
   if(window!=window.top){
      wo = window.top.document;
      frameID = window.self.name;
   }

   if(getE('modalIframe')){return;}

   if(Br.IE6)
   {
   		var clona = wo.createElement('iframe');
	    clona.id='clona';
	    clona.src = '/administration/clonaIE6.htm';
   		wo.body.appendChild(clona);
   }
   else
   {
   		var div=wo.createElement('div');
	    div.id='clona';
   		wo.body.appendChild(div);
   }


   var clona=wo.createElement('div');
   clona.id='clona1'; // margin nelze pouzit, bug v IE

   url += ((url.indexOf("?")>-1)?"&":"?") +"title="+ title+"&frameID="+ frameID;

   clona.innerHTML="<iframe name='modalIframe' id='modalIframe' width='"+sizeX+"' height='"+sizeY+"' frameborder='0' scrolling='auto' src='"+ url +"'></iframe>";

   wo.body.appendChild(clona);
   if(top!==undefined){
      wo.getElementById('modalIframe').style.top=top;
   }
}

function CloseMyModalDialog(){

	if(window.top.document.getElementById('clona1') && window.top.document.getElementById('clona'))
	{
    window.top.document.body.removeChild(getE('clona1'));
    window.top.document.body.removeChild(getE('clona'));
    }
}

