
// Navigation

function nav_hrz(txt) {
    Vertical_Navigation(txt);
    Body_Text(txt);
}


function Vertical_Navigation(txt) {
    switch (txt) {
        case "About Us":
            document.getElementById('nav_ver').innerHTML = '' +
            '<ul> ' +
            '    <li><a href="javascript:Body_Text(\'About_Profile\')">Company Profile</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'About_History\')">Company History</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Customer Service\')">Customer Service</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'About_Press\')">Carlisle in the Press</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'About_Recent\')">Recently!</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Associate_Store\')">Company Store</a></li> ' 
            '</ul>';
            break;
        case "Contact Us":
            document.getElementById("nav_ver").innerHTML =
            '<ul> ' +
            '    <li><a href="javascript:Body_Text(\'Contact Us Email\')">Email Form</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Contact Us Map\')">Map: Headquarters</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Contact_Us_Map_Operating_Centers\')">Map: Operating Ctr.s</a></li> ' +
            '</ul>';
            break;
        case "Employment":
            document.getElementById("nav_ver").innerHTML =
            '<ul> ' +
            '    <li><a href="javascript:Body_Text(\'Employment_Company_Pay\')">Company Driver Pay</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Employment_Contract_Rates\')">Contract Driver Rates</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Employment_Driver_App\')">Driver Application</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Employment_Application\')">Non-Driver Application</a></li> ' +
            '</ul>';
            break;
        case "Awards":
            document.getElementById("nav_ver").innerHTML =
            '<ul> ' +
            '    <li>&nbsp;</li> ' +
            '</ul>';
            break;
        case "Associate":
            document.getElementById("nav_ver").innerHTML =
            '<ul> ' +
            '    <li><a href="javascript:Body_Text(\'Associates/CSA2010\')">CSA 2010</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Associates/DriveCam\')">DriveCam</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Associate_Store\')">Company Store</a></li> ' +
            '    <li><a href="javascript:Body_Text(\'Associates/Recognition\')">Recognition/Awards</a></li> ' +
            '    <li>&nbsp;</li> ' +
            '    <li>Policies and Forms</li> ' +
            '    <li><a href="javascript:Body_Text(\'Associates/Forms\')">Company Forms</a></li> ' +
            '</ul>';
            break;
        case "Customers":
            document.getElementById("nav_ver").innerHTML =
            '<ul> ' +
            '    <li><a href="javascript:Body_Text(\'Customers\/POD_Inquiry\')">Proof of Delivery</a></li> ' +
            '</ul>';
            break;
        case "Login":
            document.getElementById("nav_ver").innerHTML =
            '<ul> ' +
            '    <li>&nbsp;</li> ' +
            '</ul>';
            break;
        default: ;
    }
}

function Body_Text(txt) {

    switch (txt) {
        case "About Us":
            Load_URL("Body-Text", "About_Carlisle.htm", false);
            break;
        case "About_History":
            Load_URL("Body-Text", txt + ".htm", false);
            break;
        case "About_Press":
            Load_URL("Body-Text", txt + ".htm", false);
            break;
        case "About_Profile":
            Load_URL("Body-Text", txt + ".htm", false);
            break;
        case "About_Recent":
            Load_URL("Body-Text", txt + ".htm", false);
            break;
        case "Associate":
            Load_URL("Body-Text", "Associates/" + txt + ".aspx", true);
            break;
        case "Associate_Store":
            window.open('http://www.chesapeakedesign.com/default.cfm?customerid=5');
            break;
        case "Awards":
            Load_URL("Body-Text", txt + ".htm", false);
            break;
        case "Customer Service":
            Load_URL("Body-Text", "Customer_Service.htm", false);
            break;
        case "Customers":
            Load_URL("Body-Text", "Customers\/Customers_Welcome.aspx", true);
            break;
        case "Contact Us":
            Load_URL("Body-Text", "Contact_Us_Addresses.htm", true);
            break;
        case "Contact Us Email":
            Load_URL("Body-Text", "Contact_Us_Email.aspx", true);
            break;
        case "Contact Us Map":
            Load_URL("Body-Text", "Contact_Us_Map.htm", false);
            break;
        case "Contact_Us_Map_Operating_Centers":
            Load_URL("Body-Text", txt + ".htm", false);
            break;
        case "Employment":
            Load_URL("Body-Text", txt + ".htm", true);
            break;
        case "Employment_Application":
            Load_URL("Body-Text", txt + ".aspx", true);
            break;
        case "Employment_Contract_Rates":
            Load_URL("Body-Text", txt + ".htm", true);
            break;
        case "Employment_Company_Pay":
            Load_URL("Body-Text", txt + ".htm", true);
            break;
        case "Employment_Driver_App":
            Load_URL("Body-Text", txt + ".aspx", true);
            break;
        case "Login":
            Load_URL("Body-Text", txt + ".aspx", true);
            break;
        case "Tempate":
            Load_URL("Body-Text", "Employment.htm", true);
            break;
        default:
            Load_URL("Body-Text", txt + ".aspx", true);
            break;
    }
}


function Load_URL(sElementID, sURL, bInFrame) {

    var elem = document.getElementById(sElementID);

    if (!bInFrame) {
        elem.style.height = iFrame_Size() + "px";
        elem.style.overflow = "auto";
        elem.innerHTML = ReadHTML(sURL);
    }
    else {
        elem.style.overflow = "";
        elem.innerHTML = "<iframe id='iFrame' name='iFrame' " +
                         "src='" + sURL + "' Class='iframe' " +
                         "frameborder='0' allowautotransparency=false " + 
                         "style='height: " + iFrame_Size() + "px'> " +
                         "ReadHTML('" + sURL + "')</iframe>";
    }
}


