
var hi_cats = [
	[60,"Additions and Remodels"],
	[61,"Appraisers and Home Inspectors"],
	[62,"Architects"],
	[63,"Bathroom Remodeling"],
	[64,"Cabinets and Countertops"],
	[65,"Carpentry"],
	[66,"Carpet"],
	[67,"Cleaning"],
	[68,"Concrete and Masonry"],
	[69,"Custom Homes"],
	[70,"Decks and Porches"],
	[71,"Decorators and Designers"],
	[72,"Doors"],
	[73,"Drywall"],
	[74,"Electrical"],
	[75,"Engineers"],
	[76,"Fences"],
	[77,"Flooring"],
	[78,"Foundations"],
	[79,"Garage Doors"],
	[80,"Handyman"],
	[97,"Home Security"],
	[81,"HVAC"],
	[82,"Kitchen Remodeling"],
	[83,"Landscaping"],
	[84,"Moving"],
	[85,"Painting"],
	[86,"Pest Control"],
	[87,"Plumbing"],
	[88,"Roofing"],
	[89,"Siding"],
	[90,"Small Projects and Repairs"],
	[91,"Solar Energy"],
	[92,"Sunrooms"],
	[93,"Swimming Pools"],
	[94,"Tile Work"],
	[95,"Walls"],
	[96,"Windows"]
];

var hi_tasks = [
	[60,"Additions - Closet"],
	[60,"Additions - Garage"],
	[60,"Additions - To Existing Structure"],
	[60,"Remodel - Accommodate a Disability"],
	[60,"Remodel - Basement"],
	[60,"Remodel - Garage"],
	[60,"Remodel - Multiple Rooms"],
	[60,"Other"],
	[61,"Appraisers - Real Estate"],
	[61,"Inspection - General Home"],
	[61,"Inspection - Roofing"],
	[61,"Other"],
	[64,"Cabinets - Custom Build"],
	[64,"Cabinets - Install"],
	[64,"Cabinets - Reface"],
	[64,"Cabinets - Refinish"],
	[64,"Countertops - Install Stone"],
	[64,"Other"],
	[65,"Built-In Furniture - Construct"],
	[65,"Exterior Trim - Install"],
	[65,"Framing - Install"],
	[65,"Interior Trim & Moldings - Install"],
	[65,"Other"],
	[66,"Carpet Cleaning"],
	[66,"Install Carpets"],
	[66,"Other"],
	[67,"Building Site - Preparation and Clearing"],
	[67,"Cleaning - Exterior"],
	[67,"Cleaning - Interior"],
	[67,"Toxicity and Mold Removal"],
	[67,"Other"],
	[68,"Brick and Stone Patios, Walks & Steps"],
	[68,"Driveways & Floors - Install"],
	[68,"Driveways & Floors - Install Interlocking Paving"],
	[68,"Patios, Walks & Steps - Install Interlocking Paving"],
	[68,"Stamped Concrete - Install"],
	[68,"Other"],
	[70,"Build or Replace"],
	[70,"Repair"],
	[71,"Designer - Bathroom"],
	[71,"Designer - Building"],
	[71,"Designer - Interior Lighting Plan"],
	[71,"Designer - Kitchen"],
	[71,"Designer - Landscape"],
	[71,"Designer - Residential"],
	[71,"Interior Decorator"],
	[71,"Stage a Home"],
	[71,"Other"],
	[72,"Install Exterior Doors"],
	[72,"Install Interior Doors"],
	[72,"Install Sliding Door(s)"],
	[73,"Install Drywall"],
	[73,"Repair Drywall"],
	[74,"Electrical Wiring or Panel Upgrade"],
	[74,"Install a Generator"],
	[74,"Install Electrical for Home Addition or Remodel"],
	[74,"Install Home Automation System"],
	[74,"Install Home Theater Surround Sound"],
	[74,"Install Home Theater System or Media Center"],
	[74,"Install Home Theater Wiring"],
	[74,"Other"],
	[76,"Install Aluminum or Steel Fence"],
	[76,"Install Wood Fence"],
	[76,"Repair Wood Fence"],
	[76,"Other"],
	[77,"Install Simulated Wood or Stone Laminate Flooring"],
	[77,"Install Wood Flooring"],
	[77,"Refinish Wood Flooring"],
	[77,"Other"],
	[78,"Concrete Foundation - Repair"],
	[81,"Install Central A/C"],
	[81,"Install Gas or Electric Boiler or Radiator"],
	[81,"Install Gas or Electric Furnace"],
	[81,"Install Heat Pump"],
	[81,"Install Oil Boiler or Radiator"],
	[81,"Install Oil Furnace"],
	[81,"Install Swamp Cooler"],
	[81,"Other"],
	[83,"Foundation Drainage Install"],
	[83,"Fountain or Waterfall Install"],
	[83,"Gazebo or Freestanding Porch - Build or Install"],
	[83,"Greenhouse or Conservatorium - Build"],
	[83,"Landscaping for Yard or Garden"],
	[83,"Pond Install"],
	[83,"Retaining Walls Over 3 ft"],
	[83,"Retaining Walls Under 3 ft"],
	[83,"Other"],
	[84,"Professional Moving Service - Long Distance / Out of State"],
	[84,"Other"],
	[85,"Exterior Painting"],
	[85,"Interior Painting"],
	[85,"Specialty Painting - Faux Finishes"],
	[85,"Specialty Painting - Textures"],
	[85,"Other"],
	[87,"Install a Water Heater"],
	[87,"Install or Replace a Sewer Main"],
	[87,"Install or Replace a Water Main"],
	[87,"Install Plumbing for an Addition or Remodel"],
	[87,"Plumbing Repair"],
	[87,"Other"],
	[88,"Install Asphalt Shingle Roofing"],
	[88,"Install Flat, Foam, or Single Ply Roofing"],
	[88,"Install Gutters"],
	[88,"Install Metal Roofing"],
	[88,"Install Natural Slate Roofing"],
	[88,"Install Traditional Tile Roofing"],
	[88,"Install Wood or Composite Roofing"],
	[88,"Roofing Repair"],
	[88,"Other"],
	[89,"Install Brick or Stone Siding"],
	[89,"Install Metal Siding"],
	[89,"Install Stucco Siding"],
	[89,"Install Vinyl Siding"],
	[89,"Install Wood or Fiber-Cement Siding"],
	[89,"Other"],
	[91,"Solar Electrical"],
	[91,"Solar Thermal"],
	[93,"Build or Install a Swimming Pool"],
	[93,"Remodel a Swimming Pool"],
	[93,"Other"],
	[94,"Install Ceramic & Porcelain Tile"],
	[94,"Install Natural Stone Tile"],
	[94,"Tile Repair"],
	[94,"Other"],
	[95,"Install Brick, Stone or Block Wall"],
	[95,"Install Plaster"],
	[95,"Other"],
	[96,"Install Multiple Windows"],
	[96,"Install One Window"],
	[96,"Install Storm Windows"],
	[96,"Window Cleaning"],
	[97,"Business Alarm or Security System - Install"],
	[97,"Residential Alarm or Security System - Install"],
	[97,"Residential Alarm or Security System - Monitor"],
	[97,"Surveillance Cameras - Install or Repair"],
	[97,"Other"]
];

