function NameCheck(name) 
{
	if ((name == null) || (name == ""))
	{
		alert("Please enter your name");
		return false;
	}

	return true;					
}

function EmailCheck(email) 
{
	if ((email == null) || (email == ""))
	{
		alert("Please enter your email");
		return false;
	}
	var indexOfAt = email.indexOf("@");
	var indexOfDot = email.indexOf(".");

	if (indexOfAt == -1 || indexOfAt == 0 || indexOfAt == email.length)
	{
	   alert("Please provide a correctly formatted email. mail@test.com");
	   return false;
	}

	if (indexOfDot == -1 || indexOfDot == 0 || indexOfDot == email.length)
	{
		alert("Please provide a correctly formatted email. mail@test.com");
		return false;
	}

	if (email.indexOf(at,(indexOfAt+1)) != -1)
	{
		alert("Please provide a correctly formatted email. mail@test.com");
		return false;
	}

	if (email.substring(indexOfAt-1,indexOfAt) == dot || email.substring(indexOfAt+1,indexOfAt+2) == dot)
	{
		alert("Please provide a correctly formatted email. mail@test.com");
		return false;
	}

	if (email.indexOf(dot,(indexOfAt+2)) == -1)
	{
		alert("Please provide a correctly formatted email. mail@test.com");
		return false;
	}
	
	if (email.indexOf(" ") != -1)
	{
		alert("Please provide a correctly formatted email. mail@test.com");
		return false;
	}

	return true;					
}

function ValidateForm()
{
	var name = document.getElementById("name");
	var email = document.getElementById("email");
	if(!NameCheck(name.value))
	{
		return false;
	} 
	if(!EmailCheck(email.value))
	{
		return false;
	} 
	return true;
 }
 
function show_progress_indicator()
{
	progress_image = document.getElementById("progress_indicator");
	progress_image.style.visibility = "visible";
}

function calculate_subtotal(item_num, price, pandh, pandh_additional_items, num_possible_items)
{
	qty = document.getElementById("quantity_"+item_num).value;
	if(qty == 1)
	{		
		document.getElementById("subtotal_"+item_num).innerHTML = (qty * price) + pandh;
	}
	else if(qty > 1)
	{
		subtotal_change = (qty * price) + pandh;
		for (i = 1; i < qty; i++)
		{
			subtotal_change += pandh_additional_items;
		}
		document.getElementById("subtotal_"+item_num).innerHTML = subtotal_change;				
	}
	else
	{
		document.getElementById("subtotal_"+item_num).innerHTML = 0;	
	}
	
	new_subtotal = 0;
	for (item_num = 1; item_num < num_possible_items; item_num++)
	{
		new_subtotal += parseFloat(document.getElementById("subtotal_"+item_num).innerHTML);
	}
	document.getElementById("subtotal").innerHTML = parseFloat(new_subtotal);

}

