/*
	This gets the price for a throw pillow.
	@serverPage the Ajax page that is called
	@pid        the product id
	@optp       upcharge price (based on site, 0.00 is default)      
*/
function am_throw_pillow(thread, serverPage, optp) {
	//if(typeof optp == 'undefined') optp = 0.000;
	while(ready == false) {}
	optp = opt_prices;

	mess = '';
	if($F('Option' + calcparam.get('d')) < 4) {
		mess += "Pillow height must be between 4 and 25 inches.\n";
		$('Option' + calcparam.get('d')).setValue(4);
	}

	if($F('Option' + calcparam.get('d')) > 25) {
		mess += "Pillow height must be between 4 and 25 inches.\n";
		$('Option' + calcparam.get('d')).setValue(25);
	}
	$('Option' + calcparam.get('d')).setValue(Math.round($F('Option' + calcparam.get('d'))*2)/2);

	if($F('Option' + calcparam.get('w')) < 12) {
		mess += "Pillow width must be between 12 and 25 inches.\n";
		$('Option' + calcparam.get('w')).setValue(12);
	}

	if($F('Option' + calcparam.get('w')) > 25) {
		mess += "Pillow width must be between 12 and 25 inches.\n";
		$('Option' + calcparam.get('w')).setValue(25);
	}
	$('Option' + calcparam.get('w')).setValue(Math.round($F('Option' + calcparam.get('w'))*2)/2);

	sid = '';
	if($('Option' + calcparam.get('sid')).disabled === false) sid = $F('Option' + calcparam.get('sid'));

	sid2='';
	if (calcparam.get('sid2')) sid2 = $F('Option' + calcparam.get('sid2'));
	
	// Even if there is an error, let's recalc prices based on the updated configuration ...
	if(mess != '') displayMessage(mess);

	sPage = serverPage + '?pid=' + product_id + '&sid=' + sid + '&sid2=' + sid2 + '&cid=' + $F('Option' + calcparam.get('cid')) + '&d=' + $F('Option' + calcparam.get('d')) + '&w=' + $F('Option' + calcparam.get('w')) + '&f=' + $F('Option' + calcparam.get('f')) + '&e=' + $F('Option' + calcparam.get('e')) + '&optp=' + optp;
	serverPage = sPage + '&price=1';
	doAjaxCall(serverPage, thread);
}

function displayMessage(mess) {
	alert(mess);
}

/*
	This gets the price for a bolster pillow.
	@serverPage the Ajax page that is called
	@pid        the product id
	@optp       upcharge price (based on site, 0.00 is default)      
*/
function am_bolster_pillow(thread, serverPage, pid, optp) {
	//if(typeof optp == 'undefined') optp = 0.000;
	while(ready == false) {}
	optp = opt_prices;

	mess = '';

	if($F('Option' + calcparam.get('w')) < 12) {
		mess += "Pillow width must be between 12 and 25 inches.\n";
		$('Option' + calcparam.get('w')).setValue(12);
	}

	if($F('Option' + calcparam.get('w')) > 52) {
		mess += "Pillow width must be between 12 and 52 inches.\n";
		$('Option' + calcparam.get('w')).setValue(52);
	}
	$('Option' + calcparam.get('w')).setValue(Math.round($F('Option' + calcparam.get('w'))*2)/2);

	sid = '';
	if($('Option' + calcparam.get('sid')).disabled === false) sid = $F('Option' + calcparam.get('sid'));

	if(mess != '') displayMessage(mess);

	sPage = serverPage + '?pid=' + product_id + '&sid=' + sid + '&d=' + $F('Option' + calcparam.get('d')) + '&w=' + $F('Option' + calcparam.get('w')) + '&f=' + $F('Option' + calcparam.get('f')) + '&e=' + $F('Option' + calcparam.get('e')) + '&optp=' + optp;
	serverPage = sPage + '&price=1';
	doAjaxCall(serverPage, thread);
}

function calc_ark_drape(thread, serverPage, pid, optp) {
	while(ready == false) {}
	optp = opt_prices;

	mess = '';
	if($F('Option' + calcparam.get('l')) < 12) {
		mess += "Drape length must be longer than 12 inches.\n";
		$('Option' + calcparam.get('l')).setValue(12);
	}
	$('Option' + calcparam.get('l')).setValue(Math.round($F('Option' + calcparam.get('l'))*2)/2);

	sid = '';
	if($('Option' + calcparam.get('sid')).disabled === false) sid = $F('Option' + calcparam.get('sid'));

	if(mess != '') displayMessage(mess);

	sPage = serverPage + '?pid=' + product_id + '&sid=' + sid + '&w=' + $F('Option' + calcparam.get('w')) + '&l=' + $F('Option' + calcparam.get('l')) + '&inner=' + $F('Option' + calcparam.get('inner')) + '&optp=' + optp + '&type=' + $F('Option' + calcparam.get('type'));
	serverPage = sPage + '&price=1';
	doAjaxCall(serverPage, thread);
}