function hi_fill_type(_tkfld, seltxt) {
	if (_tkfld==null || _tkfld.type.toLowerCase().indexOf("select")!=0)
		return;
	if (_tkfld.options.length)
		_tkfld.options.length=0;
	_tkfld.options[_tkfld.options.length] = new Option("Select Project", "");
	for (var x=0;x<hi_cats.length;x++) {
		var s01 = hi_cats[x][1];
		_tkfld.options[_tkfld.options.length] = new Option(s01, hi_cats[x][0]);
		if (trim(seltxt.toLowerCase().replace("&","and").replace(" ","").replace("-","")) == trim(hi_cats[x][1].toLowerCase().replace("&","and").replace(" ","").replace("-","")))
			_tkfld.selectedIndex=_tkfld.options.length-1;
	}
}

function hi_fill_task(_ofld, _tkfld, seltxt) {
	if (_ofld==null || _tkfld==null || _tkfld.type.toLowerCase().indexOf("select")!=0)
		return;
	var val = parseInt(_ofld.value);
	if (_tkfld.options.length)
		_tkfld.options.length=0;
	_tkfld.options[_tkfld.options.length] = new Option("Select Task", "");
	_tkfld.style.visibility ="hidden";
	for (var x=0;x<hi_tasks.length;x++) {
		if (hi_tasks[x][0]== val){
			var s01 = hi_tasks[x][1];
			_tkfld.options[_tkfld.options.length] = new Option(s01, hi_tasks[x][0]);
			if (trim(seltxt.toLowerCase().replace("&","and").replace(" ","").replace("-","")) == trim(hi_tasks[x][1].toLowerCase().replace("&","and").replace(" ","").replace("-","")))
				_tkfld.selectedIndex=_tkfld.options.length-1;
		}
	}
	if (_tkfld.options.length > 1)
	_tkfld.style.visibility ="visible";
}

