function wd_plt_ColorCode(sColorVal) {
	var sAnswer="%c0%";
	if (sColorVal) sColorVal=sColorVal.toUpperCase();
	var sNext="";
	for (sNext in arrPaletteCodes) {
		if (arrPaletteCodes[sNext].toUpperCase()==sColorVal) {
			sAnswer=sNext;
			break;
		}
	}
	return sAnswer;
}

if (window.dialogArguments&&typeof(window.dialogArguments)=="object") {
	var theTunerSheet=window.dialogArguments;
} else {
	try {
		if (typeof(document.styleSheets.item("wd_tplstyles"))!="undefined") {
			var theTunerSheet=new WD_StyleSheet(document.styleSheets.item("wd_tplstyles"));
		} else {
			var theTunerSheet=null;
		}
	} catch (theError) {
		var theTunerSheet=null;
	}
}

var tpltune_theMenu=null;

function wd_TplTuneCreateMenu(arrItems, sActivator, sExtParam) {
	var oExecItem=null; var bOnceCanceled=0;
	try {
		if (!(tpltune_theMenu && tpltune_theMenu.innerHTML)) {
			if (document.getElementById("wd_tpltune_Menu")) {
				tpltune_theMenu=document.getElementById("wd_tpltune_Menu");
				try {
					document.body.removeChild(tpltune_theMenu);
				} catch (theError2) {
					// void(0);
				}
			}
			tpltune_theMenu=document.createElement("DIV");
			tpltune_theMenu.style.position="absolute";
			tpltune_theMenu.style.visibility="hidden";
			tpltune_theMenu.style.left="-3000px";
			tpltune_theMenu.style.top="-3000px";
			tpltune_theMenu.style.width="0px";
			tpltune_theMenu.style.height="0px";
			tpltune_theMenu.style.backgroundColor="#C0C0C0";
			tpltune_theMenu.id="wd_tpltune_Menu";
			tpltune_theMenu.innerHTML="<TABLE CELLPADDING=\"0\" CELLSPACING=\"0\" BORDER=\"0\" STYLE=\"background-color:#C0C0C0;border-style:solid;border-left-color:#D4D0C8;border-top-color:#D4D0C8;border-right-color:#404040;border-bottom-color:#404040;border-width:1px;\"><TR><TD><TABLE WIDTH=\"96\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\" ID=\"wd_tpltune_MenuItems\" STYLE=\"background-color:#C0C0C0;border-style:solid;border-left-color:#FFFFFF;border-top-color:#FFFFFF;border-right-color:#808080;border-bottom-color:#808080;border-width:1px;\"><TBODY></TBODY></TD></TR></TABLE></TABLE>";
			document.body.appendChild(tpltune_theMenu);
			tpltune_theMenu.attachEvent("onmouseout", wd_TplTuneMnuOut);
		}
	} catch (theError) {
		//alert("wd_TplTuneCreateMenu1: "+theError.description);
	}
	try {
		var theMenuItems=document.getElementById("wd_tpltune_MenuItems");
		while (theMenuItems.rows.length) theMenuItems.deleteRow();
	} catch (theError) {
		//alert("wd_TplTuneCreateMenu2: "+theError.description);
	}
	try {
		var iI=0;
		var sKey="";
		for (sKey in arrItems) {
			var theTr=theMenuItems.insertRow();
			var sTitle=arrItems[sKey];
			if (sTitle.length) {
				var theTd=theTr.insertCell();
				if (sKey.substr(0, 7)=="section") {
					sTitle="&nbsp;----&nbsp;"+sTitle+"&nbsp;----";
					theTd.style.cursor="default";
					theTd.style.backgroundColor="#EDEDED";
					theTd.style.color="#767F9A";
				} else {
					if (sKey.indexOf(";;;")!=-1) {
						var arrKey=sKey.split(";;;");
						sRealActivator=arrKey[0];
						sRealKey=arrKey[1];
					} else {
						sRealActivator=sActivator;
						sRealKey=sKey;
					}
					theTd.style.cursor="hand";
					theTd.style.backgroundColor="#EDEDED";
					theTd.style.color="#000000";
					if (arrTplTunerActkeys[sRealActivator]&&arrTplTunerActkeys[sRealActivator]==sRealKey) {
						theTd.style.fontWeight="bold";
					}
					theTd.attachEvent('onmouseover', wd_TplTuneMnuItemOver);
					theTd.attachEvent('onmouseout', wd_TplTuneMnuItemOut);
					theTd.attachEvent('onclick', wd_TplTuneMnuItemClick);
					theTd.id=sRealActivator+";;;"+sRealKey+";;;"+sExtParam;
					if (!(oExecItem || bOnceCanceled)) {
						oExecItem=theTd;
					} else if (oExecItem) {
						oExecItem=null;
						bOnceCanceled=1;
					}
				}
				theTd.innerHTML="<NOBR>"+sTitle+"&nbsp;</NOBR>";
			}
		}
	} catch (theError) {
		//alert("wd_TplTuneCreateMenu3: "+theError.description);
	}
	return oExecItem;
}

function wd_TplTuneMnuOut() {
	try {
		if (!wd_IsAncestor(event.toElement, tpltune_theMenu)) {
			tpltune_theMenu.style.visibility='hidden';
		}
	} catch (theError) {
		tpltune_theMenu.style.visibility='hidden';
	}
}
function wd_TplTuneMnuItemOver() {
	var theEl=event.srcElement;
	if (theEl.tagName.toUpperCase()=="NOBR") theEl=theEl.parentElement;
	theEl.style.backgroundColor='#97AAEC';
	theEl.style.color='#FFFFFF';
}
function wd_TplTuneMnuItemOut() {
	var theEl=event.srcElement;
	if (theEl.tagName.toUpperCase()=="NOBR") theEl=theEl.parentElement;
	theEl.style.backgroundColor='#EDEDED';
	theEl.style.color='#000000';
}
function wd_TplTuneMnuItemClick(sId) {
	if (tpltune_theMenu) tpltune_theMenu.style.visibility="hidden";
	var theEl=event.srcElement;
	if (theEl.tagName.toUpperCase()=="NOBR") theEl=theEl.parentElement;
	var sId=theEl.id;
	var arrUrl=theTunerSheet.Url.split("/");
	var sUrl=arrUrl[arrUrl.length-1];
	sUrl=sUrl.substr(4, (sUrl.length-8)); // tpl_(...).css
	var arrId=sId.split(";;;");
	var sArea=""; var sTabPart=""; var sExtParam="";
	sArea=arrId[0];
	if (arrId.length>1) sTabPart=arrId[1];
	if (arrId.length>2) sExtParam=arrId[2];
	var iDlgWd=480; var iDlgHt=480;
	/*var iDlgWd=320; var iDlgHt=300;
	if (sArea=='tpltune_anchor') {
		iDlgWd=360;
		iDlgHt=280;
	} else {
		switch (sTabPart) {
			case 'base':
			case 'fsections':
			case 'leftcol':
			case 'rightcol':
				iDlgWd=420;
				break;
			case 'topmenu':
			case 'topitems':
			case 'nextmenu':
			case 'nextitems':
				iDlgWd=360;
				iDlgHt=480;
				break;
			case 'anchor':
				iDlgWd=360;
				iDlgHt=280;
				break;
			case 'tpl_h1':
			case 'textH1':
			case 'textS1':
			case 'textS2':
			case 'textS3':
				iDlgHt=280;
				break;
			default:
				break;
		}
	}*/
	//
	var sDlgSrc="/webdirector/mdl_content/shell/tpldlg.php?code="+sId+"&tpl="+sUrl+"&engine="+WD_TPL_CURRENGINEVERSION+"&deslocal="+WD_TPL_IFACELCL;
	wd_tpltuner_ChangeTplVis(amg_ModalDialog(sDlgSrc, iDlgWd, iDlgHt, theTunerSheet, 0, 0, "No"));
}

