﻿function GE(id) {
    return document.getElementById(id);
}

function popUpWin(p, w, h, x, y) {                                        	
    if(x == null) x = screenCenter(w, h)[0];
    if(y == null) y = screenCenter(w, h)[1];
	
    winOpen = window.open(p, "popUpWin", "width=" + w + ",height=" + (parseInt(h) + 30) + ",top=" + y + ",left=" + x + ",scrollbars=no,toolbar=no,location=no,resizable=no");
    winOpen.focus();
}

function screenCenter(xL, yL) {
    var scrW = screen.width;
    var scrH = screen.height;
	
    var xPos = 0;
    var yPos = 0;
	
    if(scrW > xL)
        xPos = Math.floor((scrW - xL) / 2);
		
    if(scrH > yL)
        yPos = Math.floor(((scrH - yL) / 2));
		
    cooArr = new Array(xPos, yPos);
    return cooArr;
}


function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent) {
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    } else if(obj.x) {
        curleft += obj.x;
    }

    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
    {
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    } else if(obj.y) {
        curtop += obj.y;
    }

    return curtop;
}

function MoveFloatedLayerToElementPos(divIdToMove, elementToMoveTo) {
    var divToMove = GE(divIdToMove);
    
    divToMove.style.left = findPosX(elementToMoveTo) + "px";
    divToMove.style.top = findPosY(elementToMoveTo) + "px";
    divToMove.style.visibility = 'visible';
}

var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;

var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
  if (IE) {
    var x;
    var y;
    if (document.documentElement && !document.documentElement.scrollTop) {
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    } else if (document.body && document.body.scrollTop) {
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    }     
    
    tempX = event.clientX + x;
    tempY = event.clientY + y;
  } else {
    tempX = e.pageX;
    tempY = e.pageY;
  }  

  if (tempX < 0){tempX = 0;}
  if (tempY < 0){tempY = 0;}  

  return true
}

function ShowHelp(image, dropDowns) {
    
    var divHelp = GE("Help");
    var divFrame = GE("HelpFrame");
    var divHelpShadow = GE("HelpShadow");
    
    if (image.alt == "")
        return;
    
    divHelp.innerHTML = image.alt;
    
    if (image.className == "HelpLink") {
        divHelp.innerHTML += "<a style='display:block; margin-top:5px; font-size:10px;'>(click ? for more information)</a>";
    }

    divHelp.style.left = (tempX + 25) + "px";
    divHelp.style.top = tempY + "px";
    divHelp.style.visibility = "visible";
    
    divHelpShadow.style.left = (tempX + 30) + "px";
    divHelpShadow.style.top = (tempY + 5) + "px";
    divHelpShadow.style.visibility = "visible";
    divHelpShadow.style.height = (divHelp.offsetHeight - 12) + "px";

    if(IE) {        
        divFrame.style.height = (divHelp.offsetHeight - 10) + "px";
        divFrame.style.left = (tempX + 27) + "px";
        divFrame.style.top = tempY + "px";
        divFrame.style.visibility = "visible"; 
    }    
}

function HideHelp(image) {
    GE("Help").style.visibility = "hidden";
    GE("HelpFrame").style.visibility = "hidden";
    GE("HelpShadow").style.visibility = "hidden";
 }
 
 function ShowPopupImage(imgUrl, width, height) {
    var popupBody = GE("PopupBody");
    popupBody.innerHTML = "<div style='border:solid 1px #BFAF7C;'><img src=\"" + imgUrl + "\" width=\"" + width + "\" height=\"" + height + "\" alt=\"Click image to close\" onclick=\"GE('PopupBody').style.visibility = 'hidden';\" /></div>";
    popupBody.innerHTML += "<a style='display:block; color:black; background:#BFAF7C;text-align:center;white-space:nowrap;padding:2px;' onclick=\"GE('PopupBody').style.visibility = 'hidden';\">Click to close</a>";
    PositionCenter("PopupBody");
 }
 
 function ShowPopupImage2(imgUrl, width, height) {
    var popupBody = GE("PopupBody");
    popupBody.innerHTML = "<div style='border:solid 1px #333333;'><img src=\"" + imgUrl + "\" width=\"" + width + "\" height=\"" + height + "\" alt=\"Click image to close\" onclick=\"GE('PopupBody').style.visibility = 'hidden';\" /></div>";
    popupBody.innerHTML += "<a style='display:block; color:#ffffff; background:#333333;text-align:center;white-space:nowrap;padding:2px;' onclick=\"GE('PopupBody').style.visibility = 'hidden';\">Click to close</a>";
    //PositionCenter("PopupBody");
    popupBody.style.top = 300 + "px";
    popupBody.style.left = -300 + "px";
    popupBody.style.visibility = 'visible';
 }
 
 function UpdateCount(textBoxId, charCountId, limit, limitErrorMessage) {
    var charCount = GE(charCountId);
    var textBox = GE(textBoxId);
    
    var charLength = textBox.value.length;
    
    charCount.innerText = charLength;
    
    if (charLength > limit) {
        var string = textBox.value.substring(0, limit);
        textBox.value = string;
        alert(limitErrorMessage);
        charCount.innerText = string.length;
    }
}

