// Redirect used for the Search button on Home Page and Sub Pages
function pageredirect(url) {

    var docurl = document.URL.toLowerCase();

    if ((docurl.indexOf('www-dev', 0) > -1) || (docurl.indexOf('por-portlets-dev', 0) > -1)) docurl = "http://www-dev.libertyau.com";
    else if ((docurl.indexOf('www-tst', 0) > -1) || (docurl.indexOf('por-portlets-tst', 0) > -1)) docurl = "http://www-tst.libertyau.com";
    else if ((docurl.indexOf('www-stg', 0) > -1) || (docurl.indexOf('por-portlets-stg', 0) > -1)) docurl = "http://www-stg.libertyau.com";
    else if (docurl.indexOf('libertyau.com',0) > -1) docurl = "http://www.libertyau.com";
    else docurl = "http://www.libertyagencyunderwriters.com";

    if (url == "homepage") url = "";
    
//alert(docurl + url);
    window.location = docurl + url;
  }  
  
//Cross-Browser function that hides the bottom portlet border for the last portlet on the page -- JLR 5/16/08
function dropLastPortletBorder() {
    if (document.getElementById("columnTwo")) { //get columnTwo if available
        rtPNodes = document.getElementById("columnTwo").childNodes; //get all tables within the column
        var lastPortletID = "noportlets"; //set default value
        for (var i = 0; i < rtPNodes.length; i++) {
            if (rtPNodes[i].tagName == "TABLE") { //only look at tables
                if (rtPNodes[i].id.indexOf("portlet") > -1) {
                    lastPortletID = rtPNodes[i].id; //keep re-writing last ID value as we move through the **portlet** tables
                }
            }
        }
        if (lastPortletID != "noportlets") {  //only if we got a portlet ID value from above
            lastPortlet = document.getElementById(lastPortletID); //THE last portlet table ID
            portletBodyRow = lastPortlet.lastChild.rows.length - 1; // the last row for that portlet | checks for supressed headers
            lastPortlet.lastChild.rows[portletBodyRow].firstChild.firstChild.style.border = "none";  //remove border from customapptext div
        }
    }
}
function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}

/*######################################## begin plugins.js ########################################*/
var agt = navigator.userAgent.toLowerCase();
var ie = (agt.indexOf("msie") != -1);
var ns = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win") != -1) || (agt.indexOf("32bit") != -1));
var mac = (agt.indexOf("mac") != -1);

/*if (ie && win) {
    pluginlist = detectIE("Adobe.SVGCtl", "SVG Viewer") + detectIE("SWCtl.SWCtl.1", "Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1", "Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1", "RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1", "QuickTime") + detectIE("MediaPlayer.MediaPlayer.1", "Windows Media Player") + detectIE("PDF.PdfCtrl.5", "Acrobat Reader");
}

if (ns || !win) {
    nse = "";
    for (var i = 0; i < navigator.mimeTypes.length; i++) {
        if (navigator.mimeTypes[i] != null && navigator.mimeTypes[i].type != null) {
            var s = navigator.mimeTypes[i].type
            nse += String(s).toLowerCase();
        }
    }
    pluginlist = detectNS("image/svg-xml", "SVG Viewer") + detectNS("application/x-director", "Shockwave Director") + detectNS("application/x-shockwave-flash", "Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin", "RealPlayer") + detectNS("video/quicktime", "QuickTime") + detectNS("application/x-mplayer2", "Windows Media Player") + detectNS("application/pdf", "Acrobat Reader");
}

function detectIE(ClassID, name) {

    if (name.indexOf("Flash") != -1) {

        for (var i = 11; i > 0; i--) {
            try {
                var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");

                return name + ",";
            }
            catch (e) {
            }
        }

        return "";
    }
    else {
        result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name + ','; else return '';
    }
}

function detectNS(ClassID, name) {
    n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name + ","; return n;
}

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0, pluginlist.length - 1);
*/
/*######################################## end plugins.js ########################################*/