/*
	This gets the price for a drape
	@serverPage the Ajax page that is called
	@pid        the product id
	@optp       upcharge price (based on site, 0.00 is default)      
*/
function calc_pr_drape(thread, serverPage, pid, optp) {
	//if(typeof optp == 'undefined') optp = 0.000;
	while(ready == false) {}
	optp = opt_prices;

	mess = '';
	if($F('Option' + calcparam.get('l')) < 12) {
		mess += "Drape length must be longer than 12 inches.\n";
		$('Option' + calcparam.get('l')).setValue(12);
	}
	$('Option' + calcparam.get('l')).setValue(Math.round($F('Option' + calcparam.get('l'))*2)/2);

	if($F('Option' + calcparam.get('sid')) == '') {
		clearTimeout(newPriceThread);
		mess += "Drape fabric must be selected.\n";
	}

	if(mess != '') displayMessage(mess);

	sPage = serverPage + '?pid=' + product_id + '&sid=' + $F('Option' + calcparam.get('sid')) + '&w=' + $F('Option' + calcparam.get('w')) + '&l=' + $F('Option' + calcparam.get('l')) + '&optp=' + optp + '&type=' + $F('Option' + calcparam.get('type')) + '&ftype=' + $F('Option' + calcparam.get('ftype'));
	serverPage = sPage + '&price=1';
	doAjaxCall(serverPage, thread);
}

/*
	This gets the price for a bench pillow
	@serverPage the Ajax page that is called
	@pid        the product id
	@optp       upcharge price (based on site, 0.00 is default)      
*/
function am_bench_OLD(thread, serverPage, pid, optp) {
	//if(typeof optp == 'undefined') optp = 0.000;
	while(ready == false) {}
	optp = opt_prices;

	mess = '';
	if($F('Option' + calcparam.get('d')) < 10) {
		mess += "Cushion depth must be between 10 and 40 inches.\n";
		$('Option' + calcparam.get('d')).setValue(10);
	}

	if($F('Option' + calcparam.get('d')) > 40) {
		mess += "Cushion depth must be between 10 and 40 inches.\n";
		$('Option' + calcparam.get('d')).setValue(40);
	}
	$('Option' + calcparam.get('d')).setValue(Math.round($F('Option' + calcparam.get('d'))*2)/2);

	if ($F('Option' + calcparam.get('w'))>0) {
		if($F('Option' + calcparam.get('w')) < 22) {
			mess += "Cushion width must be between 22 and 25 inches.\n";
			$('Option' + calcparam.get('w')).setValue(22);
		}
	
		if($F('Option' + calcparam.get('w')) > 205) {
			mess += "Cushion width must be between 22 and 205 inches.\n";
			$('Option' + calcparam.get('w')).setValue(205);
		}
		$('Option' + calcparam.get('w')).setValue(Math.round($F('Option' + calcparam.get('w'))*2)/2);
		w = $F('Option' + calcparam.get('w'));
	}
	if($F('Option' + calcparam.get('fw'))>0) {
		if($F('Option' + calcparam.get('fw')) < 22) {
			mess += "Cushion width must be between 22 and 25 inches.\n";
			$('Option' + calcparam.get('fw')).setValue(22);
		}
	
		if($F('Option' + calcparam.get('fw')) > 205) {
			mess += "Cushion width must be between 22 and 205 inches.\n";
			$('Option' + calcparam.get('fw')).setValue(205);
		}
		$('Option' + calcparam.get('fw')).setValue(Math.round($F('Option' + calcparam.get('fw'))*2)/2);
		w = $F('Option' + calcparam.get('fw'));
		
		if($F('Option' + calcparam.get('bw')) < 22) {
			mess += "Cushion width must be between 22 and 25 inches.\n";
			$('Option' + calcparam.get('bw')).setValue(22);
		}
	
		if($F('Option' + calcparam.get('bw')) > 205) {
			mess += "Cushion width must be between 22 and 205 inches.\n";
			$('Option' + calcparam.get('bw')).setValue(205);
		}
		$('Option' + calcparam.get('bw')).setValue(Math.round($F('Option' + calcparam.get('bw'))*2)/2);
		if($F('Option' + calcparam.get('bw')) > w) w=$F('Option' + calcparam.get('bw'));
	}

	if($F('Option' + calcparam.get('sid')) == '') {
		clearTimeout(newPriceThread);
		mess += "Cushion fabric must be selected.<br />";
	}

	if(mess != '') displayMessage(mess);

	sPage = serverPage + '?pid=' + product_id + '&sid=' + $F('Option' + calcparam.get('sid')) + '&cid=' + $F('Option' + calcparam.get('cid')) + '&d=' + $F('Option' + calcparam.get('d')) + '&w=' + w + '&t=' + $F('Option' + calcparam.get('t')) + '&cord=' + $F('Option' + calcparam.get('cord')) + '&edge=' + $F('Option' + calcparam.get('edge')) + '&optp=' + optp;
	serverPage = sPage + '&price=1';
	doAjaxCall(serverPage, thread);
}