var _divLoading = null;

function Resize() {
    PositionDivLoading();
}

function Scroll() {
    PositionDivLoading();
}

function PositionDivLoading() {

    if (_divLoading == null)
        return;
        
    var posX = ((f_clientWidth() - 200) / 2) + f_scrollLeft();
    var posY = ((f_clientHeight() - 100) / 2) + f_scrollTop();
    
    _divLoading.style.left = posX + "px";
    _divLoading.style.top = posY + "px";
}

function PositionCenter(id) {
    
    var el = GE(id);
    
    var posX = ((f_clientWidth() - el.offsetWidth) / 2) + f_scrollLeft();
    var posY = ((f_clientHeight() - el.offsetHeight) / 2) + f_scrollTop();
    
    el.style.left = posX + "px";
    el.style.top = posY + "px";
    
    el.style.visibility = 'visible';
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
 
function Fade(id, targ, opac, incr) {
    if (!IE)
        return;
        
    var el = GE(id);
    
    if (opac != targ) {
        opac += incr;
        el.filters.alpha.opacity = opac;
        setTimeout("Fade('" + id + "', " + targ + ", " + opac + ", " + incr + ")", 50); 
    }
} 

function IsValidDate(day, month, year) { 
    var date = new Date();
    date.setFullYear( year, month - 1, day );

    if ( date.getMonth() == month - 1 )
        return true;
    else
        return false;       
} 

function Frame(el) {
    var divFrame = GE("HelpFrame");
    var elBounds = Sys.UI.DomElement.getBounds(el);
    
    divFrame.style.height = (elBounds.height - 10) + "px";
    divFrame.style.width = (elBounds.width - 10) + "px";
    divFrame.style.left = (elBounds.x) + "px";
    divFrame.style.top = (elBounds.y) + "px";
    divFrame.style.visibility = "visible"; 
}

var _helpOver = false;
var _menuUp = null;
var _defaultMenu = null;
var _helpTimeout = null;

var _hcl = new Image();
_hcl.src = "/_Img/Green/Help-Bar-Curve-Left.png";

var _hcr = new Image();
_hcr.src = "/_Img/Green/Help-Bar-Curve-Right.png";   

var _hcm = new Image();
_hcm.src = "/_Img/Green/Help-Bar-Curve-Middle.png";                        

function Over(el) {
    clearTimeout(_helpTimeout);    

    if (_menuUp != null && _menuUp != el) {
        _menuUp.style.backgroundPosition = '0px -133px';
        $get("divSectionHelp" + _menuUp.id).style.display = "none";
    } else if (_menuUp == el) {
        _helpOver = true;
        return;
    }
        
    _menuUp = el;

    $get("divSectionHelp" + el.id).style.display = "block";

    el.style.backgroundPosition = '0px 0px';                
    var hbc = $get("imgHelpBarCurve");
    var offSet = 0;
    
    if (el.id == "Find") {
        hbc.src = _hcl.src;
    } else if (el.id == "Shop") {
        hbc.src = _hcr.src;
        offSet = -11;   
    } else {
        hbc.src = _hcm.src;
        offSet = -11;     
    }

    var bounds = Sys.UI.DomElement.getBounds(el);
    hbc.style.left = (bounds.x + offSet) + "px";
    hbc.style.top = (bounds.y + bounds.height - 6) + "px";
    hbc.style.visibility = 'visible';  
    
    _helpOver = true;    
}

function Out() {
    _helpOver = false;    
    clearTimeout(_helpTimeout); 
    _helpTimeout = setTimeout(HideMenuHelp, 500);
}        

function HideMenuHelp() {
    if (!_helpOver) {
        if (_menuUp != null && _menuUp != _defaultMenu) {
            $get("imgHelpBarCurve").style.visibility = 'hidden';            
               
            _menuUp.style.backgroundPosition = '0px -133px';
            $get("divSectionHelp" + _menuUp.id).style.display = "none";
            
            if (_defaultMenu) {
                Over(_defaultMenu);
                return;
            }
        }
            
        _menuUp = null;
    }
}    

function CorrectIePng() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function LadderTable(table,idAttribute,url){
    var table=$get(table);
    var trs=table.getElementsByTagName('TR');
    for(var i=0;i<trs.length;i++){
        var tr=trs[i];
        $addHandlers(tr, {
            'mouseover':trOver,
            'mouseout':trOut
        });
        if(idAttribute){
            tr.setAttribute('url',url+tr.getAttribute(idAttribute));
            $addHandler(tr,'click',trClick);
        }
    }
}

function trOver(){
    this.setAttribute('oldcolor',this.style.backgroundColor);
    this.style.backgroundColor='#F2EFE6'; 
    this.style.cursor='pointer';                   
}

function trOut(){
    this.style.backgroundColor=this.getAttribute('oldcolor');
    this.style.cursor='';
}

function trClick(){
    document.location=this.getAttribute('url');
}