Event.observe(window, 'load', init);
function init(){
	
	$('bob').style.display = 'none';
	
    //Event.observe("cty",'click', doState.bind($("cty")));
    doGraphSession();
    doPic();
   // $("homeuse").style.display='none';
    //$("homeuse").innerHTML;
    doStart();
    //if($("homeuse").style.display != 'none')
	// {
		//$("homeuse").style.display='none';
		//$("homeuse").innerHTML;
	 //}
         
  //  doUtilityStyle();
  
}

function hideLearn(){
    var hl="<img style=\"visibility:hidden;cursor: pointer\" onclick=\"window.open('http://www.climatemaster.com/index/webapp-contact-form?type=28')\" name=\"learnMore\" id=\"learnMore\" alt=\"learn more\" title=\"Click for more info on ClimateMaster Geothermal Heat Pumps\" src=\"/svcalc/images/learn_more_button.png\" border=\"0\" >";
   // var hl="<img title=\"Click for more info on ClimateMaster Geothermal Heat Pumps\" name=\"learnMore\" id=\"learnMore\" style=\"visibility:hidden\" src=\"/svcalc/images/learn_more_button.png\" border=\"0\">";
   var showL="<img style=\"visibility:show;cursor: pointer\" onclick=\"window.open('http://www.climatemaster.com/index/webapp-contact-form?type=28')\" name=\"learnMore\" id=\"learnMore\" alt=\"learn more\" title=\"Click for more info on ClimateMaster Geothermal Heat Pumps\" src=\"/svcalc/images/learn_more_button.png\" border=\"0\" >";
    //var showL="<img title=\"Click for more info on ClimateMaster Geothermal Heat Pumps\" name=\"learnMore\" id=\"learnMore\" style=\"visibility:show\" src=\"/svcalc/images/learn_more_button.png\" border=\"0\">";
    if($("ca").value!="" && !hideLearnMore) {
       hl=showL;
         //$('logo').addTip('', '', { ajax: { url: 'learnmore.html' },showOn: 'creation', showEffect: 'appear',style: 'glass', tipJoint: [ 'left', 'middle' ], delay: 5,showEffectDuration: .5,hideTrigger: 'closeButton', offset: [50,0],target: true,stem: false,stemSize: 20 });
         //$('logo').Tips.show();        
    }
    
      $("learnMore").replace(hl);
      $("learnMore").innerHTML;
     
}
	function doUtilityStyle() {
		
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
			$("toputil").setStyle("position: relative;top: -15px;left: -2px;height: 28px");
			
		} else {
			$("toputil").setStyle("position: relative;top: -15px;left: -2px;height: 28px");
			
		}
		
	}
		function getImage(pExistingImageID, pImageURL){
			
		    var img = document.createElement('img');
		    img.onload = function (evt) {
		        document.getElementById(pExistingImageID).src=this.src;	        
		    }
		    img.src = pImageURL;
		    return false;
		}	
	function updateInsulation(){
		var cEle=document.activeElement.name;
		var arrInsulation=['P','A','G','E'].entries();
		var eNameS=" onClick=\"doPic('UHQ ',this.options[selectedIndex].value);";
		var eNameO=" onMouseOver=\"doPic('UHQ ',this.value);";
    	var opDisplay=arrInsulation.clone();
    	var newOlist='<select class="easelect" '+eNameS +'" onChange="doGraphSession()" name="UHQ " id="UHQ">';
    	if(cEle=="HQ ") {
	    	opDisplay['P']="Poor";
	    	opDisplay['G']="Good";
	    	opDisplay['A']='Average';
	    	opDisplay['E']='Excellent';
	    	
	    	var hqData=$('HQ ').getValue();
	    	
	    	var ugiStart=arrInsulation.indexOf(hqData);
	    	
	    	 for (var index=ugiStart; index<arrInsulation.size();++index) {
	    		 var item=arrInsulation[index];    		 
	    		 newOlist=newOlist+'<option '+eNameO +'" class="eaoption" style="width: 120px" value="'+item+'">'+opDisplay[item]+'</option>';
	    	 }
	    	 newOlist=newOlist+"</select>";
	    	$('UHQ').replace(newOlist);
	    	$('UHQ').innerHTML;
    	}
		
	}	
	function updateApp(){
		var cEle=document.activeElement.name;
		var arrApp=['S','E'].entries();
		var opDisplay=arrApp.clone();
	    var newOlist='<select class="easelect" onChange="doGraphSession()" name="UAT " id="UAT">';
		if(cEle=="AT ") {
			opDisplay['S']="None";
			opDisplay['E']="Energy Star";
			var apData=$('AT ').getValue();
			 var uapStart=arrApp.indexOf(apData);
			 for (var index=uapStart; index<arrApp.size();++index) {
	    		 var item=arrApp[index];    		 
	    		 newOlist=newOlist+'<option class="eaoption" value="'+item+'">'+opDisplay[item]+'</option>';
	    	 }
	    	 newOlist=newOlist+"</select>";	
	    	 $('UAT').replace(newOlist);
	    	 $('UAT').innerHTML;
		}
	}
	function updateLight(){
		var cEle=document.activeElement.name;
		var arrApp=['I','C'].entries();
		var opDisplay=arrApp.clone();
	    var newOlist='<select class="easelect" onChange="doGraphSession()" name="ULT " id="ULT">';
		if(cEle=="LT ") {
			opDisplay['I']="None";
			opDisplay['C']="CFL Fluorescent";
			var apData=$('LT ').getValue();
			 var uapStart=arrApp.indexOf(apData);
			 for (var index=uapStart; index<arrApp.size();++index) {
	    		 var item=arrApp[index];    		 
	    		 newOlist=newOlist+'<option class="eaoption" value="'+item+'">'+opDisplay[item]+'</option>';
	    	 }
	    	 newOlist=newOlist+"</select>";	
	    	 $('ULT').replace(newOlist);
	    	 $('ULT').innerHTML;
	    	 
		}
	}
	function updateHCA(){
		var cEle=document.activeElement.name;
		var arrApp=Array();
		var eNameS=" onClick=\"doPic('HCA ',this.options[selectedIndex].value);";
		var eNameO=" onMouseOver=\"doPic('HCA ',this.value);";
		
	    var newOlist='<select class="easelect" style="width: 120px" onChange="doGraphSession();"'+eNameS+'" name="HCA " id="HCA ">';
	    
		if(cEle=="hometype") {			
			 var apData=$('hometype').getValue();
			  if(apData=="N") {
				  arrApp=['N'].entries();
				  var opDisplay=arrApp.clone();
				  opDisplay['N']="New";
			  }else{
				  arrApp=['N','M','O'].entries();
				  var opDisplay=arrApp.clone();
				  opDisplay['N']="<3 years old";
				  opDisplay['M']="3-15 years old";
				  opDisplay['O']=">15 years old";
			  }
			 if(apData=="E" || apData=="") { apData="N"; }
			 var uapStart=arrApp.indexOf(apData);
			 for (var index=uapStart; index<arrApp.size();++index) {
	    		 var item=arrApp[index];    		 
	    		 newOlist=newOlist+'<option '+ eNameO +'" class="eaoption" value="'+item+'">'+opDisplay[item]+'</option>';
	    	 }
	    	 newOlist=newOlist+"</select>";	
	    	 
	    	 $('HCA ').replace(newOlist);
	    	 $('HCA ').innerHTML;
	    	 
		}
	}
	function changeDetailTab(tabName){
		utab.getTab(tabName).select();
		showUtility();
		
	}
	function showUtility(){
		var tabData=utab.getSelectedChain("utab");
		
		 switch (tabData)
		 {
		 case "urate_tab":
			    showPage("urates_page");
			    break;
		 case "dd_tab":
			 	showPage("dd_page");
			 	break;
		 default:
			  	showPage("urates_page");
		 		break;		 
		 }
	}
	function showPage(_pageid) {
		
		['urates_page','dd_page'].each(Element.hide);
		$(_pageid).show();
		
	}
    function checkForms() { 
    	var cEle=document.activeElement.name;
    	updateInsulation();
    	updateApp();
    	updateLight();
    	updateHCA();
    	doPic();
        hideLearn();
       
       
    	if(cEle=='location' || cEle=='country1') {
    		var home_tab=utab.getTab('urate_tab');
    		home_tab.select();
    	}
    	if(cEle=='location') {
    		
    		if($("urate").style.display == 'none'){
    			
    			doSlide('urate');
    			
    		}
    	}
    }
    
    function doGraphSession(){
        
    	checkForms();
       var randomnumber=Math.floor(Math.random()*11);
    	var tabData=kts.getSelectedChain("kts");
    	var postdata=$('homeInfo').serialize();
    	var cnty="&country="+$F('country1');
    	var url="dosession.php";
    	var tabSelected="&dgraph="+tabData;    	
    	var pars='fdata='+postdata+tabSelected+cnty;  
    	var target='form-data';    	   	
    	var sAjax=new Ajax.Updater(target,url,{method: 'post',parameters: pars});
    	
    	Update2();
        
    	
      }
        
	function doState(){			
		if($F('loc')){
			$('city-holder').update("<select id='city' name='city' class='easelect'><option class='eaoption' value=''>------</option></select>");
			$('city-holder').innerHTML;
		}
		var postdata = $F('country1');		
		if(postdata){	
							
				
		 if(postdata=="CA") {
			 $('sp').update("Province");
			 $('sp').innerHTML;
			 
		 }else{
			 $('sp').update("State");
			 $('sp').innerHTML;
		 }
		
		 var randomnumber=Math.floor(Math.random()*11);
	     var url = 'getlocation.php';
	     var pars = 'country_list='+postdata+"&sie="+randomnumber;
	     var target = 'location';
	     var myAjax = new Ajax.Updater(target, url, {method: 'post', parameters: pars,onSuccess: doGraphSession()});
	     
		}
	     
	     
	}
	function doPic2(eName){
		
		
		
		var dd = $(eName).selectedIndex;
		
		var ss =document.getElementById(eName).options[dd].text;
		
		return ss;
	}
	
	function doPic(fName,cOptValue) {
		//var cEle=document.activeElement.name;
		var cEle=fName;
		if(cOptValue=="1") {
			var cValue=doPic2(cEle);
		}else{
			var cValue=cOptValue;
		}
		  ['img_home','img_lightcf','img_lightin','img_ac0','img_ac1','img_ac2','img_ac3','img_watere','img_waterg','img_heatere','img_heaterg','img_appstd','img_appes','img_insulation_summer','img_insulation_winter'].each(Element.hide);
		
		  switch (cEle)
		 {
		 case "HQ ":		 
			 $('img_insulation_summer').show();			 
			 break;
		 case "HCA ":
			 var isNew=doPic2(cEle);
			 
			 if(cValue=="N") {
				 $('img_ac1').show();
			 }else if(cValue=="M"){
				 $('img_ac2').show();
			 }else if(cValue=="O") {
				 $('img_ac3').show();
			 }
			 if(isNew=="New") {
				 $('img_ac1').hide();
				 $('img_ac0').show();
			 }
			
			 break;
		 case "HCE ": 
			 if(cValue=="H") {
				 $('img_ac1').show();
				 
			 }else{
				 $('img_ac3').show(); 
			 }
			 break;
		 case "WHT ":
			 if(cValue!='EP') {
				 $('img_waterg').show();
			 }else{
				 $('img_watere').show();
			 }
			 break;
		 case "HT ":
			 if(cValue!='ER' && cValue!='EP') {
				 $('img_heaterg').show();
			 }else{
				 $('img_heatere').show();				 
			 }
			 break;
		 case "AT":			 
			 $('img_energystar').show();
			 break;
		 case "LT ":			 
			 $('img_light').show();
			 break;
		 case "UHQ ":		 
			 $('img_insulation_summer').show();			 
			 break;
		 case "ULT ":
			if(cValue=='I') {
				$('img_lightin').show();
			}else{
				$('img_lightcf').show();
			}
			 break;
		 case "UAT ":	
			if(cValue=='S') {
				$('img_appstd').show();
			}else{
				$('img_appes').show();
			}
			 break;
		 default:
		 	 $('img_home').show();
		 	 break;
		 }
		
		
	}
	function doCity(){	
		 
		 var postdata = $F('loc');		 
		 var url = 'getlocation.php';
	     var pars = 'state_list='+postdata;	   
	    
	     var target = 'city-holder';
	     var myAjax2 = new Ajax.Updater(target, url, {method: 'post', parameters: pars,onSuccess: doGraphSession()});	     
	     
	}
	function doSlide(slideMe){
		Effect.toggle($(slideMe),'slide',{ duration: .5 });
				
	}
       
	function doStart() {
		if($("homeuse").style.display=='none')
		{
			Effect.SlideDown('homeuse',{ duration: .5});
			Effect.SlideUp('econuse',{ duration: .5 });
			Effect.Pulsate('cty2');
                       
                        $('bstart').hide();
			
		}else{
			Effect.Pulsate('cty2');
			Effect.Shake('homeuse',{ distance: 5 });                       
			
			
		}
		
	}
	function doSideItems() {
		
		if($("homeuse").style.display!='none')
		 {
			Effect.SlideUp('homeuse',{ duration: .5 });
			
		 }
		
	}
	function MM_jumpMenu(targ,selObj,restore){ //v3.0
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		//window.open(selObj.options[selObj.selectedIndex].value)
		if (restore) selObj.selectedIndex=0;
	}
