//====================================================================================================
//	File Name		:	login.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Client side validation in JavaScript.
//====================================================================================================

//====================================================================================================
//	Function Name	:	Form_Submit()
//	Purpose			:	This function will executed when user submits a form. It checks validity of 
//----------------------------------------------------------------------------------------------------
function Form_Submit(frm)
{
	with(frm)
    {
		if(name.value == "")
        {
			name.focus();
			alert('Please Enter Your Name.');
			return false;
        }
    	if(email.value == "")
        {
			email.focus();	
			alert('Please Enter Email Address.');
			return false;
        }
		if(!IsEmail(email,'Please enter valid email.'))
		{
			return false;
		}	

		if(company.value == "")
        {
			company.focus();
			alert('Please Enter Company Name.');
			return false;
        }
		if(phonecode.value == "")
        {
			phonecode.focus();
			alert('Please Enter Phone Code.');
			return false;
        }
		if(phone.value == "")
        {
			phone.focus();
			alert('Please Enter Phone No.');
			return false;
        }
		if(findus.value == "")
        {
			findus.focus();
			alert('Please enter how you find us.');
			return false;
        }
		if(question.value == "")
        {
			question.focus();
			alert('Please enter your question.');
			return false;
        }
		return true;
		frm.submit();
        
    }
}


//====================================================================================================
//	Function Name	:	IsEmail()
//----------------------------------------------------------------------------------------------------
function IsEmail(fld,msg)
{
	var regex = /^[\w]+(\.[\w]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

//====================================================================================================
//	Function Name	:	res()
//----------------------------------------------------------------------------------------------------
function res(t,v)
{
	var w = "";
	for (i=0; i < t.value.length; i++) 
	{
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	t.value = w;
}	

