var resizetimer = null;
var toolbarxmlhttp = null;
var contextmenuxmlhttp = null;
var updating = 0;
var dialogs=new Array();
var openmenu=null;

function documentload() {      
  Ext.enableGarbageCollector=false;
  try {
    if (window.parent!=null && window.parent!=window) {
      if (window.parent.document!=null && window.parent.document.body!=null && window.parent.document.body.mainwindow=="1") {
        window.parent.location.replace(window.parent.location.href);
      }    
    }
  } catch(err) {     
  }
  
  if (document.body.errmsg!=null && document.body.errmsg!="") {
    alert(document.body.errmsg);    
  }    
  
  if (document.getElementById("viewcontainer")!=null) {
    DoResize(document.getElementById("viewcontainer"));
    document.getElementById("viewcontainer").style.visibility="visible";
  } 
  //loadcriteriabar();
  updateiframes();
   
  updatedecimalformat();
  if (document.body.triggerUrl!=null && document.body.triggerUrl!="") {
    window.open(document.body.triggerUrl);    
    document.body.triggerUrl=null;
  }
  if (document.getElementById("view")!=null) {
    resizemorpher(document.getElementById("view"));
  }
  window.setTimeout("ping()", 60000)
  
}

function reloadpage(url,params) {    
  
  setloading();
  if (document.body.hinttimer!=-1) {
    window.clearTimeout(document.body.hinttimer);
    document.body.hinttimer=-1;
    document.body.hintobject=null;
  }
  Ext.Ajax.request({
    url:url,
    disableCaching: true,
    params:params,
    method: "GET",    
    success: function (result, request) {      
      if (document.body.hinttimer!=-1) {
        window.clearTimeout(document.body.hinttimer);
        document.body.hinttimer=-1;
        document.body.hintobject=null;
      }
      
      var content=result.responseText.split("<!--CONTENT-->")[1];
      var currentView=document.getElementById("view");      
      //var newView=docFragment.getElementById("view");
      currentView.innerHTML=content;
      //currentView.innerHTML=newView.innerHTML;
      if (document.getElementById("viewcontainer")!=null) {
        DoResize(document.getElementById("viewcontainer"));
        document.getElementById("viewcontainer").style.visibility="visible";
      } 
      
      
      var critbar=document.getElementById("criteriabarframe");
      if (critbar!=null) {
        critbar.onrendercomplete=function () {critbar.onrendercomplete=null;};
      }
      if (critbar!=null) {
        loadcriteriabar();
        //var flowgrid=document.frames["criteriabarframe"].document.getElementById("dropdowns");            
        //document.frames["criteriabarframe"].dynamicUpdateCtrl('dropdowns','width='+flowgrid.clientWidth,'change',null);        
      }
      updateiframes(true)
      updatetoolbar();
      if (document.body.progress!=null) {
        document.body.progress.hide();
        document.body.progress=null;        
      }        
    }
  })
}

function ping() {
  Ext.Ajax.request({
    url:"sessionresource.ashx",
    disableCaching: true,
    method: "GET",
    params: {
      ping: "1"
    },
    success: function () {      
      window.setTimeout("ping()",60000);
    }
  })
}

function getdragid() {
  return document.body.dragid;
}

function setdragid(dragid) {  
  
  var iframes=document.getElementsByTagName("IFRAME");
  var cnt=0;
  for (var i=0;i<=iframes.length;i++) {
    var iframe=iframes[i];
    if (iframe!=null) {
      if (iframe.hasdropzones) {
        cnt++;	        
        iframe.contentWindow.setdragid(dragid);
        //alert('dropzoneenable:'+iframe.name);
        //iframe.contentWindow.location.replace("blank.html");
      }    
    }
  }
  
  document.body.dragid=dragid;
}

function extNewDateMenu() {
  return new Ext.menu.DateMenu();
}

function setdialogvar(frame,name,value) {  
  var varstore=frame.frameElement;  
  if (varstore.vars==null) {
    varstore.vars=new Object();
  }
  varstore.vars[name]=value;  
}

function getdialogvar(frame,name) {
  var varstore=frame.frameElement;  
  if (varstore.vars!=null) {
    return varstore.vars[name];
  }  
}

function selectstart() {
  if ((event.srcElement!=null) && (event.srcElement.tagName=="INPUT")) {
    return true;
  }
  return event.ctrlKey;
}

function resizemorpher(container) {  
  
  var frame=document.getElementById("Morpher");
  if (frame!=null) {  
    container.style.overflow="hidden";
    if (frame.width!=container.clientWidth) {
      frame.width=container.clientWidth;      
    }
    if (frame.style.pixelWidth!=container.clientHeight) {
      frame.height=container.clientHeight;
    }    
    if (frame.style.display!="block") {
      frame.style.display="block";
    }
  }
}


function showcolorpicker(color, setcolorfn, cancelfn,caption) {  
  if (caption==null) {
    caption='&nbsp;';
  }
  document.body.colorpicker=new Ext.Window({           
                layout      : 'fit',
                width      : 300,
                height     : 200,
                closable   : false,
                plain       : true,                
                title       : caption,                
                hidden : true,
                border : true,
                html: '<iframe frameborder="0" src="colorselector.aspx?color='+color+'" style="width:100%;height:100%"></iframe>',
                resizable:false,                
                modal: true,
                x:-1000                               
            });  
  document.body.colorpicker.setcolor=setcolorfn;
  document.body.colorpicker.cancel=cancelfn;
  document.body.colorpicker.show();  
}

function resizecolorpicker(w,h) {
  var win=document.body.colorpicker;
  win.setSize(w+win.getFrameWidth(),h+win.getFrameHeight());  
  win.center();    
}

function closecolorpicker(colorvalue) {
  document.body.colorpicker.close();
  
  if (colorvalue!=null) {
    document.body.colorpicker.setcolor(colorvalue);
  } else {
    if (document.body.colorpicker.cancel!=null) {
      document.body.colorpicker.cancel();
    }
  }
  document.body.colorpicker=null;
}

function offsetElementBox(box,frame) {  
  box.x+=Ext.get(frame.frameElement).getX();
  box.y+=Ext.get(frame.frameElement).getY();    
  return box;
} 

function showdynamiccontextmenu(menudiv,x,y,dialog) {                    
  var menuitems=new Array();            
  var menuelement=menudiv.firstChild;  
  while (menuelement!=null) {
    var menuitem={text:menuelement.text,icon:menuelement.image,disabled:menuelement.enabled=='false'}
    if (menuelement.action!=null) {
      menuitem.xaction=menuelement.action;      
      menuitem.xdialog=dialog;
      menuitem.listeners={'click':function(menuItem,e) {menuitem.xdialog.dynamicEvent(menuItem.xaction,'click');closecombo()}};
    }
    if (menuelement.checked=='true') {
      menuitem.xtype='menucheckitem';
      menuitem.checked=true;
      if (menuitem.icon=='') {
        menuitem.icon='resource.ashx?resname=mi_ok16';
      }      
    }
    if (menuelement.className=='separator') {
      menuitem='-';
    }                            
    

    menuitems[menuitems.length]=menuitem;

    menuelement=menuelement.nextSibling;
  }
  var menu = new Ext.menu.Menu({
  id: 'extcontextmenu',
  items: menuitems  
  })            
  
  menu.showAt([-1000,-1000]);
  if (x+menu.getWidth()+5>document.body.clientWidth) {
    x=document.body.clientWidth-menu.getWidth()-5;
  }
  if (y+menu.getHeight()+5>document.body.clientHeight) {
    x=document.body.clientHeight-menu.getHeight()-5;
  }
  menu.showAt([x,y]);                     
  modalbackground.style.display="block";
  modalbackground.style.zIndex=9999;
  openmenu=menu;
}

function showdatemenu(menu,box) {
  for (var i = 0; i < Date.monthNames.length; i++) {
    Date.monthNames[i]=vbmonthname(i+1);
  }
  
  for (var i = 0; i < Date.dayNames.length; i++) {
    Date.dayNames[i]=vbdayname(i+1);
  }
  modalbackground.style.display="block";
  modalbackground.style.zIndex=9999;
  openmenu=menu;
  var ypos=box.y+box.height;  
  var xpos=box.x;  
  menu.showAt([xpos,ypos]);  
  var menubox=menu.picker.getEl().getBox();
  var move=false;
  if (menubox.height+ypos>document.body.clientHeight) {
    ypos=box.y-menubox.height;
    move=true;
  }
  if (xpos+menubox.width>document.body.clientWidth) {
    xpos=(box.x+box.width)-menubox.width;
    move=true;
  }
  if (move) {
    menu.hide();
    menu.showAt([xpos,ypos]);
  }
  
}


function showcombo(combobox,items,valueitem,onchange,displayitem,framewindow) {
  
  var popup=combopopup;  
  popup.onchange=onchange;
  popup.valueitem=valueitem;
  popup.displayitem=displayitem;
  var content=combocontent;
  combocontent.innerHTML=items.innerHTML;
  popup.style.display="none";
  popup.style.width="1px";
  popup.style.height="1px";  
  popup.style.top="-1000px";
  popup.style.left="-1000px";
  
  var box=Ext.get(combobox).getBox();  
  box.x+=Ext.get(framewindow.frameElement).getX();
  box.y+=Ext.get(framewindow.frameElement).getY();  
  popup.style.visibility="hidden";
  
  
  popup.style.display="block";    
  var contentwidth=content.offsetWidth;  
  popup.style.width=box.width+'px';  
  popup.style.height="100px";      
  popup.style.width=box.width+'px';    
  var neededwidth=contentwidth+(popup.offsetWidth-popup.clientWidth);  
  if (neededwidth>box.width) {
    if (neededwidth>400) {
      popup.style.width='400px';
    } else {
      popup.style.width=neededwidth+'px';
    }
  }
  var maxheight=(content.firstChild.offsetHeight*8)+2;  
  var neededheight=content.offsetHeight+(popup.offsetHeight-popup.clientHeight);
  if (neededheight<maxheight) {    
    popup.style.height=neededheight+'px';
  } else {
    popup.style.height=maxheight+'px';    
  }      
  var ypos=box.y+box.height;
  if (popup.offsetHeight+ypos>document.body.clientHeight) {
    ypos=box.y-popup.offsetHeight;
  }
  var xpos=box.x;
  if (xpos+popup.offsetWidth>document.body.clientWidth) {
    xpos=(box.x+box.width)-popup.offsetWidth;
  }
  if (xpos<0) {
    xpos=0;
  }
  if (ypos<0) {
    ypos=0;
  }
  popup.style.pixelLeft=xpos;  
  popup.style.top=ypos;
  
  popup.style.zIndex=10000;
  
  modalbackground.style.display="block";
  modalbackground.style.zIndex=9999;
  popup.style.visibility="visible";
  
}

