﻿// Common Scripts Created and used by Lance Faler


    
// =======================================================================================================================
// General Functions
// =======================================================================================================================

function findPos(obj) {
    var curleft = 0, curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
	        curleft += obj.offsetLeft
	        curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

function findSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof( window.innerWidth ) == 'number' ) {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth,myHeight];
}


// =======================================================================================================================
// Balloon Functions
// =======================================================================================================================

function InitBalloon(){
    document.write("<div id='balloon' class='balloon' onmouseover='OnBalloon();' onmouseout='HideBalloon();' style=' display: none; '><div id='balloontext' class='balloontext'></div></div>");
}

function ShowBalloon(el, str){
    var b = document.getElementById("balloon");
    b.style.display = "block";
    b.style.left = (findPos(el)[0] + 6) + "px";
    b.style.top = (findPos(el)[1] - 68) + "px";
    var btext = document.getElementById("balloontext");
    btext.innerHTML = str;
}

function HideBalloon(){
    var b = document.getElementById("balloon");
    b.style.display = "none";
}

function OnBalloon(el, str){
    var b = document.getElementById("balloon");
    b.style.display = "block";
}


// =======================================================================================================================
// Pup-Up Functions
// =======================================================================================================================

function ShowPopup(name){   
    var bkgd = document.getElementById("popupbkgd");
    bkgd.style.display = "block";
    CenterPopup(name); 
    var b = document.getElementById(name);
    b.style.display = "block";
}

function HidePopup(name){
    var bkgd = document.getElementById("popupbkgd");
    bkgd.style.display = "none";
    var b = document.getElementById(name);
    b.style.display = "none";
    document.body.style.overflow = 'auto';
}

function CenterPopup(name) {
    var b = document.getElementById(name);
    b.style.left = ( ( findSize()[0] / 2 ) - 225 ) + "px";
    b.style.top = ( ( findSize()[1] / 2 ) - 150 ) + "px";
}



// =======================================================================================================================
// AJAX Functions
// =======================================================================================================================

function ajaxReplace(element, target, spinner) {
  
    var xmlHttp;
    var spin;
    
    try {
        spin = document.getElementById(spinner);
    } catch (e) { 
        spin = null; 
    }
  
    try { 
        xmlHttp=new XMLHttpRequest(); 
    } catch(e) {
        try { 
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) {
            try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e) { 
                alert("Your browser does not support AJAX!");
                return false;        
            }      
        }    
    }
    
  
    if (spin != null){
        spin.style.display = 'block';
    } 
    
    xmlHttp.onreadystatechange = function() {
        if(xmlHttp.readyState == 4) { 
            document.getElementById(element).innerHTML = xmlHttp.responseText;
            if (spin != null){
                spin.style.display = 'none';
            } 
        } 
    }
    
    xmlHttp.open("GET", target, true);
    xmlHttp.send(null);  
}

