var agt=navigator.userAgent.toLowerCase();
// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1)); 
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false

function isfirefoxornavigator(){
    return is_nav6;
}
function issafari(){
    return is_safari;
}
function isie(){
    return is_ie5up;
}
            

/**
 * the method allows the client to make an asynchronus call to the server
 * passing a return method to which the server's reponse XML will be passed.
 * the url called is also passed as a parameter to the method.
 */
function makeAjaxCall(tabContentUrl,callBackMethod){
    var ajaxObject = new sack();
    ajaxObject.requestFile = tabContentUrl;
    ajaxObject.onCompletion = function(){ 
        /*if( ajaxObject.responseXML != null ){
            var i, v, n_elems, elems = ajaxObject.responseXML.getElementsByTagName("option");
            n_elems = elems.length;
            for (i = 0; i < n_elems; i++){
                v = elems[i].firstChild.nodeValue;
                if( v == 'logoff' ){
                    window.location = 'exit.do';
                    clearserverping();
                    alert('Your session timed out. Please log in again.');
                    break;
                }
            }
        }else{
            window.location = 'exit.do';
            clearserverping();
        }*/
        callBackMethod(ajaxObject.responseXML);
    };
    // Execute AJAX function
    ajaxObject.runAJAX();		
}

function makeAjaxCallFillDiv(tableContentUrl,fillElem,callBackMethod){
    var ajaxObject = new sack();
    ajaxObject.requestFile = tableContentUrl;
    ajaxObject.element = fillElem;
    ajaxObject.onCompletion = function(){ 
        callBackMethod(ajaxObject.responseXML);
    };
    // Execute AJAX function
    ajaxObject.runAJAX();		
}

/**
 * creates a div with id passed as the first parameter at the location of
 * the element whose reference id is passed as the second parameter.
 */
function createDIV( divId, referenceElementId, parent, dispX, dispY ){
    var mObj = document.createElement('div');
    mObj.id = divId;
    /**
     * position the div
     */
    if( document.getElementById( referenceElementId ) != null ){
        coordinates = findPos( document.getElementById( referenceElementId ) );
        /**
         * set div coordinates as per the reference elements coordinates.
         */
        mObj.style.left = ( coordinates[0] + dispX ) + 'px';
        mObj.style.top = ( coordinates[1] + dispY ) + 'px';
    }else{
        mObj.style.left = ( dispX ) + 'px';
        mObj.style.top = ( dispY ) + 'px';
    }
    mObj.style.visibility = 'visible';
    /**
     * put div as child of specified parent.
     */
    document.getElementById(parent).appendChild(mObj);
}

/**
 * generates an array of integers representing the left x, top y, width
 * and height of the object passed. the object is assumed to be an HTML 
 * element.
 */
function findPos(obj) {
    var curleft = curtop = curwidth = curheight = 0;
    curwidth = obj.style.width;
    curheight = obj.style.height;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop,curwidth,curheight];
}

// Removes leading whitespaces
function LTrim( value ) {
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value ) {
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim( value ) {
    return LTrim(RTrim(value));
}

/**
 * the function expects an XML object as input parses the XML data and
 * converts to a javascript array.
 *
 * the xml is expected to have the data under the option tag.
 * the xml is expected to have the data in the option tag under 'val' tag.
 */
function arrayFromXML( theXMLObject, optionTag, valTag ){
    var response = theXMLObject.documentElement;
    var x = response.getElementsByTagName( optionTag );
    var val,val2,val3;
    var retArray = [];
    
    for(var i = 0;i < x.length; i++){
        val = x[i].getElementsByTagName( valTag )[0].firstChild.data;
        retArray[i] = val;
    }
    
    return retArray;
}

function foldString( initialString, lengthToFoldAt ){
    var retval = "";
    var len = initialString.length, currentX = 0, a = 1;
    if( len > lengthToFoldAt ){
        while( a == 1 ){
            if( currentX + lengthToFoldAt < len )
                retval += initialString.substring( currentX, currentX + lengthToFoldAt ) + '<br>';
            else 
                retval += initialString.substring( currentX, len );
            currentX += lengthToFoldAt;
            if( currentX > len )break;
        }
    }else{
        retval = initialString;
    }
    return retval;
}

//IMAGE PROCESSING
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var args=MM_swapImgRestore.arguments;
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=args[0];
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var image_change_step = 1;
function opacity(id, opacStart, opacEnd, millisec) {
        var speed = Math.round(millisec / 100);
        var timer = 0;
        if(opacStart > opacEnd) { 
                for(i = opacStart; i >= opacEnd; i-=image_change_step) {
                        setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                        timer++;
                }
        } else if(opacStart < opacEnd) {
                for(i = opacStart; i <= opacEnd; i+=image_change_step){
                        setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
                        timer++;
                }
        }
}

function changeOpac(opacity, id) {
        var object = document.getElementById(id).style;
        object.opacity = (opacity / 100);
        object.MozOpacity = (opacity / 100);
        object.KhtmlOpacity = (opacity / 100);
        object.filter = "alpha(opacity=" + opacity + ")";
}