
window.onload = init;
window.onresize=footerfix;

var newWin = null;

function setWidth(item,subtract,findBy){
	// Set default value
    findBy = typeof(findBy) != 'undefined' ? findBy : 'objectID';
    if(findBy == 'objectID'){
        item.style.width = document.body.offsetWidth - subtract;
    }
    else{
        item.invoke('setStyle', { width:document.body.offsetWidth - subtract});
    }
}

function popUp(url, variant, width, height,winName) {
	 if(winName == null)
		 winName = "newWin"
     if (newWin != null && !newWin.closed)
       newWin.close();
     var options="";
     if (variant=="console")
       options="resizable=1,height="+
         height+",width="+width;
     if (variant=="fixed")
       options="status=0,height="+
         height+",width="+width;
     if (variant=="elastic")
       options="toolbar=0,menubar=1,scrollbars=1,status=1,"+
         "resizable=1,height="+
         height+",width="+width;
     if (variant=="standard")
       options="toolbar=0,menubar=0,scrollbars=1,status=1,"+
         "resizable=1,height="+
         height+",width="+width;
     newWin = window.open(url, winName, options);
     newWin.focus();
}

function uppercaseFirst( word ){
    return word.charAt(0).toUpperCase() + word.substring(1).toLowerCase();
}

function get(x){
    return document.getElementById(x)?document.getElementById(x).offsetHeight+90:0
}

function init() {
    tooltip.init();
    footerfix();
}

function getWindowHeight() {
    if( window.innerHeight && window.scrollMaxY ) // Firefox
    {
        pageHeight = window.innerHeight + window.scrollMaxY;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
    {
        pageHeight = document.body.scrollHeight;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    {
        pageHeight = document.body.offsetHeight + document.body.offsetTop;
    }
    return pageHeight;
}

function footerfix() {
    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        var footerElement = document.getElementById('tail');
        if(footerElement){
	        if (windowHeight > 0) {
	            footerElement.style.top = windowHeight + 'px';
	        }
	        else {
	            footerElement.style.top = '0px';
	        }
        }
    }
}

function getHeight(){
    return document.getElementById("content").clientHeight;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function centerContent() {
    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        if (windowHeight > 0) {
            var contentElement = document.getElementById('content');
            var contentHeight = contentElement.offsetHeight;
            if (windowHeight - contentHeight > 0) {
                contentElement.style.position = 'relative';
                contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
            }
            else {
                contentElement.style.position = 'static';
            }
        }
    }
}


//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com | http://solardreamstudios.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//////////////////////////////////////////////////////////////////



var qTipTag = "span"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipClass = "text_tooltip"; //Classname of the tag to qTip-ize (have empty if all tag is to be qTip-ized)
var qTipX = -30; //This is qTip's X offset//javascript add element
var qTipY = 25; //This is qTip's Y offset//



//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

tooltip.init = function () {
    var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
    if(!tipContainerID){ var tipContainerID = "qTip";}
    var tipContainer = document.getElementById(tipContainerID);

    if(!tipContainer) {
      tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
        tipContainer.setAttribute("id", tipContainerID);
      document.getElementsByTagName("body").item(0).appendChild(tipContainer);
    }

    if (!document.getElementById) return;
    this.tip = document.getElementById (this.name);
    if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

    var a, sTitle;
    var anchors = document.getElementsByTagName (qTipTag);

    for (var i = 0; i < anchors.length; i ++) {
        a = anchors[i];
        //
        if( qTipClass == '' || a.className == qTipClass )
        {
            sTitle = a.getAttribute("title");
            if(sTitle) {
                a.setAttribute("tiptitle", sTitle);
                a.removeAttribute("title");
                a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
                a.onmouseout = function() {tooltip.hide()};
        }
        }
    }
}

tooltip.move = function (evt) {
    var x=0, y=0;
    if (document.all) {//IE
        x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
        y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
        x += window.event.clientX;
        y += window.event.clientY;

    } else {//Good Browsers
        x = evt.pageX;
        y = evt.pageY;
    }
    this.tip.style.left = (x + this.offsetX) + "px";
    this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
    if (!this.tip) return;
    this.tip.innerHTML = text;
    this.tip.style.display = "block";
}

tooltip.hide = function () {
    if (!this.tip) return;
    this.tip.innerHTML = "";
    this.tip.style.display = "none";
}

// temporary fix for IE 6 handling of png
// remove when IE6 is obsolete!
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage)
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters))
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
       var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
       var imgTitle = (myImage.title) ?
                     "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
       var imgStyle = "display:inline-block;" + myImage.style.cssText
       var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width
                  + "px; height:" + myImage.height
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
       myImage.outerHTML = strNewHTML
    }
}

/*
    Helper function to swap images on events.
*/
function imgSwap(objectSwap,imageSwap){
    $(objectSwap).src=imageSwap;
}
