﻿// JScript File

var UsrArg=false;
var UsrEdt=false;
var RStDef=true;

var NumRow=0;
var NumCol=0;
var SplCod=0;

var MnuDsp=false;
var MnuFoc=false;
var MnuSel=0;
var MnuTmr;
var MnuTOt=0;

var MstGry=false;

function SetAoE(Sel)
{
	if (Sel==0)
  {
		Bgd="";
		UsrArg=false; UsrEdt=false;
		document.getElementById("ISlZon").style.display="";
		document.getElementById("CSlZon").style.display="";
		document.getElementById("txtILsHdr").style.display="";
		document.getElementById("divArgStd").style.display="none";
		document.getElementById("divArgSgl").style.display="none";
		document.getElementById("divArgDbl").style.display="none";
		document.getElementById("divEdtInt").style.display="none";  
		document.getElementById("divArgHdr").style.display="none";
		document.getElementById("divEdtHdr").style.display="none";  
  }
	if (Sel==1)
	{
	  UsrArg=true; UsrEdt=false;
	  document.getElementById("divEdtHdr").style.display="none";  
		document.getElementById("divArgHdr").style.display="";
		if (SupArg==1) 
		{
			document.getElementById("PCtZon").style.display="";
			document.getElementById("divArgStd").style.display="none";
			document.getElementById("divArgSgl").style.display="";
			document.getElementById("divArgDbl").style.display="none";
			document.getElementById("divLOtOpt").style.display="none";
			document.getElementById("divLOtSgl").style.display="";
			document.getElementById("divLOtFaB").style.display="none";
		}
		if (SupArg==2) 
		{
			document.getElementById("PCtZon").style.display="";
			document.getElementById("divArgStd").style.display="";
			document.getElementById("divArgSgl").style.display="none";
			document.getElementById("divArgDbl").style.display="none";
			document.getElementById("divLOtOpt").style.display="";
			document.getElementById("divLOtSgl").style.display="none";
			document.getElementById("divLOtFaB").style.display="none";
		}
		if (SupArg==3)
		{
			document.getElementById("PCtZon").style.display="none";
		  document.getElementById("divArgStd").style.display="none";
		  document.getElementById("divArgSgl").style.display="none";
		  document.getElementById("divArgDbl").style.display="";
			document.getElementById("divLOtOpt").style.display="none";
			document.getElementById("divLOtSgl").style.display="none";
			document.getElementById("divLOtFaB").style.display="";
		}
		document.getElementById("divEdtInt").style.display="none";
		document.getElementById("divPCtBlk").style.display="none";  
		document.getElementById("ISlZon").style.display="";
		document.getElementById("CSlZon").style.display="";
		document.getElementById("txtILsHdr").style.display="";
		if (SimOpt==1)
		{
			document.getElementById("CSlZon").style.display="none";
		}
	}
	if (Sel==2)
	{
	  UsrArg=false; UsrEdt=true;
	  document.getElementById("divArgStd").style.display="none";
	  document.getElementById("divArgSgl").style.display="none";
	  document.getElementById("divArgDbl").style.display="none";
		document.getElementById("divEdtInt").style.display="";
		document.getElementById("divArgHdr").style.display="none";
		document.getElementById("divEdtHdr").style.display="";  
		if (FmtTyp==1) document.getElementById("imgEdtTtl").src=PLbPth+"ESdTtl.jpg";
		if (FmtTyp==2) document.getElementById("imgEdtTtl").src=PLbPth+"ELmTtl.jpg";
		if (FmtTyp==3) document.getElementById("imgEdtTtl").src=PLbPth+"EPrTtl.jpg";
		if (SupArg==3) document.getElementById("divLOtFaB").style.display="";		
	  else					 document.getElementById("divLOtFaB").style.display="none";		
		document.getElementById("divPCtBlk").style.display="none";  	
		document.getElementById("ISlZon").style.display="none";
		document.getElementById("DelZon").style.display="none";
		document.getElementById("CSlZon").style.display="none";
		document.getElementById("txtILsHdr").style.display="none";
	}
	EdtGrd(0,PanLst[0].IIx);
	return false;
}

