// Initialize variables
// Product Details: Image path to support where PNG files are located
//var imagePath = "img/products/";
var imagePath = "/wcsstore/SonyStyleStorefrontAssetStore/img/718x407/";
// My Account:  javascript counter.
var newNum = 0;
// My Account: Number of images available for users to scroll.
var my_account_max_images = 4;
// My Account: Array Declaration
var previous_images = new Array();
// Variable to store "show more" or "show less" type copy.
var showCopy = '';

// Navigation flags to control when to Hide/Show HTML SELECT dropdowns in IE6's browser bug.
var selectBoxFlag = 0;

// variable to access CTO steps
var pageAccessFlag = 1;

// Controls highlighting the various series types on rollover
function seriesControl(whatToHide){
	if ((whatToHide == 'reset')&&(previous_images != '')) {
		var whatToHideArray = previous_images.split(" ");
		action = '';
	}
	else {
		var whatToHideArray = whatToHide.split(" ");
		action = 'block';
	}
	for (i=0; i<whatToHideArray.length; i++) {
		$(whatToHideArray[i]).style.display = action;
	}
	previous_images = whatToHide;
}

// clear field value function: removes the default value onfocus, and adds back if nothing entered 
function fieldClear(obj) {
	if(obj.Val) {
		if (obj.value == '') { 
			obj.value = obj.Val;
			obj.Val = null;
			obj.first = null;
		} 
		else {
			obj.Val = null;
		}
	} else if (!obj.first) { 
		obj.Val = obj.value;
		obj.value = ''; 
		obj.first = 'true';
	} 
}

/* popup functions: show/hide popup layer */
function popOpen(id, topAdjustment) {
	if ($(id)){
	  	setSize();
		var overShade = document.getElementById(id);
		// position popup 170px from top of browser
		var topPad =  pos+70;
		if (topAdjustment) topPad = topAdjustment;
		// height-padding = div height
		overShade.style.height = ph-topPad + 'px';
		overShade.style.paddingTop = topPad + 'px';
		overShade.style.display = 'block';	

		if (browser.isIE6x) {
			coverSelects(overShade);
		}
	}
}
function popClose(id) {
	var popShade = document.getElementById(id);
	popShade.style.display = "";
	if (browser.isIE6x) {
		document.getElementById("popup-cover").outerHTML = "";
	}
	if (selectBoxFlag) {
		hideSelectBoxes('visible');
		selectBoxFlag = 0;
	}
}
/* covers select form elements for IE only so they do not show through the popup */
function coverSelects(par) {
	for (var x = 0; x < par.childNodes.length; x++) {
		// look for popup container
		if (par.childNodes[x].className == "popup-container" || par.childNodes[x].id == "popup-container") {
			var popEl = par.childNodes[x];
			var parTop = par.style.paddingTop; 
			var covTop = parTop.replace("px","")-3+"px"; // get top and account for the negative margin
			var covHeight = popEl.offsetHeight+3+"px"; // add the negative margin to the height			
			var coverFrame = "<IFRAME id='popup-cover' style='";
			coverFrame = coverFrame + "top: "+covTop+"; height:"+covHeight+";' ";
			coverFrame = coverFrame + "src='javascript:false;' frameBorder='0' scrolling='no'></IFRAME>";
			par.insertAdjacentHTML("afterEnd",coverFrame); // create new iframe that is the size of the popup window
		}		
	}			
}
function setSize() { /* sets size of shade */
	if (window.pageYOffset != null) { /* moz and safari */
		pos = window.pageYOffset;
		ph = document.documentElement.scrollHeight;
		pw = document.documentElement.scrollWidth;
		if (document.body.scrollHeight > document.documentElement.scrollHeight) {
			ph = document.body.scrollHeight;
			pw = document.body.scrollWidth;
		}
	} else if (document.documentElement.scrollTop > document.body.scrollTop) { /* ie, catch if Standards compliance mode */
		pos = document.documentElement.scrollTop;
		ph = document.documentElement.scrollHeight;
		pw = document.documentElement.scrollWidth;
		if (document.documentElement.clientHeight > document.documentElement.scrollHeight) {
			ph = document.documentElement.clientHeight;					
		}
	} else if (document.body != null) {
		pos = document.body.scrollTop;
		ph = document.body.scrollHeight;
		pw = document.body.scrollWidth;
		if (document.documentElement.scrollHeight > document.body.scrollHeight) {
			ph = document.documentElement.scrollHeight;
		}			
	}
}	

