// 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 EmailControl(f){
	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;
		}
	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.nOrder.value = arrData[8];
//	document.forms.EditCategory.elements.PackageDescription.value = arrData[7];
	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[9].toString() == "True"){
		document.EditCategory.bMain.checked = "True";
	}else{
		document.EditCategory.bMain.checked = "" ;
	}
	
	
	document.getElementById('TakeItID').value = arrData[10];
	document.getElementById('sTakeITKeyword').value = arrData[11];
	
}
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 InsertAddAdjective(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.AdjectiveCode.length) == "number"){
		document.all.IdCommodityAdjective[intNoInput].value = arrString[0];
		document.all.AdjectiveCode[intNoInput].value = arrString[1];
		document.all.AdjectiveName[intNoInput].value = arrString[2];
	}else{
		document.all.IdCommodityAdjective.value = arrString[0];
		document.all.AdjectiveCode.value = arrString[1];
		document.all.AdjectiveName.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;
	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="AddCommodityItem.asp?TMP=1&IdItem="+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;
			}
		}
	}
}

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 checkStates() {
var bVseVyrizeno = true;
var intOrderState = getE('OrderState').value;
var sEmailtext = getE('sEmailOrderClient').value;

  if(typeof (document.EditOrder.IdItem[1]) == "object"){
		lengthItem = document.EditOrder.IdItem.length;
		for(var i = 0; i < lengthItem; i++){
			if (document.EditOrder.StateItem[i].value == 0) {
            bVseVyrizeno = true; } else 
            {bVseVyrizeno = false; break; }
  		}
	}else{
	 if (document.EditOrder.StateItem.value == 0) {
      bVseVyrizeno = true; } else {
      bVseVyrizeno = false; }
		}
		
				
  if (intOrderState != 0 && bVseVyrizeno == true){
    alert('Všechny položky jskou vyřízený, satus objednávky musí být také vyřízna.');
    return false;
  } else {
  
  
  
  if (sEmailtext.length == 0 && bVseVyrizeno == true) {
    alert('Pokoušíte se odeslat prázdnou zprávu, prosím zadejte ji.');
    return false;
  }
  
  
  return true;
  }

}    

function trim(str)               {  return str.replace(/^\s*|\s*$/g,"");}