/*
arrTplTunerActkeys
what items are bold:
['activator']="menu key";
*/
var arrTplTunerActkeys=new Array();
//arrTplTunerActkeys['tpl_style0']="text";
arrTplTunerActkeys['tpl_style1']="textS1";
arrTplTunerActkeys['tpl_style2']="textS2";
arrTplTunerActkeys['tpl_style3']="textS3";
arrTplTunerActkeys['tpl_h1']="tpl_h1";
arrTplTunerActkeys['tpl_xh1']="textXH1";
arrTplTunerActkeys['tpl_xh2']="textXH2";
arrTplTunerActkeys['tpl_xh3']="textXH3";
arrTplTunerActkeys['tpl_xh4']="textXH4";
arrTplTunerActkeys['tpltune_anchor']="anchor";
arrTplTunerActkeys['TOP_menu1']="topmenu";
arrTplTunerActkeys['TOP_menu2']="topmenu";
arrTplTunerActkeys['TOP_vmenu']="topmenu";
arrTplTunerActkeys['menu1']="nextmenu";
arrTplTunerActkeys['menu2']="nextmenu";
arrTplTunerActkeys['vmenu']="nextmenu";
arrTplTunerActkeys['osnsmall']="base";
arrTplTunerActkeys['formplot']="fsections";
arrTplTunerActkeys['formal']="leftcol";
arrTplTunerActkeys['formar']="rightcol";
arrTplTunerActkeys['WDTBL']="table";
arrTplTunerActkeys['WDTH']="th";
arrTplTunerActkeys['WDTD']="td";
arrTplTunerActkeys['WDTFH']="tf";
arrTplTunerActkeys['tpl_style4']="textI4";
arrTplTunerActkeys['tpl_style5']="textI5";
arrTplTunerActkeys['tpl_style6']="textI6";
/*
arrTpltunerSections
menu types array
*/
var arrTpltunerSections=new Array();
//
function wd_TplTuneOnAreaLblClick() {
	var theEvent=event;
	var theEl=theEvent.srcElement;
	if (theEl) {
		var sID="";
		if (theEl.id) sID=theEl.id;
		if (sID.substr(0, "tpltune_arealbl_".length)==="tpltune_arealbl_") wd_TplTuneOnClick(0);
	}
	return true;
}
function wd_TplTuneOnClick(iNeedMenu) {
	var theEvent=event;
	var oExecItem=null;
	try {
		if (tpltune_theMenu && tpltune_theMenu.style.visibility=="visible") {
			tpltune_theMenu.style.visibility="hidden";
		} else {
			var theEl=theEvent.srcElement;
			var sTag=theEl.tagName.toUpperCase();
			while (theEl.parentElement && sTag!="A" && sTag!="DIV" && sTag!="TD" && sTag!="TH" && sTag!="TABLE" && sTag!="BODY" && sTag!="H1" && sTag!="H2" && sTag!="H3" && sTag!="H4" && sTag!="SPAN") {
				theEl=theEl.parentElement;
				sTag=theEl.tagName.toUpperCase();
			}
			var sID=""; if (theEl.id) sID=theEl.id;
			var sClass="";  if (theEl.className) sClass=theEl.className;
			//
			if (sID.substr(0, "tpltune_arealbl_".length)==="tpltune_arealbl_") {
				switch (sID) {
					case 'tpltune_arealbl_logo1':
					case 'tpltune_arealbl_logo1_a':
						sClass="tpl_logo1";
						break;
					case 'tpltune_arealbl_logo2':
					case 'tpltune_arealbl_logo2_a':
						sClass="tpl_logo2";
						break;
					case 'tpltune_arealbl_ltarea':
					case 'tpltune_arealbl_ltarea_a':
						sClass="tpl_vmenu";
						break;
					case 'tpltune_arealbl_rtarea':
					case 'tpltune_arealbl_rtarea_a':
						sClass="tpl_rtarea";
						break;
					case 'tpltune_arealbl_hmenu1area':
					case 'tpltune_arealbl_hmenu1area_a':
						sClass="tpl_hmenu1";
						break;
					case 'tpltune_arealbl_hmenu2area':
					case 'tpltune_arealbl_hmenu2area_a':
						sClass="tpl_hmenu2";
						break;
					case 'tpltune_arealbl_header':
					case 'tpltune_arealbl_header_a':
						sClass="tpl_header";
						break;
					case 'tpltune_arealbl_mainarea':
					case 'tpltune_arealbl_mainarea_a':
						sClass="tpl_mainarea";
						break;
					case 'tpltune_arealbl_footer':
					case 'tpltune_arealbl_footer_a':
						sClass="tpl_footer";
						break;
					default:
						break;
				}
			}
			//
			var sExtParam="";
			// detect area:
			var sAreaId="";
			if (sTag=="BODY") {
				sAreaId=sTag; // BODY
			} else if (sTag=="H1" && sClass!="tpl_h1") {
				sAreaId="tpl_xh1";
			} else if (sTag=="H2") {
				sAreaId="tpl_xh2";
			} else if (sTag=="H3") {
				sAreaId="tpl_xh3";
			} else if (sTag=="H4") {
				sAreaId="tpl_xh4";
			} else if (sID=="tpltune_anchor") {
				sAreaId="tpltune_anchor"; // tpltune_anchor
				sExtParam=sClass; // '', 'paths' or 'nests'
			} else if (sClass=="WDTBL" || sClass=="WDTH" || sClass=="WDTD" || sClass=="WDTFH" || sClass=="osnsmall" || sClass=="formplot" || sClass=="formal" || sClass=="formar" || sClass=="tpl_vmenu" || sClass=="tpl_mainarea" || sClass=="tpl_rtarea" || sClass=="tpl_header" || sClass=="tpl_logo1" || sClass=="tpl_logo2" || sClass=="tpl_hmenu1" || sClass=="tpl_hmenu2" || sClass=="tpl_h1" || sClass=="tpl_style1" || sClass=="tpl_style2" || sClass=="tpl_style3" || sClass=="tpl_style4" || sClass=="tpl_style5" || sClass=="tpl_style6" || sClass=="TOP_menu1" || sClass=="TOP_menu2" || sClass=="TOP_vmenu" || sClass=="menu1" || sClass=="menu2" || sClass=="vmenu" || sClass=="tpl_footer") {
				sAreaId=sClass; // for tables, forms, menus, areas, user styles, page header
			} else if (!(theEl.id&&theEl.id.indexOf(";;;")!=-1)) {
				while (theEl.parentElement&&!(theEl.id&&theEl.id.indexOf(";;;")!=-1)) {
					theEl=theEl.parentElement;
					sTag=theEl.tagName.toUpperCase();
					if (theEl.id) sID=theEl.id;
					if (theEl.className) sClass=theEl.className;
					if (sTag=="BODY") {
						sAreaId=sTag;
					} else if (sID=="tpltune_anchor") {
						sAreaId=sID;
						sExtParam=sClass;
					} else if (sClass=="WDTBL"||sClass=="WDTH"||sClass=="WDTD"||sClass=="WDTFH"||sClass=="osnsmall"||sClass=="formplot"||sClass=="formal"||sClass=="formar"||sClass=="tpl_vmenu"||sClass=="tpl_mainarea"||sClass=="tpl_rtarea"||sClass=="tpl_header"||sClass=="tpl_logo1"||sClass=="tpl_logo2"||sClass=="tpl_hmenu1"||sClass=="tpl_hmenu2"||sClass=="tpl_h1"||sClass=="tpl_style1"||sClass=="tpl_style2"||sClass=="tpl_style3"||sClass=="tpl_style4"||sClass=="tpl_style5"||sClass=="tpl_style6"||sClass=="TOP_menu1"||sClass=="TOP_menu2"||sClass=="TOP_vmenu"||sClass=="menu1"||sClass=="menu2"||sClass=="vmenu"||sClass=="tpl_footer") {
						sAreaId=sClass;
					}
					if (sAreaId.length) break;
				}
			}
			// menu:
			if (arrTpltunerSections[sAreaId]) {
				// create:
				oExecItem=wd_TplTuneCreateMenu(arrTpltunerSections[sAreaId], sAreaId, sExtParam);
				// position:
				var iX=theEvent.clientX-4+document.body.scrollLeft;
				var iY=theEvent.clientY-4+document.body.scrollTop;
				if (iX+tpltune_theMenu.offsetWidth>(document.body.offsetWidth+document.body.scrollLeft)) {
					iX-=(tpltune_theMenu.offsetWidth-8);
				}
				if (iY+tpltune_theMenu.offsetHeight>(document.body.offsetHeight+document.body.scrollTop)) {
					iY-=(tpltune_theMenu.offsetHeight-8);
				}
				tpltune_theMenu.style.left=iX;
				tpltune_theMenu.style.top=iY;
				// visualize or execute:
				if (!iNeedMenu && oExecItem) {
					oExecItem.click();
				} else {
					tpltune_theMenu.style.visibility="visible";
				}
			}
		}
	} catch (theError) {
		//alert("wd_TplTuneOnClick: "+theError.description);
	}
	return false;
}
function wd_TplTuneEvCanc() {
	event.returnValue=false;
	return false;
}
function wd_TplTuneSize() {
	wd_PrepareTuneVisArea();
}
// template areas:
var theContentArea=null; var theHMenu1Area=null; var theLogo1Area=null;
var theHeaderArea=null; var theLogo2Area=null; var theHMenu2Area=null;
var theLtArea=null; var theMainArea=null; var theRtArea=null; var theFooterArea=null;
// template guidelines:
var theGdlPglt=null; var theGdlPgrt=null;
var theGdlLg1rt=null; var theGdlLg2lt=null;
var theGdlLtart=null; var theGdlRtalt=null;
var theGdlHmenu1=null; var theGdlHmenu2=null;
var theGdlHeader=null; var theGdlFooter=null;
function wd_GdlOnDrag() {
	if (event.type=="dragstart") {
		var theMbGdl=event.srcElement.parentElement;
		if (theMbGdl) {
			if (theGdlPglt && theMbGdl.id==theGdlPglt.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlPgrt && theMbGdl.id==theGdlPgrt.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlLg1rt && theMbGdl.id==theGdlLg1rt.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlLg2lt && theMbGdl.id==theGdlLg2lt.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlLtart && theMbGdl.id==theGdlLtart.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlRtalt && theMbGdl.id==theGdlRtalt.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlHmenu1 && theMbGdl.id==theGdlHmenu1.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlHmenu2 && theMbGdl.id==theGdlHmenu2.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlHeader && theMbGdl.id==theGdlHeader.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			} else if (theGdlFooter && theMbGdl.id==theGdlFooter.id) {
				var oData = window.event.dataTransfer;
				oData.effectAllowed = "move";
			}
		}
	} else if (event.type=="drag") {
		var theDoc=document.getElementById("wd_tpltune_doc");
		var theMbGdl=event.srcElement.parentElement;
		var iX=event.clientX+theDoc.scrollLeft;
		if (iX>(theDoc.offsetLeft+theDoc.offsetWidth)) iX=(theDoc.offsetLeft+theDoc.offsetWidth);
		if (iX<theDoc.offsetLeft) iX=theDoc.offsetLeft;
		var sX=iX+"px";
		var iY=event.clientY+theDoc.scrollTop; var sY=iY+"px";
		if (theMbGdl) {
			if (theGdlPglt && theMbGdl.id==theGdlPglt.id) {
				theGdlPglt.style.left=sX;
			} else if (theGdlPgrt && theMbGdl.id==theGdlPgrt.id) {
				theGdlPgrt.style.left=sX;
			} else if (theGdlLg1rt && theMbGdl.id==theGdlLg1rt.id) {
				theGdlLg1rt.style.left=sX;
			} else if (theGdlLg2lt && theMbGdl.id==theGdlLg2lt.id) {
				theGdlLg2lt.style.left=sX;
			} else if (theGdlLtart && theMbGdl.id==theGdlLtart.id) {
				theGdlLtart.style.left=sX;
			} else if (theGdlRtalt && theMbGdl.id==theGdlRtalt.id) {
				theGdlRtalt.style.left=sX;
			} else if (theGdlHmenu1 && theMbGdl.id==theGdlHmenu1.id) {
				theGdlHmenu1.style.top=sY;
			} else if (theGdlHmenu2 && theMbGdl.id==theGdlHmenu2.id) {
				theGdlHmenu2.style.top=sY;
			} else if (theGdlHeader && theMbGdl.id==theGdlHeader.id) {
				theGdlHeader.style.top=sY;
			} else if (theGdlFooter && theMbGdl.id==theGdlFooter.id) {
				theGdlFooter.style.top=sY;
			}
		}
	} else if (event.type=="dragend") {
		var theDoc=document.getElementById("wd_tpltune_doc");
		var iX=event.clientX+theDoc.scrollLeft; var sX=iX+"px";
		var iY=event.clientY+theDoc.scrollTop; var sY=iY+"px";
		if (theDoc) {
			var theMbGdl=event.srcElement.parentElement;
			if (theMbGdl) {
				if (theGdlPglt && theMbGdl.id==theGdlPglt.id) {
					theContentArea=document.getElementById('wd_inproc_contentarea');
					var iWidth=(theDoc.scrollWidth-(iX*2));
					if (iWidth<0) iWidth=0;
					theTunerSheet.SetStyle(".tpl_content", "width", iWidth+"px", new Array());
					wd_PrepareTuneVisArea();
				} else if (theGdlPgrt && theMbGdl.id==theGdlPgrt.id) {
					theContentArea=document.getElementById('wd_inproc_contentarea');
					var iWidth=(theDoc.scrollWidth-((theDoc.scrollWidth-iX)*2));
					if (iWidth<0) iWidth=0;
					theTunerSheet.SetStyle(".tpl_content", "width", iWidth+"px", new Array());
					wd_PrepareTuneVisArea();
				} else if (theGdlLg1rt && theMbGdl.id==theGdlLg1rt.id) {
					theLogo1Area=document.getElementById('wd_inproc_logo1area');
					var arrPos=wd_AbsPos(theLogo1Area, theDoc);
					var iWidth=(iX-arrPos[0]);
					if (WD_TPL_CURRENGINEVERSION>0) {
						iWidth+=2;
						if (theLogo1Area.currentStyle.paddingLeft) iWidth=iWidth-parseInt(theLogo1Area.currentStyle.paddingLeft);
						if (theLogo1Area.currentStyle.paddingRight) iWidth=iWidth-parseInt(theLogo1Area.currentStyle.paddingRight);
					}
					if (iWidth>=0) {
						//if (iWidth<0) iWidth=0;
						theTunerSheet.SetStyle(".tpl_logo1", "width", iWidth+"px", new Array());
					}
					wd_PrepareTuneVisArea();
				} else if (theGdlLg2lt && theMbGdl.id==theGdlLg2lt.id) {
					theLogo2Area=document.getElementById('wd_inproc_logo2area');
					var arrPos=wd_AbsPos(theLogo2Area, theDoc);
					var iWidth=((arrPos[0]+theLogo2Area.offsetWidth)-iX);
					if (WD_TPL_CURRENGINEVERSION>0) {
						iWidth-=1;
						if (theLogo2Area.currentStyle.paddingLeft) iWidth=iWidth-parseInt(theLogo2Area.currentStyle.paddingLeft);
						if (theLogo2Area.currentStyle.paddingRight) iWidth=iWidth-parseInt(theLogo2Area.currentStyle.paddingRight);
					}
					if (iWidth>=0) {
						//if (iWidth<0) iWidth=0;
						theTunerSheet.SetStyle(".tpl_logo2", "width", iWidth+"px", new Array());
					}
					wd_PrepareTuneVisArea();
				} else if (theGdlLtart && theMbGdl.id==theGdlLtart.id) {
					theLtArea=document.getElementById('wd_inproc_ltarea');
					var arrPos=wd_AbsPos(theLtArea, theDoc);
					var iWidth=(iX-arrPos[0]);
					if (WD_TPL_CURRENGINEVERSION>0) {
						iWidth+=2;
						if (theLtArea.currentStyle.paddingLeft) iWidth=iWidth-parseInt(theLtArea.currentStyle.paddingLeft);
						if (theLtArea.currentStyle.paddingRight) iWidth=iWidth-parseInt(theLtArea.currentStyle.paddingRight);
					}
					if (iWidth>=0) {
						//if (iWidth<0) iWidth=0;
						theTunerSheet.SetStyle(".tpl_vmenu", "width", iWidth+"px", new Array());
					}
					wd_PrepareTuneVisArea();
				} else if (theGdlRtalt && theMbGdl.id==theGdlRtalt.id) {
					theRtArea=document.getElementById('wd_inproc_rtarea');
					var arrPos=wd_AbsPos(theRtArea, theDoc);
					var iWidth=((arrPos[0]+theRtArea.offsetWidth)-iX);
					if (WD_TPL_CURRENGINEVERSION>0) {
						iWidth-=1;
						if (theRtArea.currentStyle.paddingLeft) iWidth=iWidth-parseInt(theRtArea.currentStyle.paddingLeft);
						if (theRtArea.currentStyle.paddingRight) iWidth=iWidth-parseInt(theRtArea.currentStyle.paddingRight);
					}
					if (iWidth>=0) {
						//if (iWidth<0) iWidth=0;
						theTunerSheet.SetStyle(".tpl_rtarea", "width", iWidth+"px", new Array());
					}
					wd_PrepareTuneVisArea();
				} else if (theGdlHmenu1 && theMbGdl.id==theGdlHmenu1.id) {
					theHMenu1Area=document.getElementById('wd_inproc_hmenu1area');
					var arrPos=wd_AbsPos(theHMenu1Area, theDoc);
					var iHeight=(iY-arrPos[1]);
					if (iHeight<0) iHeight=0;
					theTunerSheet.SetStyle(".tpl_hmenu1", "height", iHeight+"px", new Array());
					wd_PrepareTuneVisArea();
				} else if (theGdlHmenu2 && theMbGdl.id==theGdlHmenu2.id) {
					theHMenu2Area=document.getElementById('wd_inproc_hmenu2area');
					var arrPos=wd_AbsPos(theHMenu2Area, theDoc);
					var iHeight=(iY-arrPos[1]);
					if (iHeight<0) iHeight=0;
					theTunerSheet.SetStyle(".tpl_hmenu2", "height", iHeight+"px", new Array());
					wd_PrepareTuneVisArea();
				} else if (theGdlHeader && theMbGdl.id==theGdlHeader.id) {
					theHeaderArea=document.getElementById('wd_inproc_headerarea');
					var arrPos=wd_AbsPos(theHeaderArea, theDoc);
					var iHeight=(iY-arrPos[1]);
					if (iHeight<0) iHeight=0;
					theTunerSheet.SetStyle(".tpl_header", "height", iHeight+"px", new Array());
					wd_PrepareTuneVisArea();
				} else if (theGdlFooter && theMbGdl.id==theGdlFooter.id) {
					theFooterArea=document.getElementById('wd_inproc_footerarea');
					var arrPos=wd_AbsPos(theFooterArea, theDoc);
					var iHeight=((arrPos[1]+theFooterArea.offsetHeight)-iY);
					if (iHeight<0) iHeight=0;
					theTunerSheet.SetStyle(".tpl_footer", "height", iHeight+"px", new Array());
					wd_PrepareTuneVisArea();
				}
			}
		}
	}
}

