//*** sets up browserType variable ***//
var browserType;
var callingDiv;

//Wishlist link is disabled after click for this many ms
var _jsLinkTimeout = 3000;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {browserType= "gecko"}

function togglehide(divID)
{
    divID.style.display='none';
}
function toggleunhide(divID)
{
    divID.style.display='inline';
}

var shoppingCartLinksEventHandlers = {
	addClicked : function(product, aj, supplierID)
	{
			$(aj).style.display = 'none';
			$('pre'+aj).innerHTML = 'Adding item to your shopping cart.';
			$('pre'+aj).style.display = '';
			
			var opt = {method: 'get', onSuccess: function(t) {shoppingCartLinksEventHandlers.onCompleteAdd(t, aj);}}
			new Ajax.Request('addtocart.aspx?prod=' + product + '&supp=' + supplierID, opt);
	},
	
	switchToWishClicked : function(ShopWishID, aj)
	{
			$(aj).style.display = 'none';
			$('pre'+aj).innerHTML = 'Adding item to your wish list.';
			$('pre'+aj).style.display = '';
			
			var opt = {method: 'get', onSuccess: function(t) {shoppingCartLinksEventHandlers.onCompleteSwitch(t, aj);}}
			new Ajax.Request('ShopWishAddToWishListFromShopCart.aspx?shopWishID=' + ShopWishID, opt);
	},	
	
	onCompleteAdd : function(request, aj){
		this.oncomplete(request, aj, 'Item added to your shopping cart.')
	},
	
	onCompleteSwitch : function(request, aj){
		this.oncomplete(request, aj, 'Item added to your wish list.')
	},

	oncomplete : function(request, aj, message)
	{
			$('pre'+aj).style.display = 'none';
			$(aj).innerHTML = message;
			$(aj).style.display = '';
			new Effect.Highlight(aj);
	}
}

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

//*** begin ajax call on searchresults.aspx ***//
function addToCart(product, div, aj, supplierID)
{
    $(aj).style.display = 'none';
    $('pre'+aj).innerHTML = 'Adding item to your shopping cart.';
    $('pre'+aj).style.display = '';
	var opt = {method: 'get', onSuccess: function(t) {completeCart(t, div, aj);}}
    new Ajax.Request('addtocart.aspx?prod=' + product + '&supp=' + supplierID, opt);
}

function completeCart(request, st, aj)
{
    $('pre'+aj).style.display = 'none';
    $(aj).innerHTML = request.responseText;
    $(aj).style.display = '';
    new Effect.Highlight(aj);
}
//*** end ajax call on searchresults.aspx ***//

//*** begin ajax call on searchresults.aspx ***//
function showClosedCenter(id) {
    setShowClosedCenterInfo(id);
    Effect.SlideDown('closed' + id);
    t = null;
    t = setTimeout("closeClosedCenter('" + id + "')", 10000); //changed to function closer
}

function showClosedCenterNoSlide(id) {

    setShowClosedCenterInfo(id);
    document.getElementById('closed' + id).style.display = 'inline';
    t = null;
    t = setTimeout("closeClosedCenterNoSlide('" + id + "')", 10000); //changed to function closer
}