function removemodalbackground() {
  modalbackground.style.display="none";
  modalbackground.style.zIndex=450;
}

function closecombo() {  
  removemodalbackground();
  combopopup.style.display="none";
  combocontent.innerHTML="";
  if (openmenu!=null) {
    openmenu.hide();
    openmenu.destroy();
    openmenu=null;    
  }
}

function comboselect(combo) {
  
  var element=event.srcElement;
  if (element.className=="comboitem") {
    if ((element.value!="@null@") && (combopopup.valueitem.value!=element.value)) {      
      if (combopopup.displayitem!=null) {
        combopopup.displayitem.value=element.innerText;
      }
      combopopup.valueitem.value=element.value;
      closecombo();
      combopopup.onchange(combopopup.valueitem,element.value);
    }
  }
  closecombo();
}

function combomousemove(combo) {
  var element=event.srcElement;
  if (element.className=="comboitem") {
    if (element.offsetWidth>combo.clientWidth) {
      element.title=element.innerHTML;
    }
  }
}

function updatedecimalformat() {
  //FF
  if (Ext.isIE) { 
    if (document.getElementById("decimalformat")!=null) {	        
      Ext.Ajax.request({
        url:"default.aspx",
        disableCaching: true,
        params:{decimalformat:decimalformat()}}
      );
    }
  }
}

function stop() {  
  var iframes=document.getElementsByTagName("IFRAME");
  var cnt=0;
  setloading();
  for (var i=0;i<=iframes.length;i++) {
    var iframe=iframes[i];
    if (iframe!=null) {
      if (iframe.readyState!="complete") {
		iframe.contentWindow.location.replace("blank.html");
      }    
    }
  }
  
  document.location.replace("default.aspx?stop=1");  
} 

function calcpos(element) {
  var leftpos=0;
  var toppos=0;  
  while (element!=null && element!=document.body && element.offsetParent!=element) {
    leftpos+=element.offsetLeft;
    toppos+=element.offsetTop;
    element=element.offsetParent;
  }

  return new Array(leftpos,toppos);
}

function criteriabarwindow() {
  var critbarframe=document.frames["criteriabarframe"];
  return critbarframe;
}

function loadcriteriabar() {  
  var critbarframe=document.frames["criteriabarframe"];
  var critbar=document.getElementById("criteriabarframe");
  
  if (critbar!=null && critbarframe!=null) {  
	  critbar.onrendercomplete=function () {critbar.style.visibility="visible";critbar.onrendercomplete=null;updateiframes(true)};
	  critbarframe.document.location.replace(critbar.loadsrc+"&rnd="+Math.random());
  } 
}

function updateiframes(critbarloaded) {
  var critbar=document.getElementById("criteriabarframe");
  if ((critbar!=null) && !critbarloaded) {
    loadcriteriabar();
    return;
  }
  updating=1;
  var iframes=document.getElementsByTagName("IFRAME");
  var cnt=0;
  for (var i=0;i<=iframes.length;i++) {
    var iframe=iframes[i];
    if (iframe!=null) {
      if (iframe.loaded==null) {
        iframe.loaded=true;
        if (iframe.getAttribute("objrealsrc")!=null) {
          cnt++;          
          iframe.src=iframe.objrealsrc;          
          iframe.objrealsrc=null;
        }
      }
    }    
    if (cnt==2) {      
      setTimeout("updateiframes(true)",20000);
      break;
    }
  }    
  updating=0;
}

function setloading() {    
  if (window.createPopup) {
    document.body.progress = window.createPopup();
    var oPopBody = document.body.progress.document.body;
    oPopBody.style.backgroundColor = "white";
    oPopBody.style.border = "none";
    oPopBody.innerHTML = '<table width="100%" height="100%"><tr><td align="center" valign="middle"><img src="images/working.gif"></td></tr></table>';  
    var xpos=(view.clientWidth/2)-30;
    var ypos=(view.clientHeight/2)-30;
    document.body.progress.show(xpos, ypos, 60, 60, view);
  }
}

function removeloading() {
  if (document.body.progress!=null) {
    document.body.progress.hide();
    document.body.progress=null;
  }  
  window.setTimeout("updateiframes(true)",20);
}

function body_unload() {  
  removeloading();      
}

function absleft(element) {
  var leftpx=0;
  while (element.parentElement!=document.body) {
    leftpx+=element.offsetLeft; 
    element=element.parentElement;  
  }
  return leftpx;
}

function abstop(element) {
  var toppx=0;
  while (element.parentElement!=null) {
    toppx+=element.offsetTop;    
    element=element.parentElement;  
  }
  return toppx;
}

function loadframecmd(cmd) {
   var loadframe=document.frames["loadframe"];
   loadframe.document.location.replace("default.aspx?cmd="+cmd);
}



function openview(viewname) {      
  if (closeopendropdown()) {    
    if (viewname!=null) {
      setloading();  
      Default.loadview.value=viewname;
      Default.submit();
    }
  }  
}

function showhelp() {
  window.open("help.aspx");
}

function Cmd(command) {
  
  if (command==5060000) {
    showwizard("metamorpher.aspx?start=1&noselect=1&name=Stored Criteria");    
  } else if (command==5070000) {
    showwizard("metamorpher.aspx?start=1&noselect=1&name=Stored Comparisons");    
  } else if (command=="1040500") {
    showwizard("savedialog.aspx");
  } else if (command=="6000000") {
    showhelp();
  } else if (command=="3300000") {
	  stop();
  } else if (closeopendropdown()) {
      
    if (document.body.selectedobject!=null && command=="4410000" || command=="4420000" ) {
      if (document.body.selectedobject!=null) {    
        document.frames["frame"+document.body.selectedobject.id].objcommand(command);        
      }
      if (command="4420000") {
        if (document.getElementById("smartpad")!=null) {
          tcViewSourceDatatabbutton.click();
        }        
      }
    } else  if (command=="1070000" || command=="4280600" || command=="4280700" || command=="1090000" || command=="3340000" || command=="3340150" || 
                command=="3340100" || command=="3400100" || command=="12040000" || command=="12050000" || command=="12060000" || command=="12070000" ||
                command=="12080000" || command=="4230400" || command=="1196800") {      

      if (command=="4230400") {      	
		    showwizard("metamorpher.aspx?start=1&name=editcolors&noselect=1");		     
		  } else if (command=="3340150") {
		    showwizard("metamorpher.aspx?start=1&name=DocumentSmileyPage&noselect=1");		     
		  } else if (command=="3340100") {
		    showwizard("metamorpher.aspx?start=1&name=SmileyDialog&noselect=1");
		  } else if (command=="3340000") {          
        showwizard("metamorpher.aspx?start=1&name=DocumentProperties&noselect=1");          
        } else if (command=="3400100") {
        showwizard("metamorpher.aspx?start=1&name=ViewExportWizard&noselect=1");          
      } else if (command=="12050000") {
        showwizard("metamorpher.aspx?start=1&name=AgentsSource&noselect=1");
      } else if (command=="12060000") {
        showwizard("metamorpher.aspx?start=1&name=AgentsDelivery&noselect=1");
      } else if (command=="12070000") {
        showwizard("metamorpher.aspx?start=1&name=AgentsSchedule&noselect=1");  
      } else if (command=="12080000") {
        showwizard("metamorpher.aspx?start=1&name=AgentsHistory&noselect=1");          
      } else if (command=="1090000") {
        showwizard("metamorpher.aspx?start=1&name=Preferences&noselect=1");
      } else if (command=="1196800") {
        showwizard("metamorpher.aspx?start=1&name=desktopmanage&noselect=1");                          
      } else if (document.body.printobj!=null) {        
        if (command=="4280600") {
          document.body.printobj.printobject("pdf");
        } else if (command=="4280700") {
          document.body.printobj.printobject("rtf");
        } else {
          document.body.printobj.printobject();
        }
      } else if (command=="1070000") {        
        window.print();
      }  
      
    } else {
      setloading();    
      location.replace("Default.aspx?cmd="+command);
    }
  }
}

function selectobject(objdoc,lobj) {
  if (closeopendropdown()) {  
    var smartpad=document.getElementById("smartpad");
    if (smartpad!=null) {
      
      var obj=null;      
      obj=objdoc.document.body.obj;      
      var objcell=null;
      if (lobj!=null) {        
        objcell=document.getElementById("layoutobj"+obj.replace("L",""));
        obj=lobj;
      } else {
        objcell=document.getElementById("obj"+obj);
      }
      
      
      if (objcell!=null) {

        objcell.style.borderColor="black";
        if ((document.body.selectedobject!=null) && (document.body.selectedobject!=objcell)) 
        {
          var frame=document.frames["frame"+document.body.selectedobject.id];
          if (frame!=null && frame.startdrag != null) {
            frame.startdrag("none");
          }
          document.body.selectedobject.style.borderColor="";
        }
        if (document.body.selectedobject!=objcell) {
          document.body.selectedobject=objcell;        
          document.body.selectedobjectid=obj;
        
          //refreshsmartpad();
 
          updatetoolbar(obj);
        }
      }
    }
  }
}    


function propertieschanged() {
  if (document.body.selectedobject!=null) {    
    var doc=document.frames["frame"+document.body.selectedobject.id].document;
    doc.location.replace(doc.location.href);
  }
}

