/* 
-----------------------------------------------------------------
	URS MyHome Tool // shared.js
	
	version 2 - DS's tried and trusted
-----------------------------------------------------------------
*/

//	Load additional functions

	var imported_scripts = '';	
	var scripts = new Array();	
	scripts[0] = ('/resources/scripts/imported/browserdetect.js');	
	scripts[1] = ('/resources/scripts/imported/homesmarts.js');		

	for (var i=0; i<scripts.length; i++)
	{
		imported_scripts += ('\n<script type="text/javascript" src="' + scripts[i] + '"></script>' + '\n');
	}
	
	document.write(imported_scripts);	

	window.onload = init;
	window.onresize = function() { if (whichbrowser.isHiFi) { widenInterface();} };
	

// DOM shorthand wrappers - these are MR's but are probably ok
	
	/**
	* getElementById
	* @return DomElement
	*/
	function $id(id) {
		return document.getElementById(id);
	}
	
	/**
	* getElementsByClassName
	* @return DomElement if single result, else array of DomElements
	*/
	function $class(name) {
		result = new Array();
		eAll = document.getElementsByTagName("*");
		for (var i=0; i<eAll.length; i++) {
			if (eAll[i].className.match(name)) {
				result.push(eAll[i]);
			}
		}
		return (result.length > 1) ? result : result[0];
	}
	
	/**
	* getElementsByTagName
	* @return DomElement if single result, else collection of DomElements
	*/
	function $tag(name) {
		result = document.getElementsByTagName(name);
		return (result.length > 1) ? result : result[0]; 
	}
	
// trigger conditional functions
	
	function init()
	{	
	// this method of launching functions works in IE5, but $class() appears to fail, so we'll suppress all functions in IE5 (and other browsers that don't make the grade)
		if (whichbrowser.isHiFi)
		{	
			t = $class('shell').getAttribute('id');	
			st = $class('main').getAttribute('id');	
	
			gBodyClass = $tag('body').className;
			
			$tag('body').className = gBodyClass.replace(/lofi/, 'hifi'); // show js-only styling		
			
			widenInterface();
			
			// doLinkTesting(); // *** remove prior to golive ***
			
			enhanceImgLinks();
			
			if (t == 't-home') 
			{
				enhancePromos();
			}
			if ((t == 't-smarthometour') && (st == 'st-home'))
			{
				enhancePromos();
				createPrintButton();			
			}		
			
			if (t == 't-getadvice')
			{
				renumberSectionNav();	
				
				//	Insert 'Choose Room' link
				// 	Degradabilty -  in the absence of JS the form will submit ('Next >') to Choose Room page anyway, so this just adds a visual cue
				// 	However on subsequent pages this step will be missing, unless the backend tracks the project type and can intelligently insert hardcode it in to the template itself			
				if (st == 'st-step1')
				{				
					enhanceRadios('Choose Your Project', 'Choose Room', 2); // 	enhanceRadios(vfieldsetLegendImgAlt, vStepText, indexOfInserterRadio)
				}
				
				if ($id('suggestions'))
				{
					enhanceSuggestions();	
					insertInteractionHelpText();
					createPrintButton();
				}
			}		
			if ((t == 't-homehealthcheck') && (st != 'st-home'))
			{
				renumberSectionNav();	
			}
			if ((t == 't-homehealthcheck') && (st == 'st-home'))
			{
				createPrintButton();	
				
			}	
			/*added by Trevor George 09 2008*/
			
			
			
			
			if((t == 't-renovations') ){
				
				if(st != 'st-home'){
				renumberSectionNav();	
				}
				
				if ($id('suggestions'))
				{
					enhanceSuggestions();	
					insertInteractionHelpText();
					createPrintButton();
				}
				
				if(document.getElementById('re012_1') != null){
		
					checkbox1 = document.getElementById('re012_1');
					checkbox1.onclick = function(){
							
													if(checkbox1.checked == true){
														
														showExtraOptions('re012_1_extra');
													}else{	
																										
														hideExtraOptions('re012_1_extra');
													}
												}
				}
				if(document.getElementById('re012_2') != null){
				
					checkbox2 = document.getElementById('re012_2');
					checkbox2.onclick = function(){
							
													if(checkbox2.checked == true){
														
														showExtraOptions('re012_2_extra');
													}else{	
																										
														hideExtraOptions('re012_2_extra');
													}
												}
				}
				if(document.getElementById('re011_7') != null){
					
					checkbox3 = document.getElementById('re011_7');
					checkbox3.onclick = function(){
						
													if(checkbox3.checked == true){
														showExtraOptions('re011_7_extra');
													}else{														
														hideExtraOptions('re011_7_extra');
													}
												}
				}
			}
		}
	}	