// Common.js


// clean out status cookie
document.cookie = "checkboxStatus = ";

function checkBackButton() 
{
   document.body.background="/blade_background.jpg";
    /*
    removed it because it doesn't work
    if (window.location.href.match(/\/help\//)) {
        document.cookie= "timeStamp=" + document.body.getAttribute("now");
        
        return;
    }
        
    var cookieNow = document.cookie.match(/timeStamp=(\d+);/);
    if (cookieNow) {
        if (cookieNow[1] != document.body.getAttribute("now")) {
            alert("Using the Back button can cause unpredictable behaviour." 
                  + "\nUse the breadcrumb at the top of the page instead.");
            document.cookie= "timeStamp=" + document.body.getAttribute("now");
            window.location.href = "/WorkflowHandler?makeUrlDifferent=" + new Date().getTime();
            
        }
    }
    
    */
}


function getWindowDimensions() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        var d = new Object();
        d.width = document.body.clientWidth;
        d.height = document.body.clientHeight;
        return d;
    } else {
        var d = new Object();
        d.width = window.outerWidth;
        d.height = window.outerHeight
        return d;

    }
}


function getEventObject(e) {  // utility function to retrieve object from event
    if (navigator.appName == "Microsoft Internet Explorer") {
        return window.event.srcElement;
    } else {  // is mozilla/netscape
        // need to crawl up the tree to get the first "real" element
        // i.e. a tag, not raw text
        var o = e.target;
        while (!o.tagName) {
            o = o.parentNode;
        }
        return o;
    }
}


function addEvent(name, obj, funct) { // utility function to add event handlers
    if (obj) {
        
        if (navigator.appName == "Microsoft Internet Explorer") {
            obj.attachEvent("on"+name, funct);
        } else {  // is mozilla/netscape
            obj.addEventListener(name, funct, false);
        }
    }
    
}


function deleteEvent(name, obj, funct) { // utility function to delete event handlers

    if (navigator.appName == "Microsoft Internet Explorer") {
        obj.detachEvent("on"+name, funct);
    } else {  // is mozilla/netscape
        obj.removeEventListener(name, funct, false);
    }
}


function openHelpWithScreen(screen) 
{
    var height = Math.min(800, window.screen.availHeight - 80);
    
    
     var w = window.open('/screenHelp?screen='+screen,'prodhelp', 'width=600,height=' 
                 + height +',resizable=1,scrollbars=1,top=40');

     w.focus();
     
     return false;
    
}


function openWindow(url, windowName, width, height, scrollbars, resizable)
{
        windowName = windowName.replace(' ','');
	target = window.open(url, windowName, 'width='+width+',height='+height+',location=off,status=off,scrollbars='+scrollbars+',resizable='+resizable+',toolbar=no,status=yes');
	target.focus();
}

function closeWindow()
{
	window.close();
}


function hideAllSelects() 
{
    
    var selects = document.getElementsByTagName("SELECT");
    for (var i = 0 ; i < selects.length ; i++) {
        var s = selects[i];
        s.style.visibility = "hidden";
    }
    
}

function bw_check()
{
    var is_major = parseInt( navigator.appVersion );
    this.nver = is_major;
    this.ver = navigator.appVersion;
    this.agent = navigator.userAgent;
    this.dom = document.getElementById ? 1 : 0;
    this.opera = window.opera ? 1 : 0;
    this.ie5 = ( this.ver.indexOf( "MSIE 5" ) > -1 && this.dom && !this.opera ) ? 1 : 0;
    this.ie6 = ( this.ver.indexOf( "MSIE 6" ) > -1 && this.dom && !this.opera ) ? 1 : 0;
    this.ie4 = ( document.all && !this.dom && !this.opera ) ? 1 : 0;
    this.ie = this.ie4 || this.ie5 || this.ie6;
    this.mac = this.agent.indexOf( "Mac" ) > -1;
    this.ns6 = ( this.dom && parseInt( this.ver ) >= 5 ) ? 1 : 0;
    this.ie3 = ( this.ver.indexOf( "MSIE" ) && ( is_major < 4 ) );
    this.hotjava = ( this.agent.toLowerCase().indexOf( 'hotjava' ) != -1 ) ? 1 : 0;
    this.ns4 = ( document.layers && !this.dom && !this.hotjava ) ? 1 : 0;
    this.bw = ( this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera );
    this.ver3 = ( this.hotjava || this.ie3 );
    this.opera7 = ( ( this.agent.toLowerCase().indexOf( 'opera 7' ) > -1 ) || ( this.agent.toLowerCase().indexOf( 'opera/7' ) > -1 ) );
    this.operaOld = this.opera && !this.opera7;
    return this;
};

function trim(s) 
{ 
    if (!s) {
        return null;
    }
    
    s = s.replace(/^\s+(\S*)/g, "$1");
    s = s.replace(/(\S*)\s+$/g, "$1");
    return s;
}


function doIeHack(div)
{
    dw = div.offsetWidth;
    dh = div.offsetHeight;
    
    
    div.zIndex = 400;
    
    var els = document.getElementsByTagName("body");
    var body = els[0];
    if( !body ) return;
    
    //paste iframe under the modal
    var underDiv = div.cloneNode(false); 
    underDiv.style.zIndex="390";
    underDiv.style.margin = "0px";
    underDiv.style.padding = "0px";
    underDiv.style.display = "block";
    underDiv.style.width = dw;
    underDiv.style.height = dh;
    underDiv.style.border = "1px solid WindowText";

    var iframe = document.createElement("IFRAME");
    var m = location.href.match(/^(https?:\/\/.*)\/(.*)$/);
    
    iframe.src = m[1] + "/blank.jsp";
    
    iframe.width = dw - 2;
    iframe.height = dh - 2;
    iframe.frameBorder = 0;
    underDiv.appendChild(iframe);

    body.appendChild(underDiv);
    div.underDiv = underDiv;

}


// Point x, y class
function Point(iX, iY)
{
   this.x = iX;
   this.y = iY;
}

// Get the Point of the given tag
function getPoint(aTag)
{
   var oTmp = aTag;  
   var point = new Point(0,0);
  
   do 
   {
      point.x += oTmp.offsetLeft;
      point.y += oTmp.offsetTop;
      oTmp = oTmp.offsetParent;
   } 
   while (oTmp.tagName != "BODY");

   return point;
}

function Clickheretoprint()
{ 
  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById("print_content").innerHTML; 
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><link rel = "stylesheet" href = "stylesheet/bca_style.css" type = "text/css"/><link rel = "stylesheet" href = "stylesheet/bca_style_print.css" type = "text/css" media = "print"/><title>Floodsafe</title>'); 
   docprint.document.write('</head><body onLoad="self.print()"><center>'); 
   docprint.document.write(content_vlue);
   docprint.document.write('<br /><input type="button" name="close" value="Close this page" onclick="window.close()"/>');
   docprint.document.write('</center></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}