function selectedobjectchanged() {
  if (document.body.selectedobject!=null) {        
    var doc=document.frames["frame"+document.body.selectedobject.id].document;    
    doc.location.replace(doc.location.href);
  }
}

function chartleave(event_transfer) {
  if (document.body.hintobject==event_transfer.srcElement) {
    if (document.body.hinttimer>-1) {
      window.clearTimeout(document.body.hinttimer);
      document.body.hinttimer=-1;
      document.body.hintobject=null;
      hidehint();
    }
  }
}



function chartmousemove(event_transfer,frame) {  
  if ((document.body.progress==null) || (!document.body.progress.isOpen)) {
    var hintwin=document.getElementById("hintwindow");  
    if (document.body.hintobject!=event_transfer.srcElement) {
      if (document.body.hinttimer>-1) {
        window.clearTimeout(document.body.hinttimer);
        document.body.hinttimer=-1;
        document.body.hintobject=null;
        hidehint();
      }
    }
    
    var chart= (event_transfer.target) ? event_transfer.target : event_transfer.srcElement;
    
    if (chart.className=="chart") {     
      if (document.body.hintobject==null || document.body.hintobject!=chart || document.body.hintobject.hintX!=event_transfer.offsetX || document.body.hintobject.hintY!=event_transfer.offsetY) {
        document.body.hintobject=chart;
        chart.hintX=event_transfer.offsetX;
        chart.hintY=event_transfer.offsetY;      
        var pos=calcpos(frame);
        
        var leftpos=pos[0]+event_transfer.clientX+2;
        var toppos=pos[1]+event_transfer.clientY+22;
        hidehint();
        if (hintwin!=null) {          
          hintwin.leftpos=leftpos;
          hintwin.toppos=toppos;
        }
        if (document.body.hinttimer>-1) {
          window.clearTimeout(document.body.hinttimer);
        }
        
        document.body.hinttimer=window.setTimeout("gethint()",500);         
      }
    } else {
      hidehint();
      document.body.hintobject=null;
    }
  }
}

function chartclick() {
  if (closeopendropdown()) {
    var chart=event.srcElement;
    var xsize=chart.realWidth;
    var ysize=chart.realHeight;
    var clickX=Math.round(xsize/chart.clientWidth*event.offsetX);
    var clickY=Math.round(ysize/chart.clientHeight*event.offsetY);    
    setloading();
    if (event.ctrlKey) {
      location.replace("default.aspx?drillchart="+clickX+","+clickY+","+xsize+","+ysize+","+chart.obj+"&multi=1");
    } else {
      location.replace("default.aspx?drillchart="+clickX+","+clickY+","+xsize+","+ysize+","+chart.obj);
    }
  }
}



function openhintdialog(box,url,closemethod,updatemethod) {   
   
   document.body.hintdialogopen=true;
   modalbackground.style.display="block";
   modalbackground.style.zIndex=9999;
   var hintframe=document.frames("hintdialogframe");      
   hintframe.document.location.replace(url)      
   var hintwrapper=document.getElementById("hintframewrapper");   
   hintwrapper.closemethod=closemethod;
   hintwrapper.updatemethod=updatemethod;
   hintwrapper.box=box;   
   hintwrapper.style.pixelLeft=-1000;      
   hintwrapper.style.pixelTop=-1000;
   hintwrapper.style.height="auto";
   hintwrapper.style.width=box.width;
   hintwrapper.style.display="block";
   //window.setTimeout(hidehintdialog,10000);
}

function keepinwindow(element) {
  var element=Ext.get(element);  
}


function sethintdialogsize(x,y) {  
  var hintwrapper=Ext.get("hintframewrapper");
  var box=hintwrapper.getBox();
  var changed=false;  
  if (x!=null) {    
    if ((box.x+x)>document.body.clientWidth) {
      box.x=document.body.clientWidth-x;      
    } 
    box.width=x;
    changed=true;
  }
  if (y!=null) {
    if ((box.y+y)>document.body.clientHeight) {
      box.y=document.body.clientHeight-y;
      
    } 
    box.height=y;
    changed=true;
  }
  if (changed) {
    hintwrapper.setBox(box);
  }
}

function updateparentdialog(itemname) {
  var hintwrapper=document.getElementById("hintframewrapper");
  if (hintwrapper.updatemethod!=null) {    
    hintwrapper.updatemethod(itemname);
  }
}

function closehintdialog() {
  var hintwrapper=document.getElementById("hintframewrapper");
  var hintframe=document.frames("hintdialogframe");        
  if (hintframe.closepopup!=null) {
    hintframe.closepopup();
  }
}

function hidehintdialog() {  
  var hintwrapper=document.getElementById("hintframewrapper");
  var hintframe=document.frames("hintdialogframe");      
  if (hintframe!=null && hintwrapper!=null) {
    if (hintwrapper.closemethod!=null) {    
      hintwrapper.closemethod();    
      hintwrapper.closemethod=null;
    }  
    if (hintwrapper.style.display=="block") {
      modalbackground.style.display="none";
      modalbackground.style.zIndex=9999;
    }
    hintwrapper.style.display="none";                                                 
    hintframe.document.location.replace("blank.html");
  }
}

function sethintdialogplacement(placement) {  
  var hintwrapper=document.getElementById("hintframewrapper");   
  var frame=Ext.get(hintwrapper);        
  var alignbox=frame.dom.box;
  var box={x:alignbox.x,y:alignbox.y,width:alignbox.width,height:alignbox.height};
  
  switch (placement) {
    case "sw":      
      box.x=(box.x+box.width)-frame.getWidth();      
      box.y=box.y+box.height;     
      break;
    case "se":
      var hintwrapper=document.getElementById("hintframewrapper");   
      var frame=Ext.get(hintwrapper);                  
      box.y=box.y+box.height;
      
      break;
  }
  if (box.x+frame.getWidth()>document.body.clientWidth) {        
    box.x=document.body.clientWidth-frame.getWidth();
  }
  frame.setLocation(box.x,box.y);
}

function windowload(win) {    
  if (win.frameElement.name=="hintdialogframe") {
    var hintframe=document.getElementById("hintframewrapper");      
    hintframe.style.display="block";
  } 
}

function setDialogCaption(caption) {
  if (document.body.opendialog!=null) {
    if (caption!='') { 
      document.body.opendialog.setTitle(caption);
    }
  }
}

function closedialog(frame,update) {    
  var dialog=null;
  if (frame!=null) {
    dialog=getdialog(frame);  
  }
  if (document.body.opendialog!=null) {    
    document.body.opendialog.hide();
    var disposedialog=document.body.opendialog;    
    document.body.opendialog=dialogs.pop();    
    if (update) {    
      if (dialog.parentDialog!=null) {
        dialog.parentDialog.reloadall();
      } else if (document.body.opendialog!=null) {
        var dialogframe=document.getElementById(document.body.opendialog.dialogname);                
        dialogframe.contentWindow.reloadall();
      } 
    }
    window.setTimeout(function () {disposedialog.close()},10000);
  }
  
  if (document.body.opendialog==null) {
    if (document.body.printobj!=null) {
      document.body.printobj.showViewer();
    }
  }
}

function showcurrentdialog() {
  if ((document.body.opendialog!=null) && (document.body.opendialog.x==-1000)) {        
    document.body.opendialog.show();
    document.body.opendialog.center();
  }
}

function showwizard(url,parentDialog) {  
  if (document.body.opendialog!=null) {
    dialogs.push(document.body.opendialog);
    //document.body.modaldialog.close();
  }    
  var dialogname="modaldialog"+Math.random();
  
	document.body.opendialog=new Ext.Window({           
        layout      : 'fit',
        width      : 500,
        height     : 480,
        closable   : false,
        shadow     : true,
        plain       : true,        
        hidden     : true,
        title       : '&nbsp;',                        
        border : true,
        html: '<iframe id="'+dialogname+'" name="'+dialogname+'" frameborder="0" src="'+url+'" style="width:100%;height:100%"></iframe>',
        resizable:false,
        modal: true,
        x:-1000
    });
        
  if (document.body.printobj!=null) {
    document.body.printobj.hideViewer();
  }
  document.body.opendialog.dialogname=dialogname;
  document.body.opendialog.parentDialog=parentDialog;;
  document.body.opendialog.show();
  
}

function openactivedialog(current,parentDialog) {
  showwizard(current+'&activedialog=1',parentDialog);
  
}

function getdialog(frame) {
  var id=frame.id;
  if (document.body.opendialog.dialogname==id) {
    return document.body.opendialog;
  } else {
    for (var i=0;i<dialogs.length;i++) {
      if (dialogs[i].dialogname==id) {
        return dialogs[i];
      }
    }
  }
}

function setdialogsize(frame,w,h) {      
  win=getdialog(frame);
  if (win!=null) {        
    var size=win.getSize();
    if (size.width!=(w+win.getFrameWidth()+2) || size.height!=(h+win.getFrameHeight()+2)) {    
      win.setSize(w+win.getFrameWidth()+2,h+win.getFrameHeight()+2);    
      win.center();    
    }
  }
}

function getcontextframe() {  
  if (document.body.contextobject=="-3") {
    return document.frames["Morpher"];      
  } else if ((document.body.contextobject+"").indexOf("L")==0) {    
    return document.frames["framelayoutobj"+document.body.contextobject.replace("L","")];      
  } else {
    return document.frames["frameobj"+document.body.contextobject];      
  }
  
}