var cssdropdown = {
    disappeardelay: 250,
    enablereveal: [true, 1],
    selectedmenuitem: null,

    dropmenuobj: null, asscmenuitem: null, domsupport: document.all || document.getElementById, standardbody: null, 

iframeshimadded: false, revealtimers: {},

    getposOffset: function(what, offsettype) {
        var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
        var parentEl = what.offsetParent;
        while (parentEl != null) {
            totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
            parentEl = parentEl.offsetParent;
        }
        return totaloffset;
    },

    css: function(el, targetclass, action) {
        var needle = new RegExp("(^|\\s+)" + targetclass + "($|\\s+)", "ig")
        if (action == "check")
            return needle.test(el.className)
        else if (action == "remove")
            el.className = el.className.replace(needle, "")
        else if (action == "add" && !needle.test(el.className))
            el.className += " " + targetclass
    },

    showmenu: function(dropmenu, e) {
        if (this.enablereveal[0]) {
            if (!dropmenu._trueheight || dropmenu._trueheight < 10)
                dropmenu._trueheight = dropmenu.offsetHeight
            clearTimeout(this.revealtimers[dropmenu.id])
            dropmenu.style.height = dropmenu._curheight = 0
            dropmenu.style.overflow = "hidden"
            dropmenu.style.visibility = "visible"
            this.revealtimers[dropmenu.id] = setInterval(function() { cssdropdown.revealmenu(dropmenu) }, 10)
        }
        else {
            dropmenu.style.visibility = "visible"
        }

        this.css(this.asscmenuitem, "selected", "add")
    },

    revealmenu: function(dropmenu, dir) {
        var curH = dropmenu._curheight, maxH = dropmenu._trueheight, steps = this.enablereveal[1]
        if (curH < maxH) {
            var newH = Math.min(curH, maxH)
            dropmenu.style.height = newH + "px"
            dropmenu._curheight = newH + Math.round((maxH - newH) / steps) + 1
        }
        else {
            dropmenu.style.height = "auto"
            dropmenu.style.overflow = "hidden"
            clearInterval(this.revealtimers[dropmenu.id])
        }
    },

    clearbrowseredge: function(obj, whichedge) {
        var edgeoffset = 0

        var topedge = document.all && !window.opera ? this.standardbody.scrollTop : window.pageYOffset
        var windowedge = document.all && !window.opera ? this.standardbody.scrollTop + this.standardbody.clientHeight - 15 : 

window.pageYOffset + window.innerHeight - 18
        var dropmenuH = this.dropmenuobj._trueheight
        if (windowedge - this.dropmenuobj.y < dropmenuH) {
            edgeoffset = dropmenuH + obj.offsetHeight
            if ((this.dropmenuobj.y - topedge) < dropmenuH)
                edgeoffset = this.dropmenuobj.y + obj.offsetHeight - topedge
        }

        return edgeoffset
    },

    dropit: function(obj, e, dropmenuID) {
        if (this.dropmenuobj != null)
            this.hidemenu()

        var dropWidth = "";
        var dropLeft = "";
        var dropLineWidth1 = 0;
        var dropLineWidth2 = 0;

        this.clearhidemenu()
        this.dropmenuobj = document.getElementById(dropmenuID)
        this.asscmenuitem = obj

        this.showmenu(this.dropmenuobj, e)

        var agt = navigator.userAgent.toLowerCase();
        var ie = (agt.indexOf("msie") != -1);

        var firefox = (ie != true);

        // IE
        switch (this.dropmenuobj.id) {
            case "dropProducts": dropWidth = "140px"; dropLeft = "312"; dropLineWidth1 = 88; dropLineWidth2 = 55; break;
            case "dropFAA": dropWidth = "176px"; dropLeft = "408"; dropLineWidth1 = 136; dropLineWidth2 = 59; break;
            case "dropInsurance": dropWidth = "181px"; dropLeft = "541"; dropLineWidth1 = 95; dropLineWidth2 = 45; break;
            case "dropClaims": dropWidth = "160px"; dropLeft = "674"; dropLineWidth1 = 66; dropLineWidth2 = 94; break;
            case "dropAboutUs": dropWidth = "130px"; dropLeft = "750"; dropLineWidth1 = 109; dropLineWidth2 = 54; break;
            case "dropAccount": dropWidth = "139px"; dropLeft = "847"; dropLineWidth1 = 124; dropLineWidth2 = 39; break;
        }

        //Firefox
        if (firefox) {
            switch (this.dropmenuobj.id) {
                case "dropProducts": dropWidth = "150px"; dropLineWidth1 = dropLineWidth1 - 1 ; dropLineWidth2 = 

dropLineWidth2 + 10; break;
                case "dropFAA": dropWidth = "186px"; dropLineWidth1 = dropLineWidth1 - 12 ; dropLineWidth2 = dropLineWidth2 + 

5 ; break;
                case "dropInsurance": dropWidth = "193px"; dropLineWidth1 = dropLineWidth1 + 29; dropLineWidth2 = 

dropLineWidth2 + 26; break;
                case "dropClaims": dropWidth = "168px"; dropLineWidth1 = dropLineWidth1 + 1; dropLineWidth2 = dropLineWidth2 

+ 10; break;
                case "dropAboutUs": dropWidth = "136px"; dropLineWidth1 = dropLineWidth1 - 16; dropLineWidth2 = 

dropLineWidth2 - 1; break;
                case "dropAccount": dropWidth = "141px"; dropLineWidth1 = dropLineWidth1 - 17; dropLineWidth2 = 

dropLineWidth2 - 3; break;
            }
        }

        this.dropmenuobj.x = this.getposOffset(obj, "left");
        this.dropmenuobj.y = this.getposOffset(obj, "top") - 1;

        this.dropmenuobj.style.left = this.dropmenuobj.x - this.clearbrowseredge(obj, "rightedge") + "px"
        this.dropmenuobj.style.top = this.dropmenuobj.y - this.clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + "px"

        var dropLine = document.getElementById(dropmenuID + "_Line");
        var dropLine1 = document.getElementById(dropmenuID + "_Line1");
        var dropLine2 = document.getElementById(dropmenuID + "_Line2");

        if (dropLine != null) {
            dropLine1.style.width = dropLineWidth1 + "px";
            dropLine2.style.width = dropLineWidth2 + "px";
            dropLine.style.width = dropWidth;
            dropLine.style.display = "block";
        }

        this.dropmenuobj.style.width = dropWidth;
        this.positionshim()
    },

    positionshim: function() {
        if (this.iframeshimadded) {

            if (this.dropmenuobj.style.visibility == "visible") {
                this.shimobject.style.width = this.dropmenuobj.offsetWidth + "px"
                this.shimobject.style.height = this.dropmenuobj._trueheight + "px"
                this.shimobject.style.left = parseInt(this.dropmenuobj.style.left) + "px"
                this.shimobject.style.top = parseInt(this.dropmenuobj.style.top) + "px"
                this.shimobject.style.display = "block"

            }
        }
    },

    hideshim: function() {
        if (this.iframeshimadded)
            this.shimobject.style.display = 'none'
    },

    isContained: function(m, e) {
        var e = window.event || e
        var c = e.relatedTarget || ((e.type == "mouseover") ? e.fromElement : e.toElement)
        while (c && c != m) try { c = c.parentNode } catch (e) { c = m }
        if (c == m)
            return true
        else
            return false
    },

    dynamichide: function(m, e) {
        if (!this.isContained(m, e)) {
            this.delayhidemenu()
        }
    },

    delayhidemenu: function() {
        this.delayhide = setTimeout("cssdropdown.hidemenu()", this.disappeardelay) //hide menu
    },

    hidemenu: function() {
        this.css(this.asscmenuitem, "selected", "remove")
        this.dropmenuobj.style.visibility = 'hidden'
        this.dropmenuobj.style.left = this.dropmenuobj.style.top = "-1000px"
        this.hideshim()
    },

    clearhidemenu: function() {

        if (this.delayhide != "undefined")
            clearTimeout(this.delayhide)
    },

    addEvent: function(target, functionref, tasktype) {
        if (target.addEventListener)
            target.addEventListener(tasktype, functionref, false);
        else if (target.attachEvent)
            target.attachEvent('on' + tasktype, function() { return functionref.call(target, window.event) });
    },

    startnav: function() {
        if (!this.domsupport)
            return
        var selected = null;

        this.standardbody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body
        for (var ids = 0; ids < arguments.length; ids++) {
            var menuitems = document.getElementById(arguments[ids]).getElementsByTagName("a")

            for (var i = 0; i < menuitems.length; i++) {

		if (menuitems[i].getAttribute("id"))
		{
		var idvalue = menuitems[i].getAttribute("id");
			try {
                        menuitems[i].innerHTML = menuitems[i].innerHTML
                    } catch (e) { }

                    if (menuitems[i].innerHTML == this.selectedmenuitem){
                        this.css(menuitems[i], "preselected", "add");
		    }

		}

                if (menuitems[i].getAttribute("rel")) {
                    var relvalue = menuitems[i].getAttribute("rel")
                    var asscdropdownmenu = document.getElementById(relvalue)
                    this.addEvent(asscdropdownmenu, function() { cssdropdown.clearhidemenu(); }, "mouseover")
                    this.addEvent(asscdropdownmenu, function(e) { cssdropdown.dynamichide(this, e); }, "mouseout")
                    this.addEvent(asscdropdownmenu, function() { cssdropdown.delayhidemenu() }, "click")
                    try {
                        menuitems[i].innerHTML = menuitems[i].innerHTML
                    } catch (e) { }

                    if (menuitems[i].innerHTML == this.selectedmenuitem) {
                        this.css(menuitems[i], "preselected", "add");
                        selected = menuitems[i];
                    }

                    this.addEvent(menuitems[i], function(e) {
                        if (!cssdropdown.isContained(this, e)) {
                            var evtobj = window.event || e

                            cssdropdown.dropit(this, evtobj, this.getAttribute("rel"))
                        }

                        // if (selected != null) { cssdropdown.css(selected, "preselected", "remove"); }

                    }, "mouseover")
                    this.addEvent(menuitems[i], function(e) { cssdropdown.dynamichide(this, e); }, "mouseout")
                    this.addEvent(menuitems[i], function() { cssdropdown.delayhidemenu() }, "click")


                }

            }
        }
        if (document.all && !window.XDomainRequest && !this.iframeshimadded) {
            document.write('<IFRAME id="iframeshim" src="about:blank" frameBorder="0" scrolling="no" style="left:0; top:0; position:absolute; display:none;z-index:90;background: transparent; "></IFRAME>')
            this.shimobject = document.getElementById("iframeshim")
            this.shimobject.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
            this.iframeshimadded = true
        }
    }

}

