﻿ //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(){
    $(".tabContent").hide();    //Initially hide all tabs
    $("ul.tabNames li:first").addClass("selected");     //Apply selected class to first tab
    $(".tabContent:first").show();      //Show first tabs's related content
    $("ul.tabNames li").click(function(){
        $("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
        $(".tabContent").hide();    //Hide tab's content
        var activeTab = $(this).find("a").attr("href");     //Identify which tab is clicked and activate that tab
        $(activeTab).fadeIn();  //Slowly fade in the active tab
        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";
}

//Pagination fro Option and accessories

$(document).ready
(function()
    { 
                                                                          
        createPager();
        showContents(1);
                
        $("ul.optAndAccNav li a").each
        (function(index)
            {
               $(this).bind ("click",
                function()
                    {
                        
                    }
                );
            }
        );
	        
    }
);

function goToPage(pageNumber)
{
    var totalPages = Math.ceil($("div#optAndAcc div.itemList").size() / 5);
    var pageNo = parseInt(pageNumber);
    showContents(pageNo);
    
    var pager = "<ul class='optAndAccNav'>";
    if($("div#optAndAcc div.itemList").size() > 0){
        pager += "<li><b>Total Records:</b> " + $("div#optAndAcc div.itemList").size() + "</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(" + (pageNo - 1) + ")'>Prev</a></li>";
    if (pageNo < totalPages)
        pager += "<li><a href='#' onclick='return goToPage(" + (pageNo + 1) + ")'>Next</a></li>";
    
    pager += "</ul>";
    
    $("div.pagingTop").html(pager);                                               
    $("div.pagingBottom").html(pager);

    return false;
}

function createPager()
{
    var pager = "<div class='pagination'>";
    var totalPages = Math.ceil($("div#optAndAcc div.itemList").size() / 5);
    pager += "<ul class='optAndAccNav'>";
    if($("div#optAndAcc div.itemList").size() > 0){
        pager += "<li><b>Total Records:</b> " + $("div#optAndAcc div.itemList").size() + "</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(2)'>Next</a></li>";
    }
    pager += "</ul></div>";
    $("div.pagingTop").html(pager);                                               
    $("div.pagingBottom").html(pager);
}



function showContents(pageNo)
{
    $("div#optAndAcc div.itemList").each
        (function(index)
            {
                $(this).hide();
                if (index >= (parseInt(pageNo) - 1) * 5 && index < (5 * parseInt(pageNo)))
                {
                    $(this).show();
                }
            }
        );
}

//Pagination for Similar products

$(document).ready
(function()
    { 
                                                                          
        createPager1();
        showContents1(1);
                
        $("ul.similarNav li a").each
        (function(index)
            {
               $(this).bind ("click",
                function()
                    {
                        $("ul.similarNav li a").removeClass("selected");
                        showContents($(this).html());
                        $(".nav" + $(this).html()).addClass("selected");
                        return false;
                    }
                );
            }
        );
	        
    }
);

function createPager1()
{
    var totalPages = Math.ceil($("div#similarProd div.itemList").size() / 5);
    
    var pager = "&nbsp;";
    if (totalPages > 1)
    {
        pager = "<ul class='similarNav'><li><a href='#' onclick='return goToPage1(2)'>Next</a></li></ul>";
    }
    
    $("div.pagingTop1").html(pager);                                               
    $("div.pagingBottom1").html(pager);
}

function goToPage1(pageNumber)
{
    var totalPages = Math.ceil($("div#similarProd div.itemList").size() / 5);
    var pageNo = parseInt(pageNumber);
    showContents1(pageNo);
    
    var pager = "<ul class='similarNav'>"
    if (pageNo > 1)
        pager += "<li><a href='#' onclick='return goToPage1(" + (pageNo - 1) + ")'>Prev</a></li>";
    if (pageNo < totalPages)
        pager += "<li><a href='#' onclick='return goToPage1(" + (pageNo + 1) + ")'>Next</a></li>";
    
    pager += "</ul>";
    
    $("div.pagingTop1").html(pager);                                               
    $("div.pagingBottom1").html(pager);

    return false;
}

function showContents1(pageNo)
{
    $("div#similarProd div.itemList").each
        (function(index)
            {
                $(this).hide();
                if (index >= (parseInt(pageNo) - 1) * 5 && index < (5 * parseInt(pageNo)))
                {
                    $(this).show();
                }
            }
        );
}

/************ Script Funtions Use in Product Comparison ******************/

/* This function is used when any product is remove from the selected product comparison */
function hidediv(a_id, b_id, c_id, d_id, z_id) {
		var lenght = $('len').innerHTML;
		if (lenght <= 2) {
			return false;
		}
		Effect.Fade($(a_id), {duration: 0.3});Effect.Fade($(b_id), {duration: 0.3});
		Effect.Fade($(c_id), {duration: 0.3});Effect.Fade($(d_id), {duration: 0.3});		
		
		$(a_id).innerHTML = '';$(b_id).innerHTML = '';
		$(c_id).innerHTML = '';$(d_id).innerHTML = '';		
		
		var zid = "";
		var count = $('rows').innerHTML;				
		for(var index=1; index <= count; index++) {
		 		zid = "z_" + index + "_" + z_id;		 		
				Effect.Fade(zid,{duration: 0.3});
				$(zid).innerHTML = '';
		}
		lenght = lenght - 1;		
		$('len').innerHTML = lenght;		
		
		if (lenght == 2) {
			for(var i=1; i <= 4; i++) {				
				aid = "a_" + i;				
				if (a_id!=aid) {					
					var element = document.getElementById(aid);
					if (element != null)
						document.getElementById(aid).innerHTML = '<span class="a12BlackB fltL"> Selected Product </span>';
				}
			}
		}		
}

function hideRemove() {
        var lenght = $('len').innerHTML;
		if (lenght == 2) {
			for(var i=1; i <= 2; i++) {				
				aid = "a_" + i;
				var element = document.getElementById(aid);
				if (element != null)
				    document.getElementById(aid).innerHTML = '<span class="a12BlackB fltL"> Selected Product </span>';
			}
		}
}

/* This function check the number of product valid for product comparison request. */
function validateComparison() {	
	//var msg = document.getElementById('errMsg');	
	var pidstr = document.getElementById("productIds").value;
	var pids = pidstr.split(',');
	var len = pids.length - 1;	
	if (len > 4) {		
		alert("Please restrict your choice to four products\n");
		return false;
	} else if (len < 2) {		
		alert("Please select atleast two products for comparison\n");
		return false;	
	} else {
		//msg.style.display="none";
		//$('errMsgBot').hide();		
	}		
	return true;
}

/* 
   This function will first validate the product ids selected and if valdated successfully send the product
   to ProductComparison page and reset the selected comparison request.
*/
function processComparison() {

	if (validateComparison()) {
		setCompareIds(); 
		var pidstr = document.getElementById('productIds').value;
		clearSelectedProducts('compareIds');				
		document.location=comparePageUrl+"?productIDs="+pidstr;
		resetComparision();		
	}
}

/* This function every selected comparison id in hidden feild. */
function setCompareIds() {
	var params = '';
	for(var i = 0; i < productIds.length; i++) {
		if(productIds[i] > 1) params += productIds[i] + ',';
	}

	document.getElementById('productIds').value=params;
	
	//document.getElementById('<%=productIds.ClientID %>').value=params;
	
}

/* This selected ids array and hidden filed for comparison. */
function resetComparision() {
	productIds = null;
	productIds = new Array();
	//$("compare").reset();
	$('productIds').value = '';	
}

/* This function sets selected comparison ids in js array. */
function setForComparision(productId) {			
	var index = indexInComparision(productId);
	if(index == -1)
		productIds[productIds.length] = productId;
	else {
		productIds[index] = null;
		productIds[index] = undefined;
	}	
}

/* This function check whether selected id is alreay in js array. */
function indexInComparision(productId) {
	if(productId == null || productId == undefined) return -1;
	
	var index = -1;
	for(var i = 0; i < productIds.length; i++) {
		if(productIds[i] != null && productIds[i] == productId) {
			index = i;
			break;
		}
	}
	return index;
}

/* This function clears all selected checkboxes for products in search results page. */
function clearSelectedProducts(elementsName) {
	var elements = document.getElementsByName(elementsName);
	for(var i = 0; i < elements.length; i++) {
		elements[i].checked = false;
	}
}

/* Product Ids array contians selected ids for product comparison */
var productIds = new Array();