function contextcommand(cmd,param,target) {
  
  switch (target.toUpperCase()) {
    case 'SMARTPAD':
      if (document.body.currenttab!=null) {
        var loadframe=document.frames[document.body.currenttab+"tabframe"];
        var loadelement=document.getElementById(document.body.currenttab+"tabframe");
        if (loadframe!=null) {
          if (document.body.selectedobjectid==null) {
            document.body.selectedobjectid="-1";
          }
          loadframe.document.location.replace(loadelement.basesrc+"&obj="+document.body.selectedobjectid+"&cmd="+cmd);
        }
      }  
    
      break;
    case 'OBJECT/MAIN':
      
      setloading();          
      var doc=getcontextframe();      
      if (doc != null) {
        document.location.replace(doc.location.href+"&cmd="+cmd+"&cell="+param);             
      }      
      break;
    case 'PRINT' :
    
      break;
    case 'MAIN' :       
      Cmd(cmd);
      break;    
    case 'CLIPBOARD' :
      var doc=getcontextframe();      
      if (doc != null) {
        var img=doc.document.getElementById("chartimg")
        if (img==null) {
          img=doc.document.getElementById("datagrid");        
          if (img!=null) {
            var loadframe=document.frames["loadframe"];
            loadframe.document.location.replace(doc.location.href+"&cmd="+cmd);
          }
        } else {
          var oControlRange = doc.document.body.createControlRange();      
          oControlRange.addElement(img);
          oControlRange.execCommand("copy");
        }
      }
      break;    
    case 'OBJECT' : 
      setloading();          
      var doc=getcontextframe();      
      if (doc != null) {
        doc.document.location.replace(doc.location.href+"&cmd="+cmd+"&cell="+param);     
        var objcell=document.getElementById("obj"+document.body.contextobject);       
        if (objcell!=null) {          
          //selectobject(doc);          
        }    
      }
      break;
    case 'DESKTOP' :      
      var doc=document.frames["frameobj"+document.body.contextobject];      
      if (doc != null) {       
        document.location.replace(doc.location.href+"&cmd="+cmd+"&rnd="+Math.random());       
      }
      break;
    case 'EXTERNAL' :      
      var doc=getcontextframe();      
      if (doc != null) {                
        window.open(doc.location.href+"&cmd="+cmd+"&cell="+param+"&rnd="+Math.random(),target);      
      }      
      break;
    case 'EXPORTWIZARD' :
      showwizard("metamorpher.aspx?start=1&name=ExportWizard&obj="+document.body.contextobject);
      break;  
    case 'TEMPLATEWIZ' :
      showwizard("metamorpher.aspx?start=1&name=Report Templates&obj="+document.body.contextobject);
      break;      
    default :
      Cmd(cmd);
      break;
  }
} 

function contextmenucommand(cmd,cell,target,cmdtarget) {  
  if (target=="criteriabarframe") {
    var critbarwindow=criteriabarwindow();     
    if (critbarwindow!=null) {     
      critbarwindow.document.location.replace("default.aspx?cmd="+cmd);
    } else {      
      location.replace("default.aspx?reloadpage=1&cmd="+cmd);
    }
   } else if (target=="dialog") {
    showwizard("metamorpher.aspx?start=1&noselect=1&name="+cmdtarget);
  } else if (cmd=="1093600") {
    if (cell!=null && cell!="-1,-1") {
      location.replace("default.aspx?cmd=1093600&cell="+cell);    
    }
  } else if (cmd=="1070000") {    
    window.print();    
  } else {
    var islayoutobj=false;        
    
    if ((document.body.document.body.contextobject+"").indexOf("L")==0) {    
      islayoutobj=true;
      document.body.contextobject=document.body.contextobject.replace("L","");
    }
    
    if (document.body.contextobject<=-5 && document.body.contextobject>=-11) {
      cmdtarget="main";
    }
    if (cmdtarget!=null) {
      if (cmdtarget=="loadframe") {
		    var loadframe=document.frames["loadframe"];		
      } else if (cmdtarget=="main") {
        Cmd(cmd);
      } else {      
        var doc=document.frames[cmdtarget+"tabframe"].document;
        doc.location.replace(doc.location.href+"&cmd="+cmd);        
      }
    } else if (target!=null) {
      var doc=document;    
      if (document.body.contextobject<=-4 && document.body.contextobject>=-10) {
        
      } else if (document.body.contextobject=="-3") {
        doc=document.frames["Morpher"].document;
      } else {
        if (document.body.contextobject!="-1" && document.body.contextobject!="-2") {
          if (islayoutobj) {
            doc=document.frames["framelayoutobj"+document.body.contextobject].document;    
            
          } else {
            doc=document.frames["frameobj"+document.body.contextobject].document;    
          }
        }    
        if (document.body.contextobject=="-2" && cmd=="8020000") {
          var question=new String(document.body.deletequestion);
          
          question=question.replace('_NAME_',cell);
          if (!confirm(question)) {
            return false;
          };
        }
      }
      var docload=document.getElementById("documentloaded").firstChild;
      if (target=="clipboard") {
        var img=doc.getElementById("chartimg")
        if (img==null) {
          img=doc.getElementById("datagrid");        
          if (img!=null) {
            var loadframe=document.frames["loadframe"];
            loadframe.document.location.replace(doc.location.href+"&cmd="+cmd);
          }
        } else {
          var oControlRange = doc.body.createControlRange();      
          oControlRange.addElement(img);
          oControlRange.execCommand("copy");
        }
      } else if (target=="_top") {
        setloading();
        if (doc.location.href.indexOf('?')>=0) {
          document.location.replace(doc.location.href+"&cmd="+cmd+"&cell="+cell);
        } else {
          document.location.replace(doc.location.href+"?cmd="+cmd+"&cell="+cell);
        }
      } else if (target=="loadframe") {
        setloading();

        window.parent.location.replace(doc.location.href+"&cmd="+cmd+"&cell="+cell+"&rnd="+Math.random());      
      } else  {      
        setloading();
        window.open(doc.location.href+"&cmd="+cmd+"&cell="+cell+"&rnd="+Math.random(),target);      
      }
    } else {
      setloading();    
      var doc=document.frames["frameobj"+document.body.contextobject];
      if (doc != null) {
        doc.document.location.replace(doc.location.href+"&cmd="+cmd+"&cell="+cell);     
        var objcell=document.getElementById("obj"+document.body.contextobject); 
      
        if (objcell!=null) {
          selectobject(doc);
        }    
      }
    }
  }
  document.body.contextobject=null;
}

function showcontextmenu(bodywidth,bodyheight) {
  
  if (closeopendropdown()) {
    
    contextmenu.style.display="block";
    contextmenu.style.width=bodywidth;
    contextmenu.style.height=bodyheight;
    
    if (contextmenu.offsetTop+contextmenu.offsetHeight>document.body.clientHeight) {
      var toppos=(contextmenu.offsetTop-contextmenu.offsetHeight)-18;
      contextmenu.style.pixelTop=toppos;
    }
    if (contextmenu.offsetLeft+contextmenu.offsetWidth>document.body.clientWidth) {
      var leftpos=(contextmenu.offsetLeft-contextmenu.offsetWidth);
      if (contextmenu.right!=null) {
        leftpos=contextmenu.right-(contextmenu.offsetWidth-2);
        contextmenu.right=null;
      }
      contextmenu.style.pixelLeft=leftpos;
    }
    if (contextmenu.offsetTop<0) {
      contextmenu.style.pixelTop="0px";
    }
  }
}

function layoutobjectcontextmenu(obj,event_transfer,frame, typeparam) {  
  if (closeopendropdown()) {       
    document.body.contextobject="L"+obj;
    var pos=calcpos(frame);
        
    var leftpos=pos[0]+event_transfer.clientX+2;
    var toppos=pos[1]+event_transfer.clientY+22;
    if(typeparam == undefined) {
      typeparam = "layoutobject";
    }
    loadcontextmenu(leftpos,toppos,"ContextMenu.aspx?obj="+obj+"&type="+typeparam);
    
    return false;
  } else {
    return event_transfer.ctrlKey;
  }    
}

function metadatacontextmenu(obj,context,event_transfer,frame) {  
  if (closeopendropdown()) {       
    document.body.contextobject=obj;
    var pos=calcpos(frame);
        
    var leftpos=pos[0]+event_transfer.clientX+2;
    var toppos=pos[1]+event_transfer.clientY+22;
    
    loadcontextmenu(leftpos,toppos,"ContextMenu.aspx?obj="+obj+"&metadatacontext="+encodeURIComponent(context));
    return false;
  } else {
    return event_transfer.ctrlKey;
  }    
}

function tablecontextmenu(obj,xy,event_transfer, frame) {
  if (closeopendropdown()) {
    document.body.contextobject=obj;
    var pos=calcpos(frame);
        
    var leftpos=pos[0]+event_transfer.clientX+2;
    var toppos=pos[1]+event_transfer.clientY+22;
    
    loadcontextmenu(leftpos,toppos,"ContextMenu.aspx?obj="+obj+"&cell="+xy); 
    return false;
  } else {
    return event_transfer.ctrlKey;
  }
}

function contextmenuloaded() {
  if (contextmenuxmlhttp.readyState==4 && contextmenuxmlhttp.status==200) {
    if (contextmenuxmlhttp.responseText.indexOf("<!DOCTYPE")>=0) {
      location.replace("default.aspx");
    } else {
      var contextmenu=document.getElementById("contextmenu");
      var catcher=document.getElementById("contextcatcher");
      if (contextmenu!=null) {
        var left=contextmenu.reqleft;
        var top=contextmenu.reqtop;
        contextmenu.innerHTML=contextmenuxmlhttp.responseText;
        
        contextmenu.style.visibility="hidden";
        contextmenu.style.display="block";
              
        if (left+contextmenu.offsetWidth>document.body.clientWidth) {        
          left = document.body.clientWidth-contextmenu.offsetWidth;
        }
        
        if (top+contextmenu.offsetHeight>document.body.clientHeight) {
          top = top-contextmenu.offsetHeight;
        }
        
        if (top<0) {
          top = 0;
        }
        contextmenu.style.pixelLeft=left;      
        contextmenu.style.pixelTop=top;
        contextmenu.style.visibility="visible";
        //catcher.style.display="block";
        
        contextmenu.firstChild.setCapture();
        if (document.body.printobj!=null) {            
          document.body.printobj.hideViewer();      
        }
      }
    }
  }
}

