/* ------------------------------------------------ */
/* FUNCTIONS specific to B2C
/* ------------------------------------------------ */
/******* OVERLAY Javascript function starts here **********/
/*
function showTags() {
    var ele = getElementById('tagsOverlay');
    ele.style.display = 'block';
    Drag.init(document.getElementById("tagsOverlayHeader"), document.getElementById("tagsOverlay"));
    Drag.init(document.getElementById("tagsOverlayFooter"), document.getElementById("tagsOverlay"));
}

function closeTagsOverlay() {
    var ele = getElementById('tagsOverlay');
    ele.style.display = 'none';
}

function closeXsellOverlay() {
    var olay = document.getElementById("xsell-overlay");
    if(olay) {
        olay.style.display = "none";
    }
}

function tabGallery(poid) {
    showGallery(poid, 'ajaxPanel');
    changeTabImage(this);
    document.getElementById('tab3').className = 'selected';
    document.getElementById('tab3').scrollIntoView()
}

function tabReviews(poid) {
    showCustomerReviews(poid, 'desc', 'ajaxPanel');
    changeTabImage(this);
    document.getElementById('tab2').className = 'selected';
    document.getElementById('tab2').scrollIntoView()
}


function postionXsellOverlay() {
    var ele = getElementById('xsell-overlay');
    ele.style.display = 'block';
    Drag.init(document.getElementById("xsell-overlay-top"), document.getElementById("xsell-overlay"));
    ele.style.top = "350px"
    ele.style.left = "500px"
}

function positionOverlay(poid, tdIdx) {
    var ele = getElementById('overlay');
    ele.style.display = 'block';
    Drag.init(document.getElementById("prodOverlayHeader"), document.getElementById("overlay"));
    Drag.init(document.getElementById("prodOverlayFooter"), document.getElementById("overlay"));
    var divMid = document.getElementById("overlayInnerMidDivScroll");
    if (divMid && screen.height < 900) {
        divMid.style.height = '150px';
    }
}

function closeOverlay() {
    var ele = getElementById('overlay');
    ele.style.display = 'none';
}

//Drag definition begins
var Drag = {

    obj : null,

    init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
    {
        o.onmousedown = Drag.start;

        o.hmode = bSwapHorzRef ? false : true;
        o.vmode = bSwapVertRef ? false : true;

        o.root = oRoot && oRoot != null ? oRoot : o;

        if (o.hmode && isNaN(parseInt(o.root.style.left))) o.root.style.left = "0px";
        if (o.vmode && isNaN(parseInt(o.root.style.top))) o.root.style.top = "0px";
        if (!o.hmode && isNaN(parseInt(o.root.style.right))) o.root.style.right = "0px";
        if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

        o.minX = typeof minX != 'undefined' ? minX : null;
        o.minY = typeof minY != 'undefined' ? minY : null;
        o.maxX = typeof maxX != 'undefined' ? maxX : null;
        o.maxY = typeof maxY != 'undefined' ? maxY : null;

        o.xMapper = fXMapper ? fXMapper : null;
        o.yMapper = fYMapper ? fYMapper : null;

        o.root.onDragStart = new Function();
        o.root.onDragEnd = new Function();
        o.root.onDrag = new Function();
    },

    start : function(e)
    {
        var o = Drag.obj = this;
        e = Drag.fixE(e);
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        o.root.onDragStart(x, y);

        o.lastMouseX = e.clientX;
        o.lastMouseY = e.clientY;

        if (o.hmode) {
            if (o.minX != null)    o.minMouseX = e.clientX - x + o.minX;
            if (o.maxX != null)    o.maxMouseX = o.minMouseX + o.maxX - o.minX;
        } else {
            if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
            if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
        }

        if (o.vmode) {
            if (o.minY != null)    o.minMouseY = e.clientY - y + o.minY;
            if (o.maxY != null)    o.maxMouseY = o.minMouseY + o.maxY - o.minY;
        } else {
            if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
            if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
        }

        document.onmousemove = Drag.drag;
        document.onmouseup = Drag.end;

        return false;
    },

    drag : function(e)
    {
        e = Drag.fixE(e);
        var o = Drag.obj;

        var ey = e.clientY;
        var ex = e.clientX;
        var y = parseInt(o.vmode ? o.root.style.top : o.root.style.bottom);
        var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right);
        var nx, ny;

        if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
        if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
        if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
        if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

        nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
        ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

        if (o.xMapper)        nx = o.xMapper(y)
        else if (o.yMapper)    ny = o.yMapper(x)

        Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
        Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
        Drag.obj.lastMouseX = ex;
        Drag.obj.lastMouseY = ey;

        Drag.obj.root.onDrag(nx, ny);
        return false;
    },

    end : function()
    {
        document.onmousemove = null;
        document.onmouseup = null;
        Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
                parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
        Drag.obj = null;
    },

    fixE : function(e)
    {
        if (typeof e == 'undefined') e = window.event;
        if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
        if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
        return e;
    }
};*/
//Drag definition ends
/******* OVERLAY Javascript function ends here **********/


