﻿// globalni promenna------------------
var strContentElBarto = "";
//------------------------------------

function SelectKomodita() {
    Client.style.display = 'none';
    Komodita.style.display = 'inline';
}

function SelectClient() {
	Client.style.display = 'inline';
	Komodita.style.display = 'none';
}
function ChangeDevice(strString){
        var arrData;
        arrData = strString.split("##");
        document.EditCategory.NameCategory.value = arrData[1];
        document.EditCategory.IDCategory.value = arrData[0];
        document.EditCategory.ParentSelect.value = arrData[2];
        document.EditCategory.IndexCategory.value = arrData[3];
        if (arrData[2] == 0)
			window.frames.FrameDescription.location.href='BlankWhite.htm'
		else
			window.frames.FrameDescription.location.href='EditDevice.asp?DevID='+arrData[0]+'&DevName='+arrData[1]
      }

function EmptyDevice(){

        document.EditCategory.NameCategory.value = "";
        document.EditCategory.IDCategory.value = 0;
        document.EditCategory.ParentSelect.value = 0;
        window.frames.FrameDescription.location.href='BlankWhite.htm'
      }


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;
   var 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.all[intId].style.display == "none"){
                document.all[intId].style.display = ""
        }else{
                document.all[intId].style.display = "none"
        }

      }


function FrameLocation(strURL) {
      window.frames['ActionFrame'].location.href = strURL;
      }

function WriteNameAction(strName) {
      if(strName != ""){
          window.parent.document.all.NameAction.innerHTML = strName;
        }else{
         window.parent.document.all.NameAction.innerHTML = "Administrace katalogu"
        }
      }
function ChangeCategory(strString){
	var arrData;'3##Kapky##0## ## ##False'
	arrData = strString.split("##");
	document.EditCategory.IDCategory.value = arrData[0];
	document.EditCategory.NameCategory.value = arrData[1];
	document.EditCategory.ParentSelect.value = arrData[2];
	document.EditCategory.ImageCat.value = arrData[3];
	document.EditCategory.ImageCatPrint.value = arrData[4];
	document.EditCategory.nOrder.value = arrData[6];
    if (arrData[3]==''){
    	document.all.ImgCat1.src = '/foto/ImgCategory/empty.gif';
    	document.all.ImgCat2.src = '/foto/ImgCategory/Over/empty.gif';
        }
    else {    
	    document.all.ImgCat1.src = '/foto/ImgCategory/'+arrData[3];
    	document.all.ImgCat2.src = '/foto/ImgCategory/Over/'+arrData[3];
    }
    if (arrData[4]=='')
        document.all.ImgCatPrint.src = '/foto/ImgCategory/empty.gif';
    else
    	document.all.ImgCatPrint.src = '/foto/ImgCategory/'+arrData[4];
        
	window.frames.FrameDescription.location.href='BlankWhite.htm';
	if(arrData[5].toString() == "True"){
		document.EditCategory.bDisabled.checked = "True";
	}else{
		document.EditCategory.bDisabled.checked = "" ;
	}
}
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;

      }

function AddNameParameter(iItem){

	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);
	}
	document.all["parametername_" + iItem].selectedIndex = document.all["parametername_" + iItem].options.length-1;
}
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 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 InsertAddMultisave(intNoInput){

	var strReturn = showModalDialog("ListMultisave.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.MultisaveCode.length) == "number"){
		document.all.IdCommodityMultisave[intNoInput].value = arrString[0];
		document.all.MultisaveCode[intNoInput].value = arrString[1];
		document.all.MultisaveName[intNoInput].value = arrString[2];
	}else{
		document.all.IdCommodityMultisave.value = arrString[0];
		document.all.MultisaveCode.value = arrString[1];
		document.all.MultisaveName.value = arrString[2];
	}
	return 1;
}

