/*
	put footwearetc-specific javascript functions here
*/

function handle_state_tax(stateAbbr, arg) {
	//alert('handle_state_tax() with name: ' + name + ' and name2: ' + name2 + ' and stateAbbr: ' + stateAbbr);

	/* 
		you can use either convention but the first example is misleading.  
		"arg" is not an array nor some sort of a map.  it's an object with a property.
	*/
	//var el = document.getElementById(arg['elementId']);
	var el = document.getElementById(arg.elementId);
	var custCountry = readCookie('custCountry');
	
	/* cookie for 1 day */
	createCookie('custState', stateAbbr, 1);
	
	if (el && custCountry == 'US' || countryAbbr == 'US_' ) {
		if (stateAbbr == 'CA') {			
			el.innerHTML = '';
		} else {			
			el.innerHTML = 'No Sales Tax';
		}
	}  else {
		el.innerHTML = '';
	}
}





function handle_IC_state_tax(stateAbbr, countryAbbr, arg) {
	
	var el = document.getElementById(arg.elementId);
	
	/* cookie for 1 day */
	createCookie('custState', stateAbbr, 1);
	createCookie('custCountry', countryAbbr, 1);	
	
	if (el) {
		if (countryAbbr == 'US' || countryAbbr == 'US_' || countryAbbr == 'PR' || countryAbbr == 'PR_') {
			if (stateAbbr == 'CA') {
				el.innerHTML = '';
			} else {
				el.innerHTML = 'No Sales Tax';
			}
		} else {
			el.innerHTML = '';
		}
	} 
}





function handle_international_checkout(countryAbbr, arg, domain) {	
	/* 
		you can use either convention but the first example is misleading.  
		"arg" is not an array nor some sort of a map.  it's an object with a property.
	*/
	//var el = document.getElementById(arg['elementId']);
	var el = document.getElementById(arg.elementId);
	
	/* cookie for 1 day */
	createCookie('custCountry', countryAbbr, 1);	
	if (el) {
		if (countryAbbr == 'US' || countryAbbr == 'US_') {
			el.innerHTML = '<img src='+domain+'/images/international_checkout.gif alt=International_checkout>';		
		} else {
			el.innerHTML = '<img src='+domain+'/images/international_checkout.gif alt=International_checkout>';
		}
	}
}



function handle_international_headlink(countryAbbr, arg) {	
	/* 
		you can use either convention but the first example is misleading.  
		"arg" is not an array nor some sort of a map.  it's an object with a property.
	*/
	//var el = document.getElementById(arg['elementId']);	
	var el = document.getElementById(arg.elementId);
	
	/* cookie for 1 day */	
	createCookie('custCountry', countryAbbr, 1);	
	if (el) {
		if (countryAbbr == 'US' || countryAbbr == 'US_' || countryAbbr == 'PR' || countryAbbr == 'PR_') {
			el.innerHTML = 'Free Shipping <span class=subText> - on US orders over $60</span>';		
		} else {
			ic_link_id = 'intl_ic_link';
			el.innerHTML = 'Worldwide Shipping Available';
		}
	}		
}


function check_IP_International(countryAbbr, arg) {	
	//var el = document.getElementById(arg.elementId);
	
	/* cookie for 1 day */
	createCookie('custCountry', countryAbbr, 1);	

}











//powerreview

function toggleTab(target){
	var tabmenu = document.getElementById('tabmenu');
	var tabpanel;
	if (tabmenu){
		var tabitems = tabmenu.getElementsByTagName("li");
		for (var i = 0; i < tabitems.length; i++) {
			tabpanel = document.getElementById(tabitems[i].id.substring(1));			
			if (tabitems[i].id == target){				
				tabitems[i].className = "TabbedPanelsTab";
				if (tabpanel){					
					tabpanel.style.display = "block";					
					tabitems[i].className = "TabbedPanelsTab TabbedPanelsTabSelected TabbedPanelsTabFocused";
				}
			}
			else{
				tabitems[i].className = "TabbedPanelsTab";
				if (tabpanel){
					tabpanel.style.display = "none";
				}
			}
		}
	}
}
function getTabPos(tabid){
	toggleTab(tabid);
	var target = document.getElementById(tabid)
	if (target){
		window.scrollTo(0, findPos(target) - 20);
	}
}
function findPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return [curtop];
}





function trackLinks(){
	var obj;
	var thisId="";
	
	if((arguments.length==2)&&(typeof arguments[1]=='object'))
		{obj=arguments[1];}
	if((arguments.length==1)&&(typeof arguments[0]=='string'))
		{thisId=arguments[0];}
}




// get the copy from James, used to skip a javascript data loading. 
	function addLoadListener(fn) {
		if (typeof window.addEventListener != 'undefined') {
			window.addEventListener('load', fn, false);
		} else if (typeof document.addEventListener != 'undefined') {
			document.addEventListener('load', fn, false);
		} else if (typeof window.attachEvent != 'undefined') {
			window.attachEvent('onload', fn);
		} else {
			var oldfn = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = fn;
			} else {
				window.onload = function() {
					oldfn();
					fn();
				};
			}
		}
	}

//customize gift card value
	function changeGiftCardChoice(el, cust_val_id){
        if(el.options[el.selectedIndex].innerHTML == 'Customize'){
            document.getElementById(cust_val_id+'_td').style.display='';
            document.getElementById(cust_val_id).name=document.getElementById(cust_val_id).id;
        }else{
            document.getElementById(cust_val_id+'_td').style.display='none';
            document.getElementById(cust_val_id).name='nothing';
        }
    }
	
	
	function displayPrice(contextPath) {
		
		asyncGet(contextPath + '/templates/ajax/isAnniversarySale.jsp', 'handleDisplayPrice', {});
	
	}
	
	function handleDisplayPrice(response, arg){
		if(response == 'true') {
			$$('.as_price').each(function(item){$(item).setStyle({display:'inline'});});
		} else {
			$$('.rs_price').each(function(item){$(item).setStyle({display:'inline'});});
		}
	}