
function getAnotherProduct ()
{
	pic = document.getElementById('product_image_file');	
	pic_ref = document.getElementById('product_image_ref');
	
	label = document.getElementById('product_name');
	label_ref = document.getElementById('product_label_ref');

	if (pic.src.indexOf ('acetone') > 0)
	{
			pic.src = '/_images/complete.jpg';
			label.src = '/_images/complete_label.gif';
			pic_ref.href = '/products/complete/';
			label_ref.href = '/products/complete/';
	}
	else
	{
			pic.src = '/_images/acetone.jpg';
			label.src = '/_images/acetone_label.gif';
			pic_ref.href = '/products/acetone/';
			label_ref.href = '/products/acetone/';
	}

}

function switchImg (ctrl, sImage)
{
	ctrl.src = '/_images/' + sImage;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function validateForm ()
{
	firstname = document.getElementById ('edFirstName');
	lastname = document.getElementById ('edLastName');
	street = document.getElementById ('edStreet');
	town = document.getElementById ('edTown');
	county = document.getElementById ('edCounty');
	chkAgree  = document.getElementById ('chkAgree');
	edEmail = document.getElementById ('edEmail');

	
	bChecked =false;
	for (i=0; i < document.forms[0].rdHowOften.length; i++)
		if ( document.forms[0].rdHowOften[i].checked)
			bChecked = true;

	if (!bChecked)
	{
		alert ('Please answer the question as to how often you use nail polish.');
		return false;
	}

	bChecked =false;
	for (i=0; i < document.forms[0].rdProduct.length; i++)
		if ( document.forms[0].rdProduct[i].checked)
			bChecked = true;
	
	if (!bChecked)
	{
		alert ('Please choose which product you would like a free sample of');
		return false;
	}
			
	if (firstname.value=='')
	{
		alert ('Pleaes enter your first name');
		return false;
	}

	if (lastname.value=='')
	{
		alert ('Pleaes enter your last name');
		return false;
	}
	
	if (street.value=='')
	{
		alert ('Pleaes enter your street ');
		return false;
	}

	if (town.value=='')
	{
		alert ('Pleaes enter your town');
		return false;
	}


	if (county.value=='')
	{
		alert ('Pleaes enter your county');
		return false;
	}
	
	if (edEmail.value=='')
	{
		alert ('Please enter a valid email address');
		return false;
	}

	if (!echeck(edEmail.value))
		return false;


	if (!chkAgree.checked)
	{
		alert ('You must agree to the terms & conditions before submitting.');
		return false;
	}

	return true;
}

