// globalni promenna------------------
var strContentElBarto = "";
//------------------------------------

function InsertImageFromList(obj){
	var sReturn = showModalDialog("Listimagegalery.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");
	
	if(obj){
		obj.value = sReturn;
		document.getElementById('tempimg').src=sReturn;
	}
}


function SelectKomodita() {
    Client.style.display = 'none';
    Komodita.style.display = 'inline';
}

function SelectClient() {
	Client.style.display = 'inline';
	Komodita.style.display = 'none';
}
function EmailTextControl(f,g){
	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 emailu');
		return false;
		}
	if (g.length<5){ 
		alert('Délka dotazu min.5 slov');
		return false;
		}
	return true;
}
function TextControl(f){
	if (f.length<5){ 
		alert('Délka dotazu min.5 slov');
		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.all[intId].style.display == "none"){
		document.all[intId].style.display = "";
	}else{
		document.all[intId].style.display = "none";
	}
}


function FrameLocation(strURL) {
	alert(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##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.forms.EditCategory.elements.ImageCatPrint.value = arrData[4];
//	document.forms.EditCategory.elements.DeliveryPrice.value = arrData[6];
	document.forms.EditCategory.elements.nOrder.value = arrData[7];
	document.forms.EditCategory.elements.nAccountancyID.value = arrData[9];
	document.forms.EditCategory.elements.sLink.value = arrData[11];
	if(arrData[8].toString() == 'True'){
		document.forms.EditCategory.elements.bStayData.checked = true;
	}else{
		document.forms.EditCategory.elements.bStayData.checked = false;
	}
	if(arrData[9].toString() == 'True'){
		document.forms.EditCategory.elements.bShowInMenu.checked = true;
	}else{
		document.forms.EditCategory.elements.bShowInMenu.checked = false;
	}
	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(arrData[5].toString() == "True"){
		document.EditCategory.bDisabled.checked = "True";
	}else{
		document.EditCategory.bDisabled.checked = "" ;
	}
	if (arrData[12].toString() == "True") {
	    document.EditCategory.bNotTolFree.checked = "";
	} else {
	    document.EditCategory.bNotTolFree.checked = "True";
	}
	
}
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 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 InsertAddImageColorsAndForms(intNoInput){
	
	var strReturn = showModalDialog("ListAddImageColorsAndForms.asp","","status:no; center:yes; help:no; minimize:no;dialogWidth=300pt;dialogHeight=300pt");

	if (strReturn == undefined){return;};
	if(typeof(document.all.ImageAddItemColorsAndForms.length) == "number"){
	       document.all.ImageAddItemColorsAndForms[intNoInput].value = strReturn;
	}else{
	       document.all.ImageAddItemColorsAndForms.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;
	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(){
	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("/");
		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;
			}
		}
	}
}




//////////////////////////////////////////////////REMEMBER/////////////////////////////////////////


function DeleteFromCookies(strCookie,Commodity)
{

        var r, re;
        var s =  strCookie;

        re = Commodity+"#";
        r = s.replace(re,"");
        document.cookie="Remember=" + r ;
        window.location.reload();
        
}


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 už je v pamatováčku!!");
                return;
        } else {
                alert("Další položka byla přidána do pamatováčku!!");
                sValue += nIDShop + "$" + nID + "/" + nShopGRP + "#";
                document.cookie=name + "=" + sValue + ";expires="+vyprseni;
                return;
        }
}
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 "";
        }
}




