var XMLData;
function getFloorplanList(url){		
	//XMLHttpRequest
	XMLData = false;
	if(window.XMLHttpRequest) {
		// native XMLHttpRequest object
		try {
			XMLData = new XMLHttpRequest();
		} catch(e) {
			XMLData = false;
		}
	} else if(window.ActiveXObject) {
		// IE/Windows ActiveX version
		try {
			XMLData = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				XMLData = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				XMLData = false;
			}
		}
	}
	if(XMLData) {
		if (XMLData.overrideMimeType) {
			XMLData.overrideMimeType('text/xml');
		}		
		XMLData.onreadystatechange = handleGetXML;
		XMLData.open("GET", url, true);
		XMLData.send(null);
		return true;
	}
	else{
		//reload search
	}
}

function handleGetXML(){
    if (XMLData.readyState == 4) {// only if xmlhttp shows "loaded"
        if (XMLData.status == 200) {// only if "OK"
			var rootElement = XMLData.responseXML.documentElement;
			//get list
			floorplanList = new Array();
			var f_nodes = rootElement.getElementsByTagName("PlanFeaturesXML");
			var count = 0;
			for (var i=0; i < f_nodes.length; i++){
				//floorplans
				try{
					floorplanList[count] = new Array();
					floorplanList[count][0] = 0;
					floorplanList[count][1] = "floorPlans.do?planCode=";
					floorplanList[count][1] +=getXMLNodeValue(f_nodes[i],"PlfPlanName");
					floorplanList[count][1] += "&arId=";
					floorplanList[count][1] +=getXMLNodeValue(f_nodes[i],"PlfArId");
					floorplanList[count][2] = getXMLNodeValue(f_nodes[i],"PlfPlanMktName");
					floorplanList[count][3] = "";
					floorplanList[count][4] = getXMLNodeValue(f_nodes[i],"PlfPriceMin_str2");
					floorplanList[count][5] = getXMLNodeValue(f_nodes[i],"PlfPriceMax_str2");
					floorplanList[count][6] = getXMLNodeValue(f_nodes[i],"PlfSqftMin");
					floorplanList[count][7] = getXMLNodeValue(f_nodes[i],"PlfSqftMax");
					floorplanList[count][8] = getXMLNodeValue(f_nodes[i],"PlfBedroomMin");
					floorplanList[count][9] = getXMLNodeValue(f_nodes[i],"PlfBedroomMax");
					floorplanList[count][10] = getXMLNodeValue(f_nodes[i],"PlfFullBathMin");
					floorplanList[count][11] = getXMLNodeValue(f_nodes[i],"PlfFullBathMax");
					floorplanList[count][12] = getXMLNodeValue(f_nodes[i],"PlfHalfBathMin");
					floorplanList[count][13] = getXMLNodeValue(f_nodes[i],"PlfHalfBathMax");
					floorplanList[count][14] = getXMLNodeValue(f_nodes[i],"PlfGarageCarMin");
					floorplanList[count][15] = getXMLNodeValue(f_nodes[i],"PlfGarageCarMax");
					floorplanList[count][16] = getXMLNodeValue(f_nodes[i],"PlfFfOwnerSuiteMin");
					floorplanList[count][16] = (floorplanList[count][16] > 0)?('Y'):(false);
					floorplanList[count][16] = (floorplanList[count][16])?(floorplanList[count][16]):(getXMLNodeValue(f_nodes[i],"PlfFfOwnerSuiteMax"));
					floorplanList[count][16] = (floorplanList[count][16] > 0)?('(Y)'):('N');
					floorplanList[count][17] = getXMLNodeValue(f_nodes[i],"PlfFirstFloorGuestMin");
					floorplanList[count][17] = (floorplanList[count][17] > 0)?('Y'):(false);
					floorplanList[count][17] = (floorplanList[count][17])?(floorplanList[count][17]):(getXMLNodeValue(f_nodes[i],"PlfFirstFloorGuestMax"));
					floorplanList[count][17] = (floorplanList[count][17] > 0)?('(Y)'):('N');
					floorplanList[count][18] = getXMLNodeValue(f_nodes[i],"PlfLivingAreaMin");
					floorplanList[count][19] = getXMLNodeValue(f_nodes[i],"PlfDiningAreaMin");
					floorplanList[count][20] = getXMLNodeValue(f_nodes[i],"PlfIsRanch");
					floorplanList[count][20] = (floorplanList[count][20] > 0)?(floorplanList[count][20]):2;
							   var brmin = getXMLNodeValue(f_nodes[i],"PlfBonusRoomMin");
							   var brmax = getXMLNodeValue(f_nodes[i],"PlfBonusRoomMax");
							   var mrmin = getXMLNodeValue(f_nodes[i],"PlfMediaRoomMin");
							   var mrmax = getXMLNodeValue(f_nodes[i],"PlfMediaRoomMax");
							   var srmin = getXMLNodeValue(f_nodes[i],"PlfStudyMin");
							   var srmax = getXMLNodeValue(f_nodes[i],"PlfStudyMax");
					
					var includes = "";
					includes += (Number(brmin))?("Bonus Room,"):("");
					includes += (Number(mrmin))?("Media Room,"):("");
					includes += (Number(srmin))?("Library/Study"):("");
					var option = "";
					option += (Number(brmax))?("Bonus Room,"):("");
					option += (Number(mrmax))?("Media Room,"):("");
					option += (Number(srmax))?("Library/Study"):("");
					floorplanList[count][21] = includes;
					floorplanList[count][22] = option;
					floorplanList[count][23] = "";
					floorplanList[count][24] = "";
					floorplanList[count][25] = "";
					floorplanList[count][26] = getXMLNodeValue(f_nodes[i],"PlanTypeList");
					floorplanList[count][27] = getXMLNodeValue(f_nodes[i],"CmuList").split(',');
					count++;
					
					var p_nodes = f_nodes[i].getElementsByTagName("ProductListXML");
					for (var j=0; j<p_nodes.length; j++){
						//products
						try{
							floorplanList[count] = new Array();
							floorplanList[count][0] = 1;
							floorplanList[count][1] = "markethome.do?jobNumber=";
							floorplanList[count][1] += getXMLNodeValue(p_nodes[j],"PrlJobNumber");
							floorplanList[count][2] = getXMLNodeValue(p_nodes[j],"PrlPlanMktName");
										var addr	= getXMLNodeValue(p_nodes[j],"PrlAddress");
										var state	= getXMLNodeValue(p_nodes[j],"PrlStCode");
										var city	= getXMLNodeValue(p_nodes[j],"PrlCityName");
										var zip		= getXMLNodeValue(p_nodes[j],"PrlZip");
							floorplanList[count][3] = addr+" "+city+", "+state+" "+ zip;
							floorplanList[count][4] = "$"+getXMLNodeValue(p_nodes[j],"PrlPriceLow");
							floorplanList[count][5] = floorplanList[count][4];
							floorplanList[count][6] = getXMLNodeValue(p_nodes[j],"PrlSqftLow");
							floorplanList[count][7] = floorplanList[count][6];
							floorplanList[count][8] = getXMLNodeValue(p_nodes[j],"PrlBedroomS");
							floorplanList[count][9] = floorplanList[count][8];
							floorplanList[count][10] = getXMLNodeValue(p_nodes[j],"PrlFullBathS");
							floorplanList[count][11] = floorplanList[count][10];
							floorplanList[count][12] = getXMLNodeValue(p_nodes[j],"PrlHalfBathS");
							floorplanList[count][13] = floorplanList[count][12];
							floorplanList[count][14] = getXMLNodeValue(p_nodes[j],"PrlGarageCarS");
							floorplanList[count][15] = floorplanList[count][14];
							floorplanList[count][16] = getXMLNodeValue(p_nodes[j],"PrlFfOwnerSuiteS");
							floorplanList[count][16] = (floorplanList[count][16] > 0)?('Y'):('N');
							
							floorplanList[count][17] = getXMLNodeValue(p_nodes[j],"PrlFirstFloorGuestS");
							floorplanList[count][17] = (floorplanList[count][17] > 0)?('Y'):('N');
							floorplanList[count][18] = getXMLNodeValue(p_nodes[j],"PrlLivingRoomS");
							floorplanList[count][19] = getXMLNodeValue(p_nodes[j],"PrlDiningRoomS");
							floorplanList[count][20] = getXMLNodeValue(p_nodes[j],"PrlIsRanch");
							floorplanList[count][20] = (floorplanList[count][20] > 0)?(floorplanList[count][20]):2;
									   var fll   = getXMLNodeValue(p_nodes[j],"PrlFinishedLowerS");
									   var brmin = getXMLNodeValue(p_nodes[j],"PrlBonusRoomS");
									   var mrmin = getXMLNodeValue(p_nodes[j],"PrlMediaRoomS");
									   var srmin = getXMLNodeValue(p_nodes[j],"PrlStudyS");
							var includes = "";
							includes += (fll)?("Finished Lower Level, "):("");
							includes += (brmin)?("Bonus Room, "):("");
							includes += (mrmin)?("Media Room, "):("");
							includes += (srmin)?("Library/Study"):("");
							includes.replace(/^(.*),$/,"");
							floorplanList[count][21] = includes;
							floorplanList[count][22] = "";
							floorplanList[count][23] = getXMLNodeValue(p_nodes[j],"PrlMoveInDate");
							floorplanList[count][24] = getXMLNodeValue(p_nodes[j],"PrlCmuName");
							floorplanList[count][25] = getXMLNodeValue(p_nodes[j],"PrlNbName");
							floorplanList[count][26] = getXMLNodeValue(p_nodes[j],"PrlPlanType");
							floorplanList[count][27] = getXMLNodeValue(p_nodes[j],"PrlCmuCode").split(',');
							count++;
						}
						catch(e){
							handleFloorplanListError();
						}
					}
					handleFloorplanListParse();
				}
				catch(e){
					//alert(e);
					handleFloorplanListError();
				}
			}
        } else {
			//handle error
			handleFloorplanListError();
	   	}
    }
}

function outputArray(arr){
	var output = "";
	for (var i=0; i<arr.length; i++){
		output += "floorplanList["+i+"] = [<br/>";
		for (var j=0; j<27; j++){
			output += "\""+arr[i][j]+"\",<br/>";
		}
		output += "\""+arr[i][27]+"\"];";
		output += "<br/><br/>";
	}
	var op = document.createElement("div");
	op.innerHTML = output;
	document.body.appendChild(op);
}
