
/**
 *  Product detail page tab object
 */
function ProductDetailTab() {
	
	/** All the tabs in the page*/
	this.tabs = new Array("tab1", "tab2", "tab3");
	
	
	this.getTabTitle = function (tabId) {
		return $(tabId + "Title");
	};
	
	this.inactiveTile = function (tabId) {
		this.getTabTitle(tabId).className = "";
	};
	
	this.inactiveAllTiles = function () {
		for (var i = 0; i < this.tabs.length; i++) {
			this.inactiveTile(this.tabs[i]);
		}
	};
	
	this.activeTile = function (tabId) {
		this.getTabTitle(tabId).className = "active";
	};
	
	this.activeTab = function (tabId) {
		$(tabId).className = "tab_content active";
	};
	
	this.inactiveTab = function (tabId) {
		$(tabId).className = "tab_content";
	};
	
	this.inactiveAllTabs = function () {
		for (var i = 0; i < this.tabs.length; i++) {
			this.inactiveTab(this.tabs[i]);
		}
	};
	
	this.switchToTab = function (tabId) {
		this.inactiveAllTiles();
		this.inactiveAllTabs();
		this.activeTile(tabId);
		this.activeTab(tabId);
	};
}

/**
 *  Switch tabs in Product detail page 
 */
function switchProductDetailTab(nowTabId) {
	var productDetailTab = new ProductDetailTab();
	productDetailTab.switchToTab(nowTabId);
	return false;
}
/**
 *  control searchInput and signInput  in pageContainer
 */
	function inputGetFocus(inputId,inputText){
		
		var input=document.getElementsByName(inputId);
		for(var i=0;i<input.length;i++){
			if(input[i].value==inputText){
				input[i].value="";
			  }
		}
	
	}
	function inputLoseFocus(inputId,inputText){
		var input=document.getElementsByName(inputId);
		for(var i=0;i<input.length;i++){
			if(trim(input[i].value)==""){
				input[i].value=inputText;
			}
		}
	}
	
	function trim(str)
	{
		return str.replace(/^\s*/,"").replace(/\s*$/,"");;	
	}

	function highlightSelectedPersonalNav(selectedNodeId){
		var selectedNode = document.getElementById(selectedNodeId);
	    selectedNode.className=selectedNode.className + ' active';
	    //alert(document.getElementById(selectedNodeId).className)
	}

/**
 * handle alternate view clicking
 */
 
 function clickAlternateView(strImage, strName)
 {
 	var targetImage = document.getElementById(strName);
 	targetImage.src = changeImageSize(strImage,'318','318');
 }
 
 function changeImageSize(imageURL, width, height) {
     newImageURL = imageURL.substring(0,imageURL.indexOf('$'))
     newImageURL = newImageURL+'$product'+width+'x'+height+'$';
     return newImageURL;
 }
 
 function changeImageSizeAndSwitch(imageURL,imageId,width,height) {
 	document.getElementById(imageId).src = changeImageSize(imageURL,width,height);
 }
 
 function getZoomProdImgURL(productId) {
	var productURL = '/browse/gadgets/pd_popup_zoom.jsp?productId='+ productId + '&zoomImageURL='+changeImageSize(document.getElementById('mainProduct').src,'424','424');
	return productURL;
 }
 
 /**
  * Handle shipping address new field click
  */
  
function handleAddressClick()
{	
	// using new address 
	
	var objRadio = dojo.byId(strNewAddress);
	if (objRadio)
	{
		objRadio.checked = true;
	}
}

function handleBillingRadioClick()
{
	// using saved billing address
	var objRadio = dojo.byId(strSavedAddress);
	if (objRadio)
	{
		objRadio.checked = true;
	}
}

