//<![CDATA[

// Global vars
var docDomain = document.domain.toString().toLowerCase();
var docPath = window.location.toString().toLowerCase();
var homeFlag = true;
var objTimeout;

// Domain Suffix
docDomain = docDomain.replace("pemrose", "");
docDomain = docDomain.replace("corporation", "");
docDomain = docDomain.replace("corp", "");
docDomain = docDomain.replace("www.", "");

// Prototype innerText for Mozilla
if((typeof HTMLElement != 'undefined') && HTMLElement.prototype.__defineGetter__ != 'undefined')
    {
        HTMLElement.prototype.__defineGetter__("innerText", function () {
           var r = this.ownerDocument.createRange();
           r.selectNodeContents(this);
           return r.toString();
        }); 
    }

// Add left trim, right trim, and trim functions
if (!String.prototype.lTrim) {
    String.prototype.lTrim = function() { return this.replace(/^\s*/, ''); }
}
if (!String.prototype.rTrim) {
    String.prototype.rTrim = function() { return this.replace(/\s*$/, ''); }
}
if (!String.prototype.trim) {
    String.prototype.trim = function() { return this.lTrim().rTrim(); }
}

// This will remove all whitespace from a string
if (!String.prototype.removeAllWhitespace) {
    String.prototype.removeAllWhitespace = function() { return this.replace(/\s+/g, ''); }
}

function addEvent(obj, evType, fn, useCapture){
    removeEvent(obj, evType, fn, useCapture);

    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    }

    if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    }
} // end function

function removeEvent(obj, evType, fn, useCapture){
    if (obj.removeEventListener) {
        obj.removeEventListener(evType, fn, useCapture);
        return true;
    }

    if (obj.detachEvent) {
        var r = obj.detachEvent("on"+evType, fn);
        return r;
    }
} // end function

function objAnimatedWelcome_DoFSCommand(command, args) {
    if (document.all) {
        document.getElementById('objAnimatedWelcome').SetVariable("domain", docDomain);
    } else {
        window.document.objAnimatedWelcome.SetVariable("domain", docDomain);
    }
} // end function

function hideOverlay() {
    document.getElementById('animatedWelcome').className = "hidden";
    document.getElementById('animatedWelcome').innerHTML = "";
    document.getElementById('overlayPopup').className = "hidden";
    
    document.getElementById('pemroseLogo').src = "/images/animatedPemroseLogo" + docDomain + ".gif";
    document.getElementById('windowWhiteOut').className = "hidden";
    document.getElementById('windowBlackOut').className = "hidden";
    if (document.all && homeFlag)
        document.getElementById('googleVideoPlayer').SetVariable("autoPlay", "true");
        
    window.clearTimeout(objTimeout);
} // end function

function exitPage() {
    document.getElementById('windowWhiteOut').className = "shown";
} // end function

function setupPage() {
    //addEvent(document, 'selectstart', preventCopy);
    addEvent(document, 'keypress', checkESC);
    //addEvent(document, 'contextmenu', preventCopy);
    addEvent(document, 'unload', exitPage);
    
    window.scrollTo(0,0);
    overlaySize();
   
    docPath = docPath.replace(docDomain, "");
    docPath = docPath.replace("http://", "");
    docPath = docPath.replace("https://", "");
    docPath = docPath.replace("#", "");
    
    docDomain = docDomain.replace("pemrose", "");
    docDomain = docDomain.replace("corporation", "");
    docDomain = docDomain.replace("corp", "");
    docDomain = docDomain.replace("www.", "");

    if (docPath != "/" && docPath != "/default.aspx")
	homeFlag = !homeFlag;
    
    checkEmptyHide('leftContent', 'leftBodyContainer');
    checkEmptyHide('rightContent', 'rightBodyContainer');
    checkEmptyHide('breadcrumbContent', 'breadcrumbContainer');
    checkEmptyHide('lowerLeftContent', 'lowerLeftBodyContainer');
    checkEmptyHide('bottomLeftContent', 'bottomLeftBodyContainer');
    displaySize();
    
    if (homeFlag) {
        document.getElementById('titlePic').className = "hidden";
        document.getElementById('titleContainer').className = "hidden";
        
        if (window.screen.width > 800)
            document.getElementById('mainBodyTable').style.width = "950px";
        
        document.getElementById('animatedWelcome').className = "shown";
        document.getElementById('windowWhiteOut').className = "shown";
    
        if (document.all)
            document.getElementById('objAnimatedWelcome').play();
            
        objTimeout = window.setTimeout(hideOverlay, 6500);
    } else {
        objTimeout = window.setTimeout(hideOverlay, 500);
    }
} // end function

function checkEmptyHide(refContent, refContainer) {
    var objContent = document.getElementById(refContent);
    var objContainer = document.getElementById(refContainer);
    
    if (objContent && objContainer && objContent != undefined && objContainer != undefined) {
        if (objContent.innerText.removeAllWhitespace() == "") {
            objContainer.className = "hidden";
        } else {
            objContainer.className = "";
        } // end if
    } // end if
} // end function

function preventCopy() {		
    var winEvent = (window.event) ? window.event : evt;
    winEvent.returnValue = false;

    if (document.all) {
        winEvent.cancelBubble = true;
        event.returnValue = false;
        
        try {
            if (winEvent.srcElement.tagName != 'INPUT')
                document.selection.empty();
        } catch(e) {}
    } else {
        winEvent.cancel = true;
    }
} // end function