function call_hiddentypetask_load(_typefld, _taskfld, _hdtype, _hdtask, _loadtype){
	var _type="";
	var _task="";
	if (_typefld)	_type = trim(_typefld.value);
	if (_type.length >0){
		_hdtype.value="";
		var flag; var matchfield ="";
		if (!isNaN(_type)){matchfield =_type; flag = true;}
		else{matchfield = trim(_type.toLowerCase().replace("&","and").replace("-",""));	flag = false;}

		for (var x=0;x<hi_cats.length;x++) {
			var matcharray ="";
			if (flag)
				matcharray =hi_cats[x][0];
			else
				matcharray = trim(hi_cats[x][1].toLowerCase().replace("&","and").replace("-",""));
			if (matcharray==matchfield){
				_hdtype.value= hi_cats[x][0];
				if (_loadtype =="on")
					document.getElementById('m_type').innerHTML=hi_cats[x][1];
				break;
			}
		}
	}

	if (_taskfld){
		if (_taskfld.options.length > 0)
			_task =_taskfld.options[_taskfld.selectedIndex].text;
		else
			_hdtask.value="";
		if (_task.toLowerCase().indexOf("select")==0){
			_task ="";
			_hdtask.value="";
		}
	}

	var _htype ="";
	if (_hdtype) _htype = trim(_hdtype.value);
	if (_task.length >0 && _htype.length > 0){
		_hdtask.value="";
		for (var x=0;x<hi_tasks.length;x++) {
			var _taskv = hi_tasks[x][0];
			var _taskn = hi_tasks[x][1];
			if ((_htype==_taskv) && (trim(_taskn.toLowerCase().replace("&","and").replace(" ","").replace("-",""))==trim(_task.toLowerCase().replace("&","and").replace(" ","").replace("-",""))) ){
				_hdtask.value= _taskn;
				break;
			}
		}
	}
}

function call_hi_type_load(_h,_f, ddl){
	var dyntask ="";
	var matchCat="";
	if (_f)	dyntask = trim(_f.value);
	if (dyntask.length>0){
		if (_f){
			var ddltask = ddl;
			for (i = 0; i < ddltask.length; i++) {
				matchCat=trim(ddltask.options[i].text).toLowerCase().replace("&","and").replace(" ","").replace("-","");
				if (matchCat.indexOf(dyntask.toLowerCase().replace("&","and").replace(" ","").replace("-",""))>=0){
					_h.value= ddltask.options[i].value;
					document.getElementById('m_type').innerHTML=ddltask.options[i].text;
					break;
				}
			}
		}
	}
}

function call_hi_task_load(_h,_f, ddl){
	var dyntask ="";
	var matchCat="";
	if (_f)	dyntask = trim(_f.value);
	if (dyntask.length>0){
		if (_f){
			var ddltask = ddl;
			for (i = 0; i < ddltask.length; i++) {
				matchCat=trim(ddltask.options[i].text).toLowerCase().replace("&","and").replace(" ","").replace("-","");
				if (matchCat.indexOf(dyntask.toLowerCase().replace("&","and").replace(" ","").replace("-",""))>=0){
					_h.value= ddltask.options[i].text;
					break;
				}
			}
		}
	}
}

function ddl_sync_load_type(_ofld, _tkfld, _htype){
	if (_ofld.options.length > 0){
		_tkfld.selectedIndex=_ofld.selectedIndex;
		_htype.value =_ofld.options[_ofld.selectedIndex].value;
	}
}

function ddl_sync_load_task(_tkfld1, _tkfld2, _tyfld2, _htype, _htask){
	if (_htype.value!=null && _htype.value!=""){
		if (_tkfld1.options.length > 1){
			_htask.value =_tkfld1.options[_tkfld1.selectedIndex].text;
		}
		if (_tyfld2.options.length > 0){
			if (_htype.value ==_tyfld2.options[_tyfld2.selectedIndex].value){
				if (_tkfld1.options.length > 0 && _tkfld2.options.length > 0)
				_tkfld2.selectedIndex=_tkfld1.selectedIndex;
			}
		}
	}
}

function call_hi_task_load2(seltxt, ddl){
	if (ddl.length>0){
		for (i = 0; i < ddl.length; i++) {
			if (trim(seltxt.toLowerCase().replace("&","").replace(" ","").replace("-","")) ==
				trim(ddl.options[i].text).toLowerCase().replace("&","").replace(" ","").replace("-","")){
				ddl.selectedIndex=i;
				break;
			}
		}
	}
}


