/* This implementation of the XMLHttpRequest object is taken from digg.com */
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	} catch (E) {
		xmlhttp=false
	}
}
@else
	xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false
	}
}
function myXMLHttpRequest() {
	var xmlhttplocal;
	try {
		xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
			xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
		} catch (E) {
			xmlhttplocal=false;
		}
	}

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
		try {
			var xmlhttplocal = new XMLHttpRequest();
		} catch (e) {
			var xmlhttplocal=false;
			alert('couldn\'t create xmlhttp object');
		}
	}
	return(xmlhttplocal);
}

/* The variable http will hold our new XMLHttpRequest object. */
var xmlhttp = myXMLHttpRequest(); 

/* Function called to get the product categories list */
function secondaryDrivers(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/secondaryDrivers.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
	xmlhttp.onreadystatechange = handleDrivers; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleDrivers(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = "";
		var counted = document.getElementById('secondaryDriversSelect').value;
		
		/* LOOK BACK HERE FOR JAVASCRIPT INCLUDES.
		SEE HOW I DID THAT THING BELOW "response = response + ..."
		YEAH, THAT, REMEMBER THAT.*/
		for(i=0;i<counted;i++){
	   	//	var selectname = "additionalPriorCoverage" + String(i);
	   		
		//	var divname = "additionalPriorCoverageMain" + String(i);
			//response = response + xmlhttp.responseText + "<p class=\"formheader\">Prior Coverage</p> <div class=\"row\"> <span class=\"formw\"><select name=\"" + selectname + "\" onChange=\"priorCover('" + selectname + "', '" + divname + "');\"> <option value=\"Select\">Select an option below</option> <option value=\"Yes\">Yes</option> <option value=\"No\">No</option> </select> </span> </div></div> <div id=\"" + divname + "\"> </div>";
			//alert(response);
			response = response + xmlhttp.responseText;
		}
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('secondaryDriversContent').innerHTML = response;
	}
}

