var cur_o;
var offsetx;
var offsety;
var operation_type = 0;
isIE=document.all;
isNN=!document.all&&document.getElementById;
ddEnabled=false;
min_y = 250;

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  hotDog=isIE ? event.srcElement : e.target;  
  while ( !( hotDog.id.indexOf( "titleBar")==0 || hotDog.id.indexOf( "hresize")==0 || hotDog.id.indexOf( "wresize")==0 ) && hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id.indexOf( "titleBar") == 0 ){
    name = hotDog.id.substr( 8);
    cur_o = isIE?document.all[name]:document.getElementById( name);
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    operation_type = 1;
    ddEnabled=true;
  } else if (hotDog.id.indexOf( "hresize") == 0 ){
    name = hotDog.id.substr( 7);
    cur_o = isIE?document.all["Table"+name]:document.getElementById( "Table"+name);
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    operation_type = 2;
    ddEnabled=true;
  } else if (hotDog.id.indexOf( "wresize") == 0 ){
    name = hotDog.id.substr( 7);
    cur_o = isIE?document.all["Table"+name]:document.getElementById( "Table"+name);
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    operation_type = 3;
    ddEnabled=true;
  }
}
function dd(e)
{
  if (!ddEnabled) return;

  if ( operation_type == 1 ) 
  {
    now_offsetx=isIE ? event.clientX : e.clientX;
    now_offsety=isIE ? event.clientY : e.clientY;
    left_ = parseInt(cur_o.style.left)+(now_offsetx-offsetx);
    top_ = parseInt(cur_o.style.top)+(now_offsety-offsety);
    offsetx=now_offsetx;
    offsety=now_offsety;
    if ( top_ < min_y ){
      top_ = min_y;
      ddEnabled = false;
    }
    cur_o.style.left=left_;
    cur_o.style.top=top_;
  } else if ( operation_type == 2 )
  {
    now_offsety=isIE ? event.clientY : e.clientY;
    h = (parseInt( cur_o.clientHeight)==0?parseInt( cur_o.scrollHeight):parseInt( cur_o.clientHeight))+(now_offsety-offsety);
    offsety=now_offsety;
    cur_o.style.height = h;
  } else if ( operation_type == 3 )
  {
    now_offsetx=isIE ? event.clientX : e.clientX;
    w = (parseInt( cur_o.clientWidth)==0?parseInt( cur_o.scrollWidth):parseInt( cur_o.clientWidth))+(now_offsetx-offsetx);
    offsetx=now_offsetx;
    if ( w > 600 ) w = 600;
    cur_o.style.width = w;
  } 

  return;  
}
document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");
document.onmousemove=dd;

function PopLayer_setHeight( h){
  cur_o = isIE?top.document.all["Table"+this.name]:top.document.getElementById( "Table"+this.name);
  cur_o.style.height = h;
}
function PopLayer_setWidth( w){
  cur_o = isIE?top.document.all["Table"+this.name]:top.document.getElementById( "Table"+this.name);
  cur_o.style.width = w;
}
function PopLayer_setFrameHeight( h){
  cur_o = isIE?top.document.all[this.iframe_name]:top.document.getElementById( this.iframe_name);
  cur_o.style.height = h;
}
function PopLayer_setFrameWidth( w){
  cur_o = isIE?top.document.all[this.iframe_name]:top.document.getElementById( this.iframe_name);
  cur_o.style.width = w;
}

