// JavaScript Document script.js v1.3
var x = 1;
var y = 4;
var hold=0
function LoadPage(){
	if(getCookie("LocalZip")!=null){
	document.getElementById("LocalZipSearch").value=getCookie("LocalZip");
	document.getElementById("LocalZipSearch").style.color="#000";
	LocalZipSearch()
	}else{
		document.getElementById("LocalZipSearch").value="Type you zip code here";
	}

}
function setSelectedMenuItem(id){
	$('#'+id).addClass('MenuSelected');

}
function ShowINS(id){
			$('#'+id).animate({
							  display:'block',
							  },500,function(){	  });

}
function StartNewChat(ChatDesc){
	windowheight = $(window).height() - 350;
	document.getElementById("MainChatDiv").style.top=windowheight+'px';
	document.getElementById("MainChatDiv").style.display="block";
	marginleft = $(window).width()/2 - 150
	document.getElementById("MainChatDiv").style.marginLeft=marginleft+"px";

	


		$('#OpenChat').animate({
							  marginTop:'360px',
							  },500,function(){
								document.getElementById("Footer").style.marginBottom="320px"; 
								$('#ChatInner').animate({
													   marginTop:'10px'
													   },500);
							  });

	
$(window).scroll(function() {
	windowheight = $(window).scrollTop() + $(window).height() -350;
	marginleft = $(window).width()/2 - 150
	document.getElementById("MainChatDiv").style.top=windowheight+'px';
	document.getElementById("MainChatDiv").style.marginLeft=marginleft+"px";
});
$(window).resize(function() {
	windowheight = $(window).scrollTop() + $(window).height() - 350;
	marginleft = $(window).width()/2 - 150
	document.getElementById("MainChatDiv").style.top=windowheight+'px';
	document.getElementById("MainChatDiv").style.marginLeft=marginleft+"px";
});

}
function hidechat(){
		document.getElementById("MainChatDiv").style.display="block";

		windowheight = $(window).scrollTop() + $(window).height() - 350;
	marginleft = $(window).width()/2 - 150
	document.getElementById("MainChatDiv").style.top=windowheight+'px';
	document.getElementById("MainChatDiv").style.marginLeft=marginleft+"px";
	$('#ChatInner').animate({
							  marginTop:'360px',
							  },500,function(){
								document.getElementById("Footer").style.marginBottom="25px"; 
								$('#OpenChat').animate({
													   marginTop:'320px'
													   },500);
							  });
	setCookie("nochat","1",99)
$(window).scroll(function() {
	windowheight = $(window).scrollTop() + $(window).height() -350;
	marginleft = $(window).width()/2 - 150
	document.getElementById("MainChatDiv").style.top=windowheight+'px';
});
$(window).resize(function() {
	windowheight = $(window).scrollTop() + $(window).height() - 350;
	marginleft = $(window).width()/2 - 150
	document.getElementById("MainChatDiv").style.top=windowheight+'px';
});
}
function FocusHomeZip(){
	if(document.getElementById("LocalZipSearch").value=="Type you zip code here"){
		document.getElementById("LocalZipSearch").value="";
		document.getElementById("LocalZipSearch").style.color="#000";	
	}
}
function BlurHomeZip(){
	if(document.getElementById("LocalZipSearch").value==""){
		document.getElementById("LocalZipSearch").value="Type you zip code here";
		document.getElementById("LocalZipSearch").style.color="#999";	
	}
}
function LocalZipSearch(){
	if(document.getElementById("LocalZipSearch").value.length==5){
	setCookie("LocalZip",document.getElementById("LocalZipSearch").value,999)
	$("#LocalZipSearch").animate({width:'50px'},500, function(){
								 
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			  {
			  alert ("Your browser does not support AJAX!");
			  return;
			  }
			var url="/AJAX/getCity.asp";
			//var url="showcompleted.asp";
			url=url+"?z="+document.getElementById("LocalZipSearch").value;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange=StateChangedLocalZipSearch;
			//alert(stateChanged);
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
								 
								 })
	//alert("five");
	}
}
function StateChangedLocalZipSearch(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var output = "";
		var suggestion
		var currentrec
		if(recs>0){
					currentrec = xmlDoc.getElementsByTagName("record").item(0)
					city = currentrec.getAttribute("city")
					phone = currentrec.getAttribute("phone")
					zip = currentrec.getAttribute("zip")
					output = output + "<a class='LocalPhoneCall' href='tel:"+phone+"'><span id='LocalInfoPhone'>"+phone+"</span></a>";
					output = output + "<span id='LocalInfoCity'><a href='/Appointment/?z="+zip+"'>Schedule an appointment in "+city+".</a></span>";
		document.getElementById("LocalInfo").innerHTML = output;
		}else{
		document.getElementById("LocalInfo").innerHTML = "<span id='LocalInfoNotFound'>Not Found. We may not service the area.</span>";
		}
	}
		$("#LocalInfo").fadeIn('slow', function() {});

}
function GetTR(Zip){
//	alert(Zip);
	if(Zip.length==5){
	setCookie("LocalZip",Zip,999)
								 
			xmlHttp=GetXmlHttpObject();
			if (xmlHttp==null)
			  {
			  alert ("Your browser does not support AJAX!");
			  return;
			  }
			var url="/AJAX/getTRbyZip.asp";
			//var url="showcompleted.asp";
			url=url+"?z="+Zip;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange=StateChangedTRSearch;
			//alert(stateChanged);
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
								 
	//alert("five");
	}
return true;

}
function StateChangedTRSearch(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var output = "";
		var suggestion
		var currentrec
		if(recs>0){
						border=" border-bottom:1px solid #CCC;"
					output = output + "<div style='height:45px; width:320px; margin-bottom:3px;"+border+"'>";
					var tr = getCookie("tr");
//					alert(tr)
					if(tr!=null||tr==""){
						selected =""
//						alert("tr is not null")
					}else{
//						alert("tr is null")
					//	tr = getCookie("TR")
						tr=""
						selected =" checked='checked'"
//						alert("tr=null")
					}
					output = output + "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width='32px'><input name='TR' value='No preference'"+selected+" onclick='setTR(this.value)' type='radio'></td><td>";
					output = output + "<object data='/Images/Technicians/0.jpg' width='42' height='42' align='left' style=' margin-right: 10px;'>";
					output = output + "<img src='/Images/Technicians/doesnotexist.jpg' alt='' name='Photo' width='42' height='42' align='left' />";
					output = output + "</object>";
					output = output + "<div id='TechName'><strong>No preference</strong></div>";
//					output = output + "<div id='Data'>"+experience+" years of experience.</div>";
					output = output + "</td></tr></table>"
					output = output + "</div>";
//					alert(recs);
			for(i=1;i<=recs;i++){
					//alert(i);
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0)
					tech = currentrec.getAttribute("Technician")
					id = currentrec.getAttribute("ID")
					experience = currentrec.getAttribute("Experience")
					if(i!=recs){
						border=" border-bottom:1px solid #CCC;"
					}
					tr=tr.replace("+"," ")
					if(tr==tech){
						selected =" checked='checked'"
						document.getElementById("TechRequest").value = tech;
					}else{
						selected =""
					}
					output = output + "<div style='height:45px; width:320px; margin-bottom:3px;"+border+"'>";
					output = output + "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width='32px'><input name='TR' value='"+tech+"'"+selected+" onclick='setTR(this.value)' type='radio'></td><td>";
					output = output + "<object data='/Images/Technicians/"+id+".jpg' width='42' height='42' align='left' style=' margin-right: 10px;'>";
					output = output + "<img src='/Images/Technicians/doesnotexist.jpg' alt='' name='Photo' width='42' height='42' align='left' />";
					output = output + "</object>";
					output = output + "<div id='TechName'><strong>"+tech+"</strong></div>";
					output = output + "<div id='Data'>"+experience+" years of experience.</div>";
					output = output + "</td></tr></table>"
					output = output + "</div>";

//					output = output + "<a class='LocalPhoneCall' href='tel:"+phone+"'><span id='LocalInfoPhone'>"+phone+"</span></a>";
//					output = output + "<span id='LocalInfoCity'><a href='/Appointment/?z="+zip+"'>Schedule an appointment in "+city+".</a></span>";
				}
		document.getElementById("AppointmentTechnicianOutput").innerHTML = output;
		document.getElementById("AppointmentTechnicianOutput").style.overflow="scroll";
		}else{
		document.getElementById("AppointmentTechnicianOutput").innerHTML = "<span id='LocalInfoNotFound'>There are no technicians in this area.</span>";
		}
		document.getElementById("zip2").innerHTML="<span style='color:#000; font-size:.8em;'>Zip:</span> <input name='TRZipCode' onkeyup='GetTR(this.value)' value='"+getCookie('LocalZip')+"' type='text' size='5' maxlength='5' />";
	}
	//	$("#LocalInfo").fadeIn('slow', function() {});

}
function setTR(TR){
	document.getElementById("TechRequest").value = TR;
}
function MoveLeft(){
	if(hold!=1){
		hold=1
		if(x>1){
			x=x-1;
			//alert("Javascript:MoveRight("+z+")");
		$('#Appliance_'+y).animate({width:'0px',marginLeft:'0px',marginRight:'0px'}, 500, function(){})
		$('#Appliance_'+x).animate({width:'221px',marginLeft:'6px',marginRight:'6px'}, 500, function(){})
			//style.display="none";
			
			document.getElementById("ApplianceText_"+x).style.display="block";
			document.getElementById("ApplianceText_"+y).style.display="none";
			y=y-1;
		}
	}
	hold=0;
}


