function removeAllOptions(selectbox) {
	var i;
	for(i=selectbox.options.length-1;i>=0;i--) {
		selectbox.remove(i);
	}
}

function getdiameter_BK() {
	$('type').disabled = true;
	$('diameter').disabled = false;
}

function getwidth_BK(m) {
	$('diameter').disabled = true;
	$('width').disabled = false;
}

function getcap_BK() {
	removeAllOptions(document.forms[1].cap);
	$('width').disabled = true;
	
	$('diameter').disabled = false;
	var diameter = $('diameter').value;
	$('diameter').disabled = true;
	
	var cap_array = new Array();
	var cap_value_array = new Array();
	
	cap_array[0] = 'Select Cap';
	cap_value_array[0] = '';
	
	diameter = diameter * 1;
		
	if ( diameter >= 3 && diameter <= 6 ) {
		
		cap_array[1] = 'Quick Cap';
		cap_value_array[1] = 'CSLF';
		cap_array[2] = 'Quick Cap w/ No Screen';
		cap_value_array[2] = 'CNSLF';
		cap_array[3] = 'Cap w/ Screen / No Wind Guard';
		cap_value_array[3] = 'CNGLF';
		cap_array[4] = 'California Cap w/ 5/8" Screen';
		cap_value_array[4] = 'CALF';
		cap_array[5] = 'Deluxe Top Termination - Crown Mount - 8" x 8" Cap w/ 13" x 13" Top Plate';
		cap_value_array[5] = 'CDTCM|-88';
		cap_array[6] = 'Deluxe Top Termination - Crown Mount - 8" x 13" Cap w/ 13" x 17" Top Plate';
		cap_value_array[6] = 'CDTCM|-813';
		cap_array[7] = 'Deluxe Top Termination - Terra-Cotta Mount - 8" x 8" Cap w/ 13" x 13" Top Plate';
		cap_value_array[7] = 'CDTTM|-88';
		cap_array[8] = 'Deluxe Top Termination - Terra-Cotta Mount - 8" x 13" Cap w/ 13" x 17" Top Plate';
		cap_value_array[8] = 'CDTTM|-813';
		cap_array[9] = 'Do Not Include Cap';
		cap_value_array[9] = 'none';
	}
	
	if (diameter > 6) {
			
		cap_array[1] = 'Quick Cap';
		cap_value_array[1] = 'CSLF';
		cap_array[2] = 'Quick Cap w/ No Screen';
		cap_value_array[2] = 'CNSLF';
		cap_array[3] = 'Cap w/ Screen / No Wind Guard';
		cap_value_array[3] = 'CNGLF';
		cap_array[4] = 'California Cap w/ 5/8" Screen';
		cap_value_array[4] = 'CALF';
		cap_array[5] = 'Deluxe Top Termination - Crown Mount - 13" x 13" Cap w/ 17" x 17" Top Plate';
		cap_value_array[5] = 'CDTCM|-1313';
		cap_array[6] = 'Deluxe Top Termination - Terra-Cotta Mount - 13" x 13" Cap w/ 17" x 17" Top Plate';
		cap_value_array[6] = 'CDTTM|-1313';
		cap_array[7] = 'Do Not Include Cap';
		cap_value_array[7] = 'none';
	}	
	
	var cap_dropdown = document.forms[1].cap;
    var i = 0;
    if (cap_array.length > 1) {
    	for (i=0;i<cap_array.length;i++) {
        	cap_dropdown.options[i] = new Option(cap_array[i],cap_value_array[i]);
       	}
   	}
	
	$('cap').disabled = false;
	
}