function DspCtl()
{
	document.getElementById("ISlZon").style.display="none";
	document.getElementById("CSlZon").style.display="none";
	document.getElementById("PCtZon").style.display="none";
	document.getElementById("DelZon").style.display="none";
	document.getElementById("divPCtBlk").style.display="none";
	document.getElementById("txtILsHdr").style.display="none";
	document.getElementById("cmdRotPrd").style.display="none";
	if (AlwMlt)
	{
		document.getElementById("ISlZon").style.display="";
		document.getElementById("DelZon").style.display="";
		document.getElementById("txtILsHdr").style.display="";
		if (ActSec==2)
		{
			document.getElementById("DelZon").style.display="";
		}	
		if (ActSec==3)
		{
			document.getElementById("PCtZon").style.display="";
			document.getElementById("CSlZon").style.display="";
			if (SupOrn=="B") document.getElementById("cmdRotPrd").style.display="";
		}
	}
	else
	{
		document.getElementById("divPCtBlk").style.display="none";	
	}
	return false;
}

function RotPrd()
{
  var Orn;
  var Nam;
	RStDef=true;
  BrdIDN=0;
  RStDef=true;
  if (PrdOrn=="V") PrdOrn="H"; else PrdOrn="V";
	CfgOrn(PrdOrn);
	BldPan(NumRow,NumCol,SplCod);
	ShwBrd(true);
	LodRes(1);
	UpdTxt();
	RStPos();
	SetUpd(1);
	SndDsn();
	return false;
}

function SelSid(Sel)
{
  if (Sel==1) { GryBut("cmdSelFrn",false); GryBut("cmdSelBck",true);  }
  if (Sel==2) { GryBut("cmdSelFrn",true);  GryBut("cmdSelBck",false); }
	PrdSid=Sel;
	PanSel=Sel-1;
	UpdPnd=true;
	BldPan(1,2,0);
	if (ActSec==4 || ActSec==6 || ActSec==7 || ActSec==8) DspPrd();
	return false;
}

