
$(function() { 
	// add the linkname to all links.. fairly slow here - use original sdkLinkNamesToAnchors script..
	// $("a").each(function() { this.search="?"+this.search+linknamesiteparm; }) 

	// allow left side links to persist their section..
	$("div.p7ABcontent > ul > li > a").bind('click',function(event) { 
		var sectionDivID = this.parentNode.parentNode.parentNode.id;
		document.cookie="section="+sectionDivID.substr(sectionDivID.lastIndexOf('_')+1)+"; path=/";
	});

	// allow left side section links to persist themselves..
	$("div#p7ABW1 > div > h3 a").bind('click',function(event) { 
		var sectionDivID = this.id;
		// for 'section' links with no sub-links, close any open section..
		if (sectionDivID=='') { document.cookie="section=0; path=/"; }
		// need to find out if we just opened or closed this section - look at the related div's display attribute..
		var relatedDivID = sectionDivID.replace(/t/,'c');
		if (document.getElementById(relatedDivID).style.display=="block") { document.cookie="section=0; path=/"; }
		else { document.cookie="section="+sectionDivID.substr(sectionDivID.lastIndexOf('_')+1)+"; path=/" ; }
	});

	// allow the sidecart section to persist itself..
	$("a#p7ABt2_1").bind('click',function(event) { 
		// find out if we just opened or closed this sidecart.. IE gives "block" either way..
		if (document.getElementById('p7ABc2_1').style.display=="block") { document.cookie="cart=0; path=/"; }
		else { document.cookie="cart=1; path=/"; }
	});

	if (typeof(P7_opAB) != "undefined") { 
		P7_opAB(2,1,0,parseInt(readCookie("cart")),0,0);	// open or close the cart section as appropriate..
		P7_opAB(1,1,0,parseInt(readCookie("section")),0,0);   // open the last selected section, if any..
		// note that the above are also being called inline, due to IE issues..
	}
});


// sdkButtonize - apply an onclick event handler to all matching elements, which will find their containing form and submit it..
(function($) {
	$.fn.sdkButtonize = function () {
		return this.bind('click',function(event) { 
			var e = this;
			while(true) {	// loop up the elements until we find a form or hit the body element..
				if (e.tagName == 'FORM') { return e.submit(); }
				if (e.tagName == 'BODY') { return false; }
				e = e.parentNode;
			}
		}).css("cursor","pointer");	// also make the cursor display as a pointer when hovering over element..
	}
})(jQuery);



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;
}


/////////////////////////////////// C H A N G E   T A B ////////////////////////////////////////////////////////

currentTab="1";

function openTab(tabNo)
{
	//change tab where we were, then change tab we're now on.
	if (currentTab!="")
	{
		bgTab=document.getElementById("tab"+currentTab).style;
		bgTab.backgroundImage="url(images/tab.gif)";
		document.getElementById("descTab"+currentTab).style.display="none";
	}
	else
	{
		bgTab=document.getElementById("tab1").style;
		bgTab.backgroundImage="url(images/tab.gif)";
		document.getElementById("descTab1").style.display="none";
	}
	document.getElementById("tab"+tabNo).style.backgroundImage="url(images/tab_o.gif)";
	document.getElementById("descTab"+tabNo).style.display="block";
	
	//Tab we're on
	currentTab=tabNo	
}


/////////////////////////////////// C H A N G E   F L A G ////////////////////////////////////////////////////////

function showFlag()	// for BC use
{
	if (document.getElementById("forNextFlag").style.display=="block") 	{ document.getElementById("forNextFlag").style.display="none" }
	else { 	document.getElementById("forNextFlag").style.display="block"; }
}

function showFlagNum(flagNumber)	// for Pub use
{
	if (document.getElementById("forNextFlag"+flagNumber).style.display=="block") 
		{ document.getElementById("forNextFlag"+flagNumber).style.display="none" }
	else 
		{ document.getElementById("forNextFlag"+flagNumber).style.display="block"; }
}

function pickedSameCtry(cOriginalCtry)	// check to see if a new country has been picked, not just a new language..
{
	return $("#marketChoose option:selected").val().indexOf(cOriginalCtry) > 0
}