function PopLayer_hideMe(){
  l = document.getElementById( this.name);
  l.innerHTML = "";
//hide_layer( this.name);
  if (isIE||isNN) l.style.visibility="hidden";
  ddEnabled = false;
  this.open = false;
}
function PopLayer_showMe(){
  if (isIE||isNN){
    c = this.strReplace( "$$url$$", this.url, this.header);
    c = this.strReplace( "$$title$$", this.title, c);
    c = this.strReplace( "$$name$$", this.name, c);
    c = this.strReplace( "$$width$$", this.width, c);
    c = this.strReplace( "$$height$$", this.height, c);
    c = this.strReplace( "$$iframe_name$$", this.iframe_name, c);
    c = this.strReplace( "$$iframe_width$$", this.iframe_width, c);
    c = this.strReplace( "$$bgcolor$$", this.bgcolor, c);

    this.Layer_.innerHTML = c;
    this.Layer_.style.visibility="visible";
    o = document.body;
    this.m_pos_y = isIE ? (o.scrollTop+o.clientHeight/2)-(this.Layer_.clientHeight/2): (o.scrollTop+o.clientHeight/2)-(this.Layer_.scrollHeight/2);
    this.m_pos_x = isIE ? (o.scrollLeft+o.clientWidth/2)-(this.Layer_.clientWidth/2): (o.scrollLeft+o.clientWidth/2)-(this.Layer_.scrollWidth/2);
    if ( this.m_pos_y < this.min_y ) this.m_pos_y = this.min_y;
    this.Layer_.style.left = this.m_pos_x;
    this.Layer_.style.top = this.m_pos_y;
    this.open = true;
  }
}

function PopLayer_strReplace(t, r, s){value = "";pos0 = 0;pos1 = 0;if ( s.length > 0 ){while( 1 ){ pos1 = s.indexOf(t, pos0);if ( pos1 < 0 ) break;value += s.substring( pos0, pos1) + r;pos0 = pos1 + t.length;}value += s.substring( pos0, s.length);}return value;}
function PopLayer( name, title, url, header)
{
  //-------------------------------------
  //          Local Variables
  //-------------------------------------
  var dat = new Date()
  this.whichDog=false;
  this.url = url;
  this.name = name;
  this.title = title;
  this.min_y = min_y;
  this.m_pos_y = 0;
  this.m_pos_x = 0;
  this.offsetx = 0;
  this.offsety = 0;
  this.width = 1;
  this.height = 1;
  this.open = false;
  this.iframe_name = "pop_up_layer_frame"+dat;
  this.iframe_width = "100%";
  this.bgcolor = "#FFFFFF";
  if ( !header )
  {
    this.header = '\
    <table ID="Table$$name$$"  width="$$width$$" height="$$height$$" border="0" BGCOLOR="#007DBD" cellspacing="0" cellpadding="0">\
      <tr>\
        <td width="1"><img src="./images/e.gif"></td>\
        <td width="100%" height="100%">\
          <table border="0" height="100%" width="100%" cellspacing="0" cellpadding="3">\
            <tr>\
              <td ID="titleBar$$name$$" style="cursor:move" width="100%"><b class=normal style="color:#FFFFFF;cursor:move">$$title$$</b></td>\
              <td style="cursor:hand" valign="top"><a href="./" onClick="'+name+'_.hideMe();return false"><img src="./images/but_close3.gif" border=0></a></td>\
            </tr>\
            <tr>\
              <td width="100%" height="100%" bgcolor="$$bgcolor$$" style="padding:2px" colspan="2">\
                 <table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1" valign=top>\
                   <tr>\
                     <td height="100%" bgcolor="$$bgcolor$$" align=center><iframe name="$$iframe_name$$" id="$$iframe_name$$" width="$$iframe_width$$" src="$$url$$" FRAMEBORDER=0 height="360"></iframe></td>\
                   </tr>\
                 </table>\
              </td>\
            </tr>\
          </table>\
        </td>\
        <td width="1" ID="wresize$$name$$" style="cursor:w-resize;"><img src="./images/e.gif"></td>\
      </tr>\
      <tr>\
        <td colspan=3 ID="hresize$$name$$" style="cursor:n-resize;" height="1"><img src="./images/e.gif"></td>\
      </tr>\
    </table>\
    ';
  }
  else
  {
    this.header = header;
  }
  this.Layer_ = isIE ? document.all[name] : document.getElementById(name);
  //-------------------------------------
  //              Methods
  //-------------------------------------
  this.hideMe = PopLayer_hideMe;
  this.showMe = PopLayer_showMe;
  this.setHeight = PopLayer_setHeight;
  this.setWidth = PopLayer_setWidth;
  this.setFrameHeight = PopLayer_setFrameHeight;
  this.setFrameWidth = PopLayer_setFrameWidth;
  this.strReplace = PopLayer_strReplace;
}