// www.jamesburgess.co.uk :)

function disableOnLoad() {
	fields = [document.form1.customhair];
	for(i=0; i<(fields.length); i++)
	{
		fields[i].disabled = true;
	}
}

function checkNumber(input){
  var num = input.value.replace(/\,/g,'');
  if(!isNaN(num)){
    if(num.indexOf('.') > -1) {
      alert("You may not enter any decimals.");
      input.value = input.value.substring(0,input.value.length-1);
    }
  } else {
    alert('You may enter only numbers in this field!');
    input.value = input.value.substring(0,input.value.length-1);
  }
}

function updatePrice(ignore)
{
	// Base price is £5
	// If shirt/number/name decal is added, add £1 each
	// If custom hair is added, add £1.50
	decals = [document.form1.checkbox1, document.form1.checkbox2, document.form1.checkbox3];
	customHairBox = document.form1.customhaircheck;
	price = 5;
	postage = 1.5;

	for(i=0; i<(decals.length); i++)
	{
		if(decals[i].checked)
		{
			price += 1;
		}
	}

	if(customHairBox.checked)
	{
		price += 1.5;
	}

	// Update price
	totalString = (price+postage).toString();
	teamString = price.toString();
	if (totalString.indexOf('.') == -1)
	{
		totalString += '.00';
	}
	else if (totalString.indexOf('.') == totalString.length -2)
	{
		totalString += '0';
	}
	if (teamString.indexOf('.') == -1)
	{
		teamString += '.00';
	}
	else if (teamString.indexOf('.') == teamString.length -2)
	{
		teamString += '0';
	}
	document.getElementById('totalPrice').innerHTML = totalString;
	document.getElementById('playerPrice').innerHTML = teamString;

	setTimeout("updatePrice(null)",200);
}

function disableFieldsIfChecked(checkbox,fields)
{
	if(checkbox.checked)
	{
		for(i=0; i<(fields.length); i++)
		{
			fields[i].disabled = false;
		}
	} else {
		for(i=0; i<(fields.length); i++)
		{
			fields[i].disabled = true;
		}
	}
}

function cancelSubmitIfNotEqual(email,confirm)
{
	if((email.value.length>0) || (confirm.value.length>0))
	{
		if(email.value!=confirm.value)
		{
			alert("Email addresses do not match.");
			return false;
		}
	} else {
		alert("Please fill out both email fields.");
		return false;
	}

	return true;
}

function cancelSubmitIfNotPresent(field,name)
{
	if(field.value.length==0)
	{
		alert("The '"+name+"' field was not completed.");
		return false;
	}

	return true;
}