function BldPan(NRw,NCl,Spl)
{
	var Tbl=document.getElementById("tblMltImg");	
	var Bdy=document.createElement('tbody'); 
	var Row;
	var Cel;
	var Div;
	var Cvs;
	var CTx;
	var PIx=0;
	var RIx=0;
	var CIx=0;
	var IIx=0;
	var DWd=0;
	var DHt=0;
	var XPs=0;
	var YPs=0;
	var PCt=0;
	var SDf=false;
	var Brd="";
	var Orn=PrdOrn;
	if (Orn=="N") Orn="V";
	PanOvr=99;
	PCt=NRw*NCl;
	SetUpd(1);
	if (SupArg==3)
	{
		document.getElementById("colLOtOpt").innerHTML="";
	}
	else
	{
		if (Orn=="V") document.getElementById("colLOtOpt").innerHTML="Vertical Layout Options";
		if (Orn=="H") document.getElementById("colLOtOpt").innerHTML="Horizontal Layout Options";
	}
	document.getElementById("cmdPanSgl").src="Images/ImgMnu/GEN/Ar1"+Orn+"Nm.jpg";
	document.getElementById("cmdPan1x1").src="Images/ImgMnu/GEN/Ar1"+Orn+"Nm.jpg";
	document.getElementById("cmdPan1x2").src="Images/ImgMnu/GEN/Ar2"+Orn+"Nm.jpg";
	document.getElementById("cmdPan3S1").src="Images/ImgMnu/GEN/Ar3"+Orn+"Nm.jpg";
	document.getElementById("cmdPan2x2").src="Images/ImgMnu/GEN/Ar4"+Orn+"Nm.jpg";
	switch (PCt)
	{
		case 1:
			document.getElementById("cmdPan1x1").src="Images/ImgMnu/GEN/Ar1"+Orn+"Sl.jpg";
		  break;
		case 2:
			document.getElementById("cmdPan1x2").src="Images/ImgMnu/GEN/Ar2"+Orn+"Sl.jpg";
			break;
		case 3:
			document.getElementById("cmdPan3S1").src="Images/ImgMnu/GEN/Ar3"+Orn+"Sl.jpg";
			break;
		case 4:
		  if (Spl==0)	document.getElementById("cmdPan2x2").src="Images/ImgMnu/GEN/Ar4"+Orn+"Sl.jpg";
		  if (Spl==1)
		  {
				document.getElementById("cmdPan3S1").src="Images/ImgMnu/GEN/Ar3"+Orn+"Sl.jpg";
		  }
		  break;
	}
	if (NumRow!=NRw || NumCol!=NCl || SplCod!=Spl || RStDef) 
	{
		SDf=true;
		NumRow=NRw;
		NumCol=NCl;
		if (NumRow>1 || NumCol>1) 
		{
			BrdIDN=0;
			BrdDsc="";
			RStDef=true;
			AlwBrd=false; 
			DspCtl();
		}
		else AlwBrd=true;
	}
	SplCod=Spl;
	if (SDf) 
	{
		for (PIx=0; PIx<PCt; PIx++)
		{
			PanLst[PIx]=new Object;
			PanLst[PIx].Vis=true;
			PanLst[PIx].RLd=true;
			PanLst[PIx].CSp=1;
			PanLst[PIx].RSp=1;
			PanLst[PIx].OWd=0;
			PanLst[PIx].OHt=0;
			PanLst[PIx].BCl=0;
		}
	}
	if (Spl==1)
	{
	  if (PrdOrn=="V")
	  {
			PanLst[0].CSp=2;
			if (PCt>1) PanLst[1].Vis=false;
		}
		if (PrdOrn=="H")
		{
			PanLst[0].RSp=2;
			if (PCt>2) PanLst[2].Vis=false;
		}
	}
	RStILs();
	while (Tbl.rows.length>0) Tbl.deleteRow(0);
	XPs=GetXPs("tblMltImg")
  YPs=GetYPs("tblMltImg")
  PIx=0;
	for (RIx=0; RIx<NumRow; RIx++)
	{
		Row=document.createElement("tr");
		for (CIx=0; CIx<NumCol; CIx++)
		{
			PanLst[PIx].IIx=99;
		  if (PanLst[PIx].Vis)
		  {
				CalOpn(PIx);
				Brd="";
				if (CIx>0) Brd+=" border-left: white 1px dotted; "
				if (RIx>0) Brd+=" border-top: white 1px dotted; "
				if (BrwNam=="IE" && (BrwVer==6 || BrwVer==7))
				{
					Cel=document.createElement('<td colspan="'+PanLst[PIx].CSp+'" rowspan="'+PanLst[PIx].RSp+'" style="width: '+PanLst[PIx].OWd+'px; height: '+PanLst[PIx].OHt+'px; ' + Brd + '" onclick="SelPan('+PIx+')" onmouseover="SelMnu('+PIx+')" onmouseout="RlsMnu(0)">');
					Div=document.createElement('<div id="divPan'+PIx+'" style="background-color: black; position: relative; overflow: hidden; width: '+PanLst[PIx].OWd+'px; height: '+PanLst[PIx].OHt+'px">');				
				}
				else
				{
					Cel=document.createElement("td");
					Cel.setAttribute("style","width: "+PanLst[PIx].OWd+"px; height: "+PanLst[PIx].OHt+"px; " + Brd);
					Cel.setAttribute("colspan",PanLst[PIx].CSp);
					Cel.setAttribute("rowspan",PanLst[PIx].RSp);
					Cel.setAttribute("onclick","SelPan("+PIx+")");
					Cel.setAttribute("onmouseover","SelMnu("+PIx+")");
					Cel.setAttribute("onmouseout","RlsMnu(0)");
					Div=document.createElement('div');
					Div.setAttribute("style","background-color: black; position: relative; overflow: hidden; width: "+PanLst[PIx].OWd+"px; height: "+PanLst[PIx].OHt+"px");
					Div.setAttribute("id","divPan"+PIx);
					if (BrwNam!="IE")
					{
						Cvs=document.createElement('canvas');
						Cvs.setAttribute("id","canPan"+PIx);
						Cvs.setAttribute("width",PanLst[PIx].OWd);
						Cvs.setAttribute("height",PanLst[PIx].OHt);
						Cvs.setAttribute("style","display: none;");
						CTx=Cvs.getContext("2d");
					}
				}
				PanLst[PIx].Div="divPan"+PIx;
				PanLst[PIx].Cvs=Cvs;
				PanLst[PIx].CTx=CTx;
				PanLst[PIx].XPs=CIx*PanLst[PIx].OWd;
				PanLst[PIx].YPs=RIx*PanLst[PIx].OHt;
				PanLst[PIx].Img=new Image(PanLst[PIx].OWd,PanLst[PIx].OHt);
				PanLst[PIx].Img.alt="";
				PanLst[PIx].Img.style.display="none";
				for (IIx=0; IIx<ImgCnt; IIx++)
				{
					if (ImgLst[IIx].PIx==PIx && PanLst[PIx].IIx==99)
					{
						PanLst[PIx].IIx=IIx;
						if (BrwNam=="IE")	PanLst[PIx].Img.style.display="";
						else							PanLst[PIx].Cvs.style.display="";
					}
				}
				if (PIx==0 && PanLst[PIx].IIx==99 && ImgCnt>0)
				{
					PanLst[PIx].IIx=0;
					if (BrwNam=="IE")	PanLst[PIx].Img.style.display="";
					else							PanLst[PIx].Cvs.style.display="";
				}
				if (BrwNam=="IE")
				{
					Div.appendChild(PanLst[PIx].Img);
				}
				else
				{
					Div.appendChild(Cvs);
				}
				Cel.appendChild(Div);
				Row.appendChild(Cel);
				if (SDf || RStDef) CalDef(PIx,PanLst[PIx].IIx,false);
				DspPan(PIx,true)
			}
			PIx++
		}
		Bdy.appendChild(Row);	
		Tbl.appendChild(Bdy);		
	}
	RStDef=false;
	CfgSec();
	return false;
}