function am_bench(thread, serverPage, pid, optp) {
	while(ready == false) {}
	optp = opt_prices;

	var empty;
	fnb = false;
	passed = true;
	mess = "";

	d = $F('Option' + calcparam.get('d'));
	if($('Option' + calcparam.get('w')).disabled === false) w = $F('Option' + calcparam.get('w'));
		else w = '';
	if(calcparam.get('bw')) bw = $F('Option' + calcparam.get('bw'));
	if(calcparam.get('fw')) fw = $F('Option' + calcparam.get('fw'));

	if (d < 10) {
		passed = false;
		mess += "Cushion Depth must be between 10 and 40 inches.\n";
		d = 10;
	}
	if (d > 40 ) {
		passed = false;
		mess += "Cushion Depth must be between 10 and 40 inches.\n";
		d = 40;
	}
	d = Math.round(d*2)/2;
	$('Option' + calcparam.get('d')).setValue(d);
	
	if (w == '') {
		fnb = true;
	}
	if (!fnb) {
		if (w < 10 ) {
			passed = false;
			mess += "Cushion Width must be between 10 and 205 inches.\n";
			w = 22;
		}
		if (w > 205 ) {
			passed = false;
			mess += "Cushion Width must be between 10 and 205 inches.\n";
			w = 205;
		}
		w = Math.round(w*2)/2;
		$('Option' + calcparam.get('w')).setValue(w);
	} else {
		if (fw < 10 ) {
			passed = false;
			mess += "Cushion Front Width must be between 10 and 205 inches.\n";
			fw = 10;
		}
		if (fw > 205 ) {
			passed = false;
			mess += "Cushion Front Width must be between 22 and 205 inches.\n";
			fw = 205;
		}
		fw = Math.round(fw*2)/2;
		$('Option' + calcparam.get('fw')).setValue(fw);
		if (bw < 10 ) {
			passed = false;
			mess += "Cushion Back Width must be between 10 and 205 inches.\n";
			bw = 10;
		}
		if (bw > 205 ) {
			passed = false;
			mess += "Cushion Back Width must be between 22 and 205 inches.\n";
			bw = 205;
		}
		bw = Math.round(bw*2)/2;
		$('Option' + calcparam.get('bw')).setValue(bw);

		w = fw;
		if (bw > fw) w = bw;
	}

	if(mess != '') displayMessage(mess);

	if($('Option' + calcparam.get('t')).disabled == true) t = $F('Option' + calcparam.get('bt'));
		else t = $F('Option' + calcparam.get('t'));

	sid = '';
	if($('Option' + calcparam.get('sid')).disabled === false) sid = $F('Option' + calcparam.get('sid'));

	sPage = serverPage + '?pid=' + product_id + '&sid=' + sid + (calcparam.get('cid') ? '&cid=' + $F('Option' + calcparam.get('cid')) : '') + '&d=' + d + '&w=' + w + '&t=' + t + '&cord=' + $F('Option' + calcparam.get('cord')) + '&edge=' + $F('Option' + calcparam.get('edge')) + '&optp=' + optp;
	serverPage = sPage + '&price=1';
	doAjaxCall(serverPage, thread);
}