function checkESC(evt) {
    if (document.all) {
        var winEvent = (window.event) ? window.event : evt;
        
        switch (winEvent.keyCode) {
				// Escape Key
				case 0x1b: {
                    hideOverlay();
                    //closeGalery();
                    break;
                }
        }
    }
} // end function

function closeGallery() {
    hideMe(document.getElementById("galleryDisplay"));
} // end function

function hideMe(ref) {
    ref.className = 'hidden';
    
    var objBlackout = document.getElementById("windowWhiteOut");
    objBlackout.className = "hidden";
} // end function

function galleryImage(ref) {
    var objBlackout = document.getElementById("windowWhiteOut");
    objBlackout.className = "";
    
    var objGallery = document.getElementById("galleryDisplay");
    var objImage = document.getElementById("galleryImage");
    var objCaption = document.getElementById("galleryCaption");
    
    objImage.innerHTML = ref.innerHTML;
    objCaption.innerHTML = ref.title;
    objGallery.className = "";
} // end function

function checkField(ref) {
    if (ref.value.indexOf('...') > 0)
        ref.value = '';
} // end function

function submitForm(field, ref) {
    if (checkGoodToGo(field) != false)
        ref.parentElement.submit();
} // end function

function checkGoodToGo(ref) {
    if (document.getElementById(ref).value.length < 10) {
        window.alert("You must complete the field correctly before submitting a request for more information.");
        return false;
    } else {
        return true;
    }
} // end function

function loadContent(ref) {
    var source = frames['dataTransfer'].document;
    
    var content = source.getElementById('dataContent');
    var container = document.getElementById('blockContentPane');
   
    container.innerHTML = content.innerHTML;
    
    try {
        var destQuickLinks = document.getElementById('quickLinks');
        var srcQuickLinks = source.getElementById('dataQuickLinks');
       
        if (srcQuickLinks)
            destQuickLinks.innerHTML = srcQuickLinks.innerHTML; 
    } catch(e) {}
    
    try {
        var destNavigation = document.getElementById('blockNavigation');
        var srcNavigation = source.getElementById('dataNavigation');
        
        if (srcNavigation)
            destNavigation.innerHTML = srcNavigation.innerHTML;
    } catch(e) {}
    
    var imgCollection = container.getElementsByTagName('IMG');
        
    for (var index = 0; index <imgCollection.length; index++) {
        if (imgCollection[index].src == "") {
            imgCollection[index].src = imgCollection[index].alt;
            imgCollection[index].alt = "";
        }
    }
} // end function

function showOverlayPopup() {
    window.scrollTo(0,0);
    overlaySize();
    
    document.getElementById("windowBlackOut").className = "";
    document.getElementById("overlayPopup").className = "";
}

function overlaySize() {
    var objWhiteOut = document.getElementById('windowWhiteOut');
    var objBlackOut = document.getElementById('windowBlackOut');
    var htmlHeight = document.body.parentNode.scrollHeight;
    var windowHeight = window.innerHeight;
    
    if (htmlHeight < windowHeight) {
        objWhiteOut.style.height = windowHeight + "px";
        objBlackOut.style.height = windowHeight + "px";
    } else {
        objWhiteOut.style.height = htmlHeight + "px";
        objBlackOut.style.height = htmlHeight + "px";
    }
} // end function

function displaySize() {
    if (window.screen.width > 1025) {
        document.getElementById('rightContent').innerHTML = document.getElementById("bottomLeftContent").innerHTML;
        document.getElementById("bottomLeftContent").innerHTML = "";
        document.getElementById("bottomLeftBodyContainer").className = "hidden";
        
        if (document.getElementById('rightContent').innerHTML.removeAllWhitespace() != "")
            document.getElementById('rightBodyContainer').className = "";
    }
    
    if (window.screen.width < 1024) {
        document.getElementById("bottomLeftBodyContainer").className = "hidden";
        document.getElementById('leftBodyContainer').className = "hidden";
        document.getElementById('breadcrumbContainer').className = "hidden";
        document.getElementById('searchContainer').className = "hidden";
        document.getElementById('rightBodyContainer').className = "hidden";
        //addStyleSheet('styles-sm');
    }
} // end function

function randomSideImage() {
    var maxImages = 4;
    var randomImage = Math.floor(Math.random() * maxImages) + 1;
    var obj = document.getElementById('blockSideBar');

    // obj.style.backgroundImage = 'url(images/sideBars/sideBar' + randomImage + '.png)';
} // end function

function addStyleSheet(ref) {
    if(document.createStyleSheet) {
        document.createStyleSheet(ref + '.css');
    } else {
        var styles = "@import url('/themes/" + ref + ".css');";
        var newSS=document.createElement('link');
        newSS.rel='stylesheet';
        newSS.href='data:text/css,'+escape(styles);
        document.getElementsByTagName("head")[0].appendChild(newSS);
    } // end if
} //end function

function loadTestimonial(ref) {
    var objContentPane = document.getElementById("blockContentPane");
    var objBlockRef = document.getElementById(ref.id.replace("link", "content"));
    
    var objTestimonialFrame = document.getElementById("testimonialFrame");
    objTestimonialFrame.innerHTML = objBlockRef.innerHTML;
    
} // end function

//]]>