//* delete this methods and use from hi_val.js
function validateForm_homeImp1(form) {
	var empty ="";
	var zip1="";
	var zc_citystate="";
	var d_t_zip;
	var error="";

	if (isvalidobject(document.forms[0].typedd1)) {
		if (document.forms[0].typedd1.options.length > 0){
			if (document.forms[0].typedd1.options[document.forms[0].typedd1.selectedIndex].value==""){
				alert("Please select a Project.");
				document.forms[0].typedd1.focus();
				return false;
			}
		}
	}
	if (isvalidobject(document.forms[0].taskdd1)) {
		if (document.forms[0].taskdd1.options.length > 1){
			if (document.forms[0].taskdd1.options[document.forms[0].taskdd1.selectedIndex].value==""){
				alert("Please select a Task.");
				document.forms[0].taskdd1.focus();
				return false;
			}
		}
	}

	if (isvalidobject(document.forms[0].zip1)) {
		zip1 = trim(document.forms[0].zip1.value);
	}
	if (isvalidobject(document.forms[0].citystate_combo)){
		zc_citystate=document.forms[0].citystate_combo.value;
	}
	
	if (zip1+""=="" && zc_citystate+""==""){
		error="Please enter a valid Zipcode";
		if (isvalidobject(document.getElementById('d_t_zip'))){
			if (document.getElementById('d_t_zip').style.visibility=="visible")
			error ="Please enter a valid Zipcode OR City, State";
		}
		alert(error);
		document.forms[0].zip1.focus();
		return false;
	}
	if (zip1+""!=""){
		if (!isvalidzip(zip1)){
		  alert("Please enter a valid Zipcode.");
		  document.forms[0].zip1.focus();
		  return false;
		}
	}

	if (isvalidobject(document.forms[0].type)) 
		document.forms[0].type.value=empty;
	if (isvalidobject(document.forms[0].task)) 
		document.forms[0].task.value=empty;
	if (isvalidobject(document.forms[0].zip)) 
		document.forms[0].zip.value=empty;

	if (isvalidobject(document.forms[0].hdtype1)) {
		if (document.forms[0].hdtype1.value !="" || document.forms[0].hdtype1.value !=null)
			document.forms[0].type.value = document.forms[0].hdtype1.value;
	}
	
	if (isvalidobject(document.forms[0].hdtask1)) {
		if (document.forms[0].hdtask1.value !="" || document.forms[0].hdtask1.value !=null)
			document.forms[0].task.value = document.forms[0].hdtask1.value;
	}

	if (zip1!="" && zip1 !=null) 
		document.forms[0].zip.value = zip1;
	
	if (window.FL_submit_clicked) {
		FL_submit_clicked();
		return false;
	} else {
		return true;
	}
}

function validateForm_homeImp2(form) {
	var empty ="";
	if (isvalidobject(document.forms[0].typedd2)) {
		if (document.forms[0].typedd2.options.length > 0){
			if (document.forms[0].typedd2.options[document.forms[0].typedd2.selectedIndex].value==""){
				alert("Please select a Project.");
				document.forms[0].typedd2.focus();
				return false;
			}
		}
	}
	if (isvalidobject(document.forms[0].taskdd2)) {
		if (document.forms[0].taskdd2.options.length > 1){
			if (document.forms[0].taskdd2.options[document.forms[0].taskdd2.selectedIndex].value==""){
				alert("Please select a Task.");
				document.forms[0].taskdd2.focus();
				return false;
			}
		}
	}
	var zip2;
	if (isvalidobject(document.forms[0].zip2)) {
		zip2 = trim(document.forms[0].zip2.value);
	}
	if (!isvalidzip(zip2)){
	  alert("Please enter a valid Zipcode.");
	  document.forms[0].zip2.focus();
	  return false;
	}

	if (isvalidobject(document.forms[0].type)) 
		document.forms[0].type.value=empty;
	if (isvalidobject(document.forms[0].task)) 
		document.forms[0].task.value=empty;
	if (isvalidobject(document.forms[0].zip)) 
		document.forms[0].zip.value=empty;

	if (isvalidobject(document.forms[0].typedd2))
		document.forms[0].type.value =document.forms[0].typedd2.options[document.forms[0].typedd2.selectedIndex].value;
	if (isvalidobject(document.forms[0].taskdd2)){
		if (document.forms[0].taskdd2.options.length > 1)
		document.forms[0].task.value = document.forms[0].taskdd2.options[document.forms[0].taskdd2.selectedIndex].text;
	}
	if (zip2!="" && zip2 !=null) document.forms[0].zip.value = zip2;
	
    if (window.FL_submit_clicked) {
		FL_submit_clicked();
		return false;
	} else {
		return true;
	}
}