function Load_HTML(sElementID, sHTML) {
    var elem = document.getElementById(sElementID)
    elem.innerHTML = sHTML;
}

function ReadHTML(sURL) {
    var oRequest = new XMLHttpRequest();
    oRequest.open("GET", sURL, false);
    oRequest.setRequestHeader("User-Agent", navigator.userAgent);
    oRequest.send(null);
    if (oRequest.status == 200) return oRequest.responseText;
    else return "Sorry - Link to " + sURL + " is broken.  An alert has been sent to the webmaster.";
}


function BOL_Click(sBOL) {
    var elem = document.getElementById("txtID");
    if (elem != null) {
        elem.value = sBOL;
        document.forms["frmPOD"].btnDisplay.click();
    }

}


//  Sizing

function Resize_divResult(){
    if (document.getElementById('divResult') != null) {
        document.getElementById('divResult').style.height = window.frameElement.clientHeight - 150 + 'px';
    }
}


function Resize_iFrame() {
    var Height = 0;
    Height = iFrame_Size();
    if (document.getElementById('iFrame') != null) {
        document.getElementById('iFrame').style.height = Height + 'px';
    }
    
    if (Height > 25) {    
        if (document.getElementById('Body-Text') != null) {
            document.getElementById('Body-Text').style.height = Height + 'px';
        }

        if (document.getElementById('Left') != null) {
            document.getElementById('Left').style.height = 200 + Height + 'px';
        } 
        if (document.getElementById('Outer') != null) {
            document.getElementById('Outer').style.height = 200 + Height + 'px';
        }     
        if (document.getElementById('NavHrz') != null) {
            Move_Obj("NavHrz", "Banner", 10, 152);
        }
        if (document.getElementById('Logo_On_Truck') != null) {
            Move_Obj("Logo_On_Truck", "Banner", 200, 32);
        } 
    }
}

function iFrame_Size() {
    var elem = document.getElementById('Body-Text');
    var totalHeight = 0;
    if (elem != null) {
        if (elem.innerHeight)
            totalHeight = elem.innerHeight;
        else if (document.documentElement && document.documentElement.clientHeight)
            totalHeight = document.documentElement.clientHeight;
        else if (document.body)
            totalHeight = document.body.clientHeight;
        totalHeight = totalHeight - 240;
    }
    return totalHeight;
}




//  Transitions

function Fade_In(stxt) {
    var i;
    for (i = 0; i < 11; i++)
       setTimeout('Set_Opacity("' + stxt + '",' + i + ')', 100 * i);
    return false;
}

function Set_Opacity(txt, i) {
    var elem;
    elem = document.getElementById(txt).style;
    elem.display = "";
    elem.opacity = i / 10;
    elem.filter = 'alpha(opacity=' + i * 10 + ')';
}


function HideUnhide(txt) {
    var elem;
    elem = document.getElementById(txt).style;
    if (elem.display != "") {
        elem.display = "";
    }
    else {
        elem.display = "none";
    }
}


function Thumbnail_Expand(txt) {
    var elem;
    elem = document.getElementById(txt).style;
    if (elem.height == "100px") {
        var zoom = parseInt(document.getElementById('inpZoom').value);
        createCookie('POD_Inquiry_inpZoom', zoom, 0);
        elem.height = zoom +"%";
        elem.width = zoom + "%";
    }
    else {
        elem.height = "100px";
        elem.width = "100px";
    }
}

function Move_Into_Position(ObjToMoveID, ObjRefID, x, ToX, xi, y, ToY, yi, h, ToH, hi, w, ToW, wi) {

    elem = document.getElementById(ObjToMoveID).style;
 
    if (x != ToX || y != ToY || h != ToH || w != ToW) {
        if (x != ToX) x = x + xi;
        if (y != ToY) y = y + yi;
        if (w != ToW) w = w + wi;
        if (h != ToH) h = h + hi;
        Move_Obj(ObjToMoveID, ObjRefID, x, y);
        setTimeout('Move_Into_Position("' +
                    ObjToMoveID + '", "' + ObjRefID + '",' +
                    x + ',' + ToX + ',' + xi + ',' +
                    y + ',' + ToY + ',' + yi + ',' +
                    h + ',' + ToH + ',' + hi + ',' +
                    w + ',' + ToW + ',' + wi + ')', 10);
        elem.width = w + "px";
        elem.height = h + "px";
    }
}

function Move_Obj(ObjToMoveID, ObjRefID, x, y) {
    var ObjToMove;
    var ObjRef;
    ObjRef = document.getElementById(ObjRefID);
    ObjToMove = document.getElementById(ObjToMoveID).style;
    ObjToMove.left = findPosX(ObjRef) + x + "px";
    ObjToMove.top = findPosY(ObjRef) + y + "px";
}

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;
}



// Cookies!

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}


function No_Spam_Contact(name, domain) {
    document.write('<a href=\"mailto:' + name + '@' + domain + '.com\">');
    document.write(name + '@' + domain + '.com</a>');
}



// AJAX
var xmlhttp

function showData(sURL, sID) {
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    var url = sURL;
    url = url + "?q=" + sID;
    url = url + "&sid=" + Math.random();
    xmlhttp.onreadystatechange = stateChanged;
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

function stateChanged() {
    if (xmlhttp.readyState == 4) {
        document.getElementById("Data").innerHTML = xmlhttp.responseText;
    }
}

function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}




