/*
Updates current price of product on any page
*/

function get_size_price(sku){
	size_price = 0;
	size_element = 'size_'+sku;
	if (document.getElementById(size_element)) {
		sp = document.getElementById(size_element).value;
		if (sp.indexOf("=") > -1) {
			splitup = sp.split("=");
			//alert(splitup[1]);
			if (splitup[1].charAt(0) == '+') {
				size_price = splitup[1].substr(1,splitup[1].length-1);
				//alert(size_price);
			} else {
				size_price = splitup[1];
			}
		}
	}
	return size_price;
}

function get_color_price(sku){
	color_price = 0;
	color_element = 'color_'+sku;
	if (document.getElementById(color_element)) {
		csp = document.getElementById(color_element).value;
		if (csp.indexOf("=") > -1) {
			splitup = csp.split("=");
			if (splitup[1].charAt(0) == '+') {
				color_price = splitup[1].substr(1,splitup[1].length-1);
			} else {
				color_price = splitup[1];
			}
		}
	}
	return color_price;
}

function get_fabric_price(sku){
	fabric_price = 0;
	fabric_element = 'fabric_'+sku
	if (document.getElementById(fabric_element)) {
		fp = document.getElementById(fabric_element).value;
		if (fp.indexOf("=") > -1) {
			splitup = fp.split("=");
			if (splitup[1].charAt(0) == '+') {
				fabric_price = splitup[1].substr(1,splitup[1].length-1);
			} else {
				fabric_price = splitup[1];
			}
		}
	
		// item or manufacturer specific alerts
		if (document.getElementById(fabric_element).value=='Leopard (+$ 4.00)') {
			alert('Please note: Leopard fabric comes in only one color. Colors ignored.');
			color_element = 'color_'+sku;
			if (document.getElementById(color_element)) {
				document.getElementById(color_element).disabled = true;
			}
		} else {
			color_element = 'color_'+sku;
			if (document.getElementById(color_element)) {
				document.getElementById(color_element).disabled = false;
			}
		}
	
	}
	return fabric_price;
}

function get_style_price(sku){
	style_price = 0;
	style_element = 'style_'+sku
	if (document.getElementById(style_element)) {
		fp = document.getElementById(style_element).value;
		if (fp.indexOf("=") > -1) {
			splitup = fp.split("=");
			if (splitup[1].charAt(0) == '+') {
				style_price = splitup[1].substr(1,splitup[1].length-1);
			} else {
				style_price = splitup[1];
			}
		}	
	}
	return style_price;
}

function get_frame_price(sku){
	frame_price = 0;
	frame_element = 'frame_'+sku
	if (document.getElementById(frame_element)) {
		fp = document.getElementById(frame_element).value;
		if (fp.indexOf("=") > -1) {
			splitup = fp.split("=");
			if (splitup[1].charAt(0) == '+') {
				frame_price = splitup[1].substr(1,splitup[1].length-1);
			} else {
				frame_price = splitup[1];
			}
		}
	}
	return frame_price;
}

function update_price(sku){
	price = document.getElementById('initial_price_'+sku).value;
	//alert(price);
	size_price = get_size_price(sku);
	color_price = get_color_price(sku);
	fabric_price = get_fabric_price(sku);
	frame_price = get_frame_price(sku);
	style_price = get_style_price(sku);
	
	//alert(price+' + '+size_price+' + '+color_price+' + '+fabric_price+' + '+frame_price);
	new_price = parseFloat(price) + parseFloat(size_price) + parseFloat(color_price) + parseFloat(fabric_price) + parseFloat(frame_price) + parseFloat(style_price);
	document.getElementById('price_'+sku).value = new_price.toFixed(2);
	document.getElementById('show_price_'+sku).value = '$ '+new_price.toFixed(2);
	switchfocus(sku);
	return true;
}