function CalOpn(PIx)
{
  var Scl=0;
  var IIx=0;
  var Pt1;
  var Pt2;
  var Pt3;
  var XPs;
  var YPs;
  var Wid;
  var Hgt;
  var Mlt=1;
  var Tpl=document.getElementById("divMltTpl");
  var Top=document.getElementById("colTplTop");
  var Lft=document.getElementById("colTplLft");
  var Rgt=document.getElementById("colTplRgt");
  var Bot=document.getElementById("colTplBot");
  var Ctr=document.getElementById("colMltImg");
  if (BrdIDN>0) PrdOrn=BrdOrn; 
  else
  {
		if (PrdOrn=="N") CfgOrn(PrdOrn);
  }
  Scl=CalDsp();
  if (Scl>0)
  {
		if (BrdIDN>0 && BrdILs!=null) // Border
		{
		  if (BrdSCd=="S16") Mlt=2;
		  Pt1=BrdILs.Pt1.split(",");
			Pt2=BrdILs.Pt2.split(",");
			Pt3=BrdILs.Pt3.split(",");
			Tpl.style.width=DspWid+"px";
			Tpl.style.height=DspHgt+"px";
			Wid=parseInt((BrdILs.Wid/Mlt)/Scl+0.5);
			Hgt=parseInt((BrdILs.Hgt/Mlt)/Scl+0.5);
			Top.style.height=parseInt(DecTWd+(((1*Pt1[1])/Mlt)/Scl)+0.5)+"px";
			Lft.style.width =parseInt(DecLWd+(((1*Pt1[0])/Mlt)/Scl)+0.5)+"px";
			Ctr.style.width =Wid+"px";
			Ctr.style.height=Hgt+"px";
		}
		else
		{
			Tpl.style.width=DspWid+"px";
			Tpl.style.height=DspHgt+"px";
			Wid=DspWid-(DecLWd+DecRWd);
			Hgt=DspHgt-(DecTWd+DecBWd);
			Top.style.height=DecTWd+"px";
			Lft.style.width=DecLWd+"px";
			Ctr.style.width=Wid+"px";
			Ctr.style.height=Hgt+"px";
		}
		if ((NumRow==1 && NumCol==2) || (NumRow==2 && NumCol==1))
		{
			if (PrdOrn=="V")
			{
				NumRow=2;
				NumCol=1;
			}
			if (PrdOrn=="H")
			{
				NumRow=1;
				NumCol=2;
			}
		}
		if (SupArg==0 || SupArg==1 || SupArg==2)
		{
			PanLst[PIx].OWd=(Wid/NumCol)*PanLst[PIx].CSp; PanLst[PIx].WWd=PanLst[PIx].OWd;
			PanLst[PIx].OHt=(Hgt/NumRow)*PanLst[PIx].RSp; PanLst[PIx].WHt=PanLst[PIx].OHt;
		}
		if (SupArg==3)
		{
			if (PrdSid==0 || PrdSid==PIx+1) 
			{
				PanLst[PIx].OWd=Wid;
				PanLst[PIx].OHt=Hgt;
			}
			else 
			{
				PanLst[PIx].OWd=0;
				PanLst[PIx].OHt=0;
			}
			PanLst[PIx].WWd=Wid;
			PanLst[PIx].WHt=Hgt;
		}
	}
	else
	{
		PanLst[PIx].OWd=0;
		PanLst[PIx].OHt=0;
	}
}