function getplate_BK() {
	
	$('diameter').disabled = false;
	var diameter = $('diameter').value;
	$('diameter').disabled = true;
	
	var plate_array = new Array();
	var plate_value_array = new Array();

	var cap = $('cap').value;
	$('cap').disabled = true;
		
	if (cap == 'CDMTTM|-88' || cap == 'CDTTM|-88' || cap == 'CDTTM|-813' || cap == 'CDMTTM|-813' || cap == 'CDTCM|-1313' || cap == 'CDTCM|-88' || cap == 'CDTCM|-813' || cap == 'CDTTM|-1313') {
		gettee_BK();
	} else {	
		removeAllOptions(document.forms[1].plate);
		diameter = diameter * 1;
		
		plate_array[0] = 'Select Top Plate';
		plate_value_array[0] = '';
		plate_array[1] = 'No Sag / No Leak Top Plate';
		plate_value_array[1] = 'TPNS';
		plate_array[2] = 'Flat Top Plate';
		plate_value_array[2] = 'TPLF';
		plate_array[3] = 'Do Not Include Top Plate';
		plate_value_array[3] = 'none';
				
		if (diameter > 6) {
			plate_array[0] = 'Select Top Plate';
			plate_value_array[0]['value'] = '';
			plate_array[1] = 'No Sag / No Leak Top Plate';
			plate_value_array[1] = 'TPNS';
			plate_array[2] = 'Flat Top Plate';
			plate_value_array[2] = 'TPLF';
			plate_array[3] = 'Terra Cotta Plate';
			plate_value_array[3] = 'TPTC';
			plate_array[4] = 'Do Not Include Top Plate';
			plate_value_array[4] = 'none';
		}
		
		var plate_dropdown = document.forms[1].plate;
   		var i = 0;
	    if (plate_array.length > 1) {
    		for (i=0;i<plate_array.length;i++) {
        		plate_dropdown.options[i] = new Option(plate_array[i],plate_value_array[i]);
	       	}
   		}
	
		$('plate').disabled = false;
	}
}

function getplatesize_BK() {

	var plate = $('plate').value;
	
	if (plate == 'none') {
		gettee_BK();
	} else {
		removeAllOptions(document.forms[1].platesize);
		var plate_array = new Array();
		var plate_value_array = new Array();
		
		if (plate == 'TPTC') {
			plate_array[0] = 'Select Plate Size';
			plate_value_array[0] = '';
			plate_array[1] = '8" X 8"';
			plate_value_array[1] = '88';
			plate_array[2] = '8" X 13"';
			plate_value_array[2] = '813';
			plate_array[3] = '13" X 13"';
			plate_value_array[3] = '1313';
			plate_array[3] = '13" X 18"';
			plate_value_array[3] = '1318';
		} else {
			plate_array[0] = 'Select Plate Size';
			plate_value_array[0] = '';
			plate_array[1] = '13" X 13"';
			plate_value_array[1] = '1313';
			plate_array[2] = '13" X 18"';
			plate_value_array[2] = '1318';
			plate_array[3] = '18" X 18"';
			plate_value_array[3] = '1818';
		}
		
		//alert(plate_array.length)
    	 
    	$('plate').disabled = true;
		$('platesize').disabled = false;
    	    
    	var platesize_dropdown = document.forms[1].platesize;
    	var i = 0;
    	if (plate_array.length > 1) {
    		for (i=0;i<plate_array.length;i++) {
    	    	platesize_dropdown.options[i] = new Option(plate_array[i],plate_value_array[i]);
    	   	}
    	}
    }
}