function buildTopImageBar(containerid, topID) {
	
    	var imgleft = "";
	var imgright = "";
	var imgline = "";

//alert(topID);
	switch (topID)
	{

		case "About Us":
		imgright = '/plumtree/portal/custom/LAU/image/aboutUsImage.jpg';
		imgleft = '/plumtree/portal/custom/LAU/image/aboutUsTitle.gif';
		imgline = '/plumtree/portal/custom/LAU/image/greenbarShadow.jpg';
		break;

		case "Commercial Platform":
		imgright = '/plumtree/portal/custom/LAU/image/commPlatImage.jpg';
		imgleft = '/plumtree/portal/custom/LAU/image/commPlatTitle.gif';
		imgline = '/plumtree/portal/custom/LAU/image/greenbarShadow.jpg';
		break;

		case "Excess Casualty":
		imgright = '/plumtree/portal/custom/LAU/image/excessCasualtyImage.jpg';
		imgleft = '/plumtree/portal/custom/LAU/image/excessCasualtyTitle.gif';
		imgline = '/plumtree/portal/custom/LAU/image/greenbarShadow.jpg';
		break;

		case "National Programs":
		imgright = '/plumtree/portal/custom/LAU/image/natProgImage.jpg';
		imgleft = '/plumtree/portal/custom/LAU/image/natProgTitle.gif';
		imgline = '/plumtree/portal/custom/LAU/image/greenbarShadow.jpg';
		break;

		default:
		imgright = '/plumtree/portal/custom/LAU/image/headerBar.jpg';
		//imgline = '/plumtree/portal/custom/LAU/image/greenbarShadow.jpg';
		break;
	}

	var outStr = "";

	if (imgright != '')
	{
		outStr = "";
		
		if (imgleft != '') {		
			outStr = outStr + "<img style='border-top:black solid 1px' id='imgTopBar' src='" + PTIncluder.imageServerURL + imgleft + "'>";
		}

		outStr = outStr + "<img id='imgTopBarRight' style='border-top:black solid 1px' src='" + PTIncluder.imageServerURL + imgright + "'>";

		if (imgline != '')
		{
			outStr = outStr + "<img  src='" + PTIncluder.imageServerURL + imgline + "'>";
		}

		document.getElementById(containerid).innerHTML = outStr + "";
		
	}
	else
	{
		document.getElementById(containerid).width = "0";
		document.getElementById(containerid).height = "0";
	}

	//alert(PTIncluder.imageServerURL + imgleft);
	
}