function CalDef(PIx,IIx,Clr)
{
  var IWd=0;
  var IHt=0;
  var DWd=0;
  var DHt=0;
  var Orn="";
  if (IIx!=99 && PanLst.length>0)
  {
    PanLst[PIx].RLd=true;
    if (Clr) RStDef=false;
		IWd=ImgLst[IIx].IWd;
		IHt=ImgLst[IIx].IHt;
		if (PanLst[PIx].OHt>0 && PanLst[PIx].OWd>0)
		{
			if ((IHt/IWd)<(PanLst[PIx].OHt/PanLst[PIx].OWd))
			{
				DHt=PanLst[PIx].OHt;
				DWd=PanLst[PIx].OHt*(IWd/IHt)
			}
			else
			{
				DWd=PanLst[PIx].OWd;
				DHt=PanLst[PIx].OWd*(IHt/IWd)
			}
			ImgLst[IIx].DWd=DWd;
			ImgLst[IIx].DHt=DHt;
			if (ImgLst[IIx].Rot==0 || ImgLst[IIx].Rot==2)
			{
				ImgLst[IIx].XPs=Math.round((DWd-PanLst[PIx].OWd)/2); 
				ImgLst[IIx].YPs=Math.round((DHt-PanLst[PIx].OHt)/2);
			}
			if (ImgLst[IIx].Rot==1 || ImgLst[IIx].Rot==3)
			{
				ImgLst[IIx].XPs=Math.round((DHt-PanLst[PIx].OWd)/2); 
				ImgLst[IIx].YPs=Math.round((DWd-PanLst[PIx].OHt)/2); 
			}
		}
		if (PrdOrn=="N")
		{
			if (IWd>=IHt) Orn="H"; else Orn="V"
			CfgOrn(Orn);
		}
	}
}

function CfgOrn(Orn)
{
  var Scl=1;
  var DIx=0;
  var IWd=0;
  var IHt=0;
  if (SupOrn!="B") Orn=SupOrn;
  if (Orn=="N")
  {
		if (ImgLst.length>0)
		{
			IWd=ImgLst[ImgIdx].IWd;
			IHt=ImgLst[ImgIdx].IHt;		
			if (IWd>=IHt) Orn="H"; else Orn="V"
		}
  }
  PrdOrn=Orn;
  if (BrdIDN==0) BrdOrn=PrdOrn;
  CalDsp();
  OrgImg=document.getElementById("imgDspWrk");
	OrgImg.width=DspWid;
	if (PrdOrn=="V") document.getElementById("PCtZon").style.width="355px";
	if (PrdOrn=="H") document.getElementById("PCtZon").style.width="355px";
	return Orn;
}