// v=== для отложенного refresh'а области виз. редактирования =================v
var tmr_wd_TuneRefresh=null;
function wd_RefreshTuneVisArea() {
	var theTab=document.getElementById('wd_tpltune_tab'); if (theTab) theTab.refresh();
	/*
	if (tmr_wd_TuneRefresh) {
		window.clearTimeout(tmr_wd_TuneRefresh);
		tmr_wd_TuneRefresh=null;
	}
	tmr_wd_TuneRefresh=window.setTimeout("var theTab=document.getElementById('wd_tpltune_tab'); if (theTab) theTab.refresh(); window.clearTimeout(tmr_wd_TuneRefresh); tmr_wd_TuneRefresh=null;", 200);
	*/
}
var tmr_wd_TunePrepare=null;
function wd_PrepareTuneVisArea() {
	wd_TplTunePrepare(); wd_TplTunePrepare();
	/*
	if (tmr_wd_TunePrepare) {
		window.clearTimeout(tmr_wd_TunePrepare);
		tmr_wd_TunePrepare=null;
	}
	tmr_wd_TunePrepare=window.setTimeout("wd_TplTunePrepare(); window.clearTimeout(tmr_wd_TunePrepare); tmr_wd_TunePrepare=null;", 200);
	*/
}
// ^=== для отложенного refresh'а области виз. редактирования =================^
/*
var theGdlPglt=null; var theGdlPgrt=null;
var theGdlLg1rt=null; var theGdlLg2lt=null;
var theGdlLtart=null; var theGdlRtalt=null;
var theGdlHmenu1=null; var theGdlHmenu2=null;
var theGdlHeader=null; var theGdlFooter=null;
*/
function wd_tpltuner_ShideGdls(iMode) {
	var theTab=document.getElementById("wd_tpltune_tab");
	if (theTab) {
		var theDate=new Date(2040,12,20);
		var sNewDisplay="block"; if (!iMode) sNewDisplay="none";
		//if (theGdlPglt && theGdlPglt.style.display=="block") sNewDisplay="none";
		if (theGdlPglt) theGdlPglt.style.display=sNewDisplay;
		if (theGdlPgrt) theGdlPgrt.style.display=sNewDisplay;
		if (theGdlLg1rt) theGdlLg1rt.style.display=sNewDisplay;
		if (theGdlLg2lt) theGdlLg2lt.style.display=sNewDisplay;
		if (theGdlLtart) theGdlLtart.style.display=sNewDisplay;
		if (theGdlRtalt) theGdlRtalt.style.display=sNewDisplay;
		if (theGdlHmenu1) theGdlHmenu1.style.display=sNewDisplay;
		if (theGdlHmenu2) theGdlHmenu2.style.display=sNewDisplay;
		if (theGdlHeader) theGdlHeader.style.display=sNewDisplay;
		if (theGdlFooter) theGdlFooter.style.display=sNewDisplay;
		//
		var theLbl=null;
		if (theLbl=document.getElementById('tpltune_arealbl_logo1')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_logo2')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_ltarea')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_rtarea')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_hmenu1area')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_hmenu2area')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_header')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_mainarea')) theLbl.style.display=sNewDisplay;
		if (theLbl=document.getElementById('tpltune_arealbl_footer')) theLbl.style.display=sNewDisplay;
		//
		wd_sGdlnsDisplay=sNewDisplay;
		document.cookie='wd_tpltuner_cook_gdls='+sNewDisplay+'; expires='+theDate.toGMTString()+';path=/;';
		wd_RefreshTuneVisArea();
	}
}
function wd_tpltuner_FreezeGdls(sWidth) {
	var theTab=document.getElementById("wd_tpltune_tab");
	if (theTab) {
		var theDate=new Date(2040,12,20);
		var sNewVis="visible"; if (sWidth && sWidth!="0") sNewVis="hidden";
		//if (theGdlPglt && theGdlPglt.style.visibility=="visible") sNewVis="hidden";
		if (theGdlPglt) theGdlPglt.style.visibility=sNewVis;
		if (theGdlPgrt) theGdlPgrt.style.visibility=sNewVis;
		if (sWidth && sWidth!="0") {
			try {
				theTunerSheet.SetStyle(".tpl_content", "width", sWidth, new Array());
			} catch (theError) {
				//alert(theError.description);
			}
		}
		document.cookie='wd_tpltuner_cook_pgdls='+sNewVis+'; expires='+theDate.toGMTString()+';path=/;';
		wd_sGdlnsFreeze=sNewVis;
		wd_PrepareTuneVisArea();
	}
}

