var activeObject=null;
var activeDown=null;
var activeButton = null;
var activeWindow= null;

function init(sid, cid, f) { 
  if (sid!=qCookie('SID')) qCookie('SID',sid);
  if (cid!='') {
    var c=cid.split('|');
    if (c.length>2) qCookie(c[0],c[1],c[2]);
  };

  $('.comboList').bind('keydown',function(e){combolistKey(e)}).bind('mousedown',function(e){combolistMouseDown(e)}).bind('mouseover',function(e){combolistMouseOver(e)});
  $('.combomultiList').bind('mousedown',function(e){combomultiMouseDown(e);});  
  if (!$.browser.msie) $('.comboList, .combomultiList').find('li').css('margin-left','-40px');
  $('.viewGRID, .viewSTAT').bind('mouseover',function(e){listMouseOver(e)}).bind('mouseout',function(e){listMouseOut(e)}).bind('click',function(e){listClick(e)});
  $(document).bind('mousedown',function(e){hideAll(e)});
};

function windowOpen(IsWin, SId, PId, Params, URL, Scroll) { 
  var goURL="";
  var goId="";
  
  if (!SId || SId=="") SId=qCookie('SID');
  if (!Params || Params=="") {
    var r=document.getElementById("RID");    
    if (r) {if (r.tagName=="DIV") Params="RID="+r.innerText; else Params="RID="+r.value;};
  };
  
  if (URL && URL!="")
    goURL=URL;
  else
  {
    goURL="default.asp?PID="+PId+"&SID="+SId;
    if (Params!="") goURL=goURL+"&"+Params;
    
    goId=PId+Params;
    goId=escape(goId);
    goId=goId.replace(/-/gi,"");
    goId=goId.replace(/%/gi,"");
    goId=goId.replace(/=/gi,"");
    goId=goId.replace(/{/gi,"");
    goId=goId.replace(/}/gi,"");    
    goId=goId.replace(/ /gi,"");
    goId=goId.replace(/./gi,""); 
     
  }  
  if (Scroll==undefined || Scroll=="") Scroll="0";
  
  if (IsWin=="Y")
  {
    var newWindow=window.open(goURL, goId, "width=620,height=550,toolbar=0,location=0,directories=0,status=0,titlebar=0,menuBar=0,scrollbars="+Scroll+",resizable=1");
    newWindow.focus();
  }  
  else
    window.location=goURL;
};


function windowClose() {
  if (window.opener)
    if (window.opener.document.getElementById("FORMSEARCH"))
      window.opener.document.getElementById("FORMSEARCH").submit();
  window.close();
};


function windowPosition(wTop, wLeft, wHeight, wWidth) {
 
};


function hideAll(e) {
  var et;
  if (e) et=e.target;
  
  if (activeObject!=null && et!=activeObject && et!=activeDown) {
    activeObject.style.display="none";
    activeObject=null;
    activeDown=null;
  }

  if (activeButton!=null && et && et!=activeButton && et.parentElement && et.parentElement.className!="menu") {
    resetButton(activeButton);
    activeButton = null;
  }
};

function panelResize(pid,w) {  
  
  var p=document.getElementById(pid);
  if (!p) return;

  if (p.style.width=="auto")
    p.style.width=w;
  else
    p.style.width="auto";  
}

function showObject(item, parentitem, parentY, parentX, itemY, itemX, dY, dX){
  
  var el=parentitem;
  var x=0;
  var y=0;
  var frs=0;

  for(el; el && el.tagName!='BODY'; el = el.offsetParent){frs += el.scrollTop;};  
  el=parentitem;
  for(el; el && el.tagName!='BODY'; el = el.offsetParent){x += el.offsetLeft; y += el.offsetTop;}
  
  if (parentY=="B") y += parentitem.offsetHeight;
  if (parentX=="R") x += parentitem.offsetWidth; 
  if (itemY=="B")   y -= item.offsetHeight;
  if (itemX=="R")   x -= item.width;
  
  x += parentitem.offsetParent.clientLeft + dX;
  y += parentitem.offsetParent.clientTop + dY-frs;

  item.style.left = x + "px";
  item.style.top =  y + "px";
  item.style.visibility = "visible";
  item.style.display="block"
};

function uploadOpen(FId, LId, UId, Id, ImgName) {
  
  var SId=qCookie('SID');
  if (SId=="" || FId=="" || LId=="" || UId=="") return;

  var url="upload.asp?sid="+SId+"&lid="+LId+"&uid="+UId+"&id="+Id+"&fid="+ImgName;
  
  activeWindow=window.open(url, "photoupload", "width=400,height=150,toolbar=0,location=0,directories=0,status=0,titlebar=0,menuBar=0,scrollBars=0,resizable=0,top=200");
  activeWindow.focus();
  
  window.setTimeout("uploadEnd('"+FId+"')",500);

};

function uploadEnd(FId) {
  
  if (activeWindow==null) return;
  if (activeWindow.closed) {
    if (document.getElementById(FId+"#ACTION")!=undefined) document.getElementById(FId+"#ACTION").value="UPLOAD";
    document.getElementById("FORM"+FId).submit();
  }  
  else
    window.setTimeout("uploadEnd('"+FId+"')",500);
};

function qCookie(name, value, expireDate) {
  if (value) { 
    var expires='';
    if (value=='') {
      expireDate=new Date();
      expireDate.setHours(expireDate.getHours -1);
    };
    
    if (expireDate) {
      var eD=new Date(expireDate);
      if (eD && !isNaN(eD)) expires="; expires="+eD.toGMTString();
    };  
    document.cookie = escape(name) + "=" + escape(value) + expires +"; path=/";
  }  
  else {
    value='';
    var exp = new RegExp(escape(name) + "=([^;]+)");
    if (exp.test(document.cookie + ";")) {
      exp.exec(document.cookie + ";");
      value=unescape(RegExp.$1);
    }
  }  
  return value;  
};