/***********WRITE REVIEW OVERLAY starts here***********/
/*
function closeReviewOverlay(overLayName) {
    document.getElementById(overLayName).style.visibility = "hidden";
}

//Javascript function to show write review div layout with iframe pointing to bazaar voice url.
function writeReview(writeUrl) {
    var reviewsCntDiv = getElementById("writeReviewPanelOverlay");
    var bvFrameDiv = getElementById("bvframe");

    reviewsCntDiv.style.visibility = "visible";

    var top_pos = 0;
    var left_pos = "175px";
    var div_width = 850;
	
	// Get verital scroll postion in ALL BROWSERS INCLUDING IE****.
    // "window.pageYOffset" works for firefox
    // "document.documentElement.scrollTop" works for IE (if scrollTop property is not defaulted to '0')
    // "document.body.scrollTop" works for IE (Even if scrollTop property is defaulted to '0')
    var top_pos = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;

	// Get horizontal scroll postion in ALL BROWSERS INCLUDING IE****.
    //var left_pos = window.pageXOffset || document.documentElement.scrollLeft || 0;

    if (screen) {
        left_pos = (screen.width - div_width) / 2 - 30;
    }

    reviewsCntDiv.style.top = (top_pos) + "px";
    reviewsCntDiv.style.left = left_pos + "px";

	//Insert IFrame into panel.jspf->div tag->bvFrameDiv to show bazaar voice review page.
    bvFrameDiv.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;<iframe width=' + div_width + 'px" height="650px" id="lbIframe" name="lbIframe" frameborder="no" style="opacity: 1;" src="' + writeUrl + '"/>';
}*/
/***********WRITE REVIEW OVERLAY ends here*************/



/***************Pricing label for projectors -- related methods start **************/
/*
function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
        return evt.clientX + (document.documentElement.scrollLeft ?
                              document.documentElement.scrollLeft :
                              document.body.scrollLeft);
    else return null;
}

function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
        return evt.clientY + (document.documentElement.scrollTop ?
                              document.documentElement.scrollTop :
                              document.body.scrollTop);
    else return null;
}

function toggleDiv(e, id, flagit) {
    var ele = document.getElementById(id);

    if (! flagit)
    {
        ele.style.visibility = "hidden"
        return;
    }

    var posx = 0;
    var posy = 0;

    if (!e) var e = window.event;

    if (e.pageX) {
        posx = e.pageX;

    } else if (e.clientX) {
        posx = e.clientX;
    }

    if (e.pageY) {
        posy = e.pageY;
    } else if (e.clientY) {
        posy = e.clientY;
    }

    posx = mouseX(e);
    posy = mouseY(e);


    if (ele)
    {
        ele.style.left = (posx + 15 ) + "px";
        ele.style.top = (posy - 5 ) + "px";
        ele.style.visibility = "visible";
    }
}
*/
/***************Pricing label for projectors -- related methods end **************/

