var s_amg_CurrColorbox=""; // 
var o_amg_TimerColorbox=null; // 

function amg_SetColorBox(oToEl) {
	if (!oToEl) var oToEl=event.srcElement;
	if (oToEl&&oToEl.id&&oToEl.id.substr(0,1)=="%") {
		if (s_amg_CurrColorbox) {
			var sColorCode=oToEl.id;
			var sColorNum=sColorCode.substr(0, (sColorCode.length-1)).substr(2);
			var sColorValue="";
			if (arrPaletteCodes[sColorCode]) {
				sColorValue=arrPaletteCodes[sColorCode];
			}
			if (sColorValue.length) {
				var oCurrColorBox=document.getElementById(s_amg_CurrColorbox);
				if (oCurrColorBox) {
					var oHiddBox=document.getElementById(s_amg_CurrColorbox+"_code");
					if (oHiddBox) oHiddBox.value=sColorCode;
					amg_HideColorBox();
					oCurrColorBox.style.backgroundColor=sColorValue;
				}
			}
		}
	}
}

function amg_FixColorBox() {
	if (o_amg_TimerColorbox) window.clearTimeout(o_amg_TimerColorbox);
	var oToEl=event.toElement;
	var oFooter=document.getElementById("amg_poptab_ftr");
	if (oToEl && ((oToEl.id && oToEl.id.substr(0,1)=="%") || (oToEl.parentNode.id && oToEl.parentNode.id.substr(0,1)=="%"))) {
		if (oFooter) {
			if (oToEl.id && oToEl.id.substr(0,1)=="%") {
				var sColorCode=oToEl.id;
			} else if (oToEl.parentNode.id && oToEl.parentNode.id.substr(0,1)=="%") {
				var sColorCode=oToEl.parentNode.id;
			}
			var sColorNum=sColorCode.substr(0, (sColorCode.length-1)).substr(2);
			var sColorValue="";
			if (arrPaletteCodes[sColorCode]) {
				sColorValue=arrPaletteCodes[sColorCode];
			}
			if (sColorNum.length) {
				if (sColorValue.length) {
					oFooter.innerHTML="#"+sColorNum+"("+sColorValue+")"+"&nbsp;";
				} else {
					oFooter.innerHTML="#"+sColorNum+"&nbsp;";
				}
			} else {
				oFooter.innerHTML="default"+"&nbsp;";
			}
		}
	} else {
		if (oFooter) oFooter.innerHTML="&nbsp;";
	}
}

function amg_HiddColorBox() {
	var oToEl=event.toElement;
	if (!oToEl) {
		amg_HideColorBox();
	} else {
		var sToEl=oToEl.id;
		var sToElPar="";
		var oToElPar=oToEl.parentElement;
		if (oToElPar) sToElPar=oToElPar.id;
		if (sToEl||sToElPar) {
			if ((sToEl.substr(0,11)!="amg_poptab_")&&(sToElPar.substr(0,11)!="amg_poptab_")) amg_HideColorBox();
		} else {
			amg_HideColorBox();
		}
	}
}

function amg_HideColorBox() {
	s_amg_CurrColorbox="";
	var theColorCtrl=document.getElementById("amg_poptab_color64");
	if (theColorCtrl) {
		theColorCtrl.style.left=-1000;
		theColorCtrl.style.top=-1000;
		theColorCtrl.style.visibility="hidden";
		if (document.getElementById("amg_poptab_ftr")) document.getElementById("amg_poptab_ftr").innerHTML="";
		if (sCurrStripId) {
			var theNextF=document.forms[sCurrStripId.replace('strip_','form_')];
			if (theNextF) {
				var iJ=0;
				for (iJ=0; iJ<theNextF.elements.length; iJ++) {
					var theFEl=theNextF.elements[iJ];
					if (theFEl.tagName.toUpperCase()=="SELECT") theFEl.style.visibility="visible";
				}
			}
		}
	}
}

