﻿ //Copyright Bridgeline Software, Inc. An unpublished work created in 2009. All rights reserved This software contains the confidential and trade secret information of Bridgeline Software, Inc. ("Bridgeline"). Copying, distribution or disclosure without Bridgeline's express written permission is prohibited

/*************************** Browser Window Size and Position****************/
/*copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005*/
function pageWidth() {
    return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
   
function pageHeight() {
    return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function posLeft() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop() {
    return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

function posRight() {
    return posLeft()+pageWidth();
} 
function posBottom() {
    return posTop()+pageHeight();
}

/*************************** Scroll height & width****************/
function getPageHeightWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight + document.body.offsetTop;
  	}
	return yWithScroll;
}

function getPageWidthWithScroll(){
	if (window.innerWidth && window.scrollMaxX) {// Firefox
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		xWithScroll = document.body.offsetWidth + document.body.offsetLeft;
  	}
	return xWithScroll;
}

/*
CSS Browser Selector v0.2.7
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();

// Supporting functions for IE6 <select> element flickering and showing through modal
/**********************Hide and show <select> elements. Used for IE6**************************/
function HideSelects (){
	var selects = document.getElementsByTagName ("SELECT");
	for (i = 0; i < selects.length; i++) {
	   selects [i].style.visibility = "hidden";
	}
}
function ShowSelects (){
	var selects = document.getElementsByTagName ("SELECT");
	for (i = 0; i < selects.length; i++) {
	   selects [i].style.visibility = "visible";
	}
}

/*************************** Pop up a modal window  ****************/

function showModal(pageUrl, height, width) {

	var custompagesFolder="";    
	var browser=navigator.appName;
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);




	var tempIframe = document.createElement('iframe');
	tempIframe.id = "modal";
	tempIframe.name = "modal";
	tempIframe.frameBorder = "0";
	tempIframe.scrolling="no";
	tempIframe.height = "1";
	tempIframe.width = "1";
	tempIframe.style.position="absolute";
	tempIframe.style.background="transparent";	
	tempIframe.allowTransparency=false;		
	tempIframe.src = pageUrl;	
	document.body.appendChild(tempIframe);
	
	// To prevent <select> elements from flickering on page scroll and showing through cover layer in IE6
	// Page scroll flickering makes <select> show through modal, too
	if (navigator.appVersion.substr(22,2)=="6."){
		// do only for IE6
		HideSelects();
	}
	
	
			

}
function CenterModal(width,height){

	var elementId = "modal";
	var visibleHeight = pageHeight();
	var visibleWidth = pageWidth();
	element = document.getElementById(elementId);
	if(element)
	{
	element.width = width;
	element.height = height+30;
	if(element.height > visibleHeight){
		element.style.top = "20px";
	}else{
		element.style.top = (visibleHeight-element.height)/2 + "px";
	}
	element.style.left = (visibleWidth-element.width)/2 + "px";
	
	var totalHeight = getPageHeightWithScroll();
	var totalWidth = getPageWidthWithScroll();
	
	if(!document.getElementById('coverLayer')){
	    var tempCoverDiv = document.createElement('div');
	    tempCoverDiv.id = "coverLayer";
	    tempCoverDiv.style.height=totalHeight+"px";
	    tempCoverDiv.style.width=totalWidth+"px";
	    tempCoverDiv.allowTransparency=false;
		document.body.appendChild(tempCoverDiv);
		getScrollXY();
	    parent.window.scrollTo(0,0);
	}
	
	
	 var wrapper=document.getElementById('wrapper');
	  if(wrapper){
	    setTimeout(function(){     
        element.height=(wrapper.offsetHeight) + "px";},50);
    }
}	
}
function closeModalWindow() {
	var tempIframe = document.getElementById('modal');
	var tempCoverDiv = document.getElementById('coverLayer');
	if(tempIframe) tempIframe.parentNode.removeChild(tempIframe);
	if(tempCoverDiv) tempCoverDiv.parentNode.removeChild(tempCoverDiv);
	parent.window.scrollTo(xPos,yPos);	
	
	// To prevent <select> elements from flickering on page scroll and showing through cover layer in IE6
	// Page scroll flickering makes <select> show through modal, too
	if (navigator.appVersion.substr(22,2)=="6."){
		// do only for IE6
		parent.ShowSelects();
	}
	
}
var xPos = 0, yPos = 0;
function getScrollXY() {
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        xPos = window.pageXOffset;
        yPos = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        xPos = document.body.scrollLeft;
        yPos = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        xPos = document.documentElement.scrollLeft;
        yPos = document.documentElement.scrollTop;
    }
}
/*************************** End pop up a modal window  ****************/