function maritalStatus(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	if(document.getElementById("maritalSelect").value == "single") {
		document.getElementById('maritalStatusContent').innerHTML = "";
	} else {
		xmlhttp.open('get', '../text/marriedDriver.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
		xmlhttp.onreadystatechange = handleMarital; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
		xmlhttp.send(null);
	}
	
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleMarital(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		
			response = xmlhttp.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('maritalStatusContent').innerHTML = response;
	}
}


function secondaryDriversMotorcycleRV(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/secondaryDriversMotorcycleRV.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
	xmlhttp.onreadystatechange = handleDrivers; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

function vehiclesAuto(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/vehicleInformation.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
	xmlhttp.onreadystatechange = handleVehicles; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

function vehiclesMotorcycle(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/vehicleInformationMotorcycle.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
	xmlhttp.onreadystatechange = handleVehicles; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

function vehiclesRV(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/vehicleInformationRV.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
	xmlhttp.onreadystatechange = handleVehicles; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleVehicles(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = "";
		var counted = document.getElementById('vehiclesSelect').value;
		for(i=0;i<counted;i++){
			response = response + xmlhttp.responseText;
		}
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('vehicles').innerHTML = response;
	}
}

function priorCover(selectname, divname){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/priorCoverage.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	xmlhttp.onreadystatechange=function() {handlePriorCoverage(selectname, divname)};
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
//function handlePriorCoverage(selectname, divname){
function handlePriorCoverage(selectname, divname){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = "";
		if(document.getElementById("priorCoverageSelect").value=="Yes"){
			
			response = xmlhttp.responseText;
			
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
			document.getElementById(divname).innerHTML = response;
		} else {
			document.getElementById(divname).innerHTML = "";
		}
	}
}

function addOwner() {
	xmlhttp.open('get', '../text/addOwner.txt', true);
	
	xmlhttp.onreadystatechange=handleAddOwner;
	
	xmlhttp.send(null);
}

function handleAddOwner() {
	if(xmlhttp.readyState == 4) {
		var response = xmlhttp.responseText;
		document.getElementById("addOwnerHack").innerHTML = response;
	}
}

function stoveCookTop() {
	if(document.drivers.stove.value == "No") {
		document.getElementById('stoveHack').innerHTML = "";
	} else {
		xmlhttp.open('get', '../text/addOwner.txt', true);
		
		xmlhttp.onreadystatechange=handleStoveCookTop;
		
		xmlhttp.send(null);
	}
}

function handleStoveCookTop() {
	if(xmlhttp.readyState == 4) {
		var response = "<p class='formheadermedium'>Factory Installed</p><div class='row'><span class='formw'><select name='factoryStove'><option value='No'>No</option><option value='Yes'>Yes</option></select></span></div>";
		document.getElementById("stoveHack").innerHTML = response;
	}
}

/*
function requestedCoverage(selection) {
	response = "";
	if(!document.getElementById('requestedCoverage'+selection).checked) {
		if(selection == "GeneralCommercialLiability") {
			response = "<p class=\"sectionheader\">General/Commercial Liability</p><div class=\"leftlong\"><p class=\"formheader\">Requested Coverage</p><div class=\"row\"><span class=\"formw\"><select name=\"generalCommercialLiabilityAmount\"><option value=\"100,000\">$100,000</option><option value=\"300,000\">$300,000</option><option value=\"500,000\">$500,000</option><option value=\"1,000,000\">$1,000,000</option><option value=\"2,000,000\">$2,000,000</option></select></span></div></div>";
		} else if(selection == "Equipment") {
			response = "<p class=\"sectionheader\">Equipment Coverage</p><div class=\"leftlong\"><p class=\"formheader\">Type of Equipment</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"typeEquipment\" /></span></div><p class=\"formheader\">Model and Serial Number</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"modelSerial\" /></span></div></div><div class=\"rightlong\"><p class=\"formheader\">Value of Equipment</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"valueEquipment\" /></span></div><p class=\"formheader\">Dollars Misc Equipment</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"dollarsMisc\" /></span></div></div>";
		} else if(selection == "Building") {
			response = "<p class=\"sectionheader\">Building Coverage</p><div class=\"leftlong\"><p class=\"formheader\">Building Value</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"buildingValue\" value=\"$\" /></span></div><p class=\"formheader\">Year Built</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"yearBuilt\" /></span></div><p class=\"formheader\">Alarm</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"alarm\" /></span></div></div><div class=\"rightlong\"><p class=\"formheader\">Construction Type</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"constructionType\" /></span></div><p class=\"formheader\">Square Footage</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"squareFootage\" /></span></div><p class=\"formheader\">Sprinklers</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"sprinklers\" /></span></div></div>";
		} else if(selection == "Bond") {
			response = "<p class=\"sectionheader\">Bond</p><div class=\"leftlong\"><p class=\"formheader\">Type of Bond</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"bondType\" /></span></div></div><div class=\"rightlong\"><p class=\"formheader\">Amount of Bond</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"bondAmount\" /></span></div></div>";
		} else if(selection == "WorkersComp") {
			response = "<p class=\"sectionheader\">Workers' Comp</p><p>Florida's workers compensation requires a specific form filled out in detail for a quote.  Please submit a fax number and we will fax the form to you with required information.  Fell free to contact us directly with questions about workers compensation as well.</p><p class=\"formheader\">Your fax number</p><div class=\"row\"><span class=\"formw\"><input type=\"text\" name=\"clientFaxNumber\" /></span></div><div class=\"row\"><p>For questions on workers comp, please call our office at any time Monday-Friday 8:30am to 5:30pm at (352)371-9696</p></div>";
		}
		document.getElementById('requestedCoverage'+selection).checked= false;
	}
	document.getElementById('requestedCoverage' + selection + 'Hack').innerHTML = response;
}*/

function requestedCoverage(selection,file,target) {
	if (document.getElementById(selection).checked) {
		xmlhttp.open('get', '../text/'+file+'.txt', true);
		/* Define a function to call once a response has been received. This will be our
			handleProductCategories function that we define below. */
		xmlhttp.onreadystatechange=function() {handleRequestedCoverage(selection,target)};
		/* Send the data. We use something other than null when we are sending using the POST
			method. */
		xmlhttp.send(null);
	} else {
		document.getElementById(target).innerHTML = "";
	}
}

function handleRequestedCoverage(selection,target) {
	if(xmlhttp.readyState == 4){ //Finished loading the response
		var response = "";
		if (document.getElementById(selection).checked) {
			response = xmlhttp.responseText;
		}
		document.getElementById(target).innerHTML = response;
	}
}


function requestedCoverageBusinessAutoFunc() {
	if(!document.getElementById('requestedCoverageBusinessAuto').checked) {
		xmlhttp.open('get', '../text/businessAuto.txt', true);
		
		xmlhttp.onreadystatechange=handleBusinessAutoFunc;
		
		xmlhttp.send(null);
	} else {
		document.getElementById('requestedCoverageBusinessAutoHack').innerHTML = "";
	}
}

function handleBusinessAutoFunc() {
	if(xmlhttp.readyState == 4) {
		var response = xmlhttp.responseText;
		document.getElementById("requestedCoverageBusinessAutoHack").innerHTML = response;
	}
}



function addBusinessOwner(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/addOwner.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	
	xmlhttp.onreadystatechange = handleaddBusinessOwner; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleaddBusinessOwner(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = "";
		var counted = document.getElementById('number_owners').value;
		counted = counted - 1;
		for(i=0;i<counted;i++){
			response = response + xmlhttp.responseText;
		}
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('addOwnerHack').innerHTML = response;
	}
}


function pets(){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	xmlhttp.open('get', '../text/pets.txt', true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	xmlhttp.onreadystatechange=handlePets;
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	xmlhttp.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
//function handlePriorCoverage(selectname, divname){
function handlePets(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(xmlhttp.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = "";
		if(document.getElementById("petsSelect").value=="Yes"){
			
			response = xmlhttp.responseText;
			
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
			document.getElementById('pets').innerHTML = response;
		} else {
			document.getElementById('pets').innerHTML = "";
		}
	}
}