function amg_ShowColorBox(sBoxId) {
	var theColorCtrl=document.getElementById("amg_poptab_color64");
	var theBox=document.getElementById(sBoxId);
	if (theColorCtrl&&theBox) {
		s_amg_CurrColorbox=sBoxId;
		window.clearTimeout(o_amg_TimerColorbox);
		o_amg_TimerColorbox=null;
		o_amg_TimerColorbox=window.setTimeout("amg_HideColorBox()",1500);
		theColorCtrl.style.left=absLeft(theBox);
		theColorCtrl.style.top=absTop(theBox);//+theBox.offsetHeight;
		if ((parseInt(theColorCtrl.style.top)+theColorCtrl.offsetHeight)>document.body.clientHeight+document.body.scrollTop) {
			theColorCtrl.style.top=absTop(theBox)+theBox.offsetHeight-theColorCtrl.offsetHeight;
		}
		theColorCtrl.style.visibility="visible";
	}
}

function amg_OnColorBoxChange(sBoxName, sRepresName, bDontFirst, bDontNexts) {
	if (!bDontFirst) bDontFirst=false;
	if (!bDontNexts) bDontNexts=false;
	//
	if (!sRepresName) {
		if (sBoxName.substr(0,1)=="f") {
			var sRepresName=sBoxName.replace('fcolor_','repres_');
		} else if (sBoxName.substr(0,2)=="bg") {
			var sRepresName=sBoxName.replace('bgcolor_','repres_');
		} else if (sBoxName.substr(0,1)=="b") {
			var sRepresName=sBoxName.replace('bcolor_','repres_');
		} else {
			var sRepresName=sBoxName.replace('color_','repres_');
		}
	}
	sBoxButtName=sBoxName;//+"_butt";
	oColorBox=document.getElementById(sBoxButtName);
	var sNewColor=oColorBox.style.backgroundColor;
	oRepresentation=document.getElementById(sRepresName);
	if ((!bDontFirst)&&oColorBox&&oRepresentation) {
		if (sBoxName.substr(0,1)=="f") {
			oRepresentation.style.color=sNewColor;
		} else if (sBoxName.substr(0,2)=="bg") {
			oRepresentation.style.backgroundColor=sNewColor;
		} else if (sBoxName.substr(0,1)=="b") {
			oRepresentation.style.borderColor=sNewColor;
		} else {
			oRepresentation.style.backgroundColor=sNewColor;
		}
	}
	if ((!bDontNexts)&&sRepresName=="repres_tpl_hborder") {
		var i=0;
		for (i=1; i<4; i++) {
			oRepresentation=document.getElementById(sRepresName+"_"+i);
			if (oRepresentation) oRepresentation.style.backgroundColor=sNewColor;
		}
	}
	if ((!bDontNexts)&&sRepresName=="repres_tpl_vborder") {
		var i=0;
		for (i=1; i<2; i++) {
			oRepresentation=document.getElementById(sRepresName+"_"+i);
			if (oRepresentation) oRepresentation.style.backgroundColor=sNewColor;
		}
	}
	if (!bDontNexts) {
		var iTmp=1;
		for (iTmp=1;iTmp<4;iTmp++) {
			oRepresentation=document.getElementById(sRepresName+"_"+iTmp);
			if (oRepresentation) {
				if (sBoxName.substr(0,1)=="f") {
					oRepresentation.style.color=sNewColor;
				} else if (sBoxName.substr(0,2)=="bg") {
					oRepresentation.style.backgroundColor=sNewColor;
				} else if (sBoxName.substr(0,1)=="b") {
					oRepresentation.style.borderColor=sNewColor;
				} else {
					oRepresentation.style.backgroundColor=sNewColor;
				}
			}
		}
	}
}

function amg_OnColorBoxEdit(sBaseName) {
	var theColorText=document.getElementById(sBaseName);
	var theColorButt=document.getElementById(sBaseName+"_butt");
	if (theColorText&&theColorButt) {
		var sColor=theColorText.value;
		if (sColor.substr(0,1)!="#") sColor="#"+sColor;
		if (sColor.length>7) sColor=sColor.substr(0,7);
		if (sColor.length==7) {
			theColorText.value=sColor;
			theColorButt.style.backgroundColor=theColorText.value;
		}
	}
}