function CalDsp()
{
  var DIx=0;
  var Scl=0;
	if (PrdOrn=="V")
	{
	  DspWid=300;
		PrdWid=PrdSml;
		PrdHgt=PrdLrg;
		DIx=0;
	}
	if (PrdOrn=="H")
	{
	  DspWid=375;
		PrdWid=PrdLrg;
		PrdHgt=PrdSml;
		DIx=1;
	}
	if (PrdWid>0 && PrdHgt>0 && DspWid>0)
	{
		FulWid=(1*PrdWid)+(1*DecWid[DIx].LWd)+(1*DecWid[DIx].RWd);
		FulHgt=(1*PrdHgt)+(1*DecWid[DIx].TWd)+(1*DecWid[DIx].BWd);
		DspHgt=DspWid*(FulHgt/FulWid);
		if (DspHgt>350)
		{
			DspHgt=350;
			DspWid=DspHgt*(FulWid/FulHgt);
		}
		Scl=FulWid/DspWid;
		DecLWd=DecWid[DIx].LWd/Scl;
		DecRWd=DecWid[DIx].RWd/Scl;
		Scl=FulHgt/DspHgt;
		DecTWd=DecWid[DIx].TWd/Scl;
		DecBWd=DecWid[DIx].BWd/Scl;
		MrgAWd=Math.round((PrdLrg/(4*InsLrg)));
		MrgWid=Math.round((PrdLrg/(4*InsLrg))/Scl);
	}
	return Scl;
}

function ShwBrd(Vis)
{
	var BIm=document.getElementById("imgBrdImg");
	var Orn=PrdOrn;
  if (Vis)
  {
		if (PosBrd())
		{
			if (BrdIDN>0)	Orn=BrdOrn;		
			if (Orn!="N")
			{
				if (BrdIDN>0)	BIm.src="LodImg.ashx?ImgFNm=Borders/Edit/BR"+PadNum(BrdIDN,6)+"_"+DecTyp+".GIF";
				else					BIm.src="BldBrd.ashx?ImgOrn=" + Orn + "&SizCod=" + SizCod + "&DecTyp=" + DecTyp + "&PrdWid=" + PrdWid + "&PrdHgt=" + PrdHgt;		
				BIm.style.display="";
			}
			else BIm.style.display="none";
		}
		else BIm.style.display="none";
	}
	else BIm.style.display="none";
}

function PosBrd(BIm)
{
	var Ret=false;
	var Tpl=document.getElementById("divMltTpl");
	var BIm=document.getElementById("imgBrdImg");
	var XPs;
  var YPs;
  if (Tpl.style.width>"")
  {
    Ret=true;
		XPs=GetXPs("divMltTpl");
		YPs=GetYPs("divMltTpl");
		BIm.style.left=XPs+"px";
		BIm.style.top=YPs+"px";
		BIm.style.width=Tpl.style.width;
		BIm.style.height=Tpl.style.height;
	}
	return Ret;
}

function SelPan(SNm)
{
	PanSel=1*SNm;
	return false;
}

function MnuMou()
{
  MnuFoc=true; clearTimeout(MnuTOt);
}

function SelMnu(PIx)
{
	var XPs=0;
  var YPs=0;
  if (PIx==99) PIx=PanOvr;
  if (PIx!=99)
  {
		if (UsrEdt && PanLst[PIx].IIx!=99)
		{
			if (!MnuDsp || PIx!=PanSel)
			{
				PanSel=PIx;
				EdtGrd(PIx,PanLst[PIx].IIx);
				XPs=GetXPs("tblMltImg")
				YPs=GetYPs("tblMltImg")
				if (SupArg!=3)
				{
					XPs+=PanLst[PIx].XPs;
					YPs+=PanLst[PIx].YPs;
				}
				document.getElementById("divImgMnu").style.opacity=0.8;
				document.getElementById("divImgMnu").style.filter="alpha(opacity=80)";
				document.getElementById("divImgMnu").style.left  =XPs + "px";
				document.getElementById("divImgMnu").style.top   =YPs + "px";
				document.getElementById("divImgMnu").style.width =PanLst[PIx].OWd + "px";
				document.getElementById("divImgMnu").style.height=PanLst[PIx].OHt + "px";
				document.getElementById("colIMnSp1").style.height=(PanLst[PIx].OHt-102)/2 + "px";
				document.getElementById("colIMnSp2").style.height=(PanLst[PIx].OHt-102)/2 + "px";
				document.getElementById("divImgMnu").style.display="";	
			}
			MnuDsp=true; clearTimeout(MnuTOt);
		}
	}
	return false;
}

function RlsMnu(Sel)
{
  if (Sel==0) MnuDsp=false;
  if (Sel==1) MnuFoc=false;
  clearInterval(MnuTmr);
  if (!MnuDsp && !MnuFoc) MnuTOt=setTimeout("ClsMnu()",100); else clearTimeout(MnuTOt);
	return false;
}