function gettee_BK() {

	removeAllOptions(document.forms[1].tee);

	$('diameter').disabled = false;
	var diameter = $('diameter').value;
	$('diameter').disabled = true;
	
	var tee_array = new Array();
	var tee_value_array = new Array();
	
	tee_array[0] = 'Select Bottom Termination';
	tee_value_array[0] = '';
	
	if (diameter == '3') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = '90 Degree Elbow (Adjustable)';
		tee_value_array[3] = 'ELLF-|-90';
		tee_array[4] = 'Do Not Include Bottom Termination';
		tee_value_array[4] = 'none';
		
	}
	
	if (diameter == '4') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Pellet Appliance Connector';
		tee_value_array[2] = 'ACLF|3';
		tee_array[3] = 'Quick Tee with Removable Take-Off';
		tee_value_array[3] = 'TLF';
		tee_array[4] = '4" Pellet Tee with 3" Fixed Take-Off';
		tee_value_array[4] = 'TLF|3';
		tee_array[5] = '90 Degree Elbow (Adjustable)';
		tee_value_array[5] = 'ELLF-|-90';
		tee_array[6] = 'Do Not Include Bottom Termination';
		tee_value_array[6] = 'none';
	}
	
	if (diameter == '5') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = 'Quick Tee with 22" Take Off';
		tee_value_array[3] = 'TLFET';
		tee_array[4] = '22" Tee Take-Off';
		tee_value_array[4] = 'ET|22';
		tee_array[5] = 'Short Body Tee (Includes Tee Cap)';
		tee_value_array[5] = 'TLFSB';
		tee_array[6] = 'Short Body Tee 22" Take-Off';
		tee_value_array[6] = 'TLFSBET';	
		tee_array[7] = '90 Degree Elbow (Adjustable)';
		tee_value_array[7] = 'ELLF-|-90';
		tee_array[8] = 'Do Not Include Bottom Termination';
		tee_value_array[8] = 'none';
	}
	
	if (diameter == '5.5') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = 'Quick Tee with 22" Take Off';
		tee_value_array[3] = 'TLFET';
		tee_array[4] = '22" Tee Take-Off';
		tee_value_array[4] = 'ET|22';
		tee_array[5] = 'Short Body Tee (Includes Tee Cap)';
		tee_value_array[5] = 'TLFSB';
		tee_array[6] = 'Short Body Tee 22" Take-Off';
		tee_value_array[6] = 'TLFSBET';
		tee_array[7] = 'Tee with 3" Take-Off';
		tee_value_array[7] = 'TLF|3';
		tee_array[8] = 'Tee with 4" Take-Off';
		tee_value_array[8] = 'TLF|4';
		tee_array[9] = '90 Degree Elbow (Adjustable)';
		tee_value_array[9] = 'ELLF-|-90';
		tee_array[10] = 'Do Not Include Bottom Termination';
		tee_value_array[10] = 'none';
	}
	
	if (diameter == '6') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = 'Quick Tee with 22" Take Off';
		tee_value_array[3] = 'TLFET';
		tee_array[4] = '22" Tee Take-Off';
		tee_value_array[4] = 'ET|22';
		tee_array[5] = 'Short Body Tee (Includes Tee Cap)';
		tee_value_array[5] = 'TLFSB';
		tee_array[6] = 'Short Body Tee 22" Take-Off';
		tee_value_array[6] = 'TLFSBET';
		tee_array[7] = 'Tee with 3" Take-Off';
		tee_value_array[7] = 'TLF|3';
		tee_array[8] = 'Tee with 4" Take-Off';
		tee_value_array[8] = 'TLF|4';
		tee_array[9] = '90 Degree Elbow (Adjustable)';
		tee_value_array[9] = 'ELLF-|-90';
		tee_array[10] = 'Do Not Include Bottom Termination';
		tee_value_array[10] = 'none';
	}
	
	if (diameter == '6.5') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = 'Quick Tee with 22" Take Off';
		tee_value_array[3] = 'TLFET';
		tee_array[4] = '22" Tee Take-Off';
		tee_value_array[4] = 'ET|22';
		tee_array[5] = 'Short Body Tee (Includes Tee Cap)';
		tee_value_array[5] = 'TLFSB';
		tee_array[6] = '90 Degree Elbow (Adjustable)';
		tee_value_array[6] = 'ELLF-|-90';
		tee_array[7] = 'Do Not Include Bottom Termination';
		tee_value_array[7] = 'none';
	}
	
	if (diameter == '7') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = 'Quick Tee with 22" Take Off';
		tee_value_array[3] = 'TLFET';
		tee_array[4] = '22" Tee Take-Off';
		tee_value_array[4] = 'ET|22';
		tee_array[5] = 'Short Body Tee (Includes Tee Cap)';
		tee_value_array[5] = 'TLFSB';
		tee_array[6] = 'Tee with 3" Take-Off';
		tee_value_array[6] = 'TLF|3';
		tee_array[7] = 'Tee with 4" Take-Off';
		tee_value_array[7] = 'TLF|4';
		tee_array[8] = '90 Degree Elbow (Adjustable)';
		tee_value_array[8] = 'ELLF-|-90';
		tee_array[9] = 'Do Not Include Bottom Termination';
		tee_value_array[9] = 'none';
	}
	
	if (diameter == '7.5') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = 'Quick Tee with 22" Take Off';
		tee_value_array[3] = 'TLFET';
		tee_array[4] = '22" Tee Take-Off';
		tee_value_array[4] = 'ET|22';
		tee_array[5] = 'Short Body Tee (Includes Tee Cap)';
		tee_value_array[5] = 'TLFSB';
		tee_array[6] = '90 Degree Elbow (Adjustable)';
		tee_value_array[6] = 'ELLF-|-90';
		tee_array[7] = 'Do Not Include Bottom Termination';
		tee_value_array[7] = 'none';
	}
	
	if (diameter == '8') {
		tee_array[1] = 'Appliance Connector';
		tee_value_array[1] = 'ACLF';
		tee_array[2] = 'Quick Tee with Removable Take-Off';
		tee_value_array[2] = 'TLF';
		tee_array[3] = 'Quick Tee with 22" Take Off';
		tee_value_array[3] = 'TLFET';
		tee_array[4] = '22" Tee Take-Off';
		tee_value_array[4] = 'ET|22';
		tee_array[5] = 'Short Body Tee (Includes Tee Cap)';
		tee_value_array[5] = 'TLFSB';
		tee_array[6] = 'Tee with 3" Take-Off';
		tee_value_array[6] = 'TLF|3';
		tee_array[7] = 'Tee with 4" Take-Off';
		tee_value_array[7] = 'TLF|4';
		tee_array[8] = '90 Degree Elbow (Adjustable)';
		tee_value_array[8] = 'ELLF-|-90';
		tee_array[9] = 'Do Not Include Bottom Termination';
		tee_value_array[9] = 'none';
	}
	
	var tee_dropdown = document.forms[1].tee;
    var i = 0;
    if (tee_array.length > 1) {
    	for (i=0;i<tee_array.length;i++) {
        	tee_dropdown.options[i] = new Option(tee_array[i],tee_value_array[i]);
       	}
   	}

	$('platesize').disabled = true;
	$('tee').disabled = false;
}