/* Show and Hide Account Login Form */
function hideLoginForm(ElemID){
    document.getElementById(ElemID).style.display = "none";
}

function showLoginForm(ElemID){
   document.getElementById(ElemID).style.display="block";

} 


/* Clear Default text in Text Box */
function clearText(ElemID)
{
	var tempElem = document.getElementById(ElemID);
	if (tempElem) 
	{
		tempElem.value="";
	}
}

 function controlCenter (btnId, evt) 
{   
    btn = document.getElementById(btnId);
    if (btn)
    {
        if (evt.keyCode == 13)
        {
            evt.returnValue = false;
            evt.cancel = true;
            btn.click();
            return false;
        } 
    } 
}

/* jQuery code to Show and Hide Tabs */
$(document).ready(function(){
    $(".productDetails ul.tabNames li:first").addClass("selected");     //Apply selected class to first tab
    $(".productDetails .tabContent:first").show();      //Show first tabs's related content
    $(".productDetails ul.tabNames li").click(function(){
        $(".productDetails ul.tabNames li").removeClass();  //When clicked on any other tab, remove selected class for the previous tab
        $(this).addClass("selected");   //Apply selected class to the selected tab
        $(".productDetails .tabContent").hide();    //Hide tab's content
        return false;
    });
});

$(document).ready(function(){
    $("ul.productImages li:first a").addClass("selected");
    
    $("ul.productImages li").click(function(){
        var activeCount = $(this).find("a").text();
        var imagePath = "/images/products/thumbnail/";
        var theImage = imagePath + "product" + activeCount + ".jpg";
        var noImage = imagePath + "productNoPhoto.jpg";
        $("#thisProduct").error(function(){
            $(this).attr("src",noImage);
        });
        $("ul.productImages li a").removeClass();
        $(this).find("a").addClass("selected");
        $("#thisProduct").attr("src",theImage).fadeIn();
        
    });
    
    $("#thisProduct").hover(function(){
        
    });
});

$(document).ready(function(){
    $("a.headerLogin").click(
        function(){
            $(this).toggleClass("selected");
            /*$("div.header span.separator").css("padding-right","0px");*/
            $("div.accountLogin").toggle();
            /*$("div.header span.separator").css("padding-right","9px");*/
    });
});

$(document).ready(function(){
    $("div.thumbImages a img").click(
        function(){
            /*$("div.header span.separator").css("padding-right","0px");*/
            var thumbImage = $(this).attr('src');
            alert(thumbImage);
            var prodImage = $("div.productGallery img").attr('src');
            alert(prodImage);
            prodImage = thumbImage;
            alert(prodImage);
            $("div.productGallery img").attr('src', prodImage);
            /*$("div.header span.separator").css("padding-right","9px");*/
    });
});

/* Make Tab Style Default */
function defaultTab(tabID, left, mid, right){
	
	var tab = document.getElementById(tabID).className="tab0";;
	var lf = document.getElementById(left).className="tab0L";;
	var md = document.getElementById(mid).className="tab0M";;
	var rt = document.getElementById(right).className="tab0R";
	
}
/* Make Tab Style Active */
function enableTab(tabID, left, mid, right){

	var tab = document.getElementById(tabID).className="tab1";;
	var lf = document.getElementById(left).className="tab1L";;
	var md = document.getElementById(mid).className="tab1M";;
	var rt = document.getElementById(right).className="tab1R";
}

/* Default is Overview Tab, so hide it */
var lastTabID="otab";
var lastLF="o1";
var lastMD="o2";
var lastRT="o3";
var lastConDiv="overviewData";


