<!--


	/*
		Function:	validate
		Purpose:	validate fields
		In:			form object
		Out:		if all values are fine, return true. Otherwise, false			
	*/		
	function validate(whatform)
	{		
	
		with (whatform)
		{			
			/* 
				Validate required values first 
			*/
			if ( Required(product,"Please select a product.",2,200,"Please select a product") == false )
			{
				product.focus();
				return false;
			}			
			
			if ( Required(fullname,"Please provide your name.",2,100,"Please provide your name between 2 and 100 characters") == false )
			{
				fullname.focus();
				return false;
			}
			if ( alphabetsCheck(fullname,"Please provide a valid fullname (alphabets please, no quotation, dots etc)") == false )
			{
				firstname.focus();
				return false;
			}			
			
			if ( Required(emailid,"Please provide your email id.",6,100,"Please enter a valid email of less than 100 characters") == false )
			{
				emailid.focus();
				return false;
			}							
			if ( EmailCheck(emailid,"Please provide a valid email address.") == false )
			{
				emailid.focus();
				return false;
			}
			
			if ( NotRequired(comments,"Please provide your comment",2,5000,"Please keep the comment to less than 5000 characters") == false )
			{
				comments.focus();
				return false;
			}
			
			if ( Required(imagetext,"Please enter the text from the image",2,10,"Please keep the image text to less than 10 characters") == false )
			{
				imagetext.focus();
				return false;
			}	
			
		}	
		return true;
	}
	
	

	
	

	/*
		Function:	EmailCheck
		Purpose:	validates incoming email address
		In:			fieldname and message
		Out:		true if email address is valid, false otherwise
	*/
	function EmailCheck(fieldname,message)
	{
		with (fieldname)
		{
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value))) 
			{
				alert(message);
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	
	
	
	/*
		Function:	alphanumericCheck
		Purpose:	validates incoming data as alphanumeric
		In:			fieldname and message
		Out:		true if alphanumeric, false otherwise
	*/	
	function alphanumericCheck(fieldname, message)
	{
		var regex=/^([a-zA-Z0-9]+)$/; 
		with (fieldname)
		{
			if (value==null || value=="")
			{
				return true;
			}		
			if(!(regex.test(value)))
			{
				alert (message);
				return false;
			}
			else
			{				
				return true;
			}
		}
	}

	
	

	/*
		Function:	alphabetsCheck
		Purpose:	validates incoming data as alphabets
		In:			fieldname and message
		Out:		true if alphabets, false otherwise
	*/	
	function alphabetsCheck(fieldname, message)
	{
		var regex=/^([a-zA-Z ]+)$/; 
		with (fieldname)
		{
			if (value==null || value=="")
			{
				return true;
			}		
			if (!(regex.test(value)))
			{
				alert (message);
				return false;
			}
			else
			{
				return true;
			}
		}
	}	
	

	

	
	/*
		Function:	Required
		Purpose:	Checks fieldname to see if it is empty. If empty, 
					throws error message and returns false
		In:			field name and alert message text
		Out:		true if value is contained in the field, false otherwise			
	*/
	function Required(fieldname,message,minLength1,maxLength1,messageRelatedToLength)
	{

		with (fieldname)
		{		
			if (value==null || value=="")
			{
				alert(message);
				return false;
			}
			else
			{	
				if (trim(fieldname.value).length == 0)
				{
					alert (message);					
					return false;
				}
				else
				{
					if (trim(fieldname.value).length < minLength1 || trim(fieldname.value).length > maxLength1)
					{
						alert (messageRelatedToLength);
						return false;
					}
					else
						return true;
				}
			}
		}
	}		
	
	
	
	
	function trim(str)
	{
		return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '')
	}
	


	/*
		Function:	CheckLength
		Purpose:	verifies if the length of 
		In:			field name and alert message text
		Out:		true if value is contained in the field, false otherwise			
	*/
	function CheckLength(fieldname,whatlength,message)
	{
		if (fieldname.value > whatlength)
		{
			alert (message);
			return false;
		}
		else
			return true;
	}		
	



	/*
		Function:	NotRequired
		Purpose:	If there is data in the field, checks to see if it
					is between min and max length permissible
		In:			field name and alert message text
		Out:		true if value is contained in the field, false otherwise			
	*/
	function NotRequired(fieldname,message,minLength,maxLength,messageRelatedToLength)
	{
		with (fieldname)
		{		
			if (value==null || value=="")
			{
				// do nothing here
				return true;
			}
			else
			{	
				if (trim(fieldname.value).length == 0)
				{
					// do nothing here
					return true;
				}
				else
				{
					if (trim(fieldname.value).length < minLength || trim(fieldname.value).length > maxLength)
					{
						alert (messageRelatedToLength);
						return false;
					}
					else
						return true;
				}
			}
		}
	}
				
	
-->


