﻿// 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;

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("divEdtInt").style.display="none";  
		document.getElementById("divArgHdr").style.display="none";
		document.getElementById("divEdtHdr").style.display="none";  
		document.getElementById("divALmHdr").style.display="none";
		document.getElementById("divELmHdr").style.display="none";
  }
	if (Sel==1)
	{
	  UsrArg=true; UsrEdt=false;
	  document.getElementById("divEdtHdr").style.display="none";  
		document.getElementById("divELmHdr").style.display="none";
		if (FmtTyp==1) 
		{
			document.getElementById("divArgHdr").style.display="";
			document.getElementById("divALmHdr").style.display="none";
			if (SupArg==1) 
			{
				document.getElementById("divArgStd").style.display="none";
				document.getElementById("divArgSgl").style.display="";
				document.getElementById("divLOtOpt").style.display="none";
				document.getElementById("divLOtSgl").style.display="";
			}
			if (SupArg==2) 
			{
				document.getElementById("divArgStd").style.display="";
				document.getElementById("divArgSgl").style.display="none";
				document.getElementById("divLOtOpt").style.display="";
				document.getElementById("divLOtSgl").style.display="none";
			}
		}
		if (FmtTyp==2) 
	  {
			document.getElementById("divArgSgl").style.display="";
		  document.getElementById("divArgHdr").style.display="none";
		  document.getElementById("divALmHdr").style.display="";
		}
		document.getElementById("divEdtInt").style.display="none";
		document.getElementById("divPCtBlk").style.display="none";  
		document.getElementById("ISlZon").style.display="";
		document.getElementById("CSlZon").style.display="";
		if (FmtTyp==1) 
		{
			document.getElementById("PCtZon").style.display="";
			document.getElementById("divImgDsc").style.display="none";
		}
		else					 
		{
			document.getElementById("PCtZon").style.display="none";	
			document.getElementById("divImgDsc").style.display="";	
		}
		document.getElementById("txtILsHdr").style.display="";
	}
	if (Sel==2)
	{
	  UsrArg=false; UsrEdt=true;
	  document.getElementById("divArgStd").style.display="none";
	  document.getElementById("divArgSgl").style.display="none";
		document.getElementById("divEdtInt").style.display="";
		document.getElementById("divArgHdr").style.display="none";
		document.getElementById("divALmHdr").style.display="none";
		if (FmtTyp==1) 
		{
			document.getElementById("divEdtHdr").style.display="";  
			document.getElementById("divELmHdr").style.display="none";
		}
		if (FmtTyp==2) 
	  {
			document.getElementById("divEdtHdr").style.display="none";  
			document.getElementById("divELmHdr").style.display="";
	  }
		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("PCtZon").style.display="none";
		document.getElementById("txtILsHdr").style.display="none";
		document.getElementById("divImgDsc").style.display="";	
	}
	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 && ImgCnt>0)
	{
		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="";	
	}
	return false;
}

function RotPrd()
{
  var Orn;
  var Nam;
	RStDef=true;
  if (BrdIDN==0)
  {
		if (PrdOrn=="V") PrdOrn="H"; else PrdOrn="V";
		CfgOrn(PrdOrn);
	}
	else
	{
	  Orn=BrdOrn;
	  if (Orn=="V") Orn="H"; else Orn="V";
	  Nam=BrdCtl+Orn;
	  if (document.getElementById(Nam)) document.getElementById(Nam).click();
	}
	BldPan(NumRow,NumCol,SplCod);
	ShwBrd(true);
	DspBDt();
	UpdTxt();
	RStPos();
	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";
	PanSel=0;
	PanOvr=99;
	PCt=NRw*NCl;
	document.getElementById("imgLOtOpt").src="Images/ImgMnu/LOtOp"+Orn+".jpg";
	document.getElementById("cmdPanSgl").src="Images/ImgMnu/Ar1"+Orn+"Nm.jpg";
	document.getElementById("cmdPan1x1").src="Images/ImgMnu/Ar1"+Orn+"Nm.jpg";
	document.getElementById("cmdPan1x2").src="Images/ImgMnu/Ar2"+Orn+"Nm.jpg";
	document.getElementById("cmdPan3S1").src="Images/ImgMnu/Ar3"+Orn+"Nm.jpg";
	document.getElementById("cmdPan2x2").src="Images/ImgMnu/Ar4"+Orn+"Nm.jpg";
	switch (PCt)
	{
		case 1:
			document.getElementById("cmdPan1x1").src="Images/ImgMnu/Ar1"+Orn+"Sl.jpg";
		  break;
		case 2:
			document.getElementById("cmdPan1x2").src="Images/ImgMnu/Ar2"+Orn+"Sl.jpg";
			break;
		case 3:
			document.getElementById("cmdPan3S1").src="Images/ImgMnu/Ar3"+Orn+"Sl.jpg";
			 break;
		case 4:
		  if (Spl==0)	document.getElementById("cmdPan2x2").src="Images/ImgMnu/Ar4"+Orn+"Sl.jpg";
		  if (Spl==1)
		  {
				document.getElementById("cmdPan3S1").src="Images/ImgMnu/Ar3"+Orn+"Sl.jpg";
		  }
		  break;
	}
	if (NumRow!=NRw || NumCol!=NCl || SplCod!=Spl) 
	{
		SDf=true;
		NumRow=NRw;
		NumCol=NCl;
		if (NumRow>1 || NumCol>1) 
		{
			BrdIDN=0;
			BrdCod="";
			BrdDsc="";
			RStDef=true;
			AlwBrd=false; 
			ShwBrd(true);
			DspCtl();
		}
		else AlwBrd=true;
	}
	SplCod=Spl;
	for (PIx=0; PIx<PCt; PIx++)
	{
		PanLst[PIx]=new Object;
		PanLst[PIx].Vis=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;
			PanLst[1].Vis=false;
		}
		if (PrdOrn=="H")
		{
			PanLst[0].RSp=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++)
	{
		if (BrwNam!="IE")	Row=document.createElement('tr')
		else							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")
				{
					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);
					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].BCl=0;
				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 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) // Border
		{
			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/Scl+0.5);
			Hgt=parseInt(BrdILs.Hgt/Scl+0.5);
			Top.style.height=parseInt(DecTWd+((1*Pt1[1])/Scl)+0.5)+"px";
			Lft.style.width=parseInt(DecLWd+((1*Pt1[0])/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;
			}
		}
		PanLst[PIx].OWd=(Wid/NumCol)*PanLst[PIx].CSp;
		PanLst[PIx].OHt=(Hgt/NumRow)*PanLst[PIx].RSp;
	}
	else
	{
		PanLst[PIx].OWd=0;
		PanLst[PIx].OHt=0;
	}
}

