// Get years
function getlength_Chase(m) {
	var width = m.options[m.selectedIndex].value;
	$('width').disabled = true;
	$('len').disabled = false;
    //buildList_Chase('width=' + width);
}


function getprice_Chase(m) {
	var length = m.options[m.selectedIndex].value;
	$('width').disabled = false;
	width = $('width').value;
	$('width').disabled = true;
	$('len').disabled = true;
	$('skirt').disabled = false;
	/*$('extras').setStyle({
  		display: 'block'
	})*/
}

function showholes_Chase() {
	$('skirt').disabled = true;
	$('holes_count').disabled = false;
	$('holes_count').focus();
}

function showcalc_Chase() {
	
	$('calculate').disabled = false;
	
	$('width').disabled = false;
	var width = $('width').value;
	$('width').disabled = true;
	$('len').disabled = false;
	var length = $('len').value;
	$('len').disabled = true;
	
	buildList_Chase('width=' + width + '&length=' + length);
}

function showPrice_Chase(price) {

	//alert('price = ' + price);
	var extra_cost = 0;
		
	if ( $('skirt').value < 3 ) {
		$('skirt').value = 3;
	}
	
	//lets calculate the price
	if ( $('skirt').value > 3 ) {
		var extra = $('skirt').value - 3;
		var extra_cost = extra * 2;
		price = price * 1;
		price = price + extra_cost;
	}
	
	if ( $('holes_count').value > 1 ) {
		var extra_cost = $('holes_count').value * 15;
		price = price * 1;
		price = price + extra_cost;
	}
	
	//alert(price);
	
	
	$('price').value = price;
	
	$('price_per_foot').innerHTML = '<p><strong>Estimated Cost:</strong> $' + price + '</p>';
}

// Ajax Request
function buildList_Chase(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/chase_create_xml.php', 
        {method: 'post', parameters: p, onComplete: pushoptions_Chase}
        );
    
}// end reqXML()

function pushoptions_Chase(originalRequest) {

	$('price').value = 0;
	
    var length_options = new Array();
    var price_options = new Array(); // original diamater options
    
    var xmlResponse = originalRequest.responseXML;

    var lengths = xmlResponse.getElementsByTagName('lengths');
   	var prices = xmlResponse.getElementsByTagName('prices');
      
    if (lengths.length > 0) {
        
        var lengths_array = '';
		lengths_array = xmlResponse.getElementsByTagName('length');
    	
  		length_options[0] = "Select Length";
        for (i=0;i<lengths_array.length;i++) {
            length_options[i+1] = lengths_array[i].firstChild.data;
        } // end for makes
        
        var length_dropdown = document.forms[1].len;
    
    } ///

	if (prices.length > 0) {

		var price = '';
        prices_array = xmlResponse.getElementsByTagName('price');
		price = prices_array[0].firstChild.data;
		
		//alert('price = ' + price);
				
		$('price').value = price;
		
		showPrice_Chase(price);
		
    } else {
    
			if (length_options.length > 1) {
       		 for (i=0;i<length_options.length;i++) {
            	length_dropdown.options[i] = new Option(length_options[i],length_options[i]);
        	}
	    }	
    
    }
}


function redirectTo(url) {
	window.location(url);
}

function resetForm_Chase() {
	$('width').disabled = false;
	$('len').disabled = true;
	$('skirt').disabled = true;
	$('holes_count').disabled = true;
	$('price_per_foot').innerHTML = '';
	$('calculate').disabled = true;
}

function checkForm_Chase() {
	
	var price;
	price = $('price').value;
	
	$('width').disabled = false;
	$('len').disabled = false;
	$('skirt').disabled = false;
	$('holes_count').disabled = false;
	
	var error = false;
	if ( $('width').value == "" || $('len').value == "" || $('skirt').value == "" || $('holes_count').value == "" ) {
		$('width').disabled = true;
		$('len').disabled = true;
		$('skirt').disabled = true;
		$('holes_count').disabled = true;
		error = 'You must select a width, length, skirt size, and hole count.';
		alert(error);
		return false;
	}
		
	return true;	
}