function InsertAddDevice(intNoInput){

         var strReturn = showModalDialog("ListDevice.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.DeviceName.length) == "number"){
                document.all.IdDevice[intNoInput].value = arrString[0];
                document.all.DeviceName[intNoInput].value = arrString[1];
         }else{
                document.all.IdDevice.value = arrString[0];
                document.all.DeviceName.value = arrString[1];
         }
}

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='468' height='60' src='/ImgGalery/"+strReturn+"' >";
	}else{
	    var strUrl = prompt("Zadejte URL na kterou má obrázek odkazovat.","http://");
	    objForm.Body.value = "<a href='"+strUrl+"' target='blank'><img src='/ImgGalery/"+strReturn+"' border=0></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;
	document.all.ImgCat2.src = '/foto/ImgCategory/Over/'+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]}
	}
}

// function ControlNumber(obj,defvalue){
// 	if (isNaN(obj.value)) {obj.value=defvalue;}
// }

function ControlFloat(){
	if ((event.keyCode < 48) || (event.keyCode > 57) && (event.keyCode !=46)) event.returnValue = false;
}

function AddCategory(intTree){
	var arrData,arrSubData;
	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("*");
	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];
		document.all['strCategory'+intTree].options.add(el);
	}
}

function SendBulkMail(bNews,bCustomer,intID,bMailList){
	if(bMailList) {
		var msg = window.open('SendBulkMail.asp?TypeMail=MailList&NWS=0&CST=0&GRP=0','okno','toobar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width=870,height=740,left=20,top=20');
		msg.focus();
	} else {
		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();
}
function InsertElBarto2(strContent){
	strContentElBarto = strContent;
	var msg = window.open('ShowTwoElBarto.asp','EditWindow','toobar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width=700,height=550,left=20,top=20');
	msg.focus();
}

function ControlPassword(NameOne,NameTwo){
	if (document.all[NameOne].value != document.all[NameTwo].value)
	{
		alert("Špatně zadané heslo.");
		document.all[NameOne].value = "";
		document.all[NameTwo].value = "";
		document.all[NameOne].focus();
		return false;
	}
	else
	{
		return true;
	}
} 
function selectelbarto(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){
	selecthidex(sStyle,document);
	for (var i=0;i<document.frames.length;i++){
		selecthidex(sStyle,document.frames[i].document);
	}
	
}
function selecthidex(sStyle,odocument){	

	var o;
	o = odocument.getElementsByTagName("select");
	if (o !=null ){
		if (o.tagName == 'SELECT' ){
			if (selectelbarto(o))	o.style.visibility=sStyle;
		}else{
			for(var i=0;i<o.length;i++){
				if (selectelbarto(o[i]))	o[i].style.visibility=sStyle;
			}
		}
	}
}

var bAsked, bConfirmed;

function ConfirmCheck() {
	if (bAsked) return bConfirmed;
	bConfirmed = confirm("Použít změnu i na podřízené položky?");
	bAsked = true;
	return bConfirmed;
}

function CheckSubCatIf(oCHK) {
	bAsked = false;
	bConfirmed = false;
	var o, i, ct,bChecked;
	bChecked = oCHK.checked;
	i = 0;
	ct = document.all.CategoriesTree;
	o = ct.all[i];
	while (o!=null) {
		if ((o!=oCHK) && (o.tagName=='INPUT') && (o.id.indexOf(oCHK.id)==0)) {
			if ((o.checked!=bChecked) && (bConfirmed || ConfirmCheck())) {
				o.checked = bChecked;
				bConfirmed = true;
			}
		}
		i += 1;
		o = ct.all[i];
	}
}
function ChangeLang(nLang) {
	InsertCookieEx('ADM','LANG', nLang);
	window.location.href = window.location.href;
}
function GoTo(sURL) {
	window.location.href = 
		sURL +
		((sURL.indexOf("?") == -1) ? "?" : "&") + "TIM=" +
		(new Date()).getTime();
}
function ExportOrder(pk) {
	window.location.href =
		window.location.href +
		((window.location.href.indexOf("?")==-1) ? "?" : "&" ) +
		"EXPORD=" + pk;
}
function ViewOrder(pk) {
	window.location.href = '/Administration/EditOrder.asp?ID=' + pk;
}
function DelOrder(pk) {
	if (window.confirm('Opravdu chcete smazat objednávku č.:' + pk + '?')) return true;
	else return false;
}
function LangSentOrder(nLang) {
	InsertCookieEx('ADM','LANGSENTORD', nLang);
	window.location.href = window.location.href;
}



