//下面是用鼠标拖动图片的边框来调整图片的函数
//图片必须带有TABINDEX=*的属性，这样可以使图片获得焦点。
//在文件中应该包含下面几个Span对象，作为拖动点
//<span id="FocusBlock1"
//      style="position:absolute;
//      cursor:nw-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>
//
//<span id="FocusBlock2"
//      style="position:absolute;
//      cursor:n-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>
//
//<span id="FocusBlock3"
//      style="position:absolute;
//      cursor:ne-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>
//
//<span id="FocusBlock4"
//      style="position:absolute;
//      cursor:w-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>
//
//<span id="FocusBlock5"
//      style="position:absolute;
//      cursor:w-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>
//
//<span id="FocusBlock6"
//      style="position:absolute;
//      cursor:ne-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>
//
//<span id="FocusBlock7"
//      style="position:absolute;
//      cursor:n-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>
//
//<span id="FocusBlock8"
//      style="position:absolute;
//      cursor:nw-resize;
//      display:none;
//      width:5;
//      height:5;
//      font-size:1px;
//      border-style:outset;
//      border-width:1px;
//      background-color:red;"></span>


var oBody = document.body;  //Body对象
var ImgOb;   //当图片获得焦点时，就要调整该图片的大小
var ImgW;   //图片宽度
var ImgH;
var MouseDownX;  //鼠标在聚焦块上按下的位置
var MouseDownY;
var MouseMoveX;  //鼠标在窗口移动时的位置
var MouseMoveY;
var inX;         //图片增加的宽度
var inY;
var FocusBlockNum="";  //是按下了哪个聚焦块


//当在聚焦块上按了鼠标时，取得信息
function MouseDown_FocusBlock1(){
 MouseDownX=event.clientX;
 MouseDownY=event.clientY;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=1;
 oBody.style.cursor="nw-resize";
}
function MouseDown_FocusBlock2(){
 MouseDownY=event.clientY;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=2;
 oBody.style.cursor="n-resize";
}
function MouseDown_FocusBlock3(){
 MouseDownX=event.clientX;
 MouseDownY=event.clientY;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=3;
 oBody.style.cursor="ne-resize";
}
function MouseDown_FocusBlock4(){
 MouseDownX=event.clientX;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=4;
 oBody.style.cursor="w-resize";
}
function MouseDown_FocusBlock5(){
 MouseDownX=event.clientX;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=5;
 oBody.style.cursor="w-resize";
}
function MouseDown_FocusBlock6(){
 MouseDownX=event.clientX;
 MouseDownY=event.clientY;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=6;
 oBody.style.cursor="ne-resize";
}
function MouseDown_FocusBlock7(){
 MouseDownY=event.clientY;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=7;
 oBody.style.cursor="n-resize";
}
function MouseDown_FocusBlock8(){
 MouseDownX=event.clientX;
 MouseDownY=event.clientY;
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum=8;
 oBody.style.cursor="nw-resize";
}

//当在聚焦块上按了鼠标后，在窗口移动鼠标时，调整图片的大小
function AdjuestPic(){
 if(FocusBlockNum!=""){
  MouseMoveX=event.clientX;
  MouseMoveY=event.clientY;
  switch(FocusBlockNum){
   case 1:
    inX=MouseDownX-MouseMoveX;
    inY=MouseDownY-MouseMoveY;
    break;
   case 2:
    inX=0;
    inY=MouseDownY-MouseMoveY;
    break;
   case 3:
    inX=MouseMoveX-MouseDownX;
    inY=MouseDownY-MouseMoveY;
    break;
   case 4:
    inX=MouseDownX-MouseMoveX;
    inY=0;
    break;
   case 5:
    inX=MouseMoveX-MouseDownX;
    inY=0;
    break;
   case 6:
    inX=MouseDownX-MouseMoveX;
    inY=MouseMoveY-MouseDownY;
    break;
   case 7:
    inX=0;
    inY=MouseMoveY-MouseDownY;
    break;
   case 8:
    inX=MouseMoveX-MouseDownX;
    inY=MouseMoveY-MouseDownY;
  }
  ImgOb.width=ImgW+inX;
  ImgOb.height=ImgH+inY;
  ImgOb.focus();
  MoveFocusBlockToOb(ImgOb);
 }
}

//当在聚焦块上按了鼠标后，在窗口放开鼠标时，恢复原始状态
function ResetAdjuestPic(){
 ImgW=ImgOb.width; //对象的宽度
 ImgH=ImgOb.height;
 FocusBlockNum="";
 oBody.style.cursor="default";
}

//使聚焦块在图片对象的位置上
function MoveFocusBlockToOb(Ob){
 //当对象为图片时有效
 //Ob是要带聚焦块的对象
 var Point1X=Ob.offsetLeft;  //对象的位置
 var Point1Y=Ob.offsetTop;
 var ObWidth=Ob.width; //对象的宽度
 var ObHeight=Ob.height;
 //显示聚焦块
 FocusBlockDisplay();
 //把聚焦块移动到位置上
 var BodyleftMargin=parseInt(oBody.leftMargin);  //窗口的空白
 var BodytopMargin=parseInt(oBody.topMargin);
 if(isNaN(BodyleftMargin)){
  BodyleftMargin=0;
 }
 if(isNaN(BodytopMargin)){
  BodytopMargin=0;
 }
 FocusBlock1.style.pixelLeft=Point1X+BodyleftMargin;
 FocusBlock1.style.pixelTop=Point1Y+BodytopMargin;
 FocusBlock2.style.pixelLeft=Point1X+ObWidth/2-2+BodyleftMargin;
 FocusBlock2.style.pixelTop=Point1Y+BodytopMargin;
 FocusBlock3.style.pixelLeft=Point1X+ObWidth-5+BodyleftMargin;
 FocusBlock3.style.pixelTop=Point1Y+BodytopMargin;
 FocusBlock4.style.pixelLeft=Point1X+BodyleftMargin;
 FocusBlock4.style.pixelTop=Point1Y+ObHeight/2-2+BodytopMargin;
 FocusBlock5.style.pixelLeft=Point1X+ObWidth-5+BodyleftMargin;
 FocusBlock5.style.pixelTop=Point1Y+ObHeight/2-2+BodytopMargin;
 FocusBlock6.style.pixelLeft=Point1X+BodyleftMargin;
 FocusBlock6.style.pixelTop=Point1Y+ObHeight-5+BodytopMargin;
 FocusBlock7.style.pixelLeft=Point1X+ObWidth/2-2+BodyleftMargin;
 FocusBlock7.style.pixelTop=Point1Y+ObHeight-5+BodytopMargin;
 FocusBlock8.style.pixelLeft=Point1X+ObWidth-5+BodyleftMargin;
 FocusBlock8.style.pixelTop=Point1Y+ObHeight-5+BodytopMargin;
}

//显示聚焦块
function FocusBlockDisplay(){
 FocusBlock1.style.display="block";
 FocusBlock2.style.display="block";
 FocusBlock3.style.display="block";
 FocusBlock4.style.display="block";
 FocusBlock5.style.display="block";
 FocusBlock6.style.display="block";
 FocusBlock7.style.display="block";
 FocusBlock8.style.display="block";
}

//隐藏聚焦块
function FocusBlockHidden(){
 FocusBlock1.style.display="none";
 FocusBlock2.style.display="none";
 FocusBlock3.style.display="none";
 FocusBlock4.style.display="none";
 FocusBlock5.style.display="none";
 FocusBlock6.style.display="none";
 FocusBlock7.style.display="none";
 FocusBlock8.style.display="none";
}
