/*------------------------------------------------------------------------------------
* Filename: fromValidation.js
* Version: 1.1.0 (2009-08-28)
* Website: www.Fink.com
* Author: Tanvir Ahmad Ronty
* Description: Handles layout animations.
------------------------------------------------------------------------------------*/

function validate_form(thisform)
{
	
	returnValue1 = CheckEmpty('input#ProductName','Name is missing.');
	returnValue2 = CheckEmpty('input#DesignerName','Subject is missing.');
	returnValue3 = CheckEmail('input#PostEmail','Contact Email is missing.');
	returnValue4 = CheckEmpty('input#Picture','Product picture is missing.');
	
	
	if(returnValue1 && returnValue2 && returnValue3 && returnValue4)
	{
		return true;
	
	}
	else
	{
		return false;	
	}
	
	return false;	
}

function CheckEmpty(ID,MSG)
{
	if(($(ID).val()==null)||($(ID).val()==""))
	{
		if(!($(ID).next().is('div')))
		{
			$(ID).after("<div class='Error'>"+MSG+"</div>");
		}
		else
		{
				$(ID).next().get(0).innerHTML=MSG;
		}
		returnValue=false // Error found Ok
	}
	else
	{
		if($(ID).next().is('div'))
		{
			$(ID).next().get(0).innerHTML='';		
		}
		returnValue=true //No Error Found
	}
	

	
	return returnValue;
}



function CheckEmail(ID,MSG)
{
	if(($(ID).val()==null)||($(ID).val()==""))
	{
		if(!($(ID).next().is('div')))
		{
			$(ID).after("<div class='Error'>"+MSG+"</div>");
		}
		else
		{
				$(ID).next().get(0).innerHTML=MSG;
		}
		returnValue=false // Error found Ok
	}
	else
	{
		at=$(ID).val().indexOf("@");
		lastDot=$(ID).val().lastIndexOf(".");
		if (at<1||lastDot-at<2)
		{
			if(!($(ID).next().is('div')))
			{
				$(ID).after("<div class='Error'>Not a valid e-mail address</div>");
			}
			else
			{
					$(ID).next().get(0).innerHTML='Not a valid e-mail address';
			}
			returnValue=false // Error found Ok
		}
		else
		{
			if($(ID).next().is('div'))
			{
				$(ID).next().get(0).innerHTML='';		
			}
			returnValue=true //No Error Found
		}
	}
	

	
	return returnValue;
}