function validateForm_homeImp3(form) {
	if (isvalidobject(document.forms[0].task)) {
		if (document.forms[0].task.options[document.forms[0].task.selectedIndex].value==""){
			alert("Please select a Task.");
			document.forms[0].task.focus();
			return false;
		}
	}

	if (isvalidobject(document.forms[0].zip)) {
		if (!isvalidzip(document.forms[0].zip.value)){
		  alert("Please enter a valid Zipcode.");
		  document.forms[0].zip.focus();
		  return false;
		}
	}

    if (window.FL_submit_clicked) {
		FL_submit_clicked();
		return false;
	} else {
		return true;
	}
}

/* new function - delete above function when omniture test#88 is over*/
function HIOption_validateForm(form) {
	var z; var c; var option; var error="";
	option = true;
	if (isvalidobject(form.zip)) 
		z = trim(form.zip.value);
	if (isvalidobject(form.citystate_combo))
		c=form.citystate_combo.value;
	if (isvalidobject(form.task)){
		for (var i=0; i<form.task.length;i++){
			if (form.task[i].checked==true){
				option= false;
				break;
			}
		}
	}
	if (option)
		error = "Please choose your project.";
	else if (!isvalidzip(z) && c.length <=0)
		error = "Please enter a valid zip code.";
	if (error.length > 0){
		alert(error);
		return false;
	}
	
	if (z =="Enter Zip Code") form.zip.value="";
	if (window.FL_submit_clicked) {
		FL_submit_clicked();
		return false;
	} else {
		return true;
	}
}

function OptionGroup(form, index){
	if (!isvalidobject(form.task))	return;
	if (index+""!="") {
		form.task[index].checked=true;
		if (isvalidobject(document.getElementById('axBox')))
			document.getElementById('axBox').style.visibility="visible";
		for (var i=0; i<form.task.length;i++){
			var d; d= "x"+i;
			if (isvalidobject(document.getElementById(d))){
				if (i==index) document.getElementById(d).style.visibility="visible";
				else document.getElementById(d).style.visibility="hidden";
			}
		}
	}
	else {
		for (var i=1; i<form.task.length;i++){
			var d; d= "x"+i;
			if (isvalidobject(document.getElementById(d)))
			document.getElementById(d).style.visibility="hidden";
		}
	}
}
function OptionGroupDeSelect(form){
	if (!isvalidobject(form.task))	return;
	for (var i=0; i<form.task.length;i++){
		form.task[i].checked=false;
		var d; d= "x"+i;
		if (i<=0){
			if (isvalidobject(document.getElementById(d)))
			document.getElementById(d).style.visibility="visible";
		}
		else{
			if (isvalidobject(document.getElementById(d)))
			document.getElementById(d).style.visibility="hidden";
		}
	}
}

function display_zip_help() {
	if (isvalidobject(document.getElementById('d_t_zip'))){
		if (document.getElementById('d_t_zip').style.visibility=="hidden")
			document.getElementById('d_t_zip').style.visibility = "visible";
		else 
			document.getElementById('d_t_zip').style.visibility = "hidden";
    }
}
function jump_x() {
	if (isvalidobject(document.getElementById('d_t_zip'))){
		if (document.getElementById('d_t_zip').style.visibility=="visible")
			document.getElementById('d_t_zip').style.visibility = "hidden";
		else 
			document.getElementById('d_t_zip').style.visibility = "hidden";
    }

	document.getElementById('jpop').style.visibility="hidden";
	document.getElementById('overlay').style.display="none";
	OptionGroupDeSelect(document.forms[0]);
}

function _jumppop(){
	var _j = document.getElementById("jpop");
	_j.style.display = "block";
	_j.style.visibility = "visible";
	var _time = parseInt(document.body.scrollTop);
	if ( isNaN(_time) ) _time = 0;
	if ( _time == 0 ){
	var _time = parseInt(document.documentElement.scrollTop);
	if ( isNaN(_time) ) _time = 0;
	}
	_j.style.top = _time + 100 + "px";
	document.getElementById("overlay").style.display = "block";
	document.getElementById("overlay").style.visibility = "visible";
	_jtask.innerHTML="";
	for (var i=0; i<document.forms[0].task.length;i++){
	 if (document.forms[0].task[i].checked==true){
		_jtask.innerHTML= document.forms[0].task[i].value;
		break;
	 }
   }
}
function isvalidzip(s) {
	if (s.length > 5) 
		return false;
	var filter = /\d{5}(-?\d{4}){0,1}/;
	return filter.test(s);
}
function isvalidobject(objToTest) {
	if (objToTest == null || objToTest == undefined) 
		return false;
	else
		return true;
}
function trim(s) {
  return s.replace(/^\s+/, '').replace(/\s+$/, '');
}

