/*
Scripts for the builder page.
*/
	
	
	tab_material ="alum";
	tab_alum_color ="my";
	tab_alum_interior= "cb";
	tab_alum_wheel ="steel";
	
	tab_fibr_color ="wf";
	tab_fibr_interior= "jg";
	tab_fibr_wheel ="steel";

	tab_aluf_color ="my";
        tab_aluf_interior= "cb";
        tab_aluf_wheel ="steel";
	
	
	tab_floorPlan="standard";
	var session_id="";
	
	tab_fridge=false;
	
	function setMaterialDisplay(input)
	{
		if (input=="aluf")
		{
			
			document.getElementById('alumBox').className = "optionbox-options-invis";
			document.getElementById('fibrBox').className = "optionbox-options-invis";
			document.getElementById('alufBox').className = "optionbox-options-active";
		}
		else if (input=="alum")
		{
			document.getElementById('alumBox').className = "optionbox-options-active";
			document.getElementById('alufBox').className = "optionbox-options-invis";
			document.getElementById('fibrBox').className = "optionbox-options-invis";
			
		}
		else if (input=="fibr")
		{
			document.getElementById('fibrBox').className = "optionbox-options-active";
			document.getElementById('alumBox').className = "optionbox-options-invis";
			document.getElementById('alufBox').className = "optionbox-options-invis";
			
		}
	}

	function setTabImageFloorPlan(floorPlan)
	{
		tab_floorPlan=floorPlan;
		document.getElementById('tallyFrame').src="tally.php?PHPSESSID="+session_id+"&floorPlan="+floorPlan+"#floorPlan";
		replaceTapFloorPlanImage();
	}	
	/*
		They have clicked to change the bike color. Change it and replace the
		big image with one of the correct color/size.
	*/
	function setTabImageColor(material,color) {
		
		tab_material=material;
		if (tab_material=="alum")
		{
			tab_alum_color= color;
		}
		else if (tab_material=="fibr")
		{
			tab_fibr_color= color;
		}
		else
		{
			tab_aluf_color= color;
		}
		document.getElementById('tallyFrame').src="tally.php?PHPSESSID="+session_id+"&material="+tab_material+"&color="+color+"#color";
		// document.getElementById('tallyFrame').src="tally1.php?PHPSESSID="+session_id;

		replaceTabImage();
		
	}
	
	function setTabImageInterior(material,interior){
		tab_material=material;
		if (tab_material=="alum")
			tab_alum_interior= interior;
		else if (tab_material=="fibr")
			tab_fibr_interior= interior;
		else
			tab_aluf_interior= interior;
		document.getElementById('tallyFrame').src="tally.php?PHPSESSID="+session_id+"&material="+tab_material+"&interior="+interior+"#interior";
		replaceTabImage();
	}
	
	function setTabImageWheel(material,wheel){
		tab_material=material;
		if (tab_material=="alum")
			tab_alum_wheel= wheel;
		else if (tab_material=="fibr")
			tab_fibr_wheel= wheel;
		else
			tab_aluf_wheel= wheel;
		
		document.getElementById('tallyFrame').src="tally.php?PHPSESSID="+session_id+"&material="+tab_material+"&wheel="+wheel+"#wheel";
		
		
		replaceTabImage();
	}
	
	function setTabImageMaterial(material)
	{
		//tab_material=material;
		//document.getElementById('tallyFrame').src="tally.php?PHPSESSID="+session_id+"&material="+tab_material;
		//replaceTabImage();
		
	}
	/*
		Change the src attribute of the big bike image based on the size/color selected.
	*/
	function replaceTabImage() {
	
		var tabImage ;
		var interiorImage;
		
		
		
		
		if (tab_material=="alum")
		{
			if (document.getElementById('optionbox_top1')){
				document.getElementById('optionbox_top1').src = "/graphics/builder/optionbox_top_active.gif";
				document.getElementById('optionbox_content1').className = "optionbox-active-content";
				document.getElementById('optionbox_label1').className = "optionbox-active-content-label";
				document.getElementById('optionbox_bot1').src = "/graphics/builder/optionbox_bot_active.gif";
			
			
				document.getElementById('optionbox_top2').src = "/graphics/builder/optionbox_top_null.gif";
				document.getElementById('optionbox_content2').className = "optionbox-null-content";
				document.getElementById('optionbox_label2').className = "optionbox-null-content-label";
				document.getElementById('optionbox_bot2').src = "/graphics/builder/optionbox_bot_null.gif";
			}
			tabImage= '../graphics/builder/frame/frame_full_' + tab_material + '_' + tab_alum_color +'_'+tab_alum_wheel+ '.jpg';
			interiorImage="../graphics/builder/frame/frame_int_"+tab_alum_interior+".jpg";
		}
		else if (tab_material=="fibr")

		{
			if (document.getElementById('optionbox_top1')){
				document.getElementById('optionbox_top1').src = "/graphics/builder/optionbox_top_null.gif";
				document.getElementById('optionbox_content1').className = "optionbox-null-content";
				document.getElementById('optionbox_label1').className = "optionbox-null-content-label";
				document.getElementById('optionbox_bot1').src = "/graphics/builder/optionbox_bot_null.gif";
				
				document.getElementById('optionbox_top2').src = "/graphics/builder/optionbox_top_active.gif";
				document.getElementById('optionbox_content2').className = "optionbox-active-content";
				document.getElementById('optionbox_label2').className = "optionbox-active-content-label";	
				document.getElementById('optionbox_bot2').src = "/graphics/builder/optionbox_bot_active.gif";
			}			
			tabImage= '../graphics/builder/frame/frame_full_' + tab_material + '_' + tab_fibr_color +'_'+tab_fibr_wheel+ '.jpg';
			interiorImage="../graphics/builder/frame/frame_int_"+tab_fibr_interior+".jpg";
		}
		else
		{
			tabImage= '../graphics/builder/frame/frame_full_' + tab_material + '_' + tab_aluf_color +'_'+tab_aluf_wheel+ '.jpg';
                        interiorImage="../graphics/builder/frame/frame_int_"+tab_aluf_interior+".jpg";
		}
		
			
		document.getElementById('tab_full_image').src = tabImage;
		document.getElementById('interiorImage').src = interiorImage;
		var now=new Date();
		//if (document.getElementById('tallyFrameTotal'))
			document.getElementById('tallyFrameTotal').src="tally_total.php?PHPSESSID="+session_id+"&material="+tab_material;
	}
	
	
	

	function replaceTapFloorPlanImage(){
		var floorPlanImage;
		if (tab_floorPlan=="standard"){
			document.getElementById('optionbox_top1').src = "/graphics/builder/optionbox_top_active.gif";
			document.getElementById('optionbox_content1').className = "optionbox-active-content";
			document.getElementById('optionbox_label1').className = "optionbox-active-content-label";
			document.getElementById('optionbox_bot1').src = "/graphics/builder/optionbox_bot_active.gif";
			
			
			document.getElementById('optionbox_top2').src = "/graphics/builder/optionbox_top_null.gif";
			document.getElementById('optionbox_content2').className = "optionbox-null-content";
			document.getElementById('optionbox_label2').className = "optionbox-null-content-label";
			document.getElementById('optionbox_bot2').src = "/graphics/builder/optionbox_bot_null.gif";
			if (tab_material=="alum"){
				floorPlanImage="../graphics/builder/interior/alum_full_standard.gif";
			}
			else
			{
				floorPlanImage="../graphics/builder/interior/fibr_full_standard.gif";
			}
		}
		else{
			document.getElementById('optionbox_top1').src = "/graphics/builder/optionbox_top_null.gif";
			document.getElementById('optionbox_content1').className = "optionbox-null-content";
			document.getElementById('optionbox_label1').className = "optionbox-null-content-label";
			document.getElementById('optionbox_bot1').src = "/graphics/builder/optionbox_bot_null.gif";
			
			document.getElementById('optionbox_top2').src = "/graphics/builder/optionbox_top_active.gif";
			document.getElementById('optionbox_content2').className = "optionbox-active-content";
			document.getElementById('optionbox_label2').className = "optionbox-active-content-label";
			document.getElementById('optionbox_bot2').src = "/graphics/builder/optionbox_bot_active.gif";
			floorPlanImage="../graphics/builder/interior/either_full_lshaped.gif";
		}
			
		
		document.getElementById('tab_full_image').src = floorPlanImage;
	
	}

	function checkFridge()
	{
		if (document.getElementById('fridge').checked){
			document.getElementById('highElevationKitDiv').className='addoptions';
			
			document.getElementById('highElevationKit').disabled=false;
			
		}
		else{
			document.getElementById('highElevationKitDiv').className='addoptions-null';
			document.getElementById('highElevationKit').checked=false;
			document.getElementById('highElevationKit').disabled=true;
		}
		
	}
	
	
	function setRadioButton(input)
	{
		document.getElementById(input).checked=true;
		checkOption(input);
	}
	
	function setChecklist(input)
	{
		
		
		if (document.getElementById(input).checked)
			document.getElementById(input).checked=false;
		else
			document.getElementById(input).checked=true;
		if ((input=="highElevationKit")&&(!document.getElementById('fridge').checked))
			document.getElementById(input).checked=false;
		checkOption(input);
	}
	
	function checkOption(input)
	{
		
		document.getElementById('tallyFrame').src="tally.php?PHPSESSID="+session_id+"&"+input+"="+(document.getElementById(input).checked?"yes":"no")+"#"+input;
		document.getElementById('tallyFrameTotal').src="tally_total.php?PHPSESSID="+session_id+"&"+input+"="+(document.getElementById(input).checked?"yes":"no");
	}
	
	
	var newwindow;
		
	function popitup(url , title) 
	{
			if (newwindow && !newwindow.closed) 
			{ 
				newwindow.focus(); newwindow.document.clear() 
			} 
			else 
			{ 
				newwindow=window.open('','','width=750,height=500,resizable=no,scrollbars=no') 
			}
				
			newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <style type=\"text\/css\"> body {overflow: hidden;} <\/style> <\/head> <body bgcolor=\"#666666\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">');
			newwindow.document.writeln('<img src=' + url + '><br>');
			newwindow.document.writeln('<\/body> <\/html>');
			newwindow.document.close();
	}