function wd_CancelDefEvent() {
	var oEvent = window.event;
	oEvent.returnValue = false;
}
var bInn=0;
function wd_TplTunePrepare() {
	try {
		var theTab=document.getElementById("wd_tpltune_tab");
		var theToolbar=document.getElementById("wd_tpltune_toolbar");
		var theDoc=document.getElementById("wd_tpltune_doc");
		// ==== прикрепляем функции для работы с guidlines:
		/*document.body.attachEvent("ondragstart", wd_GdlOnDrag);
		document.body.attachEvent("ondrag", wd_GdlOnDrag);
		document.body.attachEvent("ondragend", wd_GdlOnDrag);
		document.body.attachEvent("ondragenter", wd_CancelDefEvent);
		document.body.attachEvent("ondragover", wd_CancelDefEvent);
		document.body.attachEvent("ondragleave", wd_CancelDefEvent);
		document.body.attachEvent("ondrop", wd_CancelDefEvent);*/
	} catch (theError) {
		//alert("wd_TplTunePrepare 1:"+theError.description);
	}
	try {
		// ==== Находим все области: ======================v
		theContentArea=null; theHMenu1Area=null; theLogo1Area=null;
		theHeaderArea=null; theLogo2Area=null; theHMenu2Area=null;
		theLtArea=null; theMainArea=null; theRtArea=null; theFooterArea=null;
		if (document.getElementById('wd_inproc_contentarea')) {
			theContentArea=document.getElementById('wd_inproc_contentarea');
			theHMenu1Area=document.getElementById('wd_inproc_hmenu1area');
			theLogo1Area=document.getElementById('wd_inproc_logo1area');
			theHeaderArea=document.getElementById('wd_inproc_headerarea');
			theLogo2Area=document.getElementById('wd_inproc_logo2area');
			theHMenu2Area=document.getElementById('wd_inproc_hmenu2area');
			theLtArea=document.getElementById('wd_inproc_ltarea');
			theMainArea=document.getElementById('wd_inproc_mainarea');
			theRtArea=document.getElementById('wd_inproc_rtarea');
			theFooterArea=document.getElementById('wd_inproc_footerarea');
		} else {
			var iEls=0; var sNextClass="";
			for (iEls = 0; iEls < theDoc.all.length; iEls++) {
				sNextClass=theDoc.all[iEls].className;
				switch (sNextClass) {
					case "tpl_content":
						theDoc.all[iEls].id='wd_inproc_contentarea';
						theContentArea=document.getElementById('wd_inproc_contentarea'); break;
					case "tpl_hmenu1":
						theDoc.all[iEls].id='wd_inproc_hmenu1area';
						theHMenu1Area=document.getElementById('wd_inproc_hmenu1area'); break;
					case "tpl_hmenu2":
						theDoc.all[iEls].id='wd_inproc_hmenu2area';
						theHMenu2Area=document.getElementById('wd_inproc_hmenu2area'); break;
					case "tpl_header":
						if (theDoc.all[iEls].tagName=="DIV") {
							theDoc.all[iEls].id='wd_inproc_headerarea';
							theHeaderArea=document.getElementById('wd_inproc_headerarea');
						}
						break;
					case "tpl_logo1":
						theDoc.all[iEls].id='wd_inproc_logo1area';
						theLogo1Area=document.getElementById('wd_inproc_logo1area'); break;
					case "tpl_logo2":
						theDoc.all[iEls].id='wd_inproc_logo2area';
						theLogo2Area=document.getElementById('wd_inproc_logo2area'); break;
					case "tpl_vmenu":
						theDoc.all[iEls].id='wd_inproc_ltarea';
						theLtArea=document.getElementById('wd_inproc_ltarea'); break;
					case "tpl_mainarea":
						theDoc.all[iEls].id='wd_inproc_mainarea';
						theMainArea=document.getElementById('wd_inproc_mainarea'); break;
					case "tpl_rtarea":
						theDoc.all[iEls].id='wd_inproc_rtarea';
						theRtArea=document.getElementById('wd_inproc_rtarea'); break;
					case "tpl_footer":
						theDoc.all[iEls].id='wd_inproc_footerarea';
						theFooterArea=document.getElementById('wd_inproc_footerarea'); break;
					default:
						break;
				}
			}
		}
		// ==== :Находим все области ======================^
	} catch (theError) {
		//alert("wd_TplTunePrepare 2:"+theError.description);
	}
	try {
		// ==== расставляем guidelines: ===================v
		theGdlPglt=null; theGdlPgrt=null; theGdlLg1rt=null; theGdlLg2rt=null;
		theGdlLtart=null; theGdlRtalt=null;	theGdlHmenu1=null; theGdlHmenu2=null;
		theGdlHeader=null; theGdlFooter=null;
		var arrCntAreaPos=wd_AbsPos(theContentArea, theDoc);
		theGdlPglt=document.getElementById('tpltune_guideln_pglt');
		if (theContentArea && theGdlPglt) {
			theGdlPglt.style.left=(arrCntAreaPos[0]-1)+"px";
			theGdlPglt.style.height=theContentArea.scrollHeight+"px";
			theGdlPglt.style.visibility=wd_sGdlnsFreeze;
		} else if (theGdlPglt) {
			theGdlPglt.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 3:"+theError.description);
	}
	try {
		theGdlPgrt=document.getElementById('tpltune_guideln_pgrt');
		if (theContentArea && theGdlPgrt) {
			theGdlPgrt.style.left=(arrCntAreaPos[0]+theContentArea.offsetWidth-2)+"px";
			theGdlPgrt.style.height=theContentArea.scrollHeight+"px";
			theGdlPgrt.style.visibility=wd_sGdlnsFreeze;
		} else if (theGdlPgrt) {
			theGdlPgrt.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 4:"+theError.description);
	}
	try {
		theGdlLg1rt=document.getElementById('tpltune_guideln_lg1rt');
		if (theLogo1Area && theGdlLg1rt) {
			var arrLg1AreaPos=wd_AbsPos(theLogo1Area, theDoc);
			theGdlLg1rt.style.left=(arrLg1AreaPos[0]+theLogo1Area.offsetWidth-2)+"px";
			theGdlLg1rt.style.top=arrLg1AreaPos[1]+"px";
			theGdlLg1rt.style.height=theLogo1Area.offsetHeight+"px";
			theGdlLg1rt.style.visibility="visible";
		} else if (theGdlLg1rt) {
			theGdlLg1rt.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 5:"+theError.description);
	}
	try {
		theGdlLg2lt=document.getElementById('tpltune_guideln_lg2lt');
		if (theLogo2Area && theGdlLg2lt) {
			var arrLg2AreaPos=wd_AbsPos(theLogo2Area, theDoc);
			theGdlLg2lt.style.left=(arrLg2AreaPos[0]-1)+"px";
			theGdlLg2lt.style.top=arrLg2AreaPos[1]+"px";
			theGdlLg2lt.style.height=theLogo2Area.offsetHeight+"px";
			theGdlLg2lt.style.visibility="visible";
		} else if (theGdlLg2lt) {
			theGdlLg2lt.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 6:"+theError.description);
	}
	try {
		theGdlLtart=document.getElementById('tpltune_guideln_ltart');
		if (theLtArea && theGdlLtart) {
			var arrLtAreaPos=wd_AbsPos(theLtArea, theDoc);
			theGdlLtart.style.left=(arrLtAreaPos[0]+theLtArea.offsetWidth-2)+"px";
			theGdlLtart.style.top=arrLtAreaPos[1]+"px";
			theGdlLtart.style.height=theLtArea.offsetHeight+"px";
			theGdlLtart.style.visibility="visible";
		} else if (theGdlLtart) {
			theGdlLtart.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 7:"+theError.description);
	}
	try {
		theGdlRtalt=document.getElementById('tpltune_guideln_rtalt');
		if (theRtArea && theGdlRtalt) {
			var arrRtAreaPos=wd_AbsPos(theRtArea, theDoc);
			theGdlRtalt.style.left=(arrRtAreaPos[0]-1)+"px";
			theGdlRtalt.style.top=arrRtAreaPos[1]+"px";
			theGdlRtalt.style.height=theRtArea.offsetHeight+"px";
			theGdlRtalt.style.visibility="visible";
		} else if (theGdlRtalt) {
			theGdlRtalt.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 8:"+theError.description);
	}
	try {
		theGdlHmenu1=document.getElementById('tpltune_guideln_hmenu1');
		if (theHMenu1Area && theGdlHmenu1) {
			var arrHM1AreaPos=wd_AbsPos(theHMenu1Area, theDoc);
			theGdlHmenu1.style.top=(arrHM1AreaPos[1]+theHMenu1Area.offsetHeight-2)+"px";
			/*theGdlHmenu1.style.left=arrHM1AreaPos[0]+"px";
			theGdlHmenu1.style.width=theHMenu1Area.offsetWidth+"px";*/
			//
			theGdlHmenu1.style.left=0+"px";
			theGdlHmenu1.style.width=100+"%";
			//
			theGdlHmenu1.style.visibility="visible";
		} else if (theGdlHmenu1) {
			theGdlHmenu1.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 9:"+theError.description);
	}
	try {
		theGdlHmenu2=document.getElementById('tpltune_guideln_hmenu2');
		if (theHMenu2Area && theGdlHmenu2) {
			var arrHM2AreaPos=wd_AbsPos(theHMenu2Area, theDoc);
			theGdlHmenu2.style.top=(arrHM2AreaPos[1]+theHMenu2Area.offsetHeight-2)+"px";
			/*
			theGdlHmenu2.style.left=arrHM2AreaPos[0]+"px";
			theGdlHmenu2.style.width=theHMenu2Area.offsetWidth+"px";
			*/
			//
			theGdlHmenu2.style.left=0+"px";
			theGdlHmenu2.style.width=100+"%";
			//
			theGdlHmenu2.style.visibility="visible";
		} else if (theGdlHmenu2) {
			theGdlHmenu2.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 10:"+theError.description);
	}
	try {
		theGdlHeader=document.getElementById('tpltune_guideln_header');
		if (theHeaderArea && theGdlHeader) {
			var arrHdrAreaPos=wd_AbsPos(theHeaderArea, theDoc);
			theGdlHeader.style.top=(arrHdrAreaPos[1]+theHeaderArea.offsetHeight-2)+"px";
			/*theGdlHeader.style.left=arrHdrAreaPos[0]+"px";
			theGdlHeader.style.width=theHeaderArea.offsetWidth+"px";*/
			//
			theGdlHeader.style.left=0+"px";
			theGdlHeader.style.width=100+"%";
			//
			theGdlHeader.style.visibility="visible";
		} else if (theGdlHeader) {
			theGdlHeader.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 11:"+theError.description);
	}
	try {
		theGdlFooter=document.getElementById('tpltune_guideln_footer');
		if (theFooterArea && theGdlFooter) {
			var arrFtrAreaPos=wd_AbsPos(theFooterArea, theDoc);
			theGdlFooter.style.top=(arrFtrAreaPos[1]-1)+"px";
			/*theGdlFooter.style.left=arrFtrAreaPos[0]+"px";
			theGdlFooter.style.width=theFooterArea.offsetWidth+"px";*/
			//
			theGdlFooter.style.left=0+"px";
			theGdlFooter.style.width=100+"%";
			//
			theGdlFooter.style.visibility="visible";
		} else if (theGdlFooter) {
			theGdlFooter.style.visibility="hidden";
		}
	} catch (theError) {
		//alert("wd_TplTunePrepare 12:"+theError.description);
	}
	//
	wd_TpltunePosAreaslbls();
	//
	try {
		// ==== :расставляем guidelines ===================^
		wd_RefreshTuneVisArea();
		/*var theDoc=document.getElementById("wd_tpltune_doc");
		if (theDoc) {
			//theDoc.attachEvent("onclick", wd_TplTuneOnClick);
			theDoc.attachEvent("oncontextmenu", wd_TplTuneOnClick);
			theDoc.attachEvent("onselectstart", wd_TplTuneEvCanc);
			theDoc.attachEvent("onselect", wd_TplTuneEvCanc);
		}*/
	} catch (theError) {
		//alert("wd_TplTunePrepare 13:"+theError.description);
	}
	try {
		var iI=0;
		/*
		в document.anchors входят только ссылки, имеющие href и id !!!
		*/
		for (iI=0; iI<document.anchors.length; iI++) {
			var theA=document.anchors[iI];
			theA.attachEvent("onclick", wd_TplTuneEvCanc);
			theA.onclick="wd_TplTuneEvCanc()";
			theA.href="javascript:void(0);";
		}
	} catch (theError) {
		alert("wd_TplTunePrepare 14:"+theError.description);
	}
	//
	var thePgSzSelector=document.getElementById('wd_tpltune_pgfreezer');
	if (theTunerSheet && thePgSzSelector) {
		var sW=theTunerSheet.GetStyle(".tpl_content", "width");
		switch (sW) {
			case '780px':
			case '990px':
			case '100%':
				thePgSzSelector.value=sW;
				break;
			default:
				thePgSzSelector.value=0;
				break;
		}
	}
}
function wd_TpltunePosAreaslbls() {
	if (theLogo1Area) wd_TpltunePosArealbl(theLogo1Area, 'tpltune_arealbl_logo1', 'logo1');
	if (theLogo2Area) wd_TpltunePosArealbl(theLogo2Area, 'tpltune_arealbl_logo2', 'logo2');
	if (theLtArea) wd_TpltunePosArealbl(theLtArea, 'tpltune_arealbl_ltarea', 'ltarea');
	if (theRtArea) wd_TpltunePosArealbl(theRtArea, 'tpltune_arealbl_rtarea', 'rtarea');
	if (theHMenu1Area) wd_TpltunePosArealbl(theHMenu1Area, 'tpltune_arealbl_hmenu1area', 'hmenu1area');
	if (theHMenu2Area) wd_TpltunePosArealbl(theHMenu2Area, 'tpltune_arealbl_hmenu2area', 'hmenu2area');
	if (theHeaderArea) wd_TpltunePosArealbl(theHeaderArea, 'tpltune_arealbl_header', 'header');
	if (theMainArea) wd_TpltunePosArealbl(theMainArea, 'tpltune_arealbl_mainarea', 'mainarea');
	if (theFooterArea) wd_TpltunePosArealbl(theFooterArea, 'tpltune_arealbl_footer', 'footer');
}
function wd_TpltunePosArealbl(theArea, sLblId, sArea) {
	var theDoc=document.getElementById("wd_tpltune_doc");
	if (!document.getElementById(sLblId)) {
		var theLbl=document.createElement('DIV');
		theLbl.style.position="absolute";
		theLbl.style.backgroundColor="#990000";
		theLbl.style.fontSize="10px";
		theLbl.style.fontFamily="Arial";
		theLbl.style.fontWeight="bold";
		theLbl.style.color="#FFFFFF";
		//theLbl.style.borderStyle="solid";
		//theLbl.style.borderWidth="1px";
		//theLbl.style.borderColor="#990000";
		theLbl.style.zIndex=199;
		theLbl.style.paddingTop="1px";
		theLbl.style.paddingBottom="1px";
		theLbl.style.paddingLeft="4px";
		theLbl.style.paddingRight="4px";
		theLbl.style.width="28px";
		theLbl.style.height="14px";
		theLbl.style.backgroundImage="url(/webdirector/mdl_content/images/editzone.gif)";
		theLbl.style.backgroundPosition="100% 0%";
		theLbl.style.backgroundRepeat="no-repeat";
		theLbl.innerText=(typeof(arrAreasNums[sArea])==='undefined'?sArea:arrAreasNums[sArea]);
		theLbl.title=(typeof(arrAreasTtls[sArea])==='undefined'?sArea:arrAreasTtls[sArea]);
		theLbl.id=sLblId;
		theLbl.style.cursor="hand";
		//theLbl.attachEvent('onclick', wd_TplTuneOnAreaLblClick);
		theDoc.appendChild(theLbl);
		//theLbl.innerHTML+="<span style=\"font-family:Wingdings;font-size:14px;\">!</span>";
	} else {
		var theLbl=document.getElementById(sLblId);
	}
	theLbl.style.display=wd_sGdlnsDisplay;
	//
	
	if (!WD_TPL_CURRENGINEVERSION && sArea==='header' && theLogo1Area) {
		var arrPos=wd_AbsPos(theArea, theDoc);
		var arrPosLogo1=wd_AbsPos(theLogo1Area, theDoc);
		theLbl.style.left=(arrPos[0]+arrPosLogo1[2])+"px";
		theLbl.style.top=(arrPos[1]+0)+"px";
	} else {
		var arrPos=wd_AbsPos(theArea, theDoc);
		theLbl.style.left=(arrPos[0]+0)+"px";
		theLbl.style.top=(arrPos[1]+0)+"px";
	}
}
//==============================================================================
// StyleSheets:
function WD_StyleSheet(oStyleSheet) {
	this.DocRef=document;
	this.StyleSheet=oStyleSheet;
	this.Url=this.StyleSheet.href;
	//
	var sType="undefined";
	//
	this.TplAreas=new Array();
	sType=typeof(arrTplAreas);
	if (sType!="undefined") this.TplAreas=arrTplAreas;
	//
	this.TplAreasCnts=new Array();
	sType=typeof(arrTplCnts);
	if (sType!="undefined") this.TplAreasCnts=arrTplCnts;
	//
	this.TplAreasOpts=new Array();
	sType=typeof(arrTplOpts);
	this.TplAreasOpts['hmenu1']=new Array();
	this.TplAreasOpts['hmenu2']=new Array();
	this.TplAreasOpts['vmenu']=new Array();
	this.TplAreasOpts['table']=new Array();
	this.TplAreasOpts['form']=new Array();
	if (sType!="undefined") this.TplAreasOpts=arrTplOpts;
}
WD_StyleSheet.prototype.Reload=function() {
	var sType="undefined";
	//
	this.TplAreas=new Array();
	sType=typeof(arrTplAreas);
	if (sType!="undefined") this.TplAreas=arrTplAreas;
	//
	this.TplAreasCnts=new Array();
	sType=typeof(arrTplCnts);
	if (sType!="undefined") this.TplAreasCnts=arrTplCnts;
	//
	this.TplAreasOpts=new Array();
	this.TplAreasOpts['hmenu1']=new Array();
	this.TplAreasOpts['hmenu2']=new Array();
	this.TplAreasOpts['vmenu']=new Array();
	this.TplAreasOpts['table']=new Array();
	this.TplAreasOpts['form']=new Array();
	sType=typeof(arrTplOpts);
	if (sType!="undefined") this.TplAreasOpts=arrTplOpts;
}
WD_StyleSheet.prototype.LoadAreas=function(arrAreas) {
	this.TplAreas=new Array();
	this.TplAreas=arrAreas;
}
WD_StyleSheet.prototype.LoadAreasCnts=function(arrCnts) {
	this.TplAreasCnts=new Array();
	this.TplAreasCnts=arrCnts;
}
WD_StyleSheet.prototype.LoadCtrlsOpts=function(arrOpts) {
	this.TplAreasOpts=new Array();
	this.TplAreasOpts['hmenu1']=new Array();
	this.TplAreasOpts['hmenu2']=new Array();
	this.TplAreasOpts['vmenu']=new Array();
	this.TplAreasOpts['table']=new Array();
	this.TplAreasOpts['form']=new Array();
	for (var sNext in arrOpts) {
		this.TplAreasOpts[sNext]=new Array();
		this.TplAreasOpts[sNext]=arrOpts[sNext];
	}
}
/*
WD_StyleSheet.prototype.GetRuleIndex(sSelectorText, sStyleName) {
	var iIndex=-1;
	//
	var iI=0;
	for (iI=0; iI<this.StyleSheet.rules.length; iI++) {
		var theRule=this.StyleSheet.rules.item(iI);
		var theStyle=theRule.style;
		var sKey="";
		for (sKey in theStyle) {
			if (theStyle[sKey].length) document.write(sKey+"="+theStyle[sKey]+"<BR>");
		}
	}
	//
	return iIndex;
}
*/
//
WD_StyleSheet.prototype.GetRule=function(sSelectorText) {
	var oRule=null;
	//
	sSelectorText=sSelectorText.toUpperCase();
	//
	var iI=0;
	for (iI=0; iI<this.StyleSheet.rules.length; iI++) {
		var theRule=this.StyleSheet.rules.item(iI);
		if (theRule.selectorText.toUpperCase()==sSelectorText) {
			oRule=theRule;
			break;
		}
	}
	//
	return oRule;
}
var arrInlineStylesNames=new Array();
arrInlineStylesNames['backgroundColor']="background-color";
arrInlineStylesNames['borderColor']="border-color";
arrInlineStylesNames['borderLeftColor']="border-left-color";
arrInlineStylesNames['borderTopColor']="border-top-color";
arrInlineStylesNames['borderRightColor']="border-right-color";
arrInlineStylesNames['borderBottomColor']="border-bottom-color";

var arrDefStylesVals=new Array();
arrDefStylesVals['backgroundColor']="transparent";
arrDefStylesVals['backgroundImage']="none";
arrDefStylesVals['backgroundPosition']="0% 0%";
arrDefStylesVals['backgroundPositionX']="0%";
arrDefStylesVals['backgroundPositionY']="0%";
arrDefStylesVals['backgroundRepeat']="repeat";
arrDefStylesVals['borderBottomStyle']="none";
arrDefStylesVals['borderBottomWidth']="0px";
arrDefStylesVals['borderLeftStyle']="none";
arrDefStylesVals['borderLeftWidth']="0px";
arrDefStylesVals['borderRightStyle']="none";
arrDefStylesVals['borderRightWidth']="0px";
arrDefStylesVals['borderTopStyle']="none";
arrDefStylesVals['borderTopWidth']="0px";
arrDefStylesVals['borderStyle']="none";
arrDefStylesVals['borderWidth']="0px";
arrDefStylesVals['cursor']="auto";
arrDefStylesVals['fontStyle']="normal";
arrDefStylesVals['fontVariant']="normal";
arrDefStylesVals['fontWeight']="normal";
arrDefStylesVals['height']="auto";
arrDefStylesVals['left']="auto";
arrDefStylesVals['marginBottom']="auto";
arrDefStylesVals['marginHeight']="0";
arrDefStylesVals['marginLeft']="auto";
arrDefStylesVals['marginRight']="auto";
arrDefStylesVals['marginTop']="auto";
arrDefStylesVals['overflow']="visible";
arrDefStylesVals['overflowX']="visible";
arrDefStylesVals['overflowY']="visible";
arrDefStylesVals['paddingBottom']="0";
arrDefStylesVals['paddingLeft']="0";
arrDefStylesVals['paddingRight']="0";
arrDefStylesVals['paddingTop']="0";
arrDefStylesVals['textAlign']="left";
arrDefStylesVals['textDecoration']="none";
arrDefStylesVals['textTransform']="none";
arrDefStylesVals['verticalAlign']="baseline";
arrDefStylesVals['visibility']="inherit";
arrDefStylesVals['width']="auto";
arrDefStylesVals['wordWrap']="normal";
arrDefStylesVals['zIndex']="auto";
WD_StyleSheet.prototype.GetStyle=function(sSelectorText, sStyleName) {
	var oRule=this.GetRule(sSelectorText);
	var sVal="";
	try {
		sVal=eval("oRule.style."+sStyleName);
		/*if (sVal==undefined && sStyleName=="borderColor") {
			sVal=oRule.style.borderLeftColor;
		}*/
		if (sVal==undefined && arrDefStylesVals[sStyleName]) {
			sVal=arrDefStylesVals[sStyleName];
		}
	} catch (theError) {
		void(0);
	}
	return sVal;
}
WD_StyleSheet.prototype.SetStyle=function(sSelectorText, sStyleName, sStyleValue, arrPackage) {
	if (typeof(arrPackage)!="object" || wd_ArrCount(arrPackage)<1) {
		var arrPackage=new Array();
		arrPackage[sStyleName]=sStyleValue;
	}
	var sNextStyleName="";
	var theError=null;
	for (sNextStyleName in arrPackage) {
		sNextStyleValue=arrPackage[sNextStyleName];
		if (this.GetStyle(sSelectorText, sNextStyleName)!=sNextStyleValue) {
			var oRule=this.GetRule(sSelectorText);
			if (oRule) {
				try {
					eval("oRule.style."+sNextStyleName+"='"+sNextStyleValue+"'");
					if (arrInlineStylesNames[sNextStyleName]) {
						sNextStyleName=arrInlineStylesNames[sNextStyleName];
						eval("oRule.style."+sNextStyleName+"='"+sNextStyleValue+"'");
					}
				} catch (theError) {
					void(0); //return theError;
				}
			} else {
				try {
					if (arrInlineStylesNames[sNextStyleName]) {
						sNextStyleName=arrInlineStylesNames[sNextStyleName];
					}
					this.StyleSheet.addRule(sSelectorText, sNextStyleName+":"+sNextStyleValue);
				} catch (theError) {
					void(0); //return theError;
				}
			}
		}
	}
	return theError;
}
WD_StyleSheet.prototype.SelectorsList=function() {
	var arrSelectors=new Array();
	for (iI=0; iI<this.StyleSheet.rules.length; iI++) {
		var theRule=oStSh.rules.item(iI);
		arrSelectors[arrSelectors.length]=theRule.selectorText;
	}
	return arrSelectors;
}
WD_StyleSheet.prototype.StylesList=function() {
	var arrStyles=new Array();
	for (iI=0; iI<this.StyleSheet.rules.length; iI++) {
		var theRule=oStSh.rules.item(iI);
		var theStyle=theRule.style;
		var sKey="";
		for (sKey in theStyle) {
			if (theStyle[sKey].length) {
				if (!arrStyles[theRule.selectorText]) {
					arrStyles[theRule.selectorText]=new Array();
				}
				arrStyles[theRule.selectorText][arrStyles[theRule.selectorText].length]=sKey+":"+theStyle[sKey];
			}
		}
	}
	return arrStyles;
}
WD_StyleSheet.prototype.SetOption=function(sControl, sOption, sValue) {
	var sType="undefined";
	sType=typeof(this.TplAreasOpts[sControl]);
	if (sType=="undefined") this.TplAreasOpts[sControl]=new Array();
	this.TplAreasOpts[sControl][sOption]=sValue;
}
WD_StyleSheet.prototype.GetOption=function(sControl, sOption) {
	var sAnswer="";
	//
	var sType1="undefined";
	sType1=typeof(this.TplAreasOpts[sControl]);
	if (sType1!="undefined") {
		var sType2="undefined";
		sType2=typeof(this.TplAreasOpts[sControl][sOption]);
		if (sType2!="undefined") {
			sAnswer=this.TplAreasOpts[sControl][sOption];
		}
	}
	//
	return sAnswer;
}
WD_StyleSheet.prototype.GetAreaCnt=function(sAreaName) {
	var sAnswer="";
	//
	var sType="undefined";
	sType=typeof(this.TplAreasCnts[sAreaName]);
	if (sType!="undefined") sAnswer=this.TplAreasCnts[sAreaName];
	//
	return sAnswer;
}
function wd_TplRepresVis(sChkName, sReprName) {
	var theChk=document.getElementById(sChkName);
	var theEl=document.getElementById(sReprName);
	if (theEl && theChk) {
		var sSChkName=theChk.name;
		var sAreaName=sSChkName.substring((sSChkName.indexOf("[")+1), sSChkName.indexOf("]"));
		var sTAreaName=sAreaName+";;;area";
		var theTArea=theChk.form.elements[sTAreaName];
		var sCstBtt=sTAreaName+"_cstbtt";
		var theCstBtt=theChk.form.elements[sCstBtt];
		var sSelectName=sTAreaName+"_selectbox";
		var theSelectbox=theChk.form.elements[sSelectName];
		var sPctdivName=sTAreaName+"_pctdiv";
		var thePctdiv=document.getElementById(sPctdivName);
		if (theChk.checked || (theChk.type=="hidden" && theChk.value=="on")) {
			if (theSelectbox) {
				if (theSelectbox.style.visibility != "hidden") {
					theSelectbox.style.display='inline';
				} else {
					theSelectbox.style.display='none';
				}
			}
			if (theTArea && theSelectbox && theSelectbox.value=="%custom%") {
				//theTArea.style.display='inline';
				if (theCstBtt) theCstBtt.style.display='block';
				theTArea.value="%custom%";
			}
			if (thePctdiv && theSelectbox && theSelectbox.value=="%picture%") thePctdiv.style.display='block';
			theEl.style.display='block';
		} else {
			if (theSelectbox) theSelectbox.style.display='none';
			//if (theTArea) theTArea.style.display='none';
			if (theCstBtt) theCstBtt.style.display='none';
			if (thePctdiv) thePctdiv.style.display='none';
			theEl.style.display='none';
		}
	}
}
function wd_McrsCtrlRedraw(sName, sCurrMode) {
	if (document.getElementById(sName+'_selectbox') && document.getElementById(sName+'_selectbox').options && document.getElementById(sName+'_selectbox').options.item(sName+'_'+sCurrMode)) {
		if (document.getElementById(sName+"_pctdiv")) {
			document.getElementById(sName+"_pctdiv").style.display='none';
		}
		var arrName=sName.split(";;;");
		var theCheckbox=document.getElementById("areavis["+arrName[0]+"]");
		var theSelBox=document.getElementById(sName+"_selectbox");
		if (sCurrMode=="custom") {
			if (document.getElementById(sName)) {
				if (theSelBox && (!theCheckbox || theCheckbox.type!="checkbox" || (theCheckbox && theCheckbox.checked))) {
					//document.getElementById(sName).style.display='block';
					document.getElementById(sName).value="%custom%";
					if (theSelBox.form.elements[sName+'_cstbtt']) {
						theSelBox.form.elements[sName+'_cstbtt'].style.display='block';
						theSelBox.form.elements[sName+'_cstbtt'].click();
					}
				} else {
					//document.getElementById(sName).style.display='none';
					if (theSelBox.form.elements[sName+'_cstbtt']) {
						theSelBox.form.elements[sName+'_cstbtt'].style.display='none';
					}
				}
			}
		} else if (sCurrMode=="picture") {
			if (theSelBox.form.elements[sName+'_cstbtt']) {
				theSelBox.form.elements[sName+'_cstbtt'].style.display='none';
			}
			if (document.getElementById(sName)) {
				document.getElementById(sName).value="%"+sCurrMode+"%";
				document.getElementById(sName).style.display='none';
			}
			if (document.getElementById(sName+"_pctdiv")) {
				if (theSelBox && (!theCheckbox || theCheckbox.type!="checkbox" || (theCheckbox && theCheckbox.checked))) {
					document.getElementById(sName+"_pctdiv").style.display='block';
				} else {
					document.getElementById(sName+"_pctdiv").style.display='none';
				}
			}
		} else {
			if (theSelBox.form.elements[sName+'_cstbtt']) {
				theSelBox.form.elements[sName+'_cstbtt'].style.display='none';
			}
			if (document.getElementById(sName)) {
				document.getElementById(sName).value="%"+sCurrMode+"%";
				document.getElementById(sName).style.display='none';
			}
		}
		if (document.getElementById(sName+'_selectbox') && document.getElementById(sName+'_selectbox').options && document.getElementById(sName+'_selectbox').options.item(sName+'_'+sCurrMode)) {
			document.getElementById(sName+'_selectbox').options(sName+'_'+sCurrMode).selected=true;
		}
	} else if (document.getElementById(sName)) {
		document.getElementById(sName).style.display='block';
	}
}
function wd_tpltuner_VislizeStSheet() {
var iT1=new Date();
iT1=iT1.getTime();
	var theTab=document.getElementById("wd_tbl_window");
	if (theTab) theTab.refresh();
	//
	var theF=document.forms["wd_tunerform"]; // это для окна-диалога
	if (!theF) {
		theF=document.forms["form_genview"]; // а это для страницы настройки структуры шаблона
	}
	if (theF) {
		var iI=0;
		for (iI=0; iI<theF.elements.length; iI++) {
			var sName=theF.elements[iI].name;
			if (sName && sName.indexOf(";;;")!=-1) {
				var arrName=sName.split(";;;");
				if (arrName && arrName.length>1) {
					var sRule=arrName[0];
					var sStyle=arrName[1]; var sStyleU=sStyle.toUpperCase();
					var iEngine=0; if (typeof(arrName[2])!=='undefined') iEngine=parseInt(arrName[2]);
					/*if (sStyle=="area") {
						var sTmp=theTunerSheet.GetAreaCnt(sRule);
						// TplMacros Control visible value setting:
						switch (sTmp) {
							case "%path%":
								wd_McrsCtrlRedraw(sName, "path");
								break;
							case "%nest%":
								wd_McrsCtrlRedraw(sName, "nest");
								break;
							case "%hmenu1%":
								wd_McrsCtrlRedraw(sName, "hmenu1");
								break;
							case "%hmenu2%":
								wd_McrsCtrlRedraw(sName, "hmenu2");
								break;
							case "%vmenu%":
								wd_McrsCtrlRedraw(sName, "vmenu");
								break;
							case "%tree%":
								wd_McrsCtrlRedraw(sName, "tree");
								break;
							case "%body%":
								wd_McrsCtrlRedraw(sName, "body");
								break;
							case "%picture%":
								wd_McrsCtrlRedraw(sName, "picture");
								break;
							default:
								wd_McrsCtrlRedraw(sName, "custom");
								break;
						}
					} else */if (sStyle.substr(0, 7)=="option_") {
						var sElCurrVal=theF.elements[iI].value;
						if (sElCurrVal.substr(0, 2)=="__") {
							var sTmp=sElCurrVal.substr(2);
						} else {
							var sTmp=theTunerSheet.GetOption(sRule, sStyle.substr(7));
							//theTunerSheet.TplAreasOpts[sRule][sStyle.substr(7)]=sVal;
						}
					} else {
						var sElCurrVal=theF.elements[iI].value;
						if (sElCurrVal.substr(0, 2)=="__") {
							var sTmp=sElCurrVal.substr(2);
						} else {
							var sTail=sStyle.substr((sStyle.length-5), 5);
							sTail=sTail.toUpperCase();
							if (sTail=="_CODE") {
								sStyle=sStyle.substr(0, (sStyle.length-5));
								sStyleU=sStyle.toUpperCase();
							}
							if (sStyle=="paddingX") {
								//sStyle="paddingLeft";
								var sTmp=theTunerSheet.GetStyle(sRule, "paddingLeft");
							} else if (sStyle=="paddingY") {
								//sStyle="paddingTop";
								var sTmp=theTunerSheet.GetStyle(sRule, "paddingTop");
							} else if (sStyle=="galign") {
								var sTmpL=theTunerSheet.GetStyle(sRule, "textAlign");
								var sTmpV=theTunerSheet.GetStyle(sRule, "verticalAlign");
								var sTmp=1;
								switch (sTmpV) {
									case "bottom":
										sTmp=7; break;
									case "middle":
										sTmp=4; break;
									case "top":
									default:
										sTmp=1; break;
								}
								switch (sTmpL) {
									case "right":
										sTmp+=2; break;
									case "center":
										sTmp+=1; break;
									case "left":
									default:
										sTmp+=0; break;
								}
								sTmp=sTmp.toString();
							} else {
								var sTmp=theTunerSheet.GetStyle(sRule, sStyle);
							}
							// correct values:
							var sCtrlName=sRule+";;;"+sStyle;
							if (sTmp!=undefined) {
								sTmp=sTmp.toString();
								if (sTmp.substr(0, 1)=="#") { // Colorbox Control
									// Colorbox Control visible value setting:
									//var theButt=document.getElementById(sCtrlName+"_butt");
									var theButt=document.getElementById(sCtrlName);
									if (theButt) theButt.style.backgroundColor=sTmp;
									// все цвета - через палитру:
									var sCode=wd_plt_ColorCode(sTmp);
									if (sTail=="_CODE") { // hidden
										sTmp=sCode;	
									} else { // visible
										sTmp="";
									}
								} else if (sStyleU=="TEXTALIGN") { // TAlign Control
									// TAlign Control visible value setting:
									var arrInsets=new Array();
									arrInsets['LEFT']=1;
									wd_tpltuner_VislizeButtImg(sCtrlName+"_l", arrInsets, sTmp);
									var arrInsets=new Array();
									arrInsets['CENTER']=1;
									wd_tpltuner_VislizeButtImg(sCtrlName+"_c", arrInsets, sTmp);
									var arrInsets=new Array();
									arrInsets['RIGHT']=1;
									wd_tpltuner_VislizeButtImg(sCtrlName+"_r", arrInsets, sTmp);
								} else if (sStyleU=="FONTWEIGHT" || sStyleU=="FONTSTYLE" || sStyleU=="TEXTDECORATION") {
									// Bold, Italic, Underline Controls visible value setting:
									var arrInsets=new Array();
									arrInsets['BOLD']=1; arrInsets['ITALIC']=1; arrInsets['UNDERLINE']=1;
									wd_tpltuner_VislizeButtImg(sCtrlName, arrInsets, sTmp);
								} else if (sStyleU=="FONTFAMILY" || sStyleU=="FONTSIZE") {
									var theButt=document.getElementById(sCtrlName);
									if (theButt) theButt.innerHTML=sTmp.split(",")[0];
								} else if (sStyleU=="GALIGN") {
									for (var i=1; i<10; i++) {
										document.images[sCtrlName+"_"+i].style.borderStyle='outset';
									}
									document.images[sCtrlName+"_"+sTmp].style.borderStyle='inset';
								} else if (iEngine===1 && sStyleU==="WIDTH") {
									// display width as including padding sizes:
									//var sPdd=theTunerSheet.GetStyle(sRule, 'padding');
									var iTmp=0; if (typeof(sTmp)==='string') iTmp=parseInt(sTmp);
									var sPddL=theTunerSheet.GetStyle(sRule, 'paddingLeft');
									var iPddL=0; if (typeof(sPddL)==='string') iPddL=parseInt(sPddL);
									var sPddR=theTunerSheet.GetStyle(sRule, 'paddingRight');
									var iPddR=0; if (typeof(sPddR)==='string') iPddR=parseInt(sPddR);
									//alert("width: "+iTmp+"\npadding-left: "+iPddL+"\npadding-right: "+iPddR);
									sTmp=(iTmp+iPddL+iPddR)+"px";
								}
							}
						}
					}
					theF.elements[iI].value=sTmp;
				}
			}
		}
	}
var iT2=new Date();
iT2=iT2.getTime();
var iT=iT2-iT1;
//alert(iT);
//600
}
function wd_tpltuner_VisOneButtImg() {
	//
}
function wd_tpltuner_VislizeButtImg(sImgName, arrInsetVals, sDetVal) {
	sDetVal=sDetVal.toUpperCase();
	var imgButt=document.images[sImgName];
	if (imgButt) {
		if (typeof(arrInsetVals[sDetVal])!="undefined") {
			imgButt.style.borderStyle="inset";
		} else {
			imgButt.style.borderStyle="outset";
		}
	}
}
function wd_tpltuner_GAlignToVals(sGAlign) {
	var arrAnswer=new Array("left", "top");
	//
	switch (sGAlign) {
		case "9":
			arrAnswer[0]="right";
			arrAnswer[1]="bottom";
			break;
		case "8":
			arrAnswer[0]="center";
			arrAnswer[1]="bottom";
			break;
		case "7":
			arrAnswer[0]="left";
			arrAnswer[1]="bottom";
			break;
		case "6":
			arrAnswer[0]="right";
			arrAnswer[1]="middle";
			break;
		case "5":
			arrAnswer[0]="center";
			arrAnswer[1]="middle";
			break;
		case "4":
			arrAnswer[0]="left";
			arrAnswer[1]="middle";
			break;
		case "3":
			arrAnswer[0]="right";
			arrAnswer[1]="top";
			break;
		case "2":
			arrAnswer[0]="center";
			arrAnswer[1]="top";
			break;
		case "1":
		default:
			arrAnswer[0]="left"; 
			arrAnswer[1]="top";
			break;
	}
	//
	return arrAnswer;
}
function wd_tpltuner_PickupStSheet() {
var iT1=new Date();
iT1=iT1.getTime();
	var theF=document.forms["wd_tunerform"];
	if (theF) {
		var arrEmpty=new Array();
		var iI=0;
		for (iI=0; iI<theF.elements.length; iI++) {
			var sName=theF.elements[iI].name;
			if (sName && sName.indexOf(";;;")!=-1) {
				var arrName=sName.split(";;;");
				if (arrName.length>1) {
					var sRule=arrName[0];
					var sStyle=arrName[1];
					var sTail=sStyle.substr((sStyle.length-5), 5);
					sTail=sTail.toUpperCase();
					var iEngine=0; if (typeof(arrName[2])!=='undefined') iEngine=parseInt(arrName[2]);
					if (sTail=="_CODE") {
						var sVal=theF.elements[iI].value;
						sStyle=sStyle.substr(0, (sStyle.length-5));
//if (sStyle==="width") alert(sRule+"\n"+sStyle+"\n"+sVal);
						//
						if (sVal.substr(0, 2)=="%c") { // palette indexed color
							if (arrPaletteCodes[sVal]) {
								sVal=arrPaletteCodes[sVal];
							} else {
								sVal="transparent";
							}
						} else if (sVal.substr(0, 2)=="%f") { // font-family
							if (arrFFamilyCodes[sVal]) {
								sVal=arrFFamilyCodes[sVal];
							} else {
								sVal="";
							}
						} else if (sVal.substr(0, 2)=="%s") { // font-size
							if (arrFSizeCodes[sVal]) {
								sVal=arrFSizeCodes[sVal];
							} else {
								sVal="";
							}
						}
						var arrPackage=new Array();
						if (sStyle=="paddingX") {
							arrPackage['paddingLeft']=sVal;
							arrPackage['paddingRight']=sVal;
						} else if (sStyle=="paddingY") {
							arrPackage['paddingTop']=sVal;
							arrPackage['paddingBottom']=sVal;
						} else if (sStyle=="galign") {
							var arrGAlign=wd_tpltuner_GAlignToVals(sVal);
							arrPackage['textAlign']=arrGAlign[0];
							arrPackage['verticalAlign']=arrGAlign[1];
						}
//alert("["+sRule+"]\n["+sStyle+"]\n["+sVal+"]");
						//
						if (sRule!="." && sRule.length) {
							//
							if (sStyle==="width" && iEngine===1) {
								// need to correct tp paddings:
								var thePddL=theF.elements[sRule+";;;paddingLeft_code"];
								var thePddR=theF.elements[sRule+";;;paddingRight_code"];
								var iPddL=0;
								if (thePddL && thePddL.value) iPddL=parseInt(thePddL.value);
								if (!iPddL) iPddL=0;
								var iPddR=0;
								if (thePddR && thePddR.value) iPddR=parseInt(thePddR.value);
								if (!iPddR) iPddR=0;
								var iVal=0;
								if (sVal) iVal=parseInt(sVal);
								if (!iVal) iVal=0;
								sVal=(iVal-iPddL-iPddR)+"px";
//alert(sVal+"=("+iVal+"-"+iPddL+"-"+iPddR+")");
							}
							// common:
							theTunerSheet.SetStyle(sRule, sStyle, sVal, arrPackage);
							// menuitems highlights identity:
							if ((sRule=='TD.TOP_menu1' || sRule=='TD.menu1' || sRule=='TD.TOP_menu2' || sRule=='TD.menu2' || sRule=='TD.TOP_vmenu' || sRule=='TD.vmenu') && (sStyle=='width' || sStyle=='height' || sStyle=='galign' || sStyle=='paddingX' || sStyle=='paddingY' || sStyle=='borderStyle' || sStyle=='borderWidth')) {
								theTunerSheet.SetStyle(sRule+"_h", sStyle, sVal, arrPackage);
							}
							// anchors with menu td's:
							if ((sRule=='TD.TOP_menu1' || sRule=='TD.menu1' || sRule=='TD.TOP_menu2' || sRule=='TD.menu2' || sRule=='TD.TOP_vmenu' || sRule=='TD.vmenu') && (sStyle=='fontFamily' || sStyle=='fontSize' || sStyle==='textTransform' || sStyle==='whiteSpace')) {
//alert("["+sRule+"]\n["+sStyle+"]\n["+sVal+"]");
								theTunerSheet.SetStyle(sRule+"_h", sStyle, sVal, arrPackage);
								var re=/TD\./gi;
								var sARule=sRule.replace(re, "A.");
								theTunerSheet.SetStyle(sARule, sStyle, sVal, arrPackage);
								theTunerSheet.SetStyle(sARule+"_h", sStyle, sVal, arrPackage);
								theTunerSheet.SetStyle(sARule+"_h:hover", sStyle, sVal, arrPackage);
							}
							//
							if ((sRule=='TD.TOP_menu1' || sRule=='TD.menu1' || sRule=='TD.TOP_menu2' || sRule=='TD.menu2' || sRule=='TD.TOP_vmenu' || sRule=='TD.vmenu') && (sStyle=='color' || sStyle=='fontWeight' || sStyle=='fontStyle' || sStyle=='textDecoration' || sStyle=='borderColor' || sStyle=='backgroundColor')) {
								theTunerSheet.SetStyle(sRule, sStyle, sVal, arrPackage);
								var re=/TD\./gi;
								var sARule=sRule.replace(re, "A.");
								if (sStyle==='backgroundColor') {
//alert("["+sARule+"]\n["+sStyle+"]\n["+sVal+"]");
									theTunerSheet.SetStyle(sARule, sStyle, 'transparent', arrPackage);
								} else if (sStyle==='backgroundImage') {
									theTunerSheet.SetStyle(sARule, sStyle, 'none', arrPackage);
								} else {
									theTunerSheet.SetStyle(sARule, sStyle, sVal, arrPackage);
								}
								theTunerSheet.SetStyle(sARule, sStyle, sVal, arrPackage);
							}
							if ((sRule=='TD.TOP_menu1_h' || sRule=='TD.menu1_h' || sRule=='TD.TOP_menu2_h' || sRule=='TD.menu2_h' || sRule=='TD.TOP_vmenu_h' || sRule=='TD.vmenu_h') && (sStyle=='color' || sStyle=='fontWeight' || sStyle=='fontStyle' || sStyle=='textDecoration' || sStyle=='borderColor' || sStyle=='backgroundColor')) {
								theTunerSheet.SetStyle(sRule, sStyle, sVal, arrPackage);
								var re=/TD\./gi;
								var sARule=sRule.replace(re, "A.");
								if (sStyle==='backgroundColor') {
//alert("["+sARule+"]\n["+sStyle+"]\n["+sVal+"]");
									theTunerSheet.SetStyle(sARule, sStyle, 'transparent', arrPackage);
									theTunerSheet.SetStyle(sARule+":hover", sStyle, 'transparent', arrPackage);
								} else if (sStyle==='backgroundImage') {
									theTunerSheet.SetStyle(sARule, sStyle, 'none', arrPackage);
									theTunerSheet.SetStyle(sARule+":hover", sStyle, 'none', arrPackage);
								} else {
									theTunerSheet.SetStyle(sARule, sStyle, sVal, arrPackage);
									theTunerSheet.SetStyle(sARule+":hover", sStyle, sVal, arrPackage);
								}
							}
							// submenuitems width
							if ((sRule=='TD.menu1' || sRule=='TD.menu2' || sRule=='TD.vmenu') && sStyle=='width') {
								var re=/TD\./gi;
								var sDIVRule=sRule.replace(re, "DIV.");
								theTunerSheet.SetStyle(sDIVRule+"BG", sStyle, sVal, arrEmpty);
							}
							// mainarea and contentarea bg identity:
							if (sRule==".tpl_mainarea" && sStyle=="backgroundColor") {
								theTunerSheet.SetStyle(".tpl_content", sStyle, sVal, arrPackage);
							}
							// link mainarea and table cell
							if (sRule==".tpl_mainarea" && sStyle=="backgroundColor" && wd_bNeedTblLink) {
								theTunerSheet.SetStyle(".WDTD", sStyle, sVal, arrPackage);
								theTunerSheet.SetStyle(".WDTH", sStyle, sVal, arrPackage);
								theTunerSheet.SetStyle(".WDTFH", sStyle, sVal, arrPackage);
							}
							//
							if (!wd_bAdvMenuTuning) {
								if (sRule=='TD.TOP_menu1' || sRule=='TD.TOP_menu2') {
									var re=/TD\.TOP/gi;
									var sSepRule=sRule.replace(re, "TD.sep");
									switch (sStyle) {
										case 'backgroundColor':
											theTunerSheet.SetStyle(sSepRule, "backgroundColor", sVal, arrEmpty);
											break;
										case 'color':
											theTunerSheet.SetStyle(sSepRule, "color", sVal, arrEmpty);
											break;
										case 'fontFamily':
											theTunerSheet.SetStyle(sSepRule, "fontFamily", sVal, arrEmpty);
											break;
										case 'fontSize':
											theTunerSheet.SetStyle(sSepRule, "fontSize", sVal, arrEmpty);
											break;
										default:
											break;
									}
								}
								/*if (sRule=='TD.TOP_vmenu' && sStyle=='color') {
									var arrFrm=new Array();
									arrFrm['borderLeftWidth']="0px";
									arrFrm['borderTopWidth']="0px";
									arrFrm['borderRightWidth']="0px";
									arrFrm['borderBottomWidth']="1px";
									arrFrm['borderColor']=sVal;
									arrFrm['borderStyle']="solid";
									theTunerSheet.SetStyle(sRule, "borderColor", sVal, arrFrm);
									theTunerSheet.SetStyle(sRule+"_h", "borderColor", sVal, arrFrm);
								}*/
							}
						}
					} else if (sStyle.substr(0, 7)=="option_") {
						var sVal=theF.elements[iI].value;
						var sOptName=sStyle.substr(7);
						theTunerSheet.SetOption(sRule, sOptName, sVal);
						var iOptCnt=0; var sPref="";
						if (sRule=="hmenu1"||sRule=="hmenu2"||sRule=="vmenu") {
							var iPref=-1;
							while (iPref<202 && !(theTunerSheet.DocRef.getElementById(iPref+"_menu0")||theTunerSheet.DocRef.getElementById(sPref+"_bar_0")||theTunerSheet.DocRef.getElementById(sPref+"_sep_0"))) {
								iPref++;
							}
							var iCorrector=0;
							var sFindedClass=(theTunerSheet.DocRef.getElementById(iPref+"_menu0").className);
							switch (sFindedClass) {
								case "TOP_vmenu":
									iCorrector-=2;
									break;
								case "TOP_menu2":
									iCorrector-=1;
									break;
								case "TOP_menu1":
								default:
									break;
							}
							if (iPref>-1 && iPref<201) {
								var sPref="";
								if (sRule==="hmenu1") sPref=iPref+iCorrector;
								if (sRule==="hmenu2") sPref=iPref+iCorrector+1;
								if (sRule==="vmenu") sPref=iPref+iCorrector+2;
								if (sOptName=="topborder") {
									if (theTunerSheet.DocRef.getElementById(sPref+"_menu0")) {
										theTunerSheet.DocRef.getElementById(sPref+"_menu0").cellSpacing=sVal;
										theTunerSheet.DocRef.getElementById(sPref+"_menu0").refresh();
									}
								} else if (sOptName=="nextborder") {
									while (theTunerSheet.DocRef.getElementById(sPref+"_bar_"+iOptCnt)) {
										theTunerSheet.DocRef.getElementById(sPref+"_bar_"+iOptCnt).cellSpacing=sVal;
										theTunerSheet.DocRef.getElementById(sPref+"_bar_"+iOptCnt).refresh();
										iOptCnt++;
									}
								} else if (sOptName=="separator") {
									while (theTunerSheet.DocRef.getElementById(sPref+"_sep_"+iOptCnt)) {
										theTunerSheet.DocRef.getElementById(sPref+"_sep_"+iOptCnt).innerHTML=sVal;
										iOptCnt++;
									}
								}
							}
						} else if (sRule=="table") {
							if (sOptName=="cellspacing") {
								if (theTunerSheet.DocRef.getElementById("tpltune_table")) {
									theTunerSheet.DocRef.getElementById("tpltune_table").cellSpacing=sVal;
									theTunerSheet.DocRef.getElementById("tpltune_table").refresh();
								}
							}
						} else if (sRule=="form") {
							//alert(sOptName);
							if (sOptName=="basepadding") {
								if (theTable=theTunerSheet.DocRef.getElementById("tpltune_osnsmall")) {
									theTable.cellPadding=sVal;
									theTable.refresh();
									//alert(theTable.cellPadding);
								}
							} else if (sOptName=="plotspacing") {
								if (theTable=theTunerSheet.DocRef.getElementById("tpltune_formplot")) {
									theTable.cellSpacing=sVal;
									theTable.refresh();
									//alert(theTable.cellSpacing);
								}
							}
						}
					}
				}
			}
		}
	}
	// + predefined functional rules:
	var arrEmpty=new Array();
	theTunerSheet.SetStyle("DIV.menu1", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1H", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1H", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1H", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1_v", "visibility", 'visible', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1_v", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1_v", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1H_v", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1H_v", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu1H_v", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2H", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2H", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2H", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2_v", "visibility", 'visible', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2_v", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2_v", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2H_v", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2H_v", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.menu2H_v", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenu", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenu", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenu", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenuH", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenuH", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenuH", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenu_v", "visibility", 'visible', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenu_v", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenu_v", "paddingTop", '0px', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenuH_v", "visibility", 'hidden', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenuH_v", "position", 'absolute', arrEmpty);
	theTunerSheet.SetStyle("DIV.vmenuH_v", "paddingTop", '0px', arrEmpty);
	//wd_PrepareTuneVisArea();
	/*var theTab=theTunerSheet.DocRef.getElementById('wd_tpltune_tab');
	if (theTab) {
		alert("theTab="+theTab);
		theTab.refresh();
	}*/
var iT2=new Date();
iT2=iT2.getTime();
var iT=iT2-iT1;
//alert(iT);
	return true;
}

function wd_tpls_SaveTemplate(sPreviewEngine, sParams) {
	/* Передаем стили, содержимое областей и опции контролов на сервер */
	// Определяем размеры экрана:
	var iScrW=screen.availWidth;
	var iScrH=screen.availHeight;
	var iWinW=940; var iWinH=620;
	if (iScrW>=1200) { // 1280
		iWinW=1240;
	} else if (iScrW>=1000) { // 1024
		iWinW=940;
	} else if (iScrW>=780) { // 800
		iWinW=780;
	}
	if (iScrH>=900) { // 1024
		iWinH=940;
	} else if (iScrH>=650) { // 768
		iWinH=620;
	} else if (iScrH>=500) { // 600
		iWinH=540;
	}
	// Предлагаем изменить:
	var arrTunerSheet=amg_ModalDialog(sPreviewEngine, iWinW, iWinH, sParams, 0, 0, "Yes");
	if (arrTunerSheet && wd_ObjCount(arrTunerSheet)) {
		// Извлекаем:
		var sStyles=arrTunerSheet[0];
		var arrAreaCnts=arrTunerSheet[1];
		var arrCtlsOpts=arrTunerSheet[2];
		var sCookies=arrTunerSheet[3];
		var bTblCellChanged=arrTunerSheet[4];
		// Вставляем и Передаем:
		var theF=document.forms["wd_tplsf_directvals"];
		if (theF) {
			//
			if (theF.elements["tbltuned"]) theF.elements["tbltuned"].value=bTblCellChanged;
			//
			if (theF.elements["fld_csstext"]) theF.elements["fld_csstext"].value=sStyles;
			//
			var sNextCnt="";
			for (sNextCnt in arrAreaCnts) {
				if (theF.elements["fld_cnt_"+sNextCnt]) {
					theF.elements["fld_cnt_"+sNextCnt].value=arrAreaCnts[sNextCnt];
				}
			}
			//
			for (var i in arrCtlsOpts) {
				var sNextOptVal="";
				for (var j in arrCtlsOpts[i]) {
					sNextOptVal=sNextOptVal+j+"="+arrCtlsOpts[i][j]+"\n";
				}
				if (theF.elements["fld_opts_"+i]) {
					theF.elements["fld_opts_"+i].value=sNextOptVal;
				}
			}
			theF.submit();
		}
	}
}
function wd_tpltuner_SaveTpl(bSave) {
	/* Необходимо вернуть вызывающему окну
	стили и содержимое областей, то есть theTunerSheet
	Превращение стилей в коды - на сервере */
	var sCssText=theTunerSheet.StyleSheet.cssText;
	var arrCnts=new Array(); arrCnts=theTunerSheet.TplAreasCnts;
	var arrOpts=new Array(); arrOpts=theTunerSheet.TplAreasOpts;
	var arrReturn=new Array();
	arrReturn[0]=sCssText;
	arrReturn[1]=arrCnts;
	arrReturn[2]=arrOpts;
	arrReturn[3]=document.cookie;
	var sCookies=arrReturn[3];
	var arrCookies=sCookies.split(";");
	for (sKey in arrCookies) {
		arrVal=arrCookies[sKey].split("=");
		var theDate=new Date(2040,12,20);
		if (arrVal[0]=='wd_tpltuner_cook_gdls'||arrVal[0]=='wd_tpltuner_cook_pgdls') {
			document.cookie=arrVal[0]+'='+arrVal[1]+'; expires='+theDate.toGMTString()+';path=/;';
		}
	}
	// совпадает ли bg ячеек таблицы с bg основной области
	var sMainBgColor=theTunerSheet.GetStyle(".tpl_mainarea", 'backgroundColor');
	var sTabCellBgColor=theTunerSheet.GetStyle(".WDTD", 'backgroundColor');
	if (wd_bAdvMenuTuning && sMainBgColor!=sTabCellBgColor) {
		arrReturn[4]=1;
	} else {
		arrReturn[4]=0;
	}
	//
	if (bSave && wd_ObjCount(theTunerSheet)) window.returnValue=arrReturn;
	//
	self.close();
}
//==============================================================================
function tpldlg_YxoShow(sYxoId) {
	if (document.getElementById('div_'+sYxoId)) {
		document.getElementById('div_'+sYxoId).style.display='block';
	}
	if (document.getElementById('tab_'+sYxoId)) {
		document.getElementById('tab_'+sYxoId).className='wd2yxoup_a';
	}
}
function tpldlg_YxoHide(sYxoId) {
	if (document.getElementById('div_'+sYxoId)) {
		document.getElementById('div_'+sYxoId).style.display='none';
	}
	if (document.getElementById('tab_'+sYxoId)) {
		document.getElementById('tab_'+sYxoId).className='wd2yxoup';
	}
}
//==============================================================================
function wd_tpltuner_ChangeTplVis(bChanged) {
	// Визуализируем изменения
	// Меняем все содержания областей
	var theTab=document.getElementById("wd_tpltune_tab");
	var theContentEl=document.getElementById("wd_tpltune_doc");
	var bTextPresent=false; var bHeaderPresent=false;
	var rgBody=/%body%/ig; var rgText=/-text-/ig; var rgHeader=/-header-/ig;
	if (theContentEl) {
		var sBody=theContentEl.innerHTML;
		var sKey="";
		try {
			var iScrllX=theContentEl.scrollLeft;
			var iScrllY=theContentEl.scrollTop;
			theContentEl.innerHTML=sBody;
			theContentEl.scrollLeft=iScrllX;
			theContentEl.scrollTop=iScrllY;
		} catch (theError) {
			//alert("1: "+theError.description+"\n\n"+sBody);
		}
		/**/
		wd_PrepareTuneVisArea();
	}
}
//==============================================================================