function loadcontextmenu(left,top,src) {
  
  var contextmenu=document.getElementById("contextmenu");
  if (contextmenu!=null) {
    contextmenu.style.pixelLeft=0;
    contextmenu.style.pixelTop=0;
    contextmenu.style.pixelWidth=10;
    contextmenu.style.pixelHeight=10;
    
    contextmenuxmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
    
    contextmenuxmlhttp.onreadystatechange=contextmenuloaded;
    contextmenuxmlhttp.open("GET",src, true);    
    
    
    contextmenu.reqleft=left;
    contextmenu.reqtop=top;
        
    contextmenuxmlhttp.send();
    //if (xmlhttp.status==200) {
      
    //}
  }  
}


function chartcontextmenu(obj,xy,event_transfer,frame) {
  
  document.body.contextobject=obj;  
  var pos=calcpos(frame);
        
  var leftpos=pos[0]+event_transfer.clientX+2;
  var toppos=pos[1]+event_transfer.clientY+22;
  
  loadcontextmenu(leftpos,toppos,"ContextMenu.aspx?obj="+obj+"&chartxy="+xy);
  
  return false;  
}

function smartpad_click(e,panelname) {
  var ev = (e) ? e : event;  
  var reload=(document.body.currenttab=='tcViewAgentsAndActions' || panelname=='tcViewAgentsAndActions');
  
  var item=panelname+"tab";
  if (closeopendropdown()) {
    
    var button=(ev.target) ? ev.target : ev.srcElement;
    
    if (button.tagName!="TD") {
      button=button.parentNode;
    }
    var panel=document.getElementById(item);
    var	pad=document.getElementById("smartpad");
    var tabs=pad.getElementsByTagName("TD");  
    for (var i=0;i<tabs.length;i++) {        
	  
      if (tabs[i].className=="tabpanel") {      
        if (tabs[i].parentNode!=panel) {
          tabs[i].parentNode.style.display="none";
        } else {		  
          tabs[i].parentNode.style.display="block";
        };
      }
      if ((tabs[i].getAttribute("baseclass")=="tabbutton") || (tabs[i].getAttribute("baseclass")=="tabbuttonsmall")) {
        if (tabs[i]!=button) {
          tabs[i].className=tabs[i].getAttribute("baseclass");
        } else {
          tabs[i].className=tabs[i].getAttribute("baseclass")+" hot";
        };
      }
    }
    
    if (reload) {      
      document.location.replace("default.aspx?redirect=1&setsmartpadpanel="+panelname);    
    } else {
    
      var loadframe=frames[item+"frame"];
      var loadelement=document.getElementById(item+"frame");
      
      if (loadframe!=null) {
        var obj=document.body.selectedobject;
        
        if (obj!=null) {
          var url=loadelement.getAttribute("basesrc")+"&obj="+obj.getAttribute("id").replace("obj","").replace("layout","L")+"&rnd="+Math.random();
          if (url.indexOf("#")>=0) {
            url=url.replace("#selected","");
            url+="#selected";            
          }
          if (loadelement.smartpadTimer!=null) {
            window.clearTimeout(loadelement.smartpadTimer);
            loadelement.smartpadTimer=null;
          }                    
          var lf=loadframe;
          smartpadTimer=window.setTimeout(function () {loadelement.smartpadTimer=null;lf.document.location.replace(url);},200);           
        } else {
          var url=loadelement.getAttribute("basesrc")+"&obj=-1"+"&rnd="+Math.random();
          if (loadelement.smartpadTimer!=null) {
            window.clearTimeout(loadelement.smartpadTimer);
            loadelement.smartpadTimer=null;
          }                    
          var lf=loadframe;
          smartpadTimer=window.setTimeout(function () {loadelement.smartpadTimer=null;lf.document.location.replace(url);},200);                     
        }
      }
      
      loadframe=frames["loadframe"];    
      loadframe.document.location.replace("default.aspx?setsmartpadpanel="+panelname);    
    }
    document.body.currenttab=panelname;
  }
}

function resize_dblclick() {
  var pad=document.getElementById("smartpad");
  if (pad!=null) {
    if (pad.style.display=="none") {
      pad.style.display="block";
      pad.tmpwidth=smartpad.style.width;
      savesmartpadsize();
    } else {
      pad.style.display="none";
      pad.tmpwidth=smartpad.style.width;
      savesmartpadsize();
    }
  }
}

function resize_mousedown() {
  if (document.readyState=="complete") {
    var pad=document.getElementById("smartpad"); 
    if ((pad!=null) && (pad.style.display!="none")) {
      if (resize) {    
        resize.capture=1;        
        pad.tmpwidth=smartpad.style.width;         
        document.body.setCapture();
      }
    }  
  }
}

function resize_onmousemove(event_transfer) {
  if (event_transfer==null) {event_transfer=event};
  if (document.readyState=="complete") {
  var resizer=document.getElementById("resize");  
  if ((resizer) && (resizer.capture==1)) {
      var width=event_transfer.clientX-2;
      if (width<20) {        
        width=20;
      }      
      smartpad.tmpwidth=width-2+"px";      
      splitter.style.pixelLeft=width;
      splitter.style.display="block";      
  }   
 }
}
 
function body_mouseup(e) {
 if (!e) {
   e=window.event;
 }
 var resizer=document.getElementById("resize");
 var split=document.getElementById("splitter");
 if (split!=null) {
   split.style.display="none";
 }
 if ((resizer!=null) && (resizer.capture==1)) {   
   var pad=document.getElementById("smartpad"); 
   if (pad!=null) {     
     //pad.style.display="block";
   } 
   resizer.capture=0;
   document.body.releaseCapture();   
 }
 
 if((e.srcElement != null) && (e.button == "2")) {     
   e.srcElement.fireEvent("oncontextmenu");
 }
}

function body_losecapture() {
  splitter.style.display="none";
  resize.capture=0;  
  savesmartpadsize();
} 

function savesmartpadsize() {
  if (smartpad.tmpwidth!=null) {
    smartpad.style.width=smartpad.tmpwidth;    
    var smartpadsize="width="+smartpad.tmpwidth;
    if (smartpad.style.display=="none") {
      smartpadsize=smartpadsize+"&visible=0";
    }
    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
	xmlhttp.open("GET","default.aspx?setsmartpadsize=1&"+smartpadsize, true);  
	xmlhttp.send();        
  }
}

function loadimage(img) {
  if (img.loaded!="1") {
    var XSize=img.parentElement.clientWidth;
    var YSize=img.parentElement.clientHeight;    
    img.realHeight=YSize;
    img.realWidth=XSize;
    if (XSize!=0) {
      img.loaded="1";                                     
      img.src="chartobject.aspx?obj="+img.obj+"&xsize="+XSize+"&ysize="+YSize;    
    }
  }
}

function tabbuttonenter() {  
  if (event.srcElement.className.indexOf(' hot')>=0) {
    event.srcElement.className=event.srcElement.baseclass+" hot mousehot";
  } else {
    event.srcElement.className=event.srcElement.baseclass+" mousehot";
  }  
}

function tabbuttonleave() {
  if (event.srcElement.className.indexOf(' hot')>=0) {
    event.srcElement.className=event.srcElement.baseclass+" hot";
  } else {
    event.srcElement.className=event.srcElement.baseclass;
  }  
}

function refreshsmartpad() {  
  if (document.body.currenttab!=null) {
    var loadframe=document.frames[document.body.currenttab+"tabframe"];
    var loadelement=document.getElementById(document.body.currenttab+"tabframe");
    if (loadframe!=null) {
      if (document.body.selectedobjectid==null) {
        document.body.selectedobjectid="-1";
      }
      loadframe.document.location.replace(loadelement.basesrc+"&obj="+document.body.selectedobjectid);
    }
  }  
}

function updatetoolbar() {
   if (updating==0) {
     updatetoolbar(document.body.selectedobjectid);
   }
}

function updatemain() {
  if (document.body.selectedobject!=null) {        
    updatetoolbar(document.body.selectedobjectid);
  }
}

//Hints

function hidehint() {
  var hintwin=document.getElementById("hintwindow");  
  if (hintwin!=null) {    
    //Ext.fly(hintwin).setOpacity(0,true);            
    hintwin.style.visibility="hidden";
    hintwin.innerHTML="";
    hintwin.style.pixelLeft=0;
    hintwin.style.pixelTop=0;        
  }
}


function gethint() {
  if (document.body.draggingview!=1) {
  var contextmenu=document.getElementById("contextmenu");

  if (document.body.hintobject!=null && contextmenu.style.display=="none") {
    var chart=document.body.hintobject;
    var xsize=chart.realWidth;
    var ysize=chart.realHeight;
    var clickX=Math.round(xsize/chart.clientWidth*chart.hintX);
    var clickY=Math.round(ysize/chart.clientHeight*chart.hintY);        
    var url="ChartHint.aspx?obj="+chart.obj+","+clickX+","+clickY+","+xsize+","+ysize;
    
    Ext.Ajax.request({
      url:url,
      disableCaching: true,    
      method: "GET",    
      success: function (result, request) {      
        var hintwin=document.getElementById("hintwindow");  
        if (hintwin!=null) {
          hintwin.style.pixelLeft=0;
          hintwin.style.pixelTop=0;
          hintwin.innerHTML=result.responseText;
          if (hintwin.innerHTML!="" && document.body.hintobject) {        
            if (hintwin.leftpos+hintwin.offsetWidth+2>document.body.clientWidth) {
              hintwin.leftpos=document.body.clientWidth-hintwin.offsetWidth-2;      
            }
            if (hintwin.toppos+hintwin.offsetHeight+2>document.body.clientHeight) {
              hintwin.toppos=hintwin.toppos-hintwin.offsetHeight-16;      
            }
            hintwin.style.pixelLeft=hintwin.leftpos;
            hintwin.style.pixelTop=hintwin.toppos;                  
            hintwin.style.visibility="visible";            
            //Ext.fly(hintwin).setOpacity(1,true);
          }
        }        
      }
    })
    
  }
  }
}