function ClsMnu()
{
	if (!MnuDsp && !MnuFoc) document.getElementById("divImgMnu").style.display="none";	
}

function MnuPrc(Sel,Act)
{
  var PIx=PanSel;
	var IIx=PanLst[PIx].IIx;
	SetUpd(1);
	MnuSel=Sel;
	if (Act==2 || Act==3)
	{
		if (Sel==1)  // Rotate
		{
			if (ImgLst[IIx].Rot<3) ImgLst[IIx].Rot++; else ImgLst[IIx].Rot=0; 
			CalDef(PIx,IIx,true);
			DspPan(PIx,false);
		}
		if (Sel==2 || Sel==4 || Sel==5 ||Sel==6 ||Sel==7 || Sel==8)  // Pan/Zoom
		{
			if (Act==2) MnuTmr=setInterval("RunMnu()",50);
			if (Act==3) clearInterval(MnuTmr);
		}
		if (Sel==3)  // Toggle Grayscale Filter
		{
			if (ImgLst[IIx].Gry) ImgLst[IIx].Gry=false; else ImgLst[IIx].Gry=true;
			DspPan(PIx,true);
		}
		if (Sel==9)  // Default Settings
		{
		  ImgLst[IIx].Rot=0;
			CalDef(PIx,IIx,true);
			DspPan(PIx,true);
		}
	}
	return false;
}

function RunMnu()
{
  var IIx=PanLst[PanSel].IIx;
  var Inc=ImgLst[IIx].DWd/200;
  if (Inc<=0) Inc=1;
  switch (MnuSel)
  {
  case 2: 
		ImgLst[IIx].YPs+=Inc; 
		break;
  case 4: 
		ImgLst[IIx].XPs+=Inc; 
		break;
  case 5: 
		ImgLst[IIx].XPs-=Inc; 
		break;
  case 6: 
		ImgLst[IIx].DWd+=4*Inc;
		ImgLst[IIx].DHt=ImgLst[IIx].DWd*(ImgLst[IIx].IHt/ImgLst[IIx].IWd);  
		ImgLst[IIx].XPs+=2*Inc;
		ImgLst[IIx].YPs+=2*Inc*(ImgLst[IIx].IHt/ImgLst[IIx].IWd);  
    break;
  case 7: 
		ImgLst[IIx].YPs-=Inc; 
		break;
  case 8:
		ImgLst[IIx].DWd-=4*Inc;
		ImgLst[IIx].DHt=ImgLst[IIx].DWd*(ImgLst[IIx].IHt/ImgLst[IIx].IWd);  
		ImgLst[IIx].XPs-=2*Inc
		ImgLst[IIx].YPs-=2*Inc*(ImgLst[IIx].IHt/ImgLst[IIx].IWd);  
    break;
  }
  DspPan(PanSel,false);
  EdtGrd(PanSel,IIx);
}

function SetGry(Sel)
{
	var IIx=0;
	var PIx=0;
	if (Sel==1) MstGry=true; else MstGry=false;
	for (IIx=0; IIx<ImgLst.length; IIx++)
	{
	  ImgLst[IIx].Gry=MstGry;
	}
	GryRdo(Sel)
	for (PIx=0; PIx<PanLst.length; PIx++)
	{
		DspPan(PIx,false);	
	}
	SetUpd(1);
	return false;
}

function GryRdo(Sel)
{
	if (Sel==0)
	{
	  MstGry=false;
		document.getElementById("rdoArgCol").src=GLbPth+"ColSel.gif";
		document.getElementById("rdoArgGry").src=GLbPth+"GryNon.gif";
		document.getElementById("rdoASgCol").src=GLbPth+"ColSel.gif";
		document.getElementById("rdoASgGry").src=GLbPth+"GryNon.gif";
		document.getElementById("rdoADbCol").src=GLbPth+"ColSel.gif";
		document.getElementById("rdoADbGry").src=GLbPth+"GryNon.gif";
		document.getElementById("rdoEdtCol").src=GLbPth+"ColSel.gif";
		document.getElementById("rdoEdtGry").src=GLbPth+"GryNon.gif";
	}
	else
	{
	  MstGry=true;
		document.getElementById("rdoArgCol").src=GLbPth+"ColNon.gif";
		document.getElementById("rdoArgGry").src=GLbPth+"GrySel.gif";
		document.getElementById("rdoASgCol").src=GLbPth+"ColNon.gif";
		document.getElementById("rdoASgGry").src=GLbPth+"GrySel.gif";
		document.getElementById("rdoADbCol").src=GLbPth+"ColNon.gif";
		document.getElementById("rdoADbGry").src=GLbPth+"GrySel.gif";
		document.getElementById("rdoEdtCol").src=GLbPth+"ColNon.gif";
		document.getElementById("rdoEdtGry").src=GLbPth+"GrySel.gif";
	}
}

