function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

function __checkTB(id, msg)
{
   var f = document.forms['frm1'];
   for (var i=0; i<f.elements.length; i++)
   {
      var o = f.elements[i];
      if (o.id == id)
      {
         var v = o.value;
         if (v.value == '')
         {
            alert(msg);
            o.select();
            return false;
         }
         return true;
      }
   }
   return true;
}


function checkcontactsubmit()
{
var f = document.getElementById('frm1');

var o, v;

//name
o = f['name'];
v = o.value;
if (v == '')
{
   alert('Please input your name');
   o.select();
   return false;
}

//email
o = f['email'];
v = o.value;
if (v == '')
{
   alert('Please input your email address');
   o.select();
   return false;
}
if (!emailcheck(v)) 
{
alert('Plese input your valid email address');
o.select();
return false;
}

//details
o = f['details'];
v = o.value;
if (v == '')
{
   alert('Please input provide some details about your project');
   o.select();
   return false;
}

return f.submit();
}

function SendContactUs()
{
  if (!__checkTB('name', 'Please input your name')) return false;
  if (!__checkTB('email', 'Please input your valid email address')) return false;
  if (!emailcheck(document.getElementById('email').value))
{
alert('Please input your valid email address');
document.getElementById('email').select();
 return false;
}

  return true;
}

function checkform()
{
	var frm = document.getElementById('form_product_registration');
		
	if (!__checkTB('firstname', 'Please input your first name'))
	{
		return false;
	}
	
	if (!__checkTB('lastname', 'Please input your last name'))
	{
		return false;
	}
	
	if (!__checkTB('email', 'Please input your email address'))
	{
		return false;
	}
	
	if (!__checkTB('dealername', 'Please input the dealer name'))
	{
		return false;
	}
	
	if (!__checkTB('dateofpurchase', 'Please input date of purchase'))
	{
		return false;
	}
	
	return frm.submit();
}

