var province_innerhtml, state_innerhtml, ship_province_innerhtml, ship_state_innerhtml, ini_val_cart;

$(function(){
	if(document.getElementById('ctv')) {
		ini_val_cart = parseFloat(document.getElementById('ctv').innerHTML);
	}
});

$(function(){
	calc_ctv();
});

function calc_ctv() {
	if(document.getElementById('ctv')) {
		shipp = document.getElementById('calc_ctv_sel').value;
		tpvalue = parseFloat(shipp) + parseFloat(ini_val_cart);
		document.getElementById('ctv').innerHTML = Math.round(tpvalue*100)/100 + ' &#36;';
	}
}

$(function(){
	if(document.getElementById("canada_province")) {
		province_innerhtml = document.getElementById("canada_province").innerHTML;
		state_innerhtml = document.getElementById("us_state").innerHTML;
		ship_province_innerhtml = document.getElementById("canada_province_shipping").innerHTML;
		ship_state_innerhtml = document.getElementById("us_state_shipping").innerHTML;
	
		place_corect_province_state_selector();
	
		$("#country").change(function(){
			place_corect_province_state_selector();	
		});
		
		$("#shipping_country").change(function(){
			place_corect_province_state_selector();
		});
	}	
});

function place_corect_province_state_selector() {

	country_val = $("#country").attr('value');
	ship_country_val = $("#shipping_country").attr('value');
	
	if(country_val == 'us') {
		$("#canada_province").html('');
		$("#us_state").html(state_innerhtml);
	} else {
		$("#us_state").html('');	
		$("#canada_province").html(province_innerhtml);
	}
	
	if(ship_country_val == 'us') {
		$("#canada_province_shipping").html('');
		$("#us_state_shipping").html(ship_state_innerhtml);
	} else {
		$("#us_state_shipping").html('');
		$("#canada_province_shipping").html(ship_province_innerhtml);
	}
	
}

function color_attribute_select_manager() {
	$("select[@name='attr[color]'] option").each(function(){
		if(this.value.substring(0,1) == '#') {
			this.style.backgroundColor = this.value;
		}		
	});
}

function show_hide(id) {
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	} 
}

$(function(){
	color_attribute_select_manager();
});


function equalize_divs(div1,div2,div3) {
	
	h1 = document.getElementById(div1).clientHeight;
	h2 = document.getElementById(div2).clientHeight;
	h3 = document.getElementById(div3).clientHeight;
	mx = Math.max(h1,h2);
	mx = Math.max(mx,h3);

	if(mx < 1050) {
		mx = 1050;
	}

	if(document.all) {
		$("#"+div1).css('height',mx);
	} else {
		$("#"+div1).css('height',(mx-10));
	}	
	
	$("#"+div2).css('height',mx);
	
	if(document.all) {
		$("#"+div3).css('height',(mx-15));
	} else {
		$("#"+div3).css('height',(mx-25));
	}
	
	if(document.all) {
		$("#leftbar_menu").css('height',(mx-97));
	} else {
		$("#leftbar_menu").css('height',(mx-107));
	}

	if(document.all) {
		$("#products").css('height',(mx-47));
	} else {
		$("#products").css('height',(mx-55));
	}
}