function am_chaise(thread, serverPage, pid, optp) {
	//if(typeof optp == 'undefined') optp = 0.000;
	while(ready == false) {}
	optp = opt_prices;

	passed = true; mess = "";
	if ($F('Option' + calcparam.get('d')) < 10 ) {
		passed = false;
		mess += "Cushion Width must be between 10 and 40 inches";
		$('Option' + calcparam.get('d')).setValue(10);
	}
	
	if ($F('Option' + calcparam.get('d')) > 80 ) {
		passed = false;
		mess += "Cushion Width must be between 10 and 80 inches";
		$('Option' + calcparam.get('d')).setValue(80);
	}
	
	$('Option' + calcparam.get('d')).setValue(Math.round($F('Option' + calcparam.get('d'))*2)/2);
	$('Option' + calcparam.get('b1')).setValue(Math.round($F('Option' + calcparam.get('b1'))*2)/2);
	$('Option' + calcparam.get('b2')).setValue(Math.round($F('Option' + calcparam.get('b2'))*2)/2);
	$('Option' + calcparam.get('b3')).setValue(Math.round($F('Option' + calcparam.get('b3'))*2)/2);
	$('Option' + calcparam.get('b4')).setValue(Math.round($F('Option' + calcparam.get('b4'))*2)/2);
	
	sid = '';
	if($('Option' + calcparam.get('sid')).disabled === false) sid = $F('Option' + calcparam.get('sid'));

	if (!passed) {
		if(mess != '') displayMessage(mess);
	} else {
		if($('Option' + calcparam.get('t')).disabled == true) t = $F('Option' + calcparam.get('bt'));
			else t = $F('Option' + calcparam.get('t'));

		sPage = serverPage+"?pid="+product_id+"&sid="+sid+"&cid="+$F('Option' + calcparam.get('cid'))+"&d="+$F('Option' + calcparam.get('d'))+"&t="+ t +"&cord=" + $F('Option' + calcparam.get('cord')) + '&edge=' + $F('Option' + calcparam.get('edge')) + "&optp="+optp+"&b1="+$F('Option' + calcparam.get('b1'))+"&b2="+$F('Option' + calcparam.get('b2'))+"&b3="+$F('Option' + calcparam.get('b3'))+"&b4="+$F('Option' + calcparam.get('b4'));
		serverPage = sPage+"&price=1";
		doAjaxCall(serverPage, thread);
	}
}

function anchor_pool_cover(thread, serverPage, pid, optp) {
	//if(typeof optp == 'undefined') optp = 0.000;
	while(ready == false) {}
	optp = opt_prices;

	passed = true; mess = "";
	if ($F('Option' + calcparam.get('l')) < 10 ) {
		passed = false;
		mess += "Pool Length must be at least 10 feet";
		$('Option' + calcparam.get('l')).setValue(10);
	}
	
	if ($F('Option' + calcparam.get('w')) < 5 ) {
		passed = false;
		mess += "Pool Width must be at least 5 feet";
		$('Option' + calcparam.get('w')).setValue(5);
	}
	
	$('Option' + calcparam.get('l')).setValue(Math.round($F('Option' + calcparam.get('l'))*2)/2);
	$('Option' + calcparam.get('w')).setValue(Math.round($F('Option' + calcparam.get('w'))*2)/2);
	
	if (!passed) {
		if(mess != '') displayMessage(mess);
	} else {
		sPage = serverPage+"?pid="+product_id+"&type="+$F('Option' + calcparam.get('type'))+"&ps="+$F('Option' + calcparam.get('ps'))+"&l="+$F('Option' + calcparam.get('l'))+"&w=" + $F('Option' + calcparam.get('w')) + '&s1=' + $F('Option' + calcparam.get('s1')) + '&s2=' + $F('Option' + calcparam.get('s2')) + '&hw=' + $F('Option' + calcparam.get('hw')) + '&optp='+optp;
		serverPage = sPage+"&price=1";
		doAjaxCall(serverPage, thread);
	}
}

function ecu_umbrellas(thread, serverPage, optp) {
	//if(typeof optp == 'undefined') optp = 0.000;
	while(ready == false) {}
	optp = opt_prices;

	mess = '';
	if($F('Option' + calcparam.get('msid')) == '') {
		clearTimeout(newPriceThread);
		mess += "Main Umbrella fabric must be selected.<br />";
	}

	// Even if there is an error, let's recalc prices based on the updated configuration ...
	if(mess != '') displayMessage(mess);

	sPage = serverPage + '?pid=' + product_id + '&msid=' + $F('Option' + calcparam.get('msid')) + '&asid=' + $F('Option' + calcparam.get('asid')) + '&optp=' + optp;
	serverPage = sPage + '&price=1';
	doAjaxCall(serverPage, thread);
}

/*
	This opens the color picker
	@root        the Ajax page that is called
	@vendor      the vendor
	@group       no idea ...
	@jsret       the return function for the JS (4 variables are returned, view the 'jsReturn' function in functions.js for more info
	@showup      no idea ...
	@addArgs     Any additional variables needed to pass to the fabric tool
*/
function open_color_pick(root, vendor, group, jsret, showup, addArgs) {
	w = window.open(root + 'include/calculators/fabricpick/fabricpick.php?v=' + vendor + '&g=' + group + '&jsfunc=' + jsret + '&showup=' + showup + addArgs, 'fabricwin', 'toolbar=no,scrollbars=yes,status=no,height=625,width=700');
	w.focus();
}

function open_color_pick_any(root, vendor, group, jsret, showup) {
	open_color_pick(root, vendor, group, jsret, showup, '&anyv');
}

// Is this old?
function childcolor(OLD, ID, Name, Upcharge) {
	alert("returned with "+ID+" and "+Name+" and "+Upcharge);
}