/***********Start Reporting *************/
/*
function doReports(isProd, googleId, yahooId, tabName, pageState, catId, sourceCode, resultCount) {
    //alert("isProd:" +isProd +"\r\ngoogleId:" +googleId +"\r\nyahooId:" +yahooId +"\r\ntabName:" +tabName +"\r\npageState:" +pageState +"\r\ncatId:" +catId +"\r\nsourceCode:" +sourceCode +"\r\nresultCount:" +resultCount);
    //Coremetrics Reporting
    if (tabName && tabName != null) {
        if (isProd)
            cmSetProduction()

    //resultCount determins if it was a search page or not.
        if (resultCount) {
            if (pageState == 'null') {
                pageState = 'NO FILTER';
            }

            //alert('cmCreatePageviewTag(\''+tabName+'\',\''+pageState+'\',\''+catId+'\',\''+resultCount+'\')');
            cmCreatePageviewTag(tabName, pageState, catId, resultCount);
        } else {
            //alert('cmCreatePageviewTag(\''+tabName+'\',\''+pageState+'\',\''+catId+'\')');
            cmCreatePageviewTag(tabName, pageState, catId);
        }

        if (sourceCode) {
            cmCreateSourceCodeTag(sourceCode);
        }
    }
  
  //Yahoo Reporting. If a valid string is passed in Yahoo reporting will be executed.
    if (yahooId && yahooId != null) {
        var ysm_accountid = yahooId;
        var script = "<SCR" + "IPT language='JavaScript' type='text/javascript' "
                + "SRC=//";

        if (isProd)
            script += "srv2.wa.marketingsolutions.yahoo.com";
        else
            script += "qasrv1.wa.marketingsolutions.yahoo.com";

        script += "/script/ScriptServlet" + "?aid=" + ysm_accountid
                + "></SCR" + "IPT>";
        document.write(script);
    }
  
  //Google reporting. If a valid string for google Id is passed in, the reporting will be executed.
    if (googleId && googleId != null) {
        _uacct = googleId;
        urchinTracker();
    }
}

// Coremetrics Element Tag
function doReporting(isProduction, elementName, elementCategory) {
    try {
	//alert(elementName + ' | ' + elementCategory);        

        if (isProduction) {
            cmSetProduction();
        }

        cmCreatePageElementTag(elementName, elementCategory);
    } catch (e) {
    }
}

function removeThousandSeparatorComma(amount) {
    amount = amount.replace(/1,/g, '1');
    amount = amount.replace(/2,/g, '2');
    amount = amount.replace(/3,/g, '3');
    amount = amount.replace(/4,/g, '4');
    amount = amount.replace(/5,/g, '5');
    amount = amount.replace(/6,/g, '6');
    amount = amount.replace(/7,/g, '7');
    amount = amount.replace(/8,/g, '8');
    amount = amount.replace(/9,/g, '9');
    //alert('Amount='+amount);
    return amount;
}
*/
/***********End Reporting *************/

/********** CSS Drop Down *************/