function checktee_BK() {
	

	var tee = $('tee').value;
	$('diameter').disabled = false;
	var diameter = $('diameter').value;
	$('diameter').disabled = true;
	
	diameter = diameter * 1;
	var teecap_array = new Array();
	var teecap_value_array = new Array();
	
	teecap_array[0] = 'Select Tee Cap';
	teecap_value_array[0] = '';
	
		
	if (tee == 'TLF' || tee == 'TLFET' || tee=='TLF|3' || tee=='TLF|4') {

		removeAllOptions(document.forms[1].teecap);
		
		teecap_array[1] = 'Tee Cap';
		teecap_value_array[1] = 'TC';
		
		if (diameter > 4) {
			teecap_array[2] = 'Pulling Tee Cap';
			teecap_value_array[2] = 'TCPULL';
			teecap_array[3] = 'Do Not Include Tee Cap';
			teecap_value_array[3] = 'none';
		} else {
			teecap_array[2] = 'Do Not Include Tee Cap';
			teecap_value_array[2] = 'none';
		}
			
		$('tee').disabled = true;
		
		var teecap_dropdown = document.forms[1].teecap;
   		var i = 0;
	    if (teecap_array.length > 1) {
    		for (i=0;i<teecap_array.length;i++) {
        		teecap_dropdown.options[i] = new Option(teecap_array[i],teecap_value_array[i]);
	       	}
    	}
		
		
		$('teecap').disabled = false;
		$('teecap').focus();
	} else {
		var teecap_dropdown = document.forms[1].teecap;
   		var i = 0;
	    if (teecap_array.length > 1) {
    		for (i=0;i<teecap_array.length;i++) {
        		teecap_dropdown.options[i] = new Option(teecap_array[i],teecap_value_array[i]);
	       	}
    	}
		$('tee').disabled = true;
		$('teecap').disabled = true;
		$('calculate').disabled = false;
		$('calculate').focus();
	}
}

function activateCalculate_BK() {
	$('tee').disabled = true;
	$('teecap').disabled = true;
	$('calculate').disabled = false;
	$('calculate').focus();
}

function checkPrice_BK() {

	$('type').disabled = false;
	var type = $('type').value;
	$('type').disabled = true;

	$('diameter').disabled = false;
	var diameter = $('diameter').value;
	$('diameter').disabled = true;
	
	$('width').disabled = false;
	var width = $('width').value;
	$('width').disabled = true;
	
	$('cap').disabled = false;
	var cap = $('cap').value;
	$('cap').disabled = true;
	
	$('plate').disabled = false;
	var plate = $('plate').value;
	$('plate').disabled = true;
	
	$('platesize').disabled = false;
	var platesize = $('platesize').value;
	$('platesize').disabled = true;
	
	var tee = $('tee').value;	
	var teecap = $('teecap').value;

		
	buildList_BK('type=' + type + '&diameter=' + diameter + '&width=' + width + '&cap=' + cap + '&plate=' + cap + '&plate=' + plate + '&platesize=' + platesize + '&tee=' + tee + '&teecap=' + teecap);	
}