/* Navigate Between the Tabs */
function navigateTab(tabID, conDiv, left,mid,right){

	//alert("tabID: " + tabID + "  conDiv: " + conDiv + "  LF: " + left + "  MD: " + mid + "  RT: " + right);   
	//alert(conDiv);
	
	defaultTab(lastTabID, lastLF, lastMD, lastRT);  /*Makes the previous selected TAB as INACTIVE */
	hideTab(lastConDiv);	/* Hides the previous selected contents of Tab */
	
	viewTab(conDiv);	/*Makes the previous selected TAB as ACTIVE */
	enableTab(tabID, left, mid, right);	/* Enables the newly selected contents of Tab */
	
	/* assinging the newly select tab to variables, so that it can be cleared on next click */
	lastConDiv = conDiv;
	lastTabID= tabID;
	lastLF= left;
	lastMD= mid;
	lastRT=right;
}

function viewTab(conDiv){
	//alert("view: " + conDiv);
	var tab = document.getElementById(conDiv);
	tab.style.display="block";
}

function hideTab(conDiv){
	//alert("hide: " + conDiv);
	var tab = document.getElementById(conDiv);
	tab.style.display="none";
}

function goToPage(containerId, pageNumber)
{
    var containerObj = $("div#" + containerId + " div.itemList");
    
    var totalPages = Math.ceil(containerObj.size() / 5);
    var pageNo = parseInt(pageNumber);
    showContents(containerId, pageNo);
    
    var pager = "<ul class='" + containerId + "'>";
    if(containerObj.size() > 0)
    {
        pager += "<li><b>Total Records:</b> " + containerObj.size() + "&nbsp;&nbsp;</li>";    
        pager += "<li><b>Page</b> " + pageNo + " <b>of</b> " + totalPages + "</li>";    
    }

    if (pageNo > 1)
        pager += "<li style='padding-left:10px;'><a href='#' onclick='return goToPage(\"" + containerId + "\", " + (pageNo - 1) + ")'>Prev</a></li>";
    if (pageNo < totalPages)
        pager += "<li><a href='#' onclick='return goToPage(\"" + containerId + "\", " + (pageNo + 1) + ")'>Next</a></li>";
    
    pager += "</ul>";
    
    $("div.pagingTop").html(pager);                                               
    $("div.pagingBottom").html(pager);

    return false;
}

function createPager(containerId)
{
    var containerObj = $("div#" + containerId + " div.itemList");

    var pager = "<div class='pagination'>";
    var totalPages = Math.ceil(containerObj.size() / 5);
    pager += "<ul class='" + containerId + "Nav'>";
    if(containerObj.size() > 0)
    {
        pager += "<li><b>Total Records:</b> " + containerObj.size() + "&nbsp;&nbsp;</li>";    
        pager += "<li><b>Page</b> 1 <b>of</b> " + totalPages + "</li>";    
    }
    else{
        pager += "&nbsp;";
    }
    
    if (totalPages > 1)
    {
        pager += "<li style='padding-left:10px;'><a href='#' onclick='return goToPage(\"" + containerId + "\", 2)'>Next</a></li>";
    }
    pager += "</ul></div>";
    $("div.pagingTop").html(pager);                                               
    $("div.pagingBottom").html(pager);
}

function showContents(containerId, pageNo)
{
    $("div#" + containerId + " div.itemList").each
        (function(index)
            {
                $(this).hide();
                if (index >= (parseInt(pageNo) - 1) * 5 && index < (5 * parseInt(pageNo)))
                {
                    $(this).show();
                }
            }
        );
}

function OnBeforeCompare()
{
    var selCount = $("span.selectProduct input:checked").length;
    
    if(selCount > 4)
    {
        alert("You can only compare atmost 4 products.\nPlease select only 4 products and click COMPARE.");
        return false;
    }
    else if (selCount <= 1)
    {
        alert("Please select atleast 2 products to compare.");
        return false;
    }
    
    return true;
}

function OnBeforeAddToCart()
{
    var selCount = $("span.selectProduct input:checked").length;
    
    if (selCount <= 0)
    {
        alert("Please select atleast one product before clicking Add to Cart.");
        return false;
    }
    
    return true;
}

$(function(){
    $("div.formPanel").each(function()
    {
        if($(this).attr("formButtonId"))
        {
            $(this).bind("keypress", function(e){
                if (e.keyCode == 13)
                {
                    e.returnValue = false;
                    e.cancel = true;
                    var button = $("#" + $(this).attr("formButtonId"));
                    
                    var retValue = button.triggerHandler("click");
                    if(retValue == undefined || retValue == true)
                        eval(button.attr("href"));
                    
                    return false;
                }
            });
        }
    });
});