// Top navigation menu control
topNav = function() {
	if ((document.all)&&(document.getElementById)&&(cssdropdownRoot = $('nav_list'))) {
		cssdropdownRoot = $('nav_list').getElementsByTagName('li');
		nodes = $A(cssdropdownRoot);
		for (x=0; x<nodes.length; x++) { // length = 7
			node = nodes[x];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					// mimics the :hover functionality
					this.className+=" over";
					selectBoxFlag++;
					hideSelectBoxes('hidden');
				}
				node.onmouseout=function() {
					// mimics the :hover functionality
					this.className=this.className.replace(" over", "");
					selectBoxFlag--;
					if (!selectBoxFlag) hideSelectBoxes('visible');
				}
			}
		}
	}
}
// Controls the utility bar's primary open/close functionality
utilityNav = function () {
	if (cssdropdownRoot = $('my_links')) {
		cssdropdownRoot = $('my_links').getElementsByTagName('li');
		liNodes = $A(cssdropdownRoot);
		for (x=0; x<liNodes.length; x++) {
			if (liNodes[x].className == '') {
				divNodes = liNodes[x].getElementsByTagName('div');
					for (y=0; y<divNodes.length; y++) {
						if (divNodes[y].className == "close") {
							aNode = divNodes[y].getElementsByTagName('a');
							aNode[0].onclick = function() {
								this.href="javascript:void(0)";
								utility(this);
							}
						}
					}
				aNode = liNodes[x].getElementsByTagName('a');
				//alert(divNode[divNode.length-1].className);
				aNode[0].onclick = function() {
				this.href="javascript:void(0)";
				utility(this);
				}
			}
		}
	}
}
// Displays alert message and hides it after some time.
alertMsg = function (idToDisplay) {
	idToShow = $(idToDisplay);
	idToShow.style.display = 'block';
	setTimeout("idToShow.style.display=''",2000);
}
// Closes any opened utility bar when the user opens a second menu without closing the first
utilityReset = function (liNodes) {
	for (i=0; i<liNodes.length; i++) {
		if (liNodes[i].className == 'on') {
			liNodes[i].className = '';
		}
	}
}
// Functionality to open utility menus
utility = function (o) {
	if(o.parentNode.nodeName == "LI") {path=o.parentNode; temp=1;}
	else if(o.parentNode.parentNode.nodeName == "LI") {path=o.parentNode.parentNode; temp=2;}
	else if(o.parentNode.parentNode.parentNode.nodeName == "LI") {path=o.parentNode.parentNode.parentNode; temp=3;}
	else if(o.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {path=o.parentNode.parentNode.parentNode.parentNode; temp=4;}
	else {path=o.parentNode.parentNode.parentNode.parentNode.parentNode; temp=5;}
	if (path.className == '') {
		utilityReset(liNodes);
		o.parentNode.parentNode.className = 'on';
		selectBoxFlag++;
		hideSelectBoxes('hidden');  
	}
	else {
		path.className = '';
		selectBoxFlag--;
		if (!selectBoxFlag) hideSelectBoxes('visible');
	}
}
// This function hides select boxes in IE that fall underneith a layer.
hideSelectBoxes = function(action) {
	if ((action == 'visible') && (selectBoxFlag)) return;
	else if ((browser.isIE6x) && ($('content') && (selectRoot = $('content').getElementsByTagName('select')))) {
		for (i=0; i<selectRoot.length; i++ ) {
			if (selectRoot[i].className.match(/elementToHideOnMenuOpen/)) {
				selectRoot[i].style.visibility = action;
			}
		}
	}
}

// adjustment class for specific browser issues
adjust = function() {
	// removes advisor go button float for safari
	if ((navigator.appVersion.indexOf("Safari")!=-1)&&(currentRoot = $('go_advisor'))) {
		currentRoot.className = currentRoot.className + " safari";
	}
}
// provides rollover functionality.  Uses classnames to determin file name.
rollover = function() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('roll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/roll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/roll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}


// runs the Image Selector on the My Account pages
my_account_image_select = function() { 
	if (heroRoot = heroRoot = $('hero')) {
		currentNum = (heroRoot.className.split('_')[1]);
		var currentRoot = heroRoot.getElementsByTagName('li'); 
		for (i=0;i<currentRoot.length;i++) {
			if (currentRoot[i].className.indexOf('previousimage')!=-1) {
				currentRoot[i].childNodes[0].onclick = function() {
					if (currentNum == 1) newNum = my_account_max_images
					else newNum = parseInt(currentNum) - 1;
					heroRoot.className = ("background" + "_" + newNum);
					currentNum = newNum;
				}
			}
			else if (currentRoot[i].className.indexOf('nextimage')!=-1) {
				currentRoot[i].childNodes[0].onclick = function() {
					if (currentNum == my_account_max_images) newNum = 1
					else newNum = parseInt(currentNum) + 1;
					heroRoot.className = ("background" + "_" + newNum);
					currentNum = newNum;	
				}
			}
		}
	}
}
checkout = function () {
	if ($('dynamic_radio_button')) {
		radioRoot = $('dynamic_radio_button').getElementsByTagName('input');
		var ulArray = new Array();
		for (i=0; i<radioRoot.length; i++) {
			if (radioRoot[i].type == 'radio') {
				ulArray.push(radioRoot[i].parentNode.getElementsByTagName('ul')[0]);
				radioRoot[i].onclick = function() {
					hideAll(ulArray);
					this.parentNode.getElementsByTagName('ul')[0].style.display = 'block';
				}
			}
		}	
	}
}
paymentMethod = function (info) {
	selectRoot = $('dynamic_select_field').getElementsByTagName('li');
	var liArray = new Array();
	for (i=0; i<selectRoot.length; i++) {
		if(selectRoot[i].className == 'option') {
			liArray.push(selectRoot[i]);	
		}
	}
	hideAll(liArray);
	if($(info.value)) {
		newItem = $(info.value);
		// When 2 CC are applied and a saved card is selected from the payment drop down, we need to set secondCreditCardAvailable = 'NO'
		// When 'Pay with Two Credit Cards' is selected we need to set secondCreditCardAvailable = 'YES'
		sca = $('secondCreditCardAvailable');
		//alert(sca + ' ' + newItem.id);
		if('2cc'==newItem.id) {
			if(sca) {
				sca.value='YES';
				//alert('secondCreditCardAvailable = '+$('secondCreditCardAvailable').value);
			}
		}else{
			if(sca) {
				sca.value='NO';
				//alert('secondCreditCardAvailable = '+$('secondCreditCardAvailable').value);
			}
		}
		newItem.style.display = 'block';
	}
	
}

changeEditability = function (actionId, actionClass) {
	if ($(actionId).getElementsByTagName('ul').length) actionRoot = $(actionId).getElementsByTagName('ul');
	else actionRoot = $(actionId).getElementsByTagName('div');
	
	for (i=0; i<actionRoot.length; i++) {
		if(actionClass == 'editable') {
			if(actionRoot[i].className.match(/editable/)) {
				actionRoot[i].style.display = 'block';
			}
			if(actionRoot[i].className.match(/non-editable/)) {
				actionRoot[i].style.display = 'none';
			}
		}
		if(actionClass == 'non-editable') {
			if(actionRoot[i].className.match(/editable/)) {
				actionRoot[i].style.display = 'none';
			}
			if(actionRoot[i].className.match(/non-editable/)) {
				actionRoot[i].style.display = 'block';
			}
		}
	}
}

// embeds functions to HREFs
eventFinder = function() {
	my_account_image_select();// runs the image selector on My Account pages
	quickRegister(); // adds shade and prevents click within content area under quick register
}

// Determins height of content area and updates the .overshade class with the value 
quickRegister = function() {
	if ($('container') != null) {
		if ($('container').className.match(/quick_register*/)) {
			divHeight = $('content').offsetHeight;
			divHeight = divHeight + 40;
			$('breadcrumb').innerHTML = $('breadcrumb').innerHTML + '<div id="overshade" style="height:' + divHeight + 'px;"></div>';
			if(browser.isIE) {
				hideSelectBoxes('hidden'); // hides select boxes in IE 
				//	actionRoot = $(actionId).getElementsByTagName('ul');
				//if(selectRoot[i].className == 'option') {
				thresholds = $('content').getElementsByTagName('li');
				for (i=0;i<thresholds.length;i++) {
					if (thresholds[i].className.match(/threshold/)) thresholds[i].style.display='none';
				}
				thresholds = $('content').getElementsByTagName('p');
				for (i=0;i<thresholds.length;i++) {
					if (thresholds[i].className.match(/threshold/)) thresholds[i].style.display='none';
				}
			}
		}
	}
}
disableMe = function(state) {
	if (state == 'disable') {
		actions = '';
		$('confirmPassword').disabled = 'disabled';
		$('confirmPassword').value = '';
	}
	else {
		actions = 'off';
		$('confirmPassword').disabled = '';
	}
	$('disabled').className = actions;
}
// embeds functions to HREFs on Product Detail pages
productDetails = function() {
	if ($('container') != null) {
		if ($('container').className.match(/detail*/)) {
			heroRoot = $('heroImage');
			if ((browser.isIE55 || browser.isIE6up) && browser.isWin) var pngAlpha = true; else pngAlpha=false;
			productDetailImages(pngAlpha);
			productDetailDim(pngAlpha);
		}
	}
}
// activates dimensions on Product Detail pages
productDetailDim = function(pngAlpha) {
	if (dimensionOnRoot = $('view_dimensions')) {
		primaryDisplayRoot = $('primary_display');
		dimensionOnRoot.onclick = function () {
			this.href="javascript:void(0)";
			primaryDisplayRoot.className = 'hide';
			if (pngAlpha) heroRoot.style.filter = "";
			setTimeout('heroRoot.style.background = "transparent url(" + imagePath + heroRoot.className + "_dim.jpg) top left";',1);
		}
		dimensionOffRoot = $('hide_dimensions');
		dimensionOffRoot.onclick = function () {
			this.href="javascript:void(0)";
			primaryDisplayRoot.className = '';
			if (pngAlpha) {
				heroRoot.style.background = "none";
				heroRoot.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imagePath + heroRoot.className + ".png', sizingMethod='scale')";
			}
			else heroRoot.style.background = "transparent url(" + imagePath + heroRoot.className + ".png)";
		}
	}
}
// activates thumbnails on Product Detail pages
productDetailImages = function(pngAlpha) {
	if ($('thumb')) {
		cssthumbnailRoot = $('thumb').getElementsByTagName('a');
		for (i=0;i<cssthumbnailRoot.length;i++) {
			cssthumbnailRoot[i].onclick = function() {
				this.href="javascript:void(0)";
				if (pngAlpha) heroRoot.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imagePath + this.name + ".png', sizingMethod='scale')";
				else heroRoot.style.background = "transparent url(" + imagePath + this.name + ".png)";
			}
		}
	}
	// SET DEFAULT PRODUCT IMAGE using the "class" attribute on DIV ID=HEROIMAGE
	if (pngAlpha) heroRoot.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imagePath + heroRoot.className + ".png', sizingMethod='scale')";
	else heroRoot.style.background = "transparent url(" + imagePath + heroRoot.className + ".png)";
	heroRoot.style.listStyleImage = "url(" + imagePath + heroRoot.className + ".png)";
}
// changes right-hand side of LEARN content area based on choices made to left-hand options.
productDetailLearn = function() {
	if ($('choice') && !($('learn').className.match(/static*/))){
		choiceRoot = $('choice').getElementsByTagName('a');
		var currentChoice = 0;
		presentationRoot = $('presentation').getElementsByTagName('div');
		// Turn on the first selection
		presentationRoot[currentChoice].style.display = 'block';
		for (i=0;i<choiceRoot.length;i++) {
			if (choiceRoot[i].className=="choice") {
				choiceRoot[i].onclick = function() {
					hideAll(presentationRoot);
					resetAll(choiceRoot);
					this.className = 'inactive';
					this.href="javascript:void(0)";
					presentationRoot[this.name-1].style.display = 'block';
				}
			}
		// SET DEFAULT STATE for first choice.
		choiceRoot[0].className='inactive';
		}
	}
}
// Product Detail - Learning Center recursive reset of 'choice' links back to default state.
resetAll = function(root) {
	for (x=0;x<root.length;x++) {
		root[x].className = 'choice';
	}
}
// Generic function to parse through an object array and change display to "none".
hideAll = function(root) {
	for (x=0;x<root.length;x++) {
		root[x].style.display = 'none';
	}
}
showWhy = function(idToShow) {
	$(idToShow).style.display = 'block';
	selectBoxFlag++;
	hideSelectBoxes('hidden');
	
}
// Function that runs the Map Selector on the Store Locator pages 
region = function (itemToTurnOn) {
	selectorRoot = $('selector').getElementsByTagName('li');
	for (x=0;x<selectorRoot.length;x++) {
		if (x == itemToTurnOn) selectorRoot[x].className = "on";
		else selectorRoot[x].className = "";
	}
}
// Generic function to open/close divs
more = function (o) {
	if (o.nextSibling.nextSibling.style.display != 'block') {
		o.nextSibling.nextSibling.style.display = 'block';
		o.href="javascript:void(0)";
		o.className = 'arrow_link up';
	}
	else {
		o.nextSibling.nextSibling.style.display = '';
		o.href="javascript:void(0)";
		o.className = 'arrow_link down';
	}
	if (browser.isIE && $('summary')) { // move summary box when height changes in IE 
		$('summary').style.bottom = '0px';
		$('summary').style.bottom = '10px';
		$('summary').style.bottom = '0px';
	}
}
// 	Displays additional options upon selecting "See More Service Plans"
seeMore = function (o,IDtoHide,textToDisplay) {
	if (o.className.match(/open*/)) {
		showCopy = o.innerHTML;
		o.innerHTML = textToDisplay;
		o.className = 'arrow_link close';
		liToHide = $(IDtoHide).getElementsByTagName('li');
		for(i=0;i<liToHide.length;i++) {
			if (liToHide[i].className == 'hidden') liToHide[i].style.display = 'block';
		}
	}
	else {
		o.innerHTML = showCopy;
		o.className = 'arrow_link open';
		liToHide = $(IDtoHide).getElementsByTagName('li');
		for(i=0;i<liToHide.length;i++) {
			if (liToHide[i].className == 'hidden') liToHide[i].style.display = '';
		}
	}
	if (browser.isIE && $('summary')) { // move summary box when height changes in IE 
		$('summary').style.bottom = '0px';
		$('summary').style.bottom = '10px';
		$('summary').style.bottom = '0px';
	}
}
seeMoreModule = function (o,IDtoHide,textToDisplay) {
	if (o.className.match(/open*/)) {
		showCopy = o.innerHTML;
		o.innerHTML = textToDisplay;
		o.className = 'arrow_link close';
		trToHide = $(IDtoHide).getElementsByTagName('tr');
		for(i=0;i<trToHide.length;i++) {
			if (trToHide[i].className == 'hidden') {
				if(browser.isIE) trToHide[i].style.display = 'inline-block';
				else trToHide[i].style.display = 'table-row';
			}
		}
	}
	else {
		o.innerHTML = showCopy;
		o.className = 'arrow_link open';
		trToHide = $(IDtoHide).getElementsByTagName('tr');
		for(i=0;i<trToHide.length;i++) {
			if (trToHide[i].className == 'hidden') trToHide[i].style.display = '';
		}
	}
}


// Controls the merged version of CTO. Gives the appearance of a step by step process.
ctoNextStep = function(action) {
	window.scrollTo(0,0);
	divRoot = $('content').getElementsByTagName('div');
	//to hide primary display section and recommend setion in Personalize and Accessorize pages
	var heroSection = document.getElementById('primary_display');
	var recomSection = document.getElementById('recommend');
	//to show/hide Special messaging section in CTO pages	
	var cusPageTop = document.getElementById('special_messaging_custop');	
	var cusPageBot = document.getElementById('special_messaging_cusbot');		
	var perPageTop = document.getElementById('special_messaging_pertop');	
	var perPageBot = document.getElementById('special_messaging_perbot');		
	var accPageTop = document.getElementById('special_messaging_acctop');	
	var accPageBot = document.getElementById('special_messaging_accbot');		

	
	for (i=0; i<divRoot.length; i++) {
		if (action == "step1") {
			if (divRoot[i].className.match(/step1/)) {
				divRoot[i].style.display = 'block';
				// if user in customize page, enable the customize special_messaging section and set pageAccessFlag = 1;
				if (cusPageTop) cusPageTop.style.display = 'block';								
				if (cusPageBot) cusPageBot.style.display = 'block';				
				pageAccessFlag = 1;
			}
			if (divRoot[i].className.match(/step2/) || divRoot[i].className.match(/step3/)) {
				divRoot[i].style.display = 'none';
			}
			//primary display section and recommend setion will be visible in Customize page			
			if (heroSection) heroSection.style.display = 'block';				
			if (recomSection) recomSection.style.display = 'block';
			// if we are in Customize page, hide other pages special messaging section			
			if (perPageTop) perPageTop.style.display = 'none';				
			if (perPageBot) perPageBot.style.display = 'none';
			if (accPageTop) accPageTop.style.display = 'none';				
			if (accPageBot) accPageBot.style.display = 'none';
		}
		if (action == "step2") {
			if (divRoot[i].className.match(/step2/)) {
				divRoot[i].style.display = 'block';
				// if user in personalize page, enable the personalize special_messaging section and set pageAccessFlag = 2;
				if (perPageTop) perPageTop.style.display = 'block';	
				if (perPageBot) perPageBot.style.display = 'block';								
				pageAccessFlag = 2;
			}
			if (divRoot[i].className.match(/step1/) || divRoot[i].className.match(/step3/)) {
				divRoot[i].style.display = 'none';
			}
			//primary display section and recommend setion will be hidden in Personalize  page
			if (heroSection) heroSection.style.display = 'none';				
			if (recomSection) recomSection.style.display = 'none';	
			// if we are in Personalize page, hide other pages special messaging section				
			if (cusPageTop) cusPageTop.style.display = 'none';				
			if (cusPageBot) cusPageBot.style.display = 'none';
			if (accPageTop) accPageTop.style.display = 'none';				
			if (accPageBot) accPageBot.style.display = 'none';
		}
		if (action == "step3") {
			if (divRoot[i].className.match(/step3/)) {
				divRoot[i].style.display = 'block';
				// if user in accessorize page, enable the accessorize special_messaging section and set pageAccessFlag = 3;				
				if (accPageTop) accPageTop.style.display = 'block';
				if (accPageBot) accPageBot.style.display = 'block';									
				pageAccessFlag = 3;	
			}
			if (divRoot[i].className.match(/step1/) || divRoot[i].className.match(/step2/)) {
				divRoot[i].style.display = 'none';
			}
			//primary display section and recommend setion will be hidden in Accessorize page			
			if (heroSection) heroSection.style.display = 'none';				
			if (recomSection) recomSection.style.display = 'none';
			// if we are in Accessorize page, hide other pages special messaging section					
			if (cusPageTop) cusPageTop.style.display = 'none';				
			if (cusPageBot) cusPageBot.style.display = 'none';
			if (perPageTop) perPageTop.style.display = 'none';				
			if (perPageBot) perPageBot.style.display = 'none';
		}
	}
	checkCTO();
	checkCTOStatus();
	if(browser.isIE) { // move summary box when height changes in IE
		if( $('summary') ) {
			$('summary').style.bottom = '0px';
			$('summary').style.bottom = '10px';
			$('summary').style.bottom = '0px';
		}
	}
}
isQuickRegister = function() {
	if(browser.isIE) {
		if ($('quick_register')) {
			selectRoot = $('content').getElementsByTagName('select');
			for(i=0;i<selectRoot.length;i++) {
				selectRoot[i].style.visibility = 'hidden';
			}
		}
	}
}
checkCTO = function() {
	if ($('container') != null) {
		if ($('container').className.match(/cto/)) {
			if ((Element.getHeight('allitems') + Element.getHeight('summary')) > Element.getHeight('main')) {
				$('modules').style.height = (Element.getHeight('summary')+Element.getHeight('allitems')-1) + 'px';
			}
		}
	}
}


getUrlValus = function(name)
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}
// validates the user is on the checkout landing page and sniffs the URL for "showLoginForm" boolean value.
showLogonForm = function() {
	if($('returning_user')) {
		var showLoginForm = getUrlValus('showLogonForm');
		if (showLoginForm) toggleReturningUser(true);
	}
}
toggleState = true; // preset the variable
areaHeight = 0; // store height value
toggleReturningUser = function(defaultLogin) {
	if(!areaHeight) areaHeight = Element.getHeight('new_user_fields');
	$('disabled').style.height = areaHeight + 'px';
	var disabled_top = document.getElementById('disabled_top');
	if (defaultLogin) {
		toggleState = true;
		$('returning').checked = true;
	}
	if (toggleState) {
		if ($('new_user')) $('new_user').style.display = 'none';
  		if ($('returning_user')) $('returning_user').style.display = 'block';
  		if ($('disabled')) $('disabled').className = '';
  		if ($('disabled_top')) $('disabled_top').style.display = 'block';
  		if ($('disabled_bottom')) $('disabled_bottom').style.display = 'block';
		/**defect 63 **/
		if ($("disabled_affilProgram") != null) {
			$('disabled_affilProgram').style.display = 'block';
			$('disabled_affilProgram').style.height = $('qrEduEppAffilApoSection').getHeight()+'px';
		}

		selectBoxFlag++;
		hideSelectBoxes('hidden');
		toggleState = false;
	}
	else {
		if ($('new_user')) $('new_user').style.display = 'block';
  		if ($('returning_user')) $('returning_user').style.display = 'none';
  		if ($('disabled')) $('disabled').className = 'off'; 
		/**defect 63 **/
		if ($("disabled_affilProgram") != null) {
			$('disabled_affilProgram').style.display = 'none';
		}
  		
  		if ($('disabled_top')) $('disabled_top').style.display = 'none';
  		if ($('disabled_bottom')) $('disabled_bottom').style.display = 'none';
		selectBoxFlag--;
		if (!selectBoxFlag) hideSelectBoxes('visible');
		toggleState = true;
	}
}
// These functions are activated upon page load. They embed JavaScript without function calls from appearing within the HTML.
init = function() {
	utilityNav(); // activate utility navigational links
	topNav(); // activate top navigation
	rollover(); // general function for embedded image rollovers
	eventFinder(); // embeds functions to HREFs 
	adjust(); // general function for javascript to control browser compatibility issues
	productDetails(); // function to call Product Detail related functions
	productDetailLearn(); // function to check for Learning section
	checkCTO(); // prevents overlap of summary module on CTO pages when there is not enough content
	isQuickRegister(); // hides select boxes for the entire page for IE6 browsers only.
	showLogonForm(); // validates the page is checkout landing and loads the appropriate state.
}


// Standard Global Fully Browser-compat onload function init call.
if (window.addEventListener)
window.addEventListener("load", init, false)
else if (window.attachEvent)
window.attachEvent("onload", init)
else if (document.getElementById)
window.onload=init;

