// JavaScript Document

jQuery.fn.validateEmail = function(){
var emailfilter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
var result=emailfilter.test(arguments[0])		
return result
}
function validateContact()
{
		var err = 0;
		
		$("input").each(function(){
			
			//Verify if any of textfield is empty except product
			if($(this).val()=='')
			{
				if($(this).attr('name')=='productLine')
				{
				
				}
				else if($(this).attr('id')=='product')
				{
					// check if product is check or not
					
					if($("input[type='radio'][name='pastProduct']:checked").val()=='yes') // yes is checked
					{
							alert("Please provide the information for the product you have purchased")
							err = 1; // used for indicating return false
							$(this).focus();
							return false; // break out of the loop
							
					}
				
				}
				else
				{
					alert("Please enter a value for "+$(this).attr('rel'))
					$(this).focus()
					err=1;
					return false;
				
				}
					
				
			}
			
			// Check if email is in a valid format 
			
			if($(this).attr('id') =='email')
			{
						if(!$(this).validateEmail($(this).val()) )
						{
							alert("Please enter a correct email format")
							$(this).focus();
							err=1;
							return false;
						}
			
						if($(this).val().toLowerCase()!=$('#confirmEmail').val().toLowerCase())
						{
							alert("Please confirm your email correctly");
							$('#confirmEmail').focus();
							err=1;
							return false;
						}
						
			}
			
			//verfity if email is re entering version
			
			
			
			
			// check if re-entering email is correct
		})
		
		if(err ==0) // check if othe fields are empty
		{
			if(typeof($("input[type='radio'][name='retailerConsumer']:checked").val())=='undefined')
			{
				alert("Please indicate whether you are a retailer or consumer")
				return false;
			}
			
						//alert($("input[type='radio'][name='pastProduct']:checked").val())

			if(typeof($("input[type='radio'][name='pastProduct']:checked").val())=='undefined') // yes is checked
			{
						alert("Please pick Yes or No to Have you purchased any Ganz products in the past?")
						err = 1;
						return false;	
			}
		
			if($("#comments").val().replace(/^\s+/,'')=='')
			{
				alert("Please enter a value for Comments");
				return false;
			}
		
		
		
			return true; // return ture if everything are fine
			
		}// error 
		else // if any field is empty , return false 
		{
			return false;	
		}

			
}




/* 
	function validateSbumitForm: validate general submit forms
*/


function validateSubmitForm()
{
	
	var err = 0;

	$("input").each(function(){
			
			//Verify if any of textfield is empty except product
			if($(this).val()=='')
			{
				alert("Please enter a value for "+$(this).attr('rel'))
				$(this).focus()
				err=1;
				return false;
				
			}
	
			
			// Check if email is in a valid format 
			
			if($(this).attr('rel') =='Email')
			{
						if(!$(this).validateEmail($(this).val()) )
						{
							alert("Please enter a correct email format")
							$(this).focus();
							err=1;
							return false;
						}
						
			}
		})

	
	
		if(err ==0)
		{
			if($("#comments").val().replace(/^\s+/,'')=='')
			{
				alert("Please enter a value for Comments");
				return false;
			}
			return true;
			
		}// error 
		else
		return false;
	
	
	
}