//Toolbar

function toolbarsubmenu(element,menuid) {  
  if (closeopendropdown()) {    
    if (menuid==-1000 || menuid==-3) {
      if (menuid==-3) {
        document.body.contextobject=-3;
      } else if (document.body.selectedobjectid!=null) {
        menuid=document.body.selectedobjectid;
        document.body.contextobject=document.body.selectedobjectid;
      }       
      menuid=menuid+"&print=1";
    } else {
      document.body.contextobject=menuid;
    }
    element.parentElement.parentElement.parentElement.fireEvent("onmouseleave");    
    var pos=calcpos(element.parentElement);
    loadcontextmenu(pos[0],pos[1]+element.offsetHeight,'contextmenu.aspx?obj='+menuid+'&cell=-1,-1');
    
  }
}


function toolbarcontextmenu(menuid) {
  if (event.ctrlKey) {
    return true;
  }
  if (closeopendropdown()) {
    event.cancelBubble=true;
    var leftpos=(event.clientX-2);
    var toppos=(event.clientY+18);
    document.body.contextobject=menuid;
    loadcontextmenu(leftpos,toppos,'contextmenu.aspx?obj='+menuid+'&cell=-1,-1');
    return false;    
  }
}

function ToolbarButtonMouseOver(item) {    
  if (item.firstChild.normalclass==null) {
    item.firstChild.normalclass=item.firstChild.className;
  }
  item.firstChild.className=item.firstChild.normalclass+" hotbutton";  
}

function ToolbarButtonMouseOut(item) {  
  item.firstChild.className=item.firstChild.normalclass;
}

function updatetoolbar(obj) {
  
  toolbarxmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
  if (obj!=null) {
    toolbarxmlhttp.open("GET","default.aspx?gettoolbar=1&obj="+obj, false);  
  } else {
    toolbarxmlhttp.open("GET","default.aspx?gettoolbar=1", false);  
  }
  toolbarxmlhttp.send();  
  if (toolbarxmlhttp.status==200) {
    
    if (toolbarxmlhttp.responseText.indexOf("<!DOCTYPE")>=0 || toolbarxmlhttp.responseText.indexOf("Toolbartable")<=0) {
      location.replace("Default.aspx");
    } else {
      var toolbar=document.getElementById("toolbar")  
      if (toolbar!=null) {        
        toolbar.innerHTML=toolbarxmlhttp.responseText;                  
        var smartpadpanel=document.getElementById("Toolbartable").getAttribute("smartpadpanel");
        if (smartpadpanel!=null) {
          var smartpadbutton=document.getElementById(smartpadpanel+"tabbutton");          
          if (smartpadbutton!=null) {
            smartpadbutton.click();
          }
        }
      }    
    }
  } 
}

//Printing

function reloadimages() {    
  var iframes=document.getElementsByTagName("IFRAME");
  for (var i=0;i<=iframes.length;i++) {
    var iframe=iframes[i];
    if (iframe!=null) {
      if (iframe.getAttribute("objframe")=="1") {        
        try {
        iframe.contentWindow.reloadimage();
        } catch (e) {
        }
      }
    }        
  }
  resizetimer=null;  
}

function beforeprint() {
  var smartpad=document.getElementById("smartpad");
  if (smartpad!=null) {
    smartpad.style.display="none";
  }
  var view=document.getElementById("viewcontainer");
  if (view!=null) {
	var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
	var format=decimalformat();
	xmlhttp.open("GET","default.aspx?getprintformat=1", false);  
	xmlhttp.send();    
	var width="17cm";
	var height="14cm";
	if (xmlhttp.responseXML!=null) {	  
	  var widthnode=xmlhttp.responseXML.selectSingleNode("format/@width");
	  var heightnode=xmlhttp.responseXML.selectSingleNode("format/@height");
	  if (widthnode!=null && heightnode!=null) {
		width=widthnode.value;
		height=heightnode.value;
	  }	  
	}
	
	view.style.width=width;
	view.style.height=height;
	  
	ForceResizeObjects();	
  }
}

function afterprint() {
  var smartpad=document.getElementById("smartpad");
  if (smartpad!=null) {
    smartpad.style.display="block";    
  }
  var view=document.getElementById("viewcontainer");
  if (view!=null) {
	view.style.width="100%";
	view.style.height="100%";
	  
	//printing=false;
	ForceResizeObjects();	  

  }
}

//Sourcedata functions

function startdrag(type) {
  document.body.dragitemtype=type;
  if (document.body.selectedobject!=null && (document.body.selectedobject.id.indexOf("layout")<0)) {
    var frame=document.frames["frame"+document.body.selectedobject.id];
    if (frame!=null) {
      frame.startdrag(type);
    }
  }
}

function tooglemeasure(measure) {
  if (document.body.selectedobject!=null) {    
    document.frames["frame"+document.body.selectedobject.id].addmeasure(measure);
  }
}

function toogledimension(dim) {
  if (document.body.selectedobject!=null) {    
    document.frames["frame"+document.body.selectedobject.id].adddimension(dim);
  }
}

//Object moving

function showglobaldropmarks() {
  dock_global_top.style.display="block";
  dock_global_bottom.style.display="block";
  dock_global_left.style.display="block";
  dock_global_right.style.display="block";
}

function hideglobaldropmarks() {
  dock_global_top.style.display="none";
  dock_global_bottom.style.display="none";
  dock_global_left.style.display="none";
  dock_global_right.style.display="none";
}

function startdragobject() {
  if (document.getElementById("viewcontainer")!=null) {  
    DoResize(document.getElementById("viewcontainer"),true);
  }
  showglobaldropmarks();
  document.body.movingobject=1;
}

function enddragobject() {
  
  if (document.getElementById("viewcontainer")!=null) {  
    DoResize(document.getElementById("viewcontainer"),true);
  }
  hideglobaldropmarks();
  showmarkers(null);  
  document.body.movingobject=null;
}

function showtarget(item) {
  var objleft=0;
  var objtop=0;
  var objwidth=droptargetmarker.offsetParent.clientWidth;
  var objheight=droptargetmarker.offsetParent.clientHeight;
  var divisor=4;
  if (item.dest=="object") {
    objleft=objectdock.objectleft;
    objtop=objectdock.objecttop;        
    objwidth=document.body.dockobject.clientWidth;
    objheight=document.body.dockobject.clientHeight;
    divisor=2;    
  } else {
    showmarkers(null);
  }
  
  if (item.destalign=="top") {
    droptargetmarker.style.pixelLeft=objleft;
    droptargetmarker.style.pixelTop=objtop;
    droptargetmarker.style.pixelWidth=objwidth;
    droptargetmarker.style.pixelHeight=objheight/divisor;      
  }
  if (item.destalign=="bottom") {
    droptargetmarker.style.pixelLeft=objleft;
    droptargetmarker.style.pixelWidth=objwidth
    droptargetmarker.style.pixelHeight=objheight/divisor;      
    droptargetmarker.style.pixelTop=objtop+objheight-droptargetmarker.style.pixelHeight;
  }
  if (item.destalign=="left") {
    droptargetmarker.style.pixelLeft=objleft;
    droptargetmarker.style.pixelWidth=objwidth/divisor;
    droptargetmarker.style.pixelHeight=objheight
    droptargetmarker.style.pixelTop=objtop;
  }
  if (item.destalign=="right") {
    droptargetmarker.style.pixelTop=objtop;
    droptargetmarker.style.pixelHeight=objheight;
    droptargetmarker.style.pixelWidth=objwidth/divisor;      
    droptargetmarker.style.pixelLeft=objleft+objwidth-droptargetmarker.style.pixelWidth;
  }
  droptargetmarker.style.display="block";
  
}


function dragover(item,dragtype) {
  if (dragtype=="criteria") {
	if (document.body.dragtype=="metadata" && document.body.dragitemtype=="dimension") {
	  event.cancelBubble=true;
	  window.event.returnValue = false;
	  event.dataTransfer.dropEffect='link';  	
	}
  } else {
	event.cancelBubble=true;
	window.event.returnValue = false;
	event.dataTransfer.dropEffect='move';  
	if (item.basesrc==null) {
		item.basesrc=item.src;
	}
	item.src=item.hotsrc;  
	showtarget(item);
  }
}

function dragleave(item) {  
  if (item.basesrc!=null) {
    item.src=item.basesrc;
  }  
  window.event.returnValue = false;
  event.dataTransfer.dropEffect='move';  
  droptargetmarker.style.display="none";
}

function drop(item,dragtype) {
  if (dragtype=="criteria") {
	if (document.body.dragtype=="metadata" && document.body.dragitemtype=="dimension") {
	  Default.method.value="addtocriteriabar";
	  Default.param.value=event.dataTransfer.getData("text");
	  Default.submit();
	}
  }
}

function dropobject(item) {
  var dragData = window.event.dataTransfer;
  
  var destid=item.destid;
  if (destid==null) {
    destid=document.body.dockobject.destid;
  }
  if (destid!=null) {
    setloading();
    location.replace("Default.aspx?moveobject="+dragData.getData("text")+"&destobject="+destid+"&align="+item.destalign);  
  }
}

function showmarkers(item) {    
  if (document.body.movingobject==1) {
    if (item!=null) {    
      document.body.dockobject=item;
      objectdock.style.display="block";    
      var leftpos=0;
      var toppos=0;
      var parent=item;
      var main=document.getElementById("viewcontainer");
      if (main!=null) {    
        while (parent!=main) {
          leftpos+=parent.offsetLeft;
          toppos+=parent.offsetTop;
          parent=parent.offsetParent;
        }
        objectdock.style.pixelLeft=leftpos+(item.clientWidth/2)-40;
        objectdock.style.pixelTop=toppos+(item.clientHeight/2)-40;
        objectdock.objectleft=leftpos;
        objectdock.objecttop=toppos;        
      }    
      
    } else {
      objectdock.style.pixelLeft=0;
      objectdock.style.pixelTop=0;
      objectdock.style.display="none";
    }  
  }
}