function MoveRight(){
//	alert("x-"+x);
//	alert("y-"+y);
	if(hold!=1){
		hold=1
		if(y<20){
			y=y+1;
	//		alert("Here");
			$('#Appliance_'+x).animate({width:'0px',marginLeft:'0px',marginRight:'0px'}, 500, HideApplianceText(x))
			$('#Appliance_'+y).animate({width:'221px',marginLeft:'6px',marginRight:'6px'}, 500, ShowApplianceText(y))
		//	document.getElementById("Appliance_"+y).style.display="block";
			x=x+1;
		}
	}
	hold=0;
//	alert("x-"+x);
//	alert("y-"+y);

}
function HideApplianceText(p){
	setTimeout("document.getElementById('ApplianceText_"+p+"').style.display='none'",500)
//	document.getElementById("ApplianceText_"+p).style.display="none";
}
function ShowApplianceText(p){
	setTimeout("document.getElementById('ApplianceText_"+p+"').style.display='block'",500)
//	document.getElementById("ApplianceText_"+p).style.display="block";
}
function Fade5Year(){
	$('#Warranty').animate({opacity: 0}, 1000, function() {
			document.getElementById('Warranty').style.marginTop='225px'
			document.getElementById('Warranty').style.marginLeft='440px'
			$('#Warranty').animate({opacity: 1}, 1000)
})
	
}
var LockSlide = 0

