function setpayment(a) {
	if (navigator.cookieEnabled) {
		document.cookie = 'pay='+a+';';
		var payments = document.getElementById('payments').childNodes;
		for(el in payments) {
			payments[el].className = '';
		}
		document.getElementById(a).className='sel';
		if(document.getElementById('paymentmethod')){
			document.getElementById('paymentmethod').value = a;
		}        
	}
}

function popup(id, a){
    if(a){
      document.getElementById(id).style.visibility='visible';
    }else{
      document.getElementById(id).style.visibility='hidden';
    }
};

function preview(pic){
  var w = document.getElementById('preview');
  w.innerHTML = '<img src="items/'+pic+'" alt="" /><a href="javascript:closepreview();" title="close picture">close [X]</a>';
  w.style.display='block';
};

function closepreview(){
  var w = document.getElementById('preview');
  w.style.display='none';
  w.innerHTML = '';
};

function watch_count(action, id)
{
	document.count.action.value = action;
	document.count.id.value = id;
	document.count.submit();
};

function recount() {
	document.cart.action.value = 'recount';
	document.cart.submit();
}

function shipping(country) {
	if (country) {
		var shippingCost = 75;
		if (country == 'United States') {
			shippingCost = 45;
		}
		var amount = parseInt(document.getElementById('totalAmount').innerHTML);
		document.getElementById('shippingCost').innerHTML = '$'+shippingCost;
		var amShip = amount+shippingCost;
		document.getElementById('amountWithShipping').innerHTML = '$'+formatCost(amShip);
	} else {
		document.getElementById('shippingCost').innerHTML = 'choose country';
		document.getElementById('amountWithShipping').innerHTML = 'choose country';
	}
}

function formatCost(cost) {
	var str = '';
	var cost2 = String(cost);
	var len = cost2.length;
	for (i = 0; i < len; i++) {
		str += cost2.substr(i, 1);
		if ((len-i) % 3 == 1 && i != (len-1)) {
			str += ',';
		}
	}
	return str;
}

function check_order() {
	if (document.getElementById('full_name').value &&
		document.getElementById('email').value &&
		document.getElementById('address').value &&
		document.getElementById('city').value &&
		document.getElementById('zip').value &&
		document.getElementById('country').value) {
		return true;	
	}
    alert('Please fill all fields with *');
	return false;
}