
function check_add_product()
{
	if (document.add_product.number.value==''||document.add_product.number.value=='0')
	{
		alert('Du skal mindst tilføje et produkt');
		document.add_product.number.focus();
		return false;
	}
	new Ajax.Request('/type.butik.php', {
		asynchronous: true,
		method: 'post',
		parameters: 'number='+document.add_product.number.value+'&product_id='+document.add_product.product_id.value,
		onSuccess: function(t) {
			$('do_order').style.display='none';
			$('order_done').style.display='block';
		},
		onFailure: function(t) {
			alert('Der opstod en fejl');
		}
	});
	return false;
}

function check_basket()
{
	return true;
}

function check_information()
{
	if (document.information.name.value=='')
	{
		alert('Du skal angive dit navn');
		document.information.name.focus();
		return false;
	}
	if (document.information.address.value=='')
	{
		alert('Du skal angive din adresse');
		document.information.address.focus();
		return false;
	}
	if (document.information.postalcode.value=='')
	{
		alert('Du skal angive dit postnummer');
		document.information.postalcode.focus();
		return false;
	}
	if (document.information.city.value=='')
	{
		alert('Du skal angive din by');
		document.information.city.focus();
		return false;
	}
	if (document.information.phone.value=='')
	{
		alert('Du skal angive dit telefonnummer');
		document.information.phone.focus();
		return false;
	}
	if (document.information.email.value=='')
	{
		alert('Du skal angive din email adresse');
		document.information.email.focus();
		return false;
	}	
	if (validate_email(document.information.email.value) == false)
	{
		alert('Du skal angive din email adresse korrekt');
		document.information.email.focus();
		return false;
	}
	return true;
}

function check_accept()
{
	if (document.accept.accept_box.checked!=true)
	{
		alert('Før du kan gå til betaling skal du acceptere betingelserne');
		return false;
	}
	return true;
}

function check_pay()
{
	var cn = document.payment.cardnumber.value;
	var month = document.payment.expMonth.value;
	var year = document.payment.expYear.value;
	var cvc = document.payment.cvc.value;
	
	if (cn=='')
	{
		alert('Du skal angive dit kortnummer');
		return false;
	}
	if (valid_number(cn) == false || cn.length>16 || cn.length<13)
	{
		alert('Du skal angive dit kortnummer korrekt');
		return false;
	}
	if (cvc=='')
	{
		alert('Du skal angive kontrolcifre');
		return false;
	}
	if (valid_number(cvc) == false || cvc.length!=3)
	{
		alert('Du skal angive kontrolcifre korrekt');
		return false;
	}	
	return true;
}

function valid_number(string) 
{
   var reg = /^[0-9]+$/;
   if(reg.test(string) == false) 
   {
      return false;
   }
   return true;
}

/*function popup(url,width,height) 
{
	pos_horizon = ((screen.width/2)-(width/2));
	pos_vertical = ((screen.height/2)-(height/2));
	var popup_win = window.open(url,'popup','width='+width+',height='+height+',left='+pos_horizon+',top='+pos_vertical+',resizable=no,scrollbars=no,menubar=no,status=no');
}*/