/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2008 Brand Labs LLC
 * 
 * Continue shopping which uses the referrer to redirect to
 * 
 * Version 1.0.2
 * 
 *--------------------------------------------------------------------------*/

function continueShopping(){var aa=null;var ba=null;var ca='/';var da=window.location.pathname;var ea=window.location.host;var fa=null;var ga;if(document.referrer){aa=document.referrer;}
try{fa=getProductHistoryURL();}
catch(e){fa=null;}
ca=(fa==null?ca:fa);if(aa==null||aa==''){window.location.href=ca;return;}
try{ga=aa.indexOf(ea);if(ga==-1){window.location.href=ca;return;}
ba=aa.substring((ga+ea.length));if(ba.toLowerCase().indexOf(da.toLowerCase())==0){window.location.href=ca;return;}
window.location.href=ba;return;}
catch(e){window.location.href=ca;return;}}
function getProductHistoryURL(){var ha='%2FHistory';var ia=null;var ja=null;var ka=null;var la=null;if(!document.cookie||document.cookie==null){return null;}
ia=document.cookie.split(';');for(index=0;index<ia.length;index++){ja=ia[index];while(ja.charAt(0)==' '){ja=ja.substring(1,ja.length);}
if(ja.indexOf(ha+'=')==0){ka=ja.substring(ha.length+1);if(ka==null||ka==''){return null;}
la=ka.split('%2C');return '/ProductDetails.asp?ProductCode='+la[0];}}
return null;}/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2008 Brand Labs LLC
 * 
 *--------------------------------------------------------------------------*/
/**
 * Update header with cart items
 */
function updateHeaderCartSummary() {
	var element;
	var items;
	var output;
	
	element = document.getElementById('view_cart_text_right');
	
	if(element == null) {
		return;
	}
	
	items = getShoppingCartItems();
	total = getShoppingCartTotal();
	
	//No items or null
	if(isShoppingCartEmpty()) {
		output = '0 Items: $0.00';
	}
	else if (items == null || total == null) {
		return;
	}
	else if(items == 0) {
		output = '0 Items: $0.00';
	}
	else {
		//Create string
		output = items + ' Item';
		if (items > 1) {
			output = output + 's';
		}
		output = output + ': ' + total;
	}
	
	//Put data into field
	element.innerHTML = output;
}/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2008 Brand Labs LLC
 * 
 * Shopping Cart Summary
 * 
 * Version 1.2.1
 * 
 *--------------------------------------------------------------------------*/

function getShoppingCartSummary(){var aa;var ba;aa=document.getElementById('display_cart_summary');if(aa==null){return null;}
return aa.innerHTML;}
function isShoppingCartEmpty(){var ca;ca=getShoppingCartSummary();if(ca==null){return null;}
if(ca.search('(Your shopping cart is empty)')!=-1){return true;}
return false;}
function getShoppingCartItems(){var da;var ea;da=getShoppingCartSummary();if(da==null){return null;}
ea=da.match(/\d+/);if(ea==null){return null;}
return ea[0];}
function getShoppingCartTotal(){var fa;var ga;var ha;var ia;fa=getShoppingCartSummary();if(fa==null){return null;}
ga=fa.match(/total\scost\sof\s.*\)/);ha=fa.match(/priced\sat\s.*\)/);if(ga==null&&ha==null){return null;}
if(ga!=null){if(ga[0]==null||ga[0].length<=15){return null;}
ia=ga[0].substr(14,ga[0].length-15);}
else{if(ha[0]==null||ha[0].length<=11){return null;}
ia=ha[0].substr(10,ha[0].length-11);}
return ia;}/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2008 Brand Labs LLC
 * 
 * Default value temporary for user
 * 
 * Version 1.0.1
 * 
 *--------------------------------------------------------------------------*/

function inputTextClicked(aa,ba){if(aa.value==aa.defaultValue){aa.value='';aa.style.color=ba;}}
function inputTextBlurred(ca,da){if(ca.value!=''){return;}
ca.style.color=da;ca.value=ca.defaultValue;}/*--------------------------------------------------------------------------*
 * 
 * Copyright (C) 2011 Brand Labs LLC
 * 
 *--------------------------------------------------------------------------*/

var Buttons = {
		
	load: function(){
		if(Buttons.isProductDetailPage(window.location.pathname)){
			try{
				var location = $('table.colors_pricebox').first().find('table').first().find('table').first().find('td').first();
				if(location == null || location == undefined){
					return;
				}
				location.prepend('<div id="product_buttons"> <a href="/contact-us-a/250.htm" title="Ask Us About This Item" onclick="window.open(this.href); return false;"><img class="first" src="/v/vspfiles/templates/Danlar/images/buttons/btn_askus.gif" alt="Ask Us About This Item"></a>'
								+ '<a href="/help_answer.asp?ID=13#21" title="Price Match PLUS+" onclick="window.open(this.href); return false;"><img src="/v/vspfiles/templates/Danlar/images/buttons/btn_pricematch.gif" alt="Price Match PLUS+"></a></div>');
			}catch(e){/*Ignore*/}
		}
	},
	
	isProductDetailPage: function(url) {
		if(null == url) {
			return false;
		} else {
			//PRODUCT
			//The product detail page (per Volusion KB)	
			return (url.toLowerCase() == '/productdetails.asp' ||
					url.toLowerCase().indexOf('-p/') != -1 ||
					url.toLowerCase().indexOf('_p/') != -1);
		}
	}
}
jQuery(document).ready(
		Buttons.load		
);