var cssdropdown = {
    disappeardelay: 500, //set delay in miliseconds before menu disappears onmouseout
    dropdownindicator: '', //specify full HTML to add to end of each menu item with a drop down menu
    enableswipe: 1, //enable swipe effect? 1 for yes, 0 for no
    enableiframeshim: 1, //enable "iframe shim" in IE5.5/IE6? (1=yes, 0=no)

    //No need to edit beyond here////////////////////////

    dropmenuobj: null, asscmenuitem: null, domsupport: document.all || document.getElementById, standardbody: null, iframeshimadded: false, swipetimer: undefined, bottomclip:0,

    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;
    },

    swipeeffect:function() {
        if (this.bottomclip < parseInt(this.dropmenuobj.offsetHeight)) {
            this.bottomclip += 10 + (this.bottomclip / 10) //unclip drop down menu visibility gradually
            this.dropmenuobj.style.clip = "rect(0 auto " + this.bottomclip + "px 0)"
        }
        else
            return
        this.swipetimer = setTimeout("cssdropdown.swipeeffect()", 5)
    },

    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
    },

    showhide:function(obj, e) {
        this.dropmenuobj.style.left = this.dropmenuobj.style.top = "-500px"
        if (this.enableswipe == 1) {
            if (typeof this.swipetimer != "undefined")
                clearTimeout(this.swipetimer)
            obj.clip = "rect(0 auto 0 0)" //hide menu via clipping
            this.bottomclip = 0
            this.swipeeffect()
        }
        obj.visibility = "visible"
        this.css(this.asscmenuitem, "selected", "add")
    },

    clearbrowseredge:function(obj, whichedge) {
        var edgeoffset = 0
        if (whichedge == "rightedge") {
            var windowedge = (document.all && !window.opera) ? this.standardbody.scrollLeft + this.standardbody.clientWidth - 15 : window.pageXOffset + window.innerWidth - 15
            this.dropmenuobj.contentmeasure = this.dropmenuobj.offsetWidth
            if (windowedge - this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
                edgeoffset = this.dropmenuobj.contentmeasure - obj.offsetWidth
        }
        else {
            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
            this.dropmenuobj.contentmeasure = this.dropmenuobj.offsetHeight
            if (windowedge - this.dropmenuobj.y < this.dropmenuobj.contentmeasure) { //move up?
                edgeoffset = this.dropmenuobj.contentmeasure + obj.offsetHeight
                if ((this.dropmenuobj.y - topedge) < this.dropmenuobj.contentmeasure) //up no good either?
                    edgeoffset = this.dropmenuobj.y + obj.offsetHeight - topedge
            }
        }
        return edgeoffset
    },

    dropit:function(obj, e, dropmenuID) {
        if (this.dropmenuobj != null) //hide previous menu
            this.hidemenu() //hide menu
        this.clearhidemenu()
        this.dropmenuobj = document.getElementById(dropmenuID) //reference drop down menu
        this.asscmenuitem = obj //reference associated menu item
        this.showhide(this.dropmenuobj.style, e)
        this.dropmenuobj.x = this.getposOffset(obj, "left")
        this.dropmenuobj.y = this.getposOffset(obj, "top")
        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 + 10 + "px"
        this.positionshim() //call iframe shim function
    },

    positionshim:function() { //display iframe shim function
        if (this.enableiframeshim && typeof this.shimobject != "undefined") {
            if (this.dropmenuobj.style.visibility == "visible") {
                this.shimobject.style.width = this.dropmenuobj.offsetWidth + "px"
                this.shimobject.style.height = this.dropmenuobj.offsetHeight + "px"
                this.shimobject.style.left = this.dropmenuobj.style.left
                this.shimobject.style.top = this.dropmenuobj.style.top
            }
            this.shimobject.style.display = (this.dropmenuobj.style.visibility == "visible") ? "block" : "none"
        }
    },

    hideshim:function() {
        if (this.enableiframeshim && typeof this.shimobject != "undefined")
            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 = 0
        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)
            });
    },

    startchrome:function() {
        if (!this.domsupport)
            return
        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("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 + " " + this.dropdownindicator
                    } catch(e) {
                    }
                    this.addEvent(menuitems[i], function(e) { //show drop down menu when main menu items are mouse over-ed
                        if (!cssdropdown.isContained(this, e)) {
                            var evtobj = window.event || e
                            cssdropdown.dropit(this, evtobj, this.getAttribute("rel"))
                        }
                    }, "mouseover")
                    this.addEvent(menuitems[i], function(e) {
                        cssdropdown.dynamichide(this, e)
                    }, "mouseout") //hide drop down menu when main menu items are mouse out
                    this.addEvent(menuitems[i], function() {
                        cssdropdown.delayhidemenu()
                    }, "click") //hide drop down menu when main menu items are clicked on
                }
            } //end inner for
        } //end outer for
        if (window.createPopup && !window.XmlHttpRequest && !this.iframeshimadded) { //if IE5.5 to IE6, create iframe for iframe shim technique
            document.write('<IFRAME id="iframeshim"  src="javascript:\'<html></html>\';" style="display: none; left: 0; top: 0; z-index: 90; position: absolute; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" frameBorder="0" scrolling="no"></IFRAME>')
            this.shimobject = document.getElementById("iframeshim") //reference iframe object
            this.iframeshimadded = true
        }
    } //end startchrome

}