﻿function js_validate_shipto(){
	var first_name = document.getElementById('first_name').value;
	var last_name = document.getElementById('last_name').value;
	var address_1 = document.getElementById('address_1').value;
	var city = document.getElementById('city').value;
	var state = document.getElementById('state').value;
	var zip = document.getElementById('zip').value;
	var phone_1 = document.getElementById('phone_1').value;
	if(!first_name){
		alert("First Name is required field!");
		return false;
	}
	if(!last_name){
		alert("Last Name is required field!");
		return false;
	}
	
	if(!address_1){
		alert("Address is required field!");
		return false;
	}
	if(!city){
		alert("City is required field!");
		return false;
	}
	if(!state){
		alert("State is required field!");
		return false;
	}
	if(!zip){
		alert("zip is required field!");
		return false;
	}
	
	if(!phone_1){
		alert("Phone is required field!");
		return false;
	}
	return true;
}
function js_syn_tax_state(status){
	var state = document.getElementById('state');
	var state_tax = document.getElementById('state_tax');
	if(status=="state"){
		if(state.value=="Ontario"){
			state_tax.value="Ontario";
		}else
		{
			state_tax.value="other";
		}
	}else if(status=="tax"){
		if(state_tax.value=="Ontario"){
			state.value="Ontario";
		}else{
			state.value="";
		}
		
	}
	js_update_amount();
	return true;
}
function js_update_amount(){
	var tax_amount=0;
	var price=document.getElementById('price');
	var quantity = document.getElementById('quantity');
	var tax = document.getElementById('state_tax');
	var total = document.getElementById('total');
	var subtotal =quantity.value * price.value;
	var shipping_amount=quantity.value*11;
	if(tax.value=="Ontario"){
		tax_amount=0.11*(subtotal+shipping_amount);
	}
	else{
		tax_amount=0.05*(subtotal+shipping_amount);
	}
	var amount_el = document.getElementById('amount');
	amount_el.innerHTML = (subtotal+shipping_amount);
	total.innerHTML = (subtotal+shipping_amount+tax_amount);
	return true;
}
function js_get_price(){
	var item_type=document.getElementById('item_type');
	var price=document.getElementById('price');
	var default_price = document.getElementById('default_price');
	if(item_type.value=="unit"){
		price.innerHTML= default_price.value;
	}else if(item_type.value=="case"){
		price.innerHTML=default_price.value*36;
	}
	js_update_amount();
	return true;
}
function js_checkZipcode()
{
	var d = document.getElementById('keywordZipCode').value;
	if (!d)
	{
		alert('Zip Code field is empty !!!');
		return false;
	}
	return true;
}

function js_checkExistedZipcode()
{
	var country = document.getElementById("country").value;
	var zip = document.getElementById("zip").value;
	if(!country)
	{
		alert('A country must be selected!!! ');
		return false;
	}
	if(!zip)
	{
		alert('A zip must be entered!!! ');
		return false;
	}
	window.open('zipcode_checked.php?country='+country+'&zip='+zip,'CheckZipcode','width=300,height=200')
	return true;
	
}