// Ajax Request
function buildList_BK(p) {
    
    // Parameters for request
    // p = parameters
    var loc = new String(window.parent.document.location);
	if (loc.indexOf("https://")!= -1)
	prefix = "https://";
	else
	prefix = "http://";
       
    var myAjax = new Ajax.Request(
        prefix+'www.olympiachimney.com/xml/kit_wizard_xml.php', 
        {method: 'post', parameters: p, onComplete: pushoptions_BK}
        );
    
}// end reqXML()

function pushoptions_BK(originalRequest) {
	   
    var xmlResponse = originalRequest.responseXML;

    var items = xmlResponse.getElementsByTagName('items');
        
    if (items.length > 0) {
    
    	var informationText = '<h3>Kit Includes:</h3>';
    	
    	var items_array = xmlResponse.getElementsByTagName('item_type');
    	var code_array = xmlResponse.getElementsByTagName('item_code');
    	
    	var varstr = '';
     	
    	if (items_array.length > 0) {
    		informationText += '<ul>';
    		for (i = 0; i<items_array.length; i++) {
    			informationText += '<li>'+items_array[i].firstChild.data + '</li>';
    			
    			if (items_array[i].firstChild.data == 'Liner') {
    				$('real_liner').value = code_array[i].firstChild.data;
    			}
    			
    			if (items_array[i].firstChild.data == 'Cap') {
    				$('real_cap').value = code_array[i].firstChild.data;
    			}
    			
    			if (items_array[i].firstChild.data == 'Plate') {
    				$('real_plate').value = code_array[i].firstChild.data;
    			}
    			
    			if (items_array[i].firstChild.data == 'Bottom Termination') {
       				$('real_tee').value = code_array[i].firstChild.data;
    			}
    			
    			if (items_array[i].firstChild.data == 'Tee Cap') {
       				$('real_teecap').value = code_array[i].firstChild.data;
    			}
    			
    		}
    		informationText += '</ul>';
    	}
    	
    	var prices_array = xmlResponse.getElementsByTagName('item_price');
    	
    	if (prices_array.length > 0) {
    		var priceTotal = new Array();
    		
    		for (i=0; i<prices_array.length; i++) {
    			priceTotal[i] = prices_array[i].firstChild.data;			
    		}
    		var estimatedCost = 0;
    		for (i=0; i<priceTotal.length;i++) {
    			
    			currentPrice = priceTotal[i];
    			
    			currentPrice = currentPrice * 1;
    			estimatedCost = estimatedCost + currentPrice;
    		}
    		
    	}
    	
    	estimatedCost = Math.round(estimatedCost*100)/100;
    	estimatedCostDiscount = estimatedCost * .07625;
    	estimatedCostDiscount = Math.round(estimatedCostDiscount * 100) / 100;
    	estimatedDiscount = estimatedCost - estimatedCostDiscount;
    	estimatedDiscount = Math.round(estimatedDiscount * 100) /100;
    	
    	if (informationText != '') {
    		informationText+= '<p><strong>Estimated Price:</strong> $' + estimatedCost + '<br />';
    		informationText+= '<strong>Estimated Discount:</strong> $' + estimatedCostDiscount + '<br />';
    		informationText+= '<strong>Estimated Price After Discount:</strong> $' + estimatedDiscount + '</p>';
    	}
    	            
       $('details').show();
       $('details').innerHTML = informationText;
       $('discount_price').value = estimatedDiscount;
       $('price').value = estimatedCost;
    
    } ///
}

function resetForm_BK() {
	$('type').disabled = false;
	$('diameter').disabled = true;
	$('width').disabled = true;
	$('cap').disabled = true;
	$('plate').disabled = true;
	$('platesize').disabled = true;
	$('tee').disabled = true;
	$('teecap').disabled = true;
	$('calculate').disabled = true;
	$('details').hide();
	$('details').innerHTML = '';
}

function checkForm_BK() {
	$('type').disabled = false;
	Field.clear('type');
	$('diameter').disabled = false;	
	$('width').disabled = false;		
	$('cap').disabled = false;	
	$('plate').disabled = false;	
	$('platesize').disabled = false;	
	return true;
}