function LockLocalSlide(Locker){
	LockSlide = Locker
	if(document.getElementById("LocalSearchZip").value=="Zip Code"){
	document.getElementById("LocalSearchZip").value="";
	}else if(document.getElementById("LocalSearchZip").value==""){
	document.getElementById("LocalSearchZip").value="Zip Code";
	}
//	alert(LockSlide);
}
function ExtendLocalSearch(){
			$('#LocalSearch').animate({height:'215px'}, 500, function(){waitforout=1})
}
function HideLocalSearch(){
	
	alert(LockSlide);
	if(!LockSlide==1){
			$('#LocalSearch').animate({height:'30px'}, 500, function(){})
	}
}
function suggestions(inputid){
	if(document.getElementById(inputid).value!=""){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/getsuggestions.asp";
		//var url="showcompleted.asp";
		url=url+"?q="+inputid;
		url=url+"&m="+document.getElementById(inputid).value;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=StateChangedsuggestions;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}
function StateChangedsuggestions(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var typerecs = xmlDoc.getElementsByTagName("typerecs")[0].childNodes[0].nodeValue;
		var list = "<div class='suggestions'>";
		var suggestion
		var currentrec
		var id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
		if(recs>0){
			if(recs!=1){
				for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0)
					suggestion = currentrec.getAttribute("suggestion")
					list = list + "<div onmouseover='highlightsuggestion(this.id)' onmouseout='unhighlightsuggestion(this.id)' onmousedown='return selectsuggestion(this.id,\""+id+"\")' id='suggestion"+i+"' class='suggestion'>"+suggestion+"</div>";
				}
			}else{
					currentrec = xmlDoc.getElementsByTagName("record1").item(0)
					brand = currentrec.getAttribute("suggestion")
				if(typerecs>0){
					for(i=1;i<=typerecs;i++){
						currentrec = xmlDoc.getElementsByTagName("typerecord"+i).item(0)
						suggestion = currentrec.getAttribute("suggestion")
						list = list + "<div onmouseover='highlightsuggestion(this.id)' onmouseout='unhighlightsuggestion(this.id)' onmousedown='return selectsuggestion(this.id,\""+id+"\")' id='suggestion"+i+"' class='suggestion'>"+ brand +" "+ suggestion+"</div>";
					}
				}
			}
		list = list + "</div>";
		document.getElementById("suggest"+id).innerHTML = list;
		}else{
		document.getElementById("suggest"+id).innerHTML = "";
		}
	}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function highlightsuggestion(id){
	var selection = document.getElementById(id);
	selection.style.backgroundColor = "blue";
	selection.style.color = "White";
}
function unhighlightsuggestion(id){
	var selection = document.getElementById(id);
	selection.style.backgroundColor = "white";
	selection.style.color = "#0D58A6";
}
function hidesuggestions(id){
	document.getElementById("suggest"+id).innerHTML = "";
}
function selectsuggestion(id, originalid){
	document.getElementById(originalid).value = document.getElementById(id).innerHTML;
	hidesuggestions(originalid)
	document.getElementById(originalid).focus();
}
function FocusInZip(){
	if(document.getElementById("ZipCode").value=="Zip Code"){
		document.getElementById("ZipCode").value="";
	}
}
function FocusOutZip(){
	if(document.getElementById("ZipCode").value==""){
		document.getElementById("ZipCode").value="Zip Code";
	}
}
function SearchTechnicians(){
	if(document.getElementById("ZipCode").value!=""||document.getElementById("ZipCode").value!="ZipCode"){
		window.location = "/Local/Technicians/?z="+document.getElementById("ZipCode").value;
	}
}
function ScrollToAppliances() {
			$("html:not(:animated),body:not(:animated)").animate({scrollTop:'175'}, 500)
	
//   var elementClicked = $(this).attr("href");
//   var destination = $(elementClicked).offset().top;
//   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: 200-20}, 500 );
//   return false;
}
function ScrollToContact() {
			ScrollTo=$(window).height()-500
		//	alert(ScrollTo);
}
function PopulateTypes(ApplianceBrand){
		document.getElementById("ApplianceTypesSelect").innerHTML = "<span class='gray CustomerInput CustomerInput4'>Loading...</span>Appliance Type";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/PopulateApplianceTypes.asp";
		//var url="showcompleted.asp";
		url=url+"?q="+ApplianceBrand;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=PopulateTypesReady;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function PopulateTypesReady(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<select class='CustomerInput CustomerInput4' id='ApplianceType' name='ApplianceType' onchange=\"PopulateProblems(this.value)\">";
		var suggestion
		var currentrec
		if(recs>0){
					list = list + "<option value=''>[Choose Appliance]</option>";
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0)
					list = list + "<option value='"+currentrec.getAttribute("suggestion")+"'>" +currentrec.getAttribute("suggestion")+"</option>";
			}
		list = list + "</select>Appliance Type";
		document.getElementById("ApplianceTypesSelect").innerHTML = list;
		}else{
		document.getElementById("ApplianceTypesSelect").innerHTML = "<span class='red CustomerInput CustomerInput4'>Error(no appliances)</span>Appliance Type";
		}
	}
}
function FindCities(str){
	
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/PopulateLocations.asp";
		//var url="showcompleted.asp";
		url=url+"?str="+str;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=PopulateFindCities;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function PopulateFindCities(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<div ";
		var suggestion
		var currentrec
		if(recs>0){
			for(i=1;i<=recs;i++){
				//alert(i);
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0)
					list = list + "<div>" +currentrec.getAttribute("City")+", CA "+currentrec.getAttribute("Zip")+"</div>";
			}
		list = list + "</div>";
		document.getElementById("LocalSearchOutput").innerHTML = list;
		}else{
		document.getElementById("LocalSearchOutput").innerHTML = "Sorry, no results for that query.";
		}
	}
}
function PopulateTypes2(ApplianceBrand){
		document.getElementById("ApplianceTypeSet").innerHTML = "<span class='gray CustomerInput CustomerInput4'>Loading...</span><label for='billing_zipcode'>Appliance:</label> ";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/PopulateApplianceTypes.asp";
		//var url="showcompleted.asp";
		url=url+"?q="+ApplianceBrand;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=PopulateTypesReady2;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function PopulateTypesReady2(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<div class=\"invalid1\" id=\"invalid_appliancetype\">*required</div> <select class='CustomerInput CustomerInput4' id='ApplianceType' name='ApplianceType' onchange=\"PopulateProblems2(this.value)\">";
		var suggestion
		var currentrec
		if(recs>0){
					list = list + "<option value=''>Select Appliance</option>";
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0)
					list = list + "<option value='"+currentrec.getAttribute("suggestion")+"'>" +currentrec.getAttribute("suggestion")+"</option>";
			}
		list = list + "</select><label for='billing_zipcode'>Appliance:</label>";
		document.getElementById("ApplianceTypeSet").innerHTML = list;
		}else{
		document.getElementById("ApplianceTypeSet").innerHTML = "<span class='red CustomerInput CustomerInput4'>Error(no appliances)</span><label for='billing_zipcode'>Appliance:</label>";
		}
	}
}
function PopulateBrands2(ApplianceType){
		document.getElementById("ApplianceBrandSet").innerHTML = "<span class='gray CustomerInput CustomerInput4'>Loading...</span><label for='ApplianceBrand'>Brand:</label> ";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/PopulateApplianceBrands.asp";
		//var url="showcompleted.asp";
		url=url+"?q="+ApplianceType;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=PopulateBrandsReady2;
		//alert(stateChanged);
	//	alert(url)
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function PopulateBrandsReady2(){
	if (xmlHttp.readyState==4){

		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<div class=\"invalid1\" id=\"invalid_brand\">*required</div> <select class='CustomerInput CustomerInput4' id='ApplianceBrand' name='ApplianceBrand' >";
		var suggestion
		var currentrec
		if(recs>0){
					list = list + "<option value=''>Select Brand</option>";
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0);
					list = list + "<option value='"+currentrec.getAttribute("suggestion")+"'>" +currentrec.getAttribute("suggestion")+"</option>";
			}
		list = list + "</select><label for='ApplianceBrand'>Brand:</label>";
		document.getElementById("ApplianceBrandSet").innerHTML = list;
	//		alert(document.getElementById("ApplianceBrandSet").innerHTML);
		}else{
		document.getElementById("ApplianceBrandSet").innerHTML = "<span class='red CustomerInput CustomerInput4'>Error(no brands)</span><label for='ApplianceBrand'>Brand:</label>";
		}



		recs = xmlDoc.getElementsByTagName("recs2")[0].childNodes[0].nodeValue;
		var list = "<div class=\"invalid1\" id=\"invalid_appliancetype\">*required</div> <select class='CustomerInput CustomerInput4' id='ApplianceProblem' name='ApplianceProblem' >";
		var suggestion
		var currentrec

				if(recs>0){
					list = list + "<option value=''>Select Problem</option>";
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("recordp"+i).item(0)
					list = list + "<option value='"+currentrec.getAttribute("suggestion")+"'>" +currentrec.getAttribute("suggestion")+"</option>";
			}
		list = list + "</select><a class='appointmentaddlink' href='javascript:moreproblemdetails()'>add details</a><label for='ApplianceProblem'>Problem:</label>";
		document.getElementById("ApplianceProblemSet").innerHTML = list;
		}else{
		document.getElementById("ApplianceProblemSet").innerHTML = "<span class='red CustomerInput CustomerInput4'>Error(no problems)</span><label for='ApplianceProblem'>Problem:</label>";
		}


}
}
function PopulateProblems(ApplianceType){
		document.getElementById("ApplianceProblemsSelect").innerHTML = "<span class='gray CustomerInput CustomerInput4'>Loading...</span>Problem";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/PopulateApplianceProblems.asp";
		//var url="showcompleted.asp";
		url=url+"?q="+ApplianceType;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=PopulateProblemsReady;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function PopulateProblemsReady(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<select class='CustomerInput CustomerInput4' id='ApplianceProblem' name='ApplianceProblem'>";
		var suggestion
		var currentrec
		if(recs>0){
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0)
					list = list + "<option value='"+currentrec.getAttribute("suggestion")+"'>" +currentrec.getAttribute("suggestion")+"</option>";
			}
		list = list + "</select>Problem";
		document.getElementById("ApplianceProblemsSelect").innerHTML = list;
		}else{
		document.getElementById("ApplianceProblemsSelect").innerHTML = "<span class='red CustomerInput CustomerInput4'>Error(no problems)</span>Problem";
		}
	}
}
function PopulateProblems2(ApplianceType){
		document.getElementById("ApplianceProblemSet").innerHTML = "<span class='gray CustomerInput CustomerInput4'>Loading...</span><label for='billing_zipcode'>Problem:</label>";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/PopulateApplianceProblems.asp";
		//var url="showcompleted.asp";
		url=url+"?q="+ApplianceType;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=PopulateProblemsReady2;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function PopulateProblemsReady2(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<select class='CustomerInput CustomerInput4' id='ApplianceProblem' name='ApplianceProblem'>";
		var suggestion
		var currentrec
		if(recs>0){
					list = list + "<option value=''>Select Problem</option>";
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0)
					list = list + "<option value='"+currentrec.getAttribute("suggestion")+"'>" +currentrec.getAttribute("suggestion")+"</option>";
			}
		list = list + "</select><a class='appointmentaddlink' href='javascript:moreproblemdetails()'>add details</a><label for='billing_zipcode'>Problem:</label>";
		document.getElementById("ApplianceProblemSet").innerHTML = list;
		}else{
		document.getElementById("ApplianceProblemSet").innerHTML = "<span class='red CustomerInput CustomerInput4'>Error(no problems)</span><label for='billing_zipcode'>Problem:</label>";
		}
	}
}
function HideInputGroup(id,id2){
			$('#'+id).fadeOut(500, function(){
											//$('#'+id2).fadeIn(500, function(){})
											//if(id2=="InputGroup2"){
											//RemoveAddedAppliance('');
											//}else{
											//document.getElementById("SingleApplianceGroup").style.display="block";
											$('#'+id2).fadeIn(500, function(){})
											//}
											hidenum=id.replace("InputGroup","");
											shownum=id2.replace("InputGroup","");
											document.getElementById("Step"+hidenum).className = "steps prestep"
											document.getElementById("Step"+shownum).className = "steps fullstep"
											})
			
}
var TotalAppliances
function AddAppointmentAppliance(q){
		var tf2 = false
		tf=true;
		document.getElementById("invalid_brand").style.display="none";
		document.getElementById("invalid_appliancetype").style.display="none";
		brand=document.getElementById("ApplianceBrand").selectedIndex;
		appliancetype = document.getElementById("ApplianceType").selectedIndex;
		if(appliancetype==0 && TotalAppliances>0){
			AddAppointmentApplianceReady2();
		}else{
		if(brand==0){
			tf=false;
			tf2=true;
			document.getElementById("invalid_brand").style.display="block";
		}
		if(appliancetype==0){
			tf=false;
			//alert("Type=false");
			document.getElementById("invalid_appliancetype").style.display="block";
		}
		if(tf!=false){
		document.getElementById("AddAnotherAppliance").innerHTML = "<a href='#'>Please wait...</a>";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/AddAppointmentAppliance.asp";
		//var url="showcompleted.asp";
		var appliancebrand = document.getElementById("ApplianceBrand").value;
		url=url+"?Brand="+appliancebrand.replace("&","ZZZ");
		url=url+"&Appliance="+document.getElementById("ApplianceType").value;
		url=url+"&Model="+document.getElementById("ApplianceModel").value;
		url=url+"&Serial="+document.getElementById("ApplianceSerial").value;
		url=url+"&Problem="+document.getElementById("ApplianceProblem").value;
		url=url+"&ProblemDesc="+document.getElementById("ApplianceProblemDesc").value;
		url=url+"&sid="+Math.random();
		if(q==2){
		xmlHttp.onreadystatechange=AddAppointmentApplianceReady2;
		}else{
		xmlHttp.onreadystatechange=AddAppointmentApplianceReady;
		}
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		}
		}
}
function RemoveAddedAppliance(id){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/RemoveAddedAppliance.asp";
		//var url="showcompleted.asp";
		url=url+"?ID="+id;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=AddAppointmentApplianceReady;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function AddAppointmentApplianceReady(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<table border='0' cellpadding='5' cellspacing='0'>";
		var suggestion
		var currentrec
		TotalAppliances = recs;
		if(recs>0){
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0);
					list = list + "<tr>";
					list = list + "<td width='100'>"+currentrec.getAttribute("ApplianceBrand")+"</td>";
					list = list + "<td width='100'>"+currentrec.getAttribute("ApplianceType")+"</td>";
					list = list + "<td width='100'>"+currentrec.getAttribute("ApplianceProblem")+"</td>";
					list = list + "<td><a href=\"javascript:RemoveAddedAppliance('"+currentrec.getAttribute("ApplianceID")+"')\">remove</a></td>";
					list = list + "</tr>";
			}
		list = list + "</table>";
		document.getElementById("AddedAppliances").innerHTML = list;
		document.getElementById("AddedAppliances").style.display = "block";
		//document.getElementById("SingleApplianceGroup").style.display="none";
//		$('#InputGroup2').fadeIn(500, function(){})
//		$('#SingleApplianceGroup').fadeOut(500, function(){})
//		$('#AddAnotherApplianceButton').fadeIn(500, function(){})
		}else{
		document.getElementById("AddedAppliances").style.display = "none";
//		$('#InputGroup2').fadeIn(500, function(){})
//		$('#SingleApplianceGroup').fadeIn(500, function(){})
//		$('#AddAnotherApplianceButton').fadeOut(500, function(){})
		}
		document.getElementById("AddAnotherAppliance").innerHTML = "<a href=\"javascript:AddAppointmentAppliance('1');\">+ add another appliance</a>";
		
	//	document.getElementById("AddApplianceButton").innerHTML = "<div class='appointmentaddbutton' onclick=\"javascript:AddAppointmentAppliance('2');\">Continue</div>";
		document.getElementById("ApplianceType").selectedIndex=0;
		document.getElementById("ApplianceBrandSet").innerHTML = "<div class=\"invalid1\" id=\"invalid_brand\">*required</div><select name=\"ApplianceBrand\" id=\"ApplianceBrand\" type=\"text\" ></select><label for=\"ApplianceBrand\">Brand:</label>";
		document.getElementById("ApplianceProblemSet").innerHTML = "<select name=\"ApplianceProblem\" id=\"ApplianceProblem\" type=\"text\" ></select><label for=\"ApplianceProblem\">Problem:</label>";
		document.getElementById("ApplianceModel").value = "optional";
		document.getElementById("ApplianceSerial").value = "optional";
		document.getElementById("ApplianceProblemDescSet").style.display = "none";
		document.getElementById("ApplianceProblemDesc").value = "";
	}
}
function AddAppointmentApplianceReady2(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		var list = "<table border='0' cellpadding='5' cellspacing='0'>";
		var suggestion
		var currentrec
		if(recs>0){
			for(i=1;i<=recs;i++){
					currentrec = xmlDoc.getElementsByTagName("record"+i).item(0);
					list = list + "<tr>";
					list = list + "<td width='100'>"+currentrec.getAttribute("ApplianceBrand")+"</td>";
					list = list + "<td width='100'>"+currentrec.getAttribute("ApplianceType")+"</td>";
					list = list + "<td width='100'>"+currentrec.getAttribute("ApplianceProblem")+"</td>";
					list = list + "<td><a href=\"javascript:RemoveAddedAppliance('"+currentrec.getAttribute("ApplianceID")+"')\">remove</a></td>";
					list = list + "</tr>";
			}
		list = list + "</table>";
		document.getElementById("AddedAppliances").innerHTML = list;
		document.getElementById("AddedAppliances").style.display = "block";
		//document.getElementById("SingleApplianceGroup").style.display="none";
		$('#InputGroup2').fadeIn(500, function(){})
//		$('#SingleApplianceGroup').fadeOut(500, function(){})
//		$('#AddAnotherApplianceButton').fadeIn(500, function(){})
		}else{
		document.getElementById("AddedAppliances").style.display = "none";
		$('#InputGroup2').fadeIn(500, function(){})
		$('#SingleApplianceGroup').fadeIn(500, function(){})
		$('#AddAnotherApplianceButton').fadeOut(500, function(){})
		}
		document.getElementById("AddAnotherAppliance").innerHTML = "<a href=\"javascript:AddAppointmentAppliance('2');\">+ add another appliance</a>";
		
		document.getElementById("AddApplianceButton").innerHTML = "<div class='appointmentaddbutton' onclick=\"javascript:AddAppointmentAppliance('2');\">Continue</div>";
		document.getElementById("ApplianceType").selectedIndex=0;
		document.getElementById("ApplianceBrandSet").innerHTML = "<div class=\"invalid1\" id=\"invalid_brand\">*required</div><select name=\"ApplianceBrand\" id=\"ApplianceBrand\" type=\"text\" ></select><label for=\"ApplianceBrand\">Brand:</label>";
		document.getElementById("ApplianceProblemSet").innerHTML = "<select name=\"ApplianceProblem\" id=\"ApplianceProblem\" type=\"text\" ></select><label for=\"ApplianceProblem\">Problem:</label>";
		document.getElementById("ApplianceModel").value = "";
		document.getElementById("ApplianceSerial").value = "";
		document.getElementById("ApplianceProblemDescSet").style.display = "none";
		document.getElementById("ApplianceProblemDesc").value = "";
		HideInputGroup('InputGroup1','InputGroup2')
	}
}
function moreproblemdetails(){
	document.getElementById("ApplianceProblemDescSet").style.display = "block";
}
function AppointmentContinue1(){
}
function AppointmentContinue2(){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/AJAX/AppointmentStep2.asp";
		//var url="showcompleted.asp";
		url=url+"?DateRequest="+document.getElementById("ServiceDate").value;
		url=url+"&TimeRequest="+document.getElementById("ServiceTime").value;
		url=url+"&Referral="+document.getElementById("Advert").value;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=AppointmentContinue2Finished;
		//alert(stateChanged);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}
function AppointmentContinue2Finished(){
	if (xmlHttp.readyState==4){
		var xmlDoc=xmlHttp.responseXML.documentElement;
		var recs = xmlDoc.getElementsByTagName("recs")[0].childNodes[0].nodeValue;
		HideInputGroup('InputGroup2','InputGroup3')
		//alert(recs+" recs submitted");
	}
}
function AppointmentFinish(){
		tf=true
	document.getElementById("invalid_homephone").style.display = "none";
	document.getElementById("invalid_firstname").style.display = "none";
	document.getElementById("invalid_lastname").style.display = "none";
	document.getElementById("invalid_address").style.display = "none";
	document.getElementById("invalid_city").style.display = "none";
	document.getElementById("invalid_state").style.display = "none";
	document.getElementById("invalid_zipcode").style.display = "none";
	hphone=document.getElementById("billing_homephone").value;
	fname=document.getElementById("billing_firstname").value;
	lname=document.getElementById("billing_lastname").value;
	address=document.getElementById("billing_address").value;
	city=document.getElementById("billing_city").value;
	state=document.getElementById("billing_state").value;
	zip=document.getElementById("billing_zipcode").value;
	if(hphone==""){
		tf=false;
		document.getElementById("invalid_homephone").style.display = "block";
	}
	if(fname==""){
		tf=false;
		document.getElementById("invalid_firstname").style.display = "block";
	}
	if(lname==""){
		tf=false;
		document.getElementById("invalid_lastname").style.display = "block";
	}
	if(address==""){
		tf=false;
		document.getElementById("invalid_address").style.display = "block";
	}
	if(city==""){
		tf=false;
		document.getElementById("invalid_city").style.display = "block";
	}
	if(state==""){
		tf=false;
		document.getElementById("invalid_state").style.display = "block";
	}
	if(zip==""){
		tf=false;
		document.getElementById("invalid_zipcode").style.display = "block";
	}

	if (!document.getElementById("confirmation").checked){
		tf=false;
		document.getElementById("InvalidCheckbox").style.display = "block";
		document.getElementById("confirmationcheckbox").style.border = "thin solid #F00";
	}
	if(tf!=false){
		document.getElementById("AppointmentForm").submit();
	}
	
}
function ContactClick(){
			$("html:not(:animated),body:not(:animated)").animate({
																 scrollTop:'570'
																 }, 500)
				$('#PageArea').animate({
								   minHeight:'850'
								   },500)

								 $('#ContactBox').animate({
														  height:'480'
														  }, 2000, function(){});
					   
}
function ContactExtend(){

				$('#PageArea').animate({
								   minHeight:'880'
								   },500)

				$('#ContactBox').animate({
										  height:'480'
										  }, 500, function(){});

}
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
function FocusInput(id){
	var divid = document.getElementById(id);
	if(divid.value=="optional"){
		divid.style.color = "black";
		divid.value="";
	}
}
function BlurInput(id){
	divid = document.getElementById(id)
	if(divid.value==""){
		divid.style.color = "#999";
		divid.value="optional";
	}
}

