/****************************************************************************
Functions for Shopping Cart Panel in navigation
****************************************************************************/
function cartOn() {
	if (okay) {
		rollOn('cart');
		rollOn('cartTab');
		rollOn('viewcart');
		document.getElementById('cart').className = 'cartOn';
		document.getElementById('cart2').className = 'cartOn';
		document.getElementById('cart3').className = 'cart3On';
	}
}

function cartOff() {
	if (okay) {
		rollOff('cart');
		rollOff('cartTab');
		rollOff('viewcart');
		document.getElementById('cart').className = 'cartOff';
		document.getElementById('cart2').className = 'cartOff';
		document.getElementById('cart3').className = 'cart3Off';
	}
}

function glossary(id){
	var url = "/glossary/popups/glossary_popup.jsp?glossaryId=" + id;
	var popupwin = window.open(url, '', 'width=300, height=200, toolbar=no, scrollbars=auto');	
	return false;
}

function updateCart(s) {
	document.getElementById('cartDetails').innerHTML = s;
}

//Property of RB do not modify this precious code
function ArticleAddToCart(productId){
	if(productId != null){
		//Variables for form submission
		var articleFormName = "articleAddToCart";
		var productToAddTextBox = "ProductToAdd";
		var skuToAddTextBox = "SkuToAdd";
		
		//Obtain all da forms as well as inputFields
		formToSubmit = document.getElementById(articleFormName);
		textBoxProduct = document.getElementById(productToAddTextBox);
		textBoxSku = document.getElementById(skuToAddTextBox);
		
		//Assign Proper Values to da boxes
		textBoxProduct.value = productId;
		textBoxSku.value = productId;
		
		//Display the appropriate pop up
		showPopup('popupCheckAvailability');
		formToSubmit.submit(); //Submit the form
	}
	return false;

}

/****************************************************************************
Functions for Scrolling Product Lists
Require 3 global variables set on page:
	iStart - usually 1 to show 1st product at top
	iViewSize - number of products to show at once - usually 4
	iTotal - total number of products in scroller
	iCurrent - currently displayed product
****************************************************************************/
function initScroller() {
	if (iTotal > iViewSize) {
		document.getElementById('scrollerUp').style.display = 'block';
		document.getElementById('scrollerUp').style.visibility = 'hidden';
		document.getElementById('scrollerDown').style.display = 'block';
	}
	if (iTotal > 0) {
		document.getElementById('scrollerHeading').innerHTML = sHeading + iCurrent + ' of ' + iTotal;
		refreshScroller();
	}
}

function refreshScroller() {
	for (var i=1; i<=iTotal; i++) {
		document.getElementById('scrollerProduct' + i).style.display = (i >= iStart && i < iStart+iViewSize)? 'block' : 'none';
		document.getElementById('scrollerUp').style.visibility = (iStart > 1)? "visible" : "hidden";
		document.getElementById('scrollerDown').style.visibility = (iStart+iViewSize <= iTotal)? "visible" : "hidden";
	}
}

function scrollerUp() {
	if (iStart > 1) iStart--;
	refreshScroller();
	return false;
}

function scrollerDown() {
	if (iStart+iViewSize <= iTotal) iStart++;
	refreshScroller();
	return false;
}

function scrollerOn(o) {
	o.className = 'scrollerOn';
}

function scrollerOff(o) {
	o.className = 'scrollerOff';
}

function bundleOn(o) {
	o.className = o.className.replace(/Off/, 'On');
}

function bundleOff(o) {
	o.className = o.className.replace(/On/, 'Off');
}

function gotoURL(sURL) {
	self.location = sURL;
}


/****************************************************************************
Product page tabs
****************************************************************************/
function showTab(sTabId) {
	//reset all tabs
	for (var i=1; i<=iTotalTabs; i++) {
		if (document.getElementById('tab' + i) != null) {
			document.getElementById('tab' + i).style.display = 'none';
		}
		/*if (document.getElementById('td' + 'tab' + i) != null) {
			document.getElementById('td' + 'tab' + i).className = 'tabLo';
		}*/
	}
	//show & highlight current tab
	document.getElementById(sTabId).style.display = 'block';
	//document.getElementById('td' + sTabId).className = 'tabHi';
	return false;
}

/****************************************************************************
checkout DHTML popups
****************************************************************************/
//array containing ids of all dhtml popups
var aPopups = new Array('popupPromotionNotAvailable','popupCheckAvailability',
						'popupAddToCart','popupProductNotAvailable',
						'popupProductNotAvailableThankyou','popupTakeupOffer', 
						'popupBackorder');

function showPopup(sId) {

	hideAllPopups();

	document.getElementById('popupsContainer').style.visibility = 'visible';
	document.getElementById(sId).style.display = 'block';

	//Scroll has been deprecated so use this complicated try..catch structure
	//for maximum chance of success
	try{
		window.scrollTo(0,0);
	}
	catch(e){
  	try{
  		window.scroll(0,0);
  	}
  	catch(e){
  	}
	}
}