function setShowClosedCenterInfo(id) {

	var newX = findPosX('left' + id);
	var newY = findPosY('tr' + id);
	
	$('closed' + id).style.top = newY + 'px';
	$('closed' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('closed' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $('closed' + id).style.height = ($('tr' + id).clientHeight - 1) + 'px';
	}
}

function closeClosedCenter(id) {
    if ($('closed'+id).style.display == '') {
      Effect.SlideUp('closed' + id);
    }
}

function closeClosedCenterNoSlide(id) {
    document.getElementById('closed' + id).style.display = 'none';
}

function showOnlineCenterNotHomeDelivery(id) {
    setShowOnlineCenterNotHomeDeliveryInfo(id);
    Effect.SlideDown('OnlineCenterNotHomeDelivery' + id);
    t = null;
    t = setTimeout("closeOnlineCenterNotHomeDelivery('" + id + "')", 10000); //changed to function closer
}

function showOnlineCenterNotHomeDeliveryNoSlide(id) {

    setShowOnlineCenterNotHomeDeliveryInfo(id);
    document.getElementById('OnlineCenterNotHomeDelivery' + id).style.display = 'inline';
    t = null;
    t = setTimeout("closeOnlineCenterNotHomeDeliveryNoSlide('" + id + "')", 10000); //changed to function closer
}

function setShowOnlineCenterNotHomeDeliveryInfo(id) {

	var newX = findPosX('left' + id);
	var newY = findPosY('tr' + id);
	
	$('OnlineCenterNotHomeDelivery' + id).style.top = newY + 'px';
	$('OnlineCenterNotHomeDelivery' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('OnlineCenterNotHomeDelivery' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $('OnlineCenterNotHomeDelivery' + id).style.height = ($('tr' + id).clientHeight - 1) + 'px';
	}
}

function closeOnlineCenterNotHomeDelivery(id) {
    if ($('OnlineCenterNotHomeDelivery'+id).style.display == '') {
      Effect.SlideUp('OnlineCenterNotHomeDelivery' + id);
    }
}

function closeOnlineCenterNotHomeDeliveryNoSlide(id) {
    document.getElementById('OnlineCenterNotHomeDelivery' + id).style.display = 'none';
}

//*** begin ajax call on searchresults.aspx ***//
function showCartNote(id) {
	setShowCartNoteInfo('NoCartPopUp', id);
    Effect.SlideDown('NoCartPopUp' + id);
    t = null;
    t = setTimeout("closeCartNote('" + id + "')", 10000); //changed to function closer
}


//*** Mike S - Wasn't added ***//
function showCartNoteCoveo(tagName, id) {
	setShowCartNoteInfo(tagName, id);
    Effect.SlideDown(tagName + id);
    t = null;
    t = setTimeout("closeCartNoteCoveo('" + tagName + id + "')", 10000); //changed to function closer
}

function showCartNoteNoSlide(tagName, id) {
	setShowCartNoteInfo(tagName, id);
    document.getElementById(tagName + id).style.display = 'inline';
    t = null;
    t = setTimeout("closeCartNoteNoSlide('" + tagName + id + "')", 10000); //changed to function closer
}

function setShowCartNoteInfo(tagName, id) {
	var newX = findPosX('left' + id);
	var newY = findPosY('tr' + id);
	
	$(tagName + id).style.top = newY + 'px';
	$(tagName + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $(tagName + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $(tagName + id).style.height = ($('tr' + id).clientHeight - 1) + 'px';
	}
}

function showCartNoteDetails(id) {

    hideDropDownsDetails();

	var newX = findPosX('leftDetail');
	var newY = findPosY('leftDetail');
		
	$('NoCartPopUp' + id).style.top = newY + 'px';
	$('NoCartPopUp' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('NoCartPopUp' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $('NoCartPopUp' + id).style.height = ($('tableDetail').clientHeight - 1) + 'px';
	}
    Effect.SlideDown('NoCartPopUp' + id);
    t = null;
    t = setTimeout("closeCartNote('" + id + "')", 10000); //changed to function closer
    
    setTimeout('ShowDropDownsDetails()', 10000);   
}


function closeCartNote(id) {
    if ($('NoCartPopUp'+id).style.display == '') {
      Effect.SlideUp('NoCartPopUp'+id);
    }
}

//*** Mike S - need this override ***//
function closeCartNoteCoveo(id) {
    if ($(id).style.display == '') {
      Effect.SlideUp(id);
    }
}

function closeCartNoteNoSlide(tagName) {
    document.getElementById(tagName).style.display = 'none';
}
//*** end ajax call on searchresults.aspx ***//


function hideDropDownsDetails() {
    try { 
        $('ctl00_ContentPlaceHolder_option1DropDown').style.display = 'none'; 
    } catch(err) {
    }
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option1DropDown').style.visibility = 'hidden'; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option2DropDown').style.display = 'none'; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option2DropDown').style.visibility = 'hidden'; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option3DropDown').style.display = 'none'; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option3DropDown').style.visibility = 'hidden'; 
          } 
          catch(err)
          {}
}


function ShowDropDownsDetails() {

    
	
	try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option1DropDown').style.display = ''; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option1DropDown').style.visibility = 'visible'; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option2DropDown').style.display = ''; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option2DropDown').style.visibility = 'visible'; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option3DropDown').style.display = ''; 
          } 
          catch(err)
          {}
          
          try 
          { 
           document.getElementById('ctl00_ContentPlaceHolder_option3DropDown').style.visibility = 'visible'; 
          } 
          catch(err)
          {}
}

