// home improvement --------------------------------
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_task(_ofld, _tkfld) {
	if (_ofld==null || _tkfld==null)
		return;
	var val = parseInt(_ofld.value);
	if (_tkfld.options.length)
		_tkfld.options.length=0;
	_tkfld.options[_tkfld.options.length] = new Option("--Select Task--", "");
	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]);
		}
	}
}

function call_hi_type_load(ddl, sel){
	if (ddl.options.length){
		for (var x=0;x<ddl.length;x++) {
			if (trim(sel) == trim(ddl.options[x].value)){
				ddl.options[x].selected = true;
				break;
			}
		}
	}
}

function set_filter_value(){
	if (!checkundefined(document.forms[0].ddlFilter)) return;
	document.forms[0].h_filter.value = "";
	var _ddlf = document.forms[0].ddlFilter;
	if (_ddlf.options.length){
		var _field = _ddlf.options[_ddlf.selectedIndex].text;
		if (trim(_field)!="--Select Task--")
		document.forms[0].h_filter.value = trim(_field);
	}
}

// autos-------------------------------------------------
function clear_auto_options(mk,md){  
	if (checkundefined(mk))
		if (mk.options.length)	mk.selectedIndex =0;
	if (checkundefined(md)){
		if (md.options.length)	md.options.length =0;
		md.options[md.options.length] = new Option("--Select Model--", "");
	}
}

// insurance ----------------------------------------------
function load_ins_options(){  
	if (!checkundefined(document.forms[0].drpInsurance)) return;
	document.getElementById('home_ins_opt').style.display = 'none';
	document.getElementById('auto_ins_opt').style.display = 'none';
	var _ddlins = document.forms[0].drpInsurance;
	if (_ddlins.options.length){
		var _v = _ddlins.options[_ddlins.selectedIndex].value;
		switch (_v){
		 case 'hi':
			document.getElementById('home_ins_opt').style.display = 'block';
			break;
		 case 'ai':
			document.getElementById('auto_ins_opt').style.display = 'block';
			break;
		}
	}
}

// Re-- insurance -------------
function load_reins_options(){ 
	if (!checkundefined(document.forms[0].drpRealEstate)) 
		return;
	document.getElementById('re_ins_opt').style.display = 'none';
	var _ddlRE = document.forms[0].drpRealEstate;
	if (_ddlRE.options.length){
		var _re = _ddlRE.options[_ddlRE.selectedIndex].value;
		if (_re=="hi")
			document.getElementById("re_ins_opt").style.display = 'block';
		else
			document.getElementById("re_ins_opt").style.display = 'none';
	}
}

// common ------------------------------------------------
function tab_loader(tbn, ldr) {

	if (tbn.length <= 0) return;
		document.getElementById('ld_home_tab').style.display = 'none';
		document.getElementById('ld_homeimp_tab').style.display = 'none';
		document.getElementById('ld_auto_tab').style.display = 'none';
		document.getElementById('ld_re_tab').style.display = 'none';
		document.getElementById('ld_loans_tab').style.display = 'none';
		document.getElementById('ld_insurance_tab').style.display = 'none';
		document.getElementById(tbn).style.display = 'block';
	
	if (ldr.length> 0){
	switch (tbn){
		case 'ld_homeimp_tab':
			if (checkundefined(document.forms[0].ddlCategory))
				call_hi_type_load(document.forms[0].ddlCategory, ldr);
			if (checkundefined(document.forms[0].ddlFilter))
				hi_fill_task(document.forms[0].ddlCategory,document.forms[0].ddlFilter);
			document.getElementById(0).style.display = 'none';
			for (var x=60;x<=97;x++){
				if (parseInt(ldr)==x)
					document.getElementById(x).style.display = 'block';
				else 
					document.getElementById(x).style.display = 'none';
			}
			break;
		case 'ld_auto_tab':
			if (checkundefined(document.forms[0].drpAutos)){
				var ddl = document.forms[0].drpAutos;
				if (ddl.options.length){
					for (var x=0;x<ddl.length;x++) {
						if (ldr == ddl.options[x].value){
							ddl.selectedIndex=x;
							break;
						}
					}
				}
			}
			break;
		case 'ld_re_tab':
			if (checkundefined(document.forms[0].drpRealEstate)){
				var ddl = document.forms[0].drpRealEstate;
				if (ddl.options.length){
					for (var x=0;x<ddl.length;x++) {
						if (ldr == ddl.options[x].value){
							ddl.selectedIndex=x;
							break;
						}
					}
				}
			}
			break;
		case 'ld_loans_tab':
			if (checkundefined(document.forms[0].drpLoans)){
				var ddl = document.forms[0].drpLoans;
				if (ddl.options.length){
					for (var x=0;x<ddl.length;x++) {
						if (ldr == ddl.options[x].value){
							ddl.selectedIndex=x;
							break;
						}
					}
				}
			}
			break;
		case 'ld_insurance_tab':
			if (checkundefined(document.forms[0].drpInsurance)){
				var ddl = document.forms[0].drpInsurance;
				if (ddl.options.length){
					for (var x=0;x<ddl.length;x++) {
						if (ldr == ddl.options[x].value){
							ddl.selectedIndex=x;
							break;
						}
					}
				}
			}
			load_ins_options();
			break;
		}
	}
 }

function hi_type_ldr(){
	if (checkundefined(document.forms[0].drpCategory))
		hi_fill_type(document.forms[0].drpCategory);
}

function checkundefined(objToTest) {
	if (objToTest == null || objToTest == undefined) {
		return false;
	}
	return true;
}

function trim(s) {
  return s.replace(/^\s+/, '').replace(/\s+$/, '');
}