//Dragdrop layoutobjects

function layoutObjectDragDrop(item) {
  if (event.ctrlKey) {
    return false;
  }  
  
  if (event.button==1) {
    //item.dragDrop(item);
    selectobject(null,item.obj);

  }
}

function startDragLayoutObject(item) { 
  var dragData = window.event.dataTransfer;  
  dragData.setData('Text', item.parentElement.cellid);
  dragData.effectAllowed = 'all';        
  dragData.dropEffect = 'move';        
  
  item.parentElement.style.display="none";
  startdragobject();
}

function endDragLayoutObject(item) {
  item.parentElement.style.display="block";
  enddragobject();
}

function layoutObjectDragOver(item) {  
  if (document.body.movingobject==1) {    
    window.event.returnValue = false;
    event.dataTransfer.dropEffect='move';  
    showmarkers(item.parentElement);
  }
}

//Object placement/sizing

function ResizeTable(table,xsize,ysize) {          
  table.style.pixelWidth=xsize;
  table.style.pixelHeight=ysize;  
  table.refresh;
  if (table.type=="vertical") {          
    ResizeTableVertical(table,xsize,ysize);
  } else {        
    ResizeTableHorizontal(table,xsize,ysize);
  }
}

function ResizeTableVertical(table,xsize,ysize) {
  var totalheight=0;
  var minheight=0;
  var resizingcell=table.resizecell;
  if (resizingcell!=null) {
    recalcheights(resizingcell,ysize);
  }
  
  var rows=table.rows;
  for (var i=0;i<rows.length;i++) {
    var row=rows[i];
    var cell=row.firstChild;
    if (cell.minheight==null || cell.minheight=="") {
      cell.minheight=32;
    } 
    if (cell.style.display!="none") {
      
      totalheight+=parseInt(cell.xheight);
      minheight+=parseInt(cell.minheight);
    }
  }
  
  var remainingsize=ysize;
  for (var i=0;i<rows.length;i++) {
    var cell=rows[i].firstChild;
    if (cell.style.display!="none") {
      cell.totalmin=minheight;
      var newheight=Math.round((ysize-minheight)*(parseInt(cell.xheight)/totalheight))+parseInt(cell.minheight);
      
      remainingsize-=newheight;          
      if (remainingsize<0) {
        newheight+=remainingsize;
        remainingsize=0;
      }
      cell.style.pixelHeight=newheight;//-(cell.offsetHeight-cell.clientHeight);
      cell.style.pixelWidth=xsize;//-(cell.offsetHeight-cell.clientHeight);
      
      if (cell.firstChild.tagName=="TABLE") {
        ResizeTable(cell.firstChild,xsize,newheight);
      }
      cell.parentElement.style.display="block";
    } else {
      cell.style.pixelHeight=0;
      cell.style.pixelWidth=0;
      cell.parentElement.style.display="none";
    }
    
  }
}

function recalcwidths(resizecell,xsize) {  
  var cell=resizecell.parentElement.firstChild;
  var minwidth=0;
  
  while (cell!=null) {  
    if (cell.minwidth==null || cell.minwidth=="") {
      cell.minwidth=32;
    } 
    minwidth+=parseInt(cell.minwidth);
    cell.xwidth=cell.offsetWidth-parseInt(cell.minwidth);    
    cell=cell.nextSibling;
  }
  if (resizecell.newright>(resizecell.offsetLeft+resizecell.xwidth+parseInt(resizecell.minwidth))) { //cell(s) to the right should be reduced
    var movepixels=resizecell.newright-(resizecell.offsetLeft+resizecell.xwidth)-parseInt(resizecell.minwidth);
    var nextcell=resizecell.nextSibling;   
    
    var minright=0;
    while (nextcell!=null) {      
      nextcell.xwidth-=movepixels;
      if (nextcell.xwidth<0) {
        movepixels=nextcell.xwidth*-1;
        nextcell.xwidth=0;
      } else {
        movepixels=0;
      }     
      minright+=parseInt(nextcell.minwidth);
      nextcell=nextcell.nextSibling;      
    }
    if (resizecell.newright>xsize-minright) {
      resizecell.newright=xsize-minright;
    }
    
    resizecell.xwidth=(resizecell.newright-resizecell.offsetLeft)-parseInt(resizecell.minwidth);
    
  } else { 
    
    var nextcell=resizecell.nextSibling;
    if (nextcell!=null) {      
      var leftoffset=resizecell.offsetLeft;
      if (resizecell.offsetLeft+parseInt(resizecell.minwidth)>resizecell.newright) {     
        var movepixels=(resizecell.offsetLeft+parseInt(resizecell.minwidth))-resizecell.newright;        
        var prevcell=resizecell.previousSibling;   
        var minleft=0;
        leftoffset=0;
        while (prevcell!=null) {      
          prevcell.xwidth-=movepixels;
          if (prevcell.xwidth<0) {
            movepixels=prevcell.xwidth*-1;
            prevcell.xwidth=0;
          } else {
            movepixels=0;
          }      
          leftoffset+=parseInt(prevcell.minwidth)+prevcell.xwidth;
          minleft+=parseInt(prevcell.minwidth);
          prevcell=prevcell.previousSibling;
        }
        if ((resizecell.newright-parseInt(resizecell.minwidth))<minleft) {
          resizecell.newright=minleft+parseInt(resizecell.minwidth);
        }
      }
      
      var movepixels=(resizecell.xwidth+resizecell.offsetLeft+parseInt(resizecell.minwidth))-resizecell.newright;
      resizecell.xwidth=(resizecell.newright-leftoffset)-parseInt(resizecell.minwidth);      
      
      nextcell.xwidth+=movepixels;            
    }
  }    
  if (resizecell.xwidth<0) {
    resizecell.xwidth=0;    
  }
  if (resizecell.resizemin==null || resizecell.resizemin>resizecell.xwidth) {
    resizecell.resizemin=resizecell.xwidth
  }
  if (resizecell.resizemax==null || resizecell.resizemax<resizecell.xwidth) {
    resizecell.resizemax=resizecell.xwidth;
  }  
}

function recalcheights(resizecell,ysize) {  
  var cell=resizecell.parentElement.parentElement.firstChild.firstChild;
  var minheight=0;
  
  while (cell!=null) {  
    if (cell.minheight==null || cell.minheight=="") {
      cell.minheight=32;
    } 
    minheight+=parseInt(cell.minheight);
    cell.xheight=cell.offsetHeight-parseInt(cell.minheight);
    if (cell.parentElement.nextSibling!=null) {
      cell=cell.parentElement.nextSibling.firstChild;
    } else {
      cell=null;
    }
  }
  if (resizecell.newbottom>(resizecell.offsetTop+resizecell.xheight+parseInt(resizecell.minheight))) { //cell(s) below should be reduced
    var movepixels=resizecell.newbottom-(resizecell.offsetTop+resizecell.xheight)-parseInt(resizecell.minheight);
    var nextcell=null;
    if (resizecell.parentElement.nextSibling!=null) {
      nextcell=resizecell.parentElement.nextSibling.firstChild;
    }
    
    var minbottom=0;
    while (nextcell!=null) {      
      nextcell.xheight-=movepixels;
      if (nextcell.xheight<0) {
        movepixels=nextcell.xheight*-1;
        nextcell.xheight=0;
      } else {
        movepixels=0;
      }     
      minbottom+=parseInt(nextcell.minheight);      
      if (nextcell.parentElement.nextSibling!=null) {
        nextcell=nextcell.parentElement.nextSibling.firstChild;
      } else {
        nextcell=null;
      }
    }
    if (resizecell.newbottom>ysize-minbottom) {
      resizecell.newbottom=ysize-minbottom;
    }
    
    resizecell.xheight=(resizecell.newbottom-resizecell.offsetTop)-parseInt(resizecell.minheight);    
  } else { 
    
    var nextcell=null;
    if (resizecell.parentElement.nextSibling!=null) {
      nextcell=resizecell.parentElement.nextSibling.firstChild;
    }
    if (nextcell!=null) {      
      var topoffset=resizecell.offsetTop;
      if (resizecell.offsetTop+parseInt(resizecell.minheight)>resizecell.newbottom) {     
        var movepixels=(resizecell.offsetTop+parseInt(resizecell.minheight))-resizecell.newbottom;
        var prevcell=null;
        if (resizecell.parentElement.previousSibling) {
          prevcell=resizecell.parentElement.previousSibling.firstChild;
        }
        var mintop=0;
        topoffset=0;
        while (prevcell!=null) {      
          prevcell.xheight-=movepixels;
          if (prevcell.xheight<0) {
            movepixels=prevcell.xheight*-1;
            prevcell.xheight=0;
          } else {
            movepixels=0;
          }      
          topoffset+=parseInt(prevcell.minheight)+prevcell.xheight;
          mintop+=parseInt(prevcell.minheight);
          if (prevcell.parentElement.previousSibling) {
            prevcell=prevcell.parentElement.previousSibling.firstChild;
          } else {
            prevcell=null;
          }
        }
        if ((resizecell.newbottom-parseInt(resizecell.minheight))<mintop) {
          resizecell.newbottom=mintop+parseInt(resizecell.minheight);
        }
      }
      
      var movepixels=(resizecell.xheight+resizecell.offsetTop+parseInt(resizecell.minheight))-resizecell.newbottom;
      resizecell.xheight=(resizecell.newbottom-topoffset)-parseInt(resizecell.minheight);      
      
      nextcell.xheight+=movepixels;            
    }
  }    
  if (resizecell.xheight<0) {
    resizecell.xheight=0;    
  }
  if (resizecell.resizemin==null || resizecell.resizemin>resizecell.xheight) {
    resizecell.resizemin=resizecell.xheight;
  }
  if (resizecell.resizemax==null || resizecell.resizemax<resizecell.xheight) {
    resizecell.resizemax=resizecell.xheight;
  }  
}