function SetDrg(IIx)
{
  var XPs=MouXPs-10;
  var YPs=MouYPs-10;
  var IXp=0;
  var IYp=0;
  var IWd=0;
  var IHt=0;
  SelILs(IIx);
  if (ActSec==3)
  {
    ImgDrg=true;
		IWd=100;
		IHt=IWd*(ImgLst[IIx].IHt/ImgLst[IIx].IWd);
		IXp=1;
		IYp=1;
		document.getElementById("imgDrgImg").style.left  =IXp + "px";
		document.getElementById("imgDrgImg").style.top   =IYp + "px";
		document.getElementById("imgDrgImg").style.width =IWd + "px";
		document.getElementById("imgDrgImg").style.height=IHt + "px";
		document.getElementById("divDrgImg").style.left  =XPs + "px";
		document.getElementById("divDrgImg").style.top   =YPs + "px";
		document.getElementById("divDrgImg").style.width =(IWd+2) + "px";
		document.getElementById("divDrgImg").style.height=(IHt+2) + "px";
		document.getElementById("divDrgImg").style.display="";
		document.getElementById("imgDrgImg").src=ImgLst[IIx].BIm.src;
	}
}

function SetCDg(Nam,Col)
{
	var XPs=MouXPs-10;
  var YPs=MouYPs-10;
  if (UsrArg)
  {
		ColDrg=true;
		BckCol=Col;
		document.getElementById("divDrgCol").style.left  =XPs+"px";
		document.getElementById("divDrgCol").style.top   =YPs+"px";
		document.getElementById("divDrgCol").style.display="";
		document.getElementById("divDrgCol").style.backgroundColor=document.getElementById(Nam).style.backgroundColor;
	}
}

function EndDrg()
{
  var BCl;
  var IIx;
  if (ImgDrg)
  {
    SetUpd(1);
    ImgDrg=false;
    document.getElementById("divDrgImg").style.display="none";
		if (PanOvr!=99)
	  {
			for (IIx=0; IIx<ImgCnt; IIx++) if (ImgLst[IIx].PIx==PanOvr) ImgLst[IIx].PIx=99;
	    PanLst[PanOvr].IIx=ImgIdx;
	    ImgLst[ImgIdx].PIx=PanOvr;
			ImgLst[ImgIdx].Rot=0;
			CalDef(PanOvr,ImgIdx,true);
			PanLst[PanOvr].RLd=true;
			DspPan(PanOvr,true);
		}
	}
	if (ColDrg)
	{
		SetUpd(1);
		ColDrg=false;
		document.getElementById("divDrgCol").style.display="none";
		if (PanOvr!=99)
	  {
			for (IIx=0; IIx<ImgCnt; IIx++) if (ImgLst[IIx].PIx==PanOvr) ImgLst[IIx].PIx=99;
			BCl=document.getElementById("divDrgCol").style.backgroundColor;
			document.getElementById(PanLst[PanOvr].Div).style.backgroundColor=BCl;
			PanLst[PanOvr].BCl=BckCol;
			PanLst[PanOvr].IIx=99;
			PanLst[PanOvr].RLd=true;
			DspPan(PanOvr,true);
		}
	}
	if (TxtDrg)
	{
		SndTxt();	
	}
	if (ArtDrg)
	{
		if (OvrAct) SavRIm(2,false);
		else				DelRIm(2);
	}
	if (WrdDrg)
	{
	  if (OvrAct) SavRIm(3,false);
		else				DelRIm(3);
	}
}