function closeHide(id) {
	var newX = findPosX('left' + id);
	var newY = findPosY('tr' + id);
	
	$('NoCartPopUp' + id).style.top = newY + 'px';
	$('NoCartPopUp' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('NoCartPopUp' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $('NoCartPopUp' + id).style.height = ($('tr' + id).clientHeight - 1) + 'px';
	}
    Effect.SlideDown('NoCartPopUp' + id);
    t = null;
    t = setTimeout("closeCartNote('" + id + "')", 10000); //changed to function closer
}



function SetLinkState(clientID, bDisable)
{
    var anchor = document.getElementById(clientID);
    anchor.disabled = bDisable; 
   
    if (bDisable)
         anchor.className = "disabledlink";
    else
         anchor.className = "popuplink option";  
}

function ReenableLink(clientID)
{
    SetLinkState(clientID, false);
}

function addToWishListHideLink(product, div, aj, supplierID, anchorID)
{
    if (! document.getElementById(anchorID).disabled == true)
    {
        SetLinkState(anchorID, true);
        var fn = "ReenableLink('" + anchorID + "');";
        setTimeout(fn, _jsLinkTimeout);
    
        $(aj).style.display = 'none';
    
        $('pre'+aj).innerHTML = 'Adding item to your wish list.';
    
        $('pre'+aj).style.display = '';
    
	    var opt = {method: 'get', onSuccess: function(t) {completeWishList(t, div, aj);}}
        new Ajax.Request('addtowishlist.aspx?prod=' + product + '&supp=' + supplierID, opt);
    }

}


function addToWishList(product, div, aj, supplierID)
{
   // if( $(aj).innerHTML == 'Adding item to your wish list.' || $(aj).innerHTML == 'Item added to your wish list.')
   //    return;
    $(aj).style.display = 'none';
    
    $('pre'+aj).innerHTML = 'Adding item to your wish list.';
    
    $('pre'+aj).style.display = '';
    
	var opt = {method: 'get', onSuccess: function(t) {completeWishList(t, div, aj);}}
    new Ajax.Request('addtowishlist.aspx?prod=' + product + '&supp=' + supplierID, opt);
}

///////////////////////////////////////////////////////////////////
// Wish List Object
///////////////////////////////////////////////////////////////////
function OptionsObject(selection){
	this.opt1 = selection.option1;
	this.prodOpt1 = selection.prodOption1;
	this.opt2 = selection.option2;
	this.prodOpt2 = selection.prodOption2;
	this.opt3 = selection.option3;		
	this.prodOpt2 = selection.prodOption2;
	
	return this;
}

wishListLinksEventHandlers = {
	options : new OptionsObject({
		option1 : -1, 
		prodOption1 : -1, 
		option2 : -1, 
		prodOption2 : -1, 
		option3 : -1, 
		prodOption3 : -1}),
	
	setOptions : function (options){
		this.options = new OptionsObject(options);
	},
	
	getUrlParams : function(){
		var urlParamStr = '';
		
		if(this.options.selection1 != -1)
			urlParamStr += '&opt1=' + this.options.opt1 + '&prodOpt1=' + this.options.prodOpt1;		
		
		if(this.options.selection2 != -1)
			urlParamStr += '&opt2=' + this.options.opt2 + '&prodOpt2=' + this.options.prodOpt2;		
		
		if(this.options.selection3 != -1)
			urlParamStr += '&opt3=' + this.options.opt3 + '&prodOpt2=' + this.options.prodOpt2;		
		
		return urlParamStr;
	},
	
	addClicked : function (product, div, aj, supplierID){	
		
		$(aj).style.display = 'none';
    
    $('pre'+aj).innerHTML = 'Adding item to your wish list.';
    
    $('pre'+aj).style.display = '';
    
		var opt = {method: 'get', onSuccess: function(t) {completeWishList(t, div, aj);}}
		new Ajax.Request('addtowishlist.aspx?prod=' + product + '&supp=' + supplierID + this.getUrlParams(), opt);
	}
}

///////////////////////////////////////////////////////////////////

function addToNewWishList(product, div, aj, supplierID)
{
    $(aj).style.display = 'none';
    
    $('pre'+aj).innerHTML = 'Creating new wish list.';
    
    $('pre'+aj).style.display = '';
    
	var opt = {method: 'get', onSuccess: function(t) {completeWishList(t, div, aj);}}
    new Ajax.Request('addtonewwishlist.aspx?prod=' + product + '&supp=' + supplierID, opt);
}

function completeWishList(request, st, aj)
{
    $('pre'+aj).style.display = 'none';
    $(aj).innerHTML = 'Item added to your wish list.';
    $(aj).style.display = '';
    new Effect.Highlight(aj);
}

function addToWishListDetails(product, div, aj, supplierID)
{    
    $(aj).style.display = 'none';
    
    $(aj).innerHTML = 'Adding item to your wish list.';
    
    $(aj).style.display = '';
    
	var opt = {method: 'get', onSuccess: function(t) {completeWishListDetails(t, div, aj);}}
    new Ajax.Request('addtowishlist.aspx?prod=' + product +'&supp=' + supplierID, opt);
}

function addToNewWishListDetails(product, div, aj, supplierID)
{
    $(aj).style.display = 'none';
    
    $(aj).innerHTML = 'Adding item to your wish list.';
    
    $(aj).style.display = '';

	var opt = {method: 'get', onSuccess: function(t) {completeWishListDetails(t, div, aj);}}
    new Ajax.Request('addtonewwishlist.aspx?prod=' + product + '&supp=' + supplierID, opt);
}

function addToCartDetails(product, div, aj, supplierID)
{
    $(aj).style.display = 'none';
    
    $(aj).innerHTML = 'Adding item to your shopping cart.';
    
    $(aj).style.display = '';
    
	var opt = {method: 'get', onSuccess: function(t) {completeCartDetails(t, div, aj);}}
    new Ajax.Request('addtocart.aspx?prod=' + product, opt);
}

function completeWishListDetails(request, st, aj)
{
    $(aj).style.display = 'none';
    $(aj).innerHTML = 'Item added to your wish list.';
    $(aj).style.display = '';
    new Effect.Highlight(aj);
}

function completeCartDetails(request, st, aj)
{
    $(aj).style.display = 'none';
    $(aj).innerHTML = 'Item added to your shopping cart.';
    $(aj).style.display = '';
    new Effect.Highlight(aj);
}

function showWishListNote(id) {
    setShowWishListNote(id);
    Effect.SlideDown('WishlistChoosePop' + id);
    setShowWishListNoteTimeout(id);
}

function showWishListNoteNoSlide(id) {
    setShowWishListNote(id);
    document.getElementById('WishlistChoosePop' + id).style.display = 'inline';
    setShowWishListNoteTimeout(id);
}

function setShowWishListNote(id) {
	var newX = findPosX('left' + id);
	var newY = findPosY('left' + id);
	
	$('WishlistChoosePop' + id).style.top = newY + 'px';
	$('WishlistChoosePop' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('WishlistChoosePop' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $('WishlistChoosePop' + id).style.height = ($('tr' + id).clientHeight - 1) + 'px';
	}
}
    
function setShowWishListNoteTimeout(id) {
    t = null;
    t = setTimeout("closeWishlistNote('" + id + "')", 10000); //changed to function closer
}

//Product Detail Page
function showWishListNoteDetails(id) 
{
   hideDropDownsDetails();

	var newX = findPosX('left' + id);
	var newY = findPosY('left' + id);
	
	$('WishlistChoosePop' + id).style.top = newY + 'px';
	$('WishlistChoosePop' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('WishlistChoosePop' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    //Mike S- we are going to get the table's height.
	    $('WishlistChoosePop' + id).style.height = ($('table' + id).clientHeight - 1) + 'px';
	}
    Effect.SlideDown('WishlistChoosePop' + id);
    
    t = null;
    t = setTimeout("closeWishlistNote('" + id + "')", 10000); //changed to function closer
    
    setTimeout('ShowDropDownsDetails()', 10000);   
}

//Mike s - this is for Product Detail page.
function closeWishlistNoteDetails(id) {
    if ($('WishlistChoosePop'+id).style.display == '') {
      Effect.SlideUp('WishlistChoosePop'+id);
    }

    // Mike S - #1607 When the Add to wish list slider closes then show the dropdown details
    //          Need this for ProductDetails for product that are View Options
    try 
    { 
       ShowDropDownsDetails();
    } 
    catch(err)
    {}
}

function closeWishlistNote(id) {
    if ($('WishlistChoosePop'+id).style.display == '') {
      Effect.SlideUp('WishlistChoosePop'+id);
    }
}

function dec(str) {
  var val = "";
  var arr = str.split("|");
  for (var counter = 0; counter < arr.length; counter++) {
    val += String.fromCharCode(arr[counter]);
  }
  return val;
}

function showDecPrice(str, msrpstr, mapstr, id, link) {
    var disLink = document.getElementById(link);
    disLink.onclick='return false;';
    setShowDecPriceInfo(str, msrpstr, mapstr, id);
    Effect.SlideDown('price' + id);
    setShowDecPriceTimeout(id);
    disLink.onclick='';
}

function showDecPriceNoSlide(str, msrpstr, mapstr, id) {
    var msrp;
    var map;
    
    if (msrpstr == '')
    {
        msrp = null;
    }
    if (mapstr == '')
    {
        map = null;
    }
    setShowDecPriceInfo(str, msrp, map, id);
    document.getElementById('price'+id).style.display = 'inline';
    setShowDecPriceTimeout(id);
}

function setShowDecPriceInfo(str, msrpstr, mapstr, id) {
    var decstr = dec(str);
    $('prnum'+id).innerHTML = dec(str);
    
    if (msrpstr != null && $('msrpnum'+id) != null ) {
        $('msrpnum'+id).innerHTML = dec(msrpstr);
    }

    if (mapstr != null &&  $('mapnum'+id) != null) {
        $('mapnum'+id).innerHTML = dec(mapstr);
    }

	var newX = findPosX('left' + id);
	var newY = findPosY('left' + id);
	$('price' + id).style.top = newY + 'px';
	$('price' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('price' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $('price' + id).style.height = ($('tr' + id).clientHeight - 1) + 'px';
	}
}

function setShowDecPriceTimeout(id) {
    t = null;
    t = setTimeout("closePopupNoSlide('" + id + "')", 10000); //changed to function closer
}

function showPopupSlideDown(div, id, findXY) {
	var newX = findPosX('left' + id);
	var newY = findPosY('left' + id);
	if (newX > 0 && newY > 0 && findXY == "true")
	{
	    $(div + id).style.top = newY + 'px';
	    $(div + id).style.left = newX + 'px';
	    if (browserType == "gecko") {
	        $(div + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	    } else {
	        $(div + id).style.height = ($('trow' + id).clientHeight - 1) + 'px';    	    
	    }
	}
    Effect.SlideDown('ManufRedir' + id);
    t = null;
    t = setTimeout("closePopupSlideDown('" + div + "', '" + id + "')", 10000); //changed to function closer    
}    

function showPopupSlideDownManufacturer(webSite) {
    document.getElementById('ManufRedir').style.display='';
    
    var varSite = webSite;
    
    document.getElementById('webSite').innerHTML = webSite;
    
    t = null;
    
    t = setTimeout("closePopupSlideDownManufacturer()", 20000); //changed to function closer    
}    

function showPopupSlideDownManufacturerShowroom(webSite) {
    
    alert("Passed in website " + webSite);
    
    document.getElementById('ManufRedir').style.display='';
    
    var varSite = webSite;
 
    document.getElementById('webSite').innerHTML = webSite; 
      
    //Showroom. yea i know it's ugly. but it is for windows 2000
    var hrefLink = document.getElementById('linkwebSite').href;
    

    
    document.getElementById('linkwebSite').href = webSite;
    
    t = null;
    
    t = setTimeout("closePopupSlideDownManufacturer()", 20000); //changed to function closer    
} 
 
function closePopupSlideDownManufacturer() {

if (document.getElementById('ManufRedir') != null){
    document.getElementById('ManufRedir').style.display='none';
    }
}

function openWindow() {

    var webURL;
    
    try
    {
    //F.M. 10/2/2008 For FireFox
     if (document.getElementById('webSite').textContent) 
         webURL = document.getElementById('webSite').textContent; 
     else
          webURL = document.getElementById('webSite').innerText;

    if(webURL == '' && document.getElementById('website') != null){
        //Product Detail page.
        webURL = document.getElementById('website').value;
    }
    if (webURL.indexOf("http") != 0)
        webURL = 'http://' + webURL;    
    var openWin = window.open(webURL, 'newWindow', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500');
    //var openWin = window.open('http://www.xplorsports.com', 'newWindow', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500');
    
    closePopupSlideDownManufacturer();
    }
    catch(e)
    {
        alert(e.toString);
    }
    
    
    return false;
}  
 
function closePopupSlideDown(div, id) {
    if ($(div + id).style.display == '') {
      Effect.SlideUp(div + id);
    }
}   


function closePopup(id) {
    if ($('price'+id).style.display == '') {
      Effect.SlideUp('price'+id);
    }
}

function closePopupNoSlide(id) {

   if(document.getElementById('price'+id) != null){
    document.getElementById('price'+id).style.display = 'none';
   }
}

function showCartItemPrice(id) {
	var newX = findPosX('trid' + id);
	var newY = findPosY('trid' + id);
	$('itemPrice' + id).style.top = newY + 'px';
	$('itemPrice' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('itemPrice' + id).style.height =  ($('trid' + id).offsetHeight - 1) + 'px';
	} else {
	    $('itemPrice' + id).style.height = ($('tdid' + id).clientHeight - 1) + 'px';
	}
    Effect.SlideDown('itemPrice' + id);
    t = null;
    t = setTimeout("hideCartItemPrice('" + id + "')", 10000); //changed to function closer        
}

function hideCartItemPrice(id) {
    if ($('itemPrice' + id).style.display == '') {
      Effect.SlideUp('itemPrice' + id);
    }
}

function showValidationCodePop(elem) {
Effect.SlideDown('securityPop');
document.getElementById(elem).style.display = 'none';
}

function hideValidationCodePop(elem) {
Effect.SlideUp('securityPop');
document.getElementById(elem).style.display = '';
}

//************** CartRowPrice() ****************************
function showCartRowPrice(id, quantId) {
    //quant = $('inputQuantity' + id).value;
    quant = $(quantId).value;
    price = $('inputPrice' + id).value;
    var totalprice = (quant * price);
        
    $('priceLabel' + id).innerHTML = USCurrencyFormatted(totalprice);

	var newX = findPosX('trid' + id);
	var newY = findPosY('trid' + id);
	$('rowPrice' + id).style.top = newY + 'px';
	$('rowPrice' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('rowPrice' + id).style.height =  ($('trid' + id).offsetHeight - 1) + 'px';
	} else {
	    $('rowPrice' + id).style.height = ($('tdid' + id).clientHeight - 1) + 'px';
	}
    Effect.SlideDown('rowPrice' + id);
    t = null;
    t = setTimeout("hideCartRowPrice('" + id + "')", 10000); //changed to function closer        
}

function hideCartRowPrice(id) {
    if ($('rowPrice' + id).style.display == '') {
      Effect.SlideUp('rowPrice' + id);
    }
}


function USCurrencyFormatted(amount)
{
    return CurrencyFormatted(amount);
}
function CurrencyFormatted(num)
{
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}
// end of function CurrencyFormatted()

//************** END CartRowPrice() ****************************

function showCartPriceTotal() {
	var newX = findPosX('totalRow');
	var newY = findPosY('totalRow');
	$('priceTotal').style.top = newY + 'px';
	$('priceTotal').style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('priceTotal').style.height =  ($('totalRow').offsetHeight - 1) + 'px';
	} else {
	    $('priceTotal').style.height = ($('totalTD').clientHeight - 1) + 'px';
	}
    Effect.SlideDown('priceTotal');
    t = null;
    t = setTimeout("hideCartPriceTotal()", 10000); //changed to function closer        
}

function hideCartPriceTotal() {
    if ($('priceTotal').style.display == '') {
      Effect.SlideUp('priceTotal');
    }
}

function showNoCart(id) {
   
	var newX = findPosX('trid' + id);
	var newY = findPosY('trid' + id);
	
	$('noCart' + id).style.top = newY + 'px';
	$('noCart' + id).style.left = newX + 'px';
	
	if (browserType == "gecko") {
	    $('noCart' + id).style.height =  ($('trid' + id).offsetHeight - 1) + 'px';
	} else {
	    $('noCart' + id).style.height = ($('tdid' + id).clientHeight - 1) + 'px';
	}
    Effect.SlideDown('noCart' + id);
    
    t = null;
    t = setTimeout("hideNoCart('" + id + "')", 10000); //changed to function closer        
}

function hideNoCart(id) {
    if ($('noCart' + id).style.display == '') {
      Effect.SlideUp('noCart' + id);
    }
}

function showEmailPrice(id) {
	var newX = findPosX('left' + id);
	var newY = findPosY('left' + id);
	
	$('email' + id).style.top = newY + 'px';
	$('email' + id).style.left = newX + 'px';
	if (browserType == "gecko") {
	    $('email' + id).style.height =  ($('left' + id).offsetHeight - 1) + 'px';
	} else {
	    $('email' + id).style.height = ($('tr' + id).clientHeight - 1) + 'px';
	}
    Effect.SlideDown('email' + id);
}

function closeEmailPrice(id) {
    if ($('email'+id).style.display == '') {
      Effect.SlideUp('email'+id);
    }
}

function SendEmailPrice(product, div, id, supplier)
{
	var opt = {method: 'get', onSuccess: function(t) {CompleteEmailPrice(t, div, id);}}
    new Ajax.Request('sendemailprice.aspx?prod=' + product + '&supplier=' + supplier, opt);
}

function CompleteEmailPrice(request, st, id)
{
    //alert(st);
    //$(st).innerHTML = 'Product Added';
    var url = window.location.href;
    var urlParts = url.split("/");
    var pageName = "";
    
    if (urlParts != null)
        pageName = urlParts[urlParts.length - 1].toLowerCase();
      
    var msg = "<table border='0' cellpadding='5' cellspacing='5' width='100%'><tr><td align='left'>";
    
    if (request.responseText == "OK")
        msg += "Thank you. The price you requested has been sent to the email address in your profile.";
    else 
        msg = 'There was an error sending the email.  Please try again later.\n' + request.responseText;  
    
    msg += "</td><td align='right'>"
    //we only need to do this on pages that do not use the coveo template
    if (pageName == "shoppingcart.aspx" || pageName == "wishlist.aspx" || pageName.indexOf("productdetail.aspx") > -1 )
    {
         msg += "<a href=\"javascript:closeEmailPrice('" + id + "');\">";
         msg += "<img src='../img/common/btn_close_win.gif' alt='close' width='19' height='18' align='absmiddle'/></a>";   
    }   
    else
        msg += "&nbsp;";
    msg += "</td></tr></table>";
    
    $(st).innerHTML = msg;
        
    t = setTimeout("closeEmailPrice('" + id + "')", 5000); //changed to function closer    
    //new Effect.Highlight(st);
}





function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function supplierWindow(supplierURL) {
var url = "ManufacturerLinkPopUp.aspx?url="+supplierURL;
window.open(url, 'manufacturerLink','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500');
}

function viewImage(supplier, image) {
    var url = "ImagePopUp.aspx?supplier="+supplier+"&image="+image;
    window.open(url, '', 'width=400,height=400');
}

function viewPrice(ctr, pid, mn, catalog, supplierID) { 
    var url = "PricePopUp.aspx?ctr="+ctr+"&pid="+pid+"&mn="+ mn + "&catalog=" + catalog + "&supplierID=" + supplierID;
    var winStatus = window.open(url, '', 'width=300,height=150');
    hidePrices();
}    

function viewTotalPrice(swid) { 
    var url = "ShoppingCartTotalPricePopUp.aspx?swid="+swid;
    window.open(url, '', 'width=300,height=150');
    hidePrices();
}    

function viewCartTotalPrice() { 
    var url = "ShoppingCartCartTotalPopUp.aspx";
    window.open(url, '', 'width=300,height=150');
    hidePrices();
} 

function viewOrderTotalPrice(total) { 
    var url = "PlaceOrderTotalPricePopUp.aspx?ordTotal=" + total;
    window.open(url, '', 'width=300,height=150');
    //hidePrices();
}
function viewManufacturerTotalPrice(merchTotal, shipping, handling, fees, surcharge, subTotal, tax, manufTotal) { 
    var url = "PlaceOrderSupplierPopUp.aspx?merchTotal=" + merchTotal + "&shipping=" + shipping + "&handling=" + handling + "&surcharge=" + surcharge + "&fees=" + fees + "&subTotal=" + subTotal + "&tax=" + tax + "&manufTotal=" + manufTotal;
    window.open(url, '', 'width=320,height=245');
    //hidePrices();
} 
function viewSupplierTotalPrice(suppTotal) { 
    var url = "PlaceOrderSupplierPricePopUp.aspx?suppTotal=5000.00";  //<%= _allTotalAmount %>";
    window.open(url, '', 'width=300,height=150');
    //hidePrices();
}  
function viewOrderBySupplier(od, oc, on, mn, s, dd, p) {
    var url = "OrderDetailManufacturer.aspx?od="+od+"&oc="+oc+"&on"+on+"&mn"+mn+"&s"+s+"&dd"+dd+"&p"+p;
    window.open(url);
}

function viewOrderDetailPrice(ctr, qty, pid, mn) { 
    var url = "OrderDetailTotalPricePopUp.aspx?ctr="+ctr+"&qty="+qty+"&pid="+pid+"&mn="+mn;
    window.open(url, '', 'width=300,height=150');
    hidePrices();
} 

function viewSupplierTotal(oid) { 
    var url = "OrderSupplierTotalPopUp.aspx?oid="+oid;
    window.open(url, '', 'width=320,height=235');
    hidePrices();
} 

function MM_closeBrWindow() { 
    var howLong = 10000;
    t = null;
    t = setTimeout("closer()", howLong); //changed to function closer
}

function closer() { //added to enable hiding of price
    window.opener.showPrices();
    self.close();  
}

function toggle(lr) {
  if (browserType == "gecko" )
     document.poppedLayer = eval('document.getElementById(lr)');
  else if (browserType == "ie")
     document.poppedLayer = eval('document.all[lr]');
  else
     document.poppedLayer = eval('document.layers[lr]');
	
	if (document.poppedLayer.style.display == "none") {
		document.poppedLayer.style.display = "";
	} else {
		document.poppedLayer.style.display = "none";
  }
}

function show(lr) {
    if (browserType == "gecko" ) {
        document.poppedLayer = eval('document.getElementById(lr)');
    } else if (browserType == "ie") {
        document.poppedLayer = eval('document.all[lr]');
    } else {
        document.poppedLayer = eval('document.layers[lr]');
    }
    if (document.poppedLayer != null) {
	    document.poppedLayer.style.display = "";
	}
}

function hide(lr) {
    if (browserType == "gecko" ) {
        document.poppedLayer = eval('document.getElementById(lr)');
    } else if (browserType == "ie") {
        document.poppedLayer = eval('document.all[lr]');
    } else {
        document.poppedLayer = eval('document.layers[lr]');
    }
    if (document.poppedLayer != null) {
	    document.poppedLayer.style.display = "none";
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//Change the state on an element based on the action...
function change (elem, action) {
	if (action == 'hide') {
		document.getElementById(elem).style.display = 'none';
	} else if (action == 'show') {
		if (document.all) {
			document.getElementById(elem).style.display = 'block';
		} else {
			document.getElementById(elem).style.display = 'table-row';
		}
	}
}

function isNumeric(text) {
 var validChars = '0123456789';
 return (validChars.indexOf(text) > -1);
}

function isCharacter(text) {
  var validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return (validChars.indexOf(text) > -1);
}

// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}