function CalDef(PIx,IIx,Clr)
{
  var IWd=0;
  var IHt=0;
  var Orn="";
  if (IIx!=99 && PanLst.length>0)
  {
    if (Clr) RStDef=false;
		IWd=ImgLst[IIx].IWd;
		IHt=ImgLst[IIx].IHt;
		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=(DWd-PanLst[PIx].OWd)/2; 
			ImgLst[IIx].YPs=(DHt-PanLst[PIx].OHt)/2; 
		}
		if (ImgLst[IIx].Rot==1 || ImgLst[IIx].Rot==3)
		{
			ImgLst[IIx].XPs=(DHt-PanLst[PIx].OWd)/2; 
			ImgLst[IIx].YPs=(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();
  WrkImg=document.getElementById("imgDspImg");
	WrkImg.width=DspWid;
	if (PrdOrn=="V") document.getElementById("PCtZon").style.width=355;
	if (PrdOrn=="H") document.getElementById("PCtZon").style.width=355;
	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=parseInt(DspWid*(FulHgt/FulWid)+0.5);
		if (DspHgt>350)
		{
			DspHgt=350;
			DspWid=parseInt(DspHgt*(FulWid/FulHgt)+0.5);
		}
		Scl=FulWid/DspWid;
		DecLWd=parseInt(DecWid[DIx].LWd/Scl+0.5);
		DecTWd=parseInt(DecWid[DIx].TWd/Scl+0.5);
		DecRWd=parseInt(DecWid[DIx].RWd/Scl+0.5);
		DecBWd=parseInt(DecWid[DIx].BWd/Scl+0.5);
		MrgWid=parseInt((PrdLrg/InsLrg)/Scl+0.5);
	}
	return Scl;
}

function ShwBrd(Vis)
{
	var BIm=document.getElementById("imgBrdImg");
	var Cod="";
  var Orn=PrdOrn;
  var Bgd=0;
  if (Vis)
  {
		PosBrd();	
		if (BrdIDN>0)			{ Cod=BrdCod; Orn=BrdOrn;		}
		if (BrdIDN>1000)	{	Bgd=BrdTLs[0].Bgd;				}
		if (Orn!="N")
		{
			BIm.src="BldBrd.ashx?BrdCod=" + Cod + "&BrdExt=" + BrdExt + "&ImgOrn=" + Orn + "&SizCod=" + SizCod + "&DecTyp=" + DecTyp + "&PrdWid=" + PrdWid + "&PrdHgt=" + PrdHgt + "&ImgTyp=1" + "&BrdBgd=" + Bgd;	
			BIm.style.display="";
		}
		else BIm.style.display="none";
	}
	else BIm.style.display="none";
}

function PosBrd(BIm)
{
	var Tpl=document.getElementById("divMltTpl");
	var BIm=document.getElementById("imgBrdImg");
	var XPs;
  var YPs;
  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 false;
}

function SelPan(SNm)
{
	PanSel=1*SNm;
	return false;
}

function MnuMou()
{
  MnuFoc=true; clearTimeout();
}

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")
				XPs+=PanLst[PIx].XPs;
				YPs+=PanLst[PIx].YPs;
				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();
		}
	}
	return false;
}

function RlsMnu(Sel)
{
  if (Sel==0) MnuDsp=false;
  if (Sel==1) MnuFoc=false;
  clearInterval(MnuTmr);
  if (!MnuDsp && !MnuFoc) setTimeout("ClsMnu()",100); else clearTimeout();
	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;
	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)  // Remove Image
		{
			PanLst[PIx].IIx=99;	
			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 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)
  {
    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);
			DspPan(PanOvr,true);
		}
	}
	if (ColDrg)
	{
		ColDrg=false;
		document.getElementById("divDrgCol").style.display="none";
		if (PanOvr!=99)
	  {
			BCl=document.getElementById("divDrgCol").style.backgroundColor;
			document.getElementById(PanLst[PanOvr].Div).style.backgroundColor=BCl;
			PanLst[PanOvr].BCl=BckCol;
			PanLst[PanOvr].IIx=99;
			DspPan(PanOvr,true);
		}
	}
	if (STxDrg)
	{
		if (!ChkCsr(1))
		{
		  if (STxIdx==0) document.getElementById("imgST1Img").style.display="none";
		  if (STxIdx==1) document.getElementById("imgST2Img").style.display="none";
		  STxNum[STxIdx]=0;
		  ShwPmt(true);
		}
	}
}