function ResizeTableHorizontal(table,xsize,ysize) {
  
  var totalwidth=0;
  var minwidth=0;  
  var cell=table.rows[0].firstChild;
  var resizingcell=table.resizecell;
  if (resizingcell!=null) {
    recalcwidths(resizingcell,xsize);
  }
  
  while (cell!=null) {  
    if (cell.minwidth==null || cell.minwidth=="") {
      cell.minwidth=32;
    } 
    if (cell.style.display!="none") {
      totalwidth+=parseInt(cell.xwidth);
      minwidth+=parseInt(cell.minwidth);     
    }    
    cell=cell.nextSibling;
  }
  
  var remainingsize=xsize;  
  var cell=table.rows[0].firstChild;  
  while (cell!=null) {          
    cell.totalmin=minwidth;
    if (cell.style.display!="none") {      
      var newwidth=Math.round((xsize-minwidth)*(parseInt(cell.xwidth)/totalwidth)+parseInt(cell.minwidth));      
      
      remainingsize-=newwidth;          
      if (remainingsize<0) {
        newwidth+=remainingsize;
        remainingsize=0;
      }
      
      cell.style.pixelHeight=ysize;//-(cell.offsetHeight-cell.clientHeight);
      cell.style.pixelWidth=newwidth;//-(cell.offsetHeight-cell.clientHeight);
      
      if (cell.firstChild.tagName=="TABLE") {
        ResizeTable(cell.firstChild,newwidth,ysize);            
      }            
    }
    cell=cell.nextSibling;    
  }        
}

function DoResize(element,force) {
  var xsize=element.clientWidth;
  var ysize=element.clientHeight;       
  if (force || element.ysize!=ysize || element.xsize!=xsize) {
    if (resizetimer !=null) {
      window.clearTimeout(resizetimer);     
    }    
    
    ResizeTable(element.firstChild,xsize,ysize);    
    resizetimer=window.setTimeout("reloadimages()",1000);    
  }
  element.xsize=xsize;
  element.ysize=ysize; 
}

function ForceResizeObjects() {  
  if (document.getElementById("viewcontainer")!=null) {      
    DoResize(document.getElementById("viewcontainer"),true);
  }
  if (resizetimer!=null) {
	resizetimer=null;
  }
}

//Object resizing events

var cursortype = null;
var sResizableElement = "TD";  
var iEdgeThreshold = 4;
var iSizeThreshold = 20;
var cursorobject = null;
var oResizing = false;
var oResizeTarget = null;
var iStartX = null;
var iEndX = null;
var iSizeX = null;


function TableResize_GetValidCell(objReference,objTable) 
{
  var oElement = objReference;
  while (oElement != null && oElement.tagName != null && oElement.tagName != "BODY") {
    if ((oElement.offsetParent==objTable) && oElement.tagName=="TD") {
      return oElement;
    }
    oElement = oElement.parentElement;
  }
  return null;
}

function TableResize_CleanUp() {
  iEndX = null;
  iSizeX = null;
  iStartX = null;
  oResizeTarget = null;
  oAdjacentCell = null;
  return true;
}

function setcursor(element,value) {
  if (element!=cursorobject) {
    clearcursor(cursorobject);
    cursorobject=element;
  }
  if (element!=null) {
    element.runtimeStyle.cursor=value;
  }
}

function clearcursor(element) {
  if (element!=null) {  
    if (element.style.cursor) {
      element.runtimeStyle.cursor = element.style.cursor;              
    } else {
      element.runtimeStyle.cursor = "";              
    }
  }
}

function findresizeablecell(element) {  
  if (element==null || element.tagName!="TD") {  
    return null;
  }
  
  var offsetleft=0;
  var offsettop=0;
  var p=element;
  while (p!=null) {
    offsetleft+=p.offsetLeft;
    offsettop+=p.offsetTop;
    p=p.offsetParent;
  } 
  
  var isleftedge=(offsetleft+10)>event.clientX;
  var istopedge=(offsettop+10)>event.clientY;  
  
  if (isleftedge || istopedge) { 

    if (isleftedge && (element.previousSibling!=null)) {
      return element=findresizeablecell(element.previousSibling);      
    } 
    if (istopedge && (element.parentElement.previousSibling!=null)) {      
      return findresizeablecell(element.parentElement.previousSibling.firstChild);
      
    }    
    return findresizeablecell(element.offsetParent.parentElement);
  } 
  
  var canresizewidth=element.nextSibling!=null;
  var canresizeheight=element.parentElement.nextSibling!=null;
  
  var rightEdge=offsetleft+element.offsetWidth+2;  
  
  if (event.clientX>=(rightEdge-iEdgeThreshold) && event.clientX<=(rightEdge+iEdgeThreshold)) {
    if (canresizewidth) {
      cursortype="e-resize";
      return element;
    } else {
      return findresizeablecell(element.offsetParent.parentElement);
    }
  }
  
  var bottomEdge=offsettop+element.offsetHeight+2;  
  if (event.clientY>=(bottomEdge-iEdgeThreshold) && event.clientY<=(bottomEdge+iEdgeThreshold)) {
    if (canresizeheight) {
      cursortype="n-resize";
      return element;
    } else {
      return findresizeablecell(element.offsetParent.parentElement);
    }
  }
  
  return null;
}

function TableResize_OnMouseMove(objTable) {    
    var cell = TableResize_GetValidCell(event.srcElement,objTable);    
    
    if (oResizing) { 
        if (oResizeTarget.offsetParent.type=="horizontal") {
          var newsize=window.event.clientX-oResizeTarget.leftpos-2;          
          objTable.resizecell=oResizeTarget;
          if (oResizeTarget.newright!=newsize) {
            oResizeTarget.newright=newsize;        
            ForceResizeObjects();
          }
        } else {
          var newsize=window.event.clientY-oResizeTarget.toppos-2;

          objTable.resizecell=oResizeTarget;
          if (oResizeTarget.newbottom!=newsize) {
            oResizeTarget.newbottom=newsize;
            ForceResizeObjects();
          }          
        }
        document.selection.empty();
    } else {
      event.cancelBubble=true;
      cell=findresizeablecell(cell);
      
      if (cell!=null) {
        setcursor(event.srcElement,cursortype);
        oResizeTarget=cell;
      } else {
        oResizeTarget=null;
        setcursor(null,"");
      }
    } 
  return true;
}

function TableResize_OnMouseDown(objTable) 
{
  if (event.button==1) {      
    var oTargetCell = oResizeTarget;
    if (!oTargetCell) return;
    
    if (oTargetCell.offsetParent!=objTable) {
      TableResize_OnMouseDown(oTargetCell.offsetParent);
      return;
    }

    if (oTargetCell.parentElement.tagName.toUpperCase() == sResizableElement) {
      oTargetCell = oTargetCell.parentElement;
    }
    event.cancelBubble=true;
    iStartX = event.screenX;
    oResizing=true;
    objTable.setAttribute("Resizing", "true");
    objTable.setCapture();    
    var toppos=0;
    var leftpos=0;
    var parent=objTable;
    while (parent!=document.body) {
      toppos+=parent.offsetTop;
      leftpos+=parent.offsetLeft;
      parent=parent.offsetParent;
    }
    oResizeTarget.leftpos=leftpos;
    oResizeTarget.toppos=toppos;
    return true;
  }
  
}

function TableResize_OnContextMenu(objTable) {
  if (event.ctrlKey) {
    
  } else {    
    event.cancelBubble=true;
    var oTargetCell = oResizeTarget;
    if (!oTargetCell) return false;
    /*
    if (oTargetCell.offsetParent!=objTable) {
      return TableResize_OnContextMenu(oTargetCell.offsetParent);      
    }

    if (oTargetCell.parentElement.tagName.toUpperCase() == sResizableElement) {
      oTargetCell = oTargetCell.parentElement;
    } */
    //window.status=oTargetCell.cellid;
    return false;
  }
}

function TableResize_OnMouseUp(objTable) 
{
  if (event.button==1) {      
    setcursor(null,"");
    var oAdjacentCell = null;
    var iAdjCellOldWidth = 0;
    var iResizeOldWidth = 0;

    if (iStartX != null && oResizeTarget != null) {
      iEndX = event.screenX;
      iSizeX = iEndX - iStartX;
              
      objTable.setAttribute("Resizing", "false");
      oResizing=false;
      submitsize(oResizeTarget);
      oResizeTarget.newwidth=null;
    }
        
    TableResize_CleanUp();
    objTable.releaseCapture();
  }
  return true;
}

function submitsize(cell) {
  if (cell.resizemin==null) { 
    return;
  }
  var celltable=cell.offsetParent;  
  if (celltable.type=="horizontal") {    
    var minwidth=0;
    var currwidth=0;
    var p=cell.previousSibling;
    while (p!=null) {
      minwidth+=parseInt(cell.minwidth);
      currwidth+=p.xwidth;
      p=p.previousSibling;
    }
    var totalxwidth=celltable.parentElement.clientWidth-cell.totalmin;
    var resizemin=cell.resizemin+currwidth;
    var resizemax=cell.resizemax+currwidth;
    var currsize=cell.xwidth+currwidth;
    document.location.replace("default.aspx?resizecell="+cell.cellid+"&size="+totalxwidth+"/"+resizemin+"/"+resizemax+"/"+currsize);
  } else {
    var minheight=0;
    var currheight=0;
    var p=null;
    if (cell.parentElement.previousSibling!=null) {
      p=cell.parentElement.previousSibling.firstChild;
    };
    while (p!=null) {
      minheight+=parseInt(cell.minheight);
      currheight+=p.xheight;
      if (p.parentElement.previousSibling!=null) {
        p=p.parentElement.previousSibling.firstChild;
      } else {
        p=null;
      };      
    }
    var totalxheight=celltable.parentElement.clientHeight-cell.totalmin;    
    var resizemin=cell.resizemin+currheight;
    var resizemax=cell.resizemax+currheight;
    var currsize=cell.xheight+currheight;
    document.location.replace("default.aspx?resizecell="+cell.cellid+"&size="+totalxheight+"/"+resizemin+"/"+resizemax+"/"+currsize);
  }
}