function hideAllPopups() {
	document.getElementById('popupsContainer').style.visibility = 'hidden';
	for (var p in aPopups) {
		document.getElementById(aPopups[p]).style.display = 'none';

	}

}


/****************************************************************************
Centered popups
http://developer.irt.org/script/1316.htm
****************************************************************************/
function showCenteredWindowPopup(url,popupWidth,popupHeight,scrollbars) {
	var w = 800, h = 680;

	if (document.all) {
	   /* the following is only available after onLoad */
	   w = document.body.clientWidth;
	   h = document.body.clientHeight;
	}
	else if (document.layers) {
	   w = window.innerWidth;
	   h = window.innerHeight;
	}

	var leftPos = (w-popupWidth)/2, topPos = (h-popupHeight)/2;

	openWindow(url,'width='+popupWidth+',height='+popupHeight+',top='+topPos+',left='+leftPos+',scrollbars='+scrollbars);
}

function showCenteredScreenPopup(url,popupWidth,popupHeight,scrollbars) {
	var w = 800, h = 680;

	if (document.all || document.layers) {
	   w = screen.availWidth;
	   h = screen.availHeight;
	}

	var leftPos = (w-popupWidth)/2, topPos = (h-popupHeight)/2;

	openWindow(url,'width='+popupWidth+',height='+popupHeight+',top='+topPos+',left='+leftPos+',scrollbars='+scrollbars);
}

/****************************************************************************
Functions for actions to be perform on page load:
* Initialising image rollovers
* Initialising menus
****************************************************************************/
//True iff the navigation is being shown on this page.
var mShowNavigation = false;
//True iff server errors are not being shown by Javascript alert boxes on this page.
var mHideJavascriptErrorAlerts = false;
//The location of the current page in the left hand side navigation trees
var currentLeftNav = "";
//The location of the current page in the top side navigation trees
var currentTopNav = "";

function showNavigation() {
	mShowNavigation = true;
}

function hideJavascriptErrorAlerts() {
	mHideJavascriptErrorAlerts = true;
}

function setCurrentLeftNav(elemListAsString) {
	currentLeftNav = elemListAsString;
}

function setCurrentTopNav(elemName) {
	currentTopNav = elemName;
}

function pageLoad(loadNav) {
	initRollovers('/sonystyle/images/');
	if (mShowNavigation == true) {
    try {
    	if (currentTopNav != "") {
    		switchOn(currentTopNav);
    	}
  		eval("initNav(" + currentLeftNav + ")");
    }
    catch(e) {
    	initNav();
    }
  }
  try {
  	if (!(mHideJavascriptErrorAlerts == true)) {
	  	alertErrors();
	  }
  }
  catch(e) {}
}

/****************************************************************************
open new browser window
****************************************************************************/
//sURL = url to open in window
//iWidth and iHeight are optional width and height of window
function openWindow(sURL, sFeatures) {
	var popupwin = window.open(sURL, 'popupwindow', sFeatures);
	return false;
}

/****************************************************************************
window dimension functions: width, height, top
****************************************************************************/
function getwindowwidth(win){
	if (typeof(win)=='object'){
		if (typeof(win.innerWidth)!='undefined'){//NN4,Mozilla/NN6
			return win.innerWidth;
		}
		else if (typeof(win.document.body.clientWidth)!='undefined'){//IE4,IE5
			return win.document.body.clientWidth;
		}
		else{
			return 0;
		}
	}
	else{
		if (typeof(window.innerWidth)!='undefined'){//NN4,Mozilla/NN6
			return window.innerWidth;
		}
		else if (typeof(window.document.body.clientWidth)!='undefined'){//IE4,IE5
			return window.document.body.clientWidth;
		}
		else{
			return 0;
		}
	}
}

function getwindowheight(win){
	
	if (typeof(win)=='object'){
		//alert(win.document);
		if (typeof(win.innerHeight)!='undefined'){
			return win.innerHeight;
		}
		else if (typeof(win.document.body.clientHeight)!='undefined'){
			return win.document.body.clientHeight
		}
		else {
			return 0;
		}
	}
	else{
		if (typeof(window.innerHeight)!='undefined'){
			return window.innerHeight;
		}
		else if (typeof(window.document.body.clientHeight)!='undefined'){
			return window.document.body.clientHeight
		}
		else {
			return 0;
		}
	}
}

function getwindowtop(){
 	if (typeof(window.pageYOffset)!='undefined'){//NN4
		return window.pageYOffset;
	}
	else if (typeof(document.body.scrollTop)!='undefined'){//IE4,IE5
		return document.body.scrollTop
	}
	else if (typeof(window.scrollY)!='undefined'){//Mozilla/NN6
		return window.scrollY;
	}
	return 0;
}

