var joinmail_thanks = 'Thank you for signing up for our special offers and promotions.';
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)
{
	if (document.getElementById(id).value == '')
	{
		alert(msg);
		document.getElementById(id).select();
		return false;
	}
	
	return true;
}

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();
}

function dojoinmail(ajaxsecuritycode)
{
	var o = document.getElementById('email'); 
        var email = o.value;
	if ((email == '') || !emailcheck(email))
	{
		alert('Your email address is invalid, please re-enter');
		o.select();
	}
	else
	{
		var e = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	        if (e) 
                {
e.onreadystatechange = function()
								{
									if (e.readyState == 4 && e.status == 200) {
										alert(joinmail_thanks);
		                                                                o.value = 'Enter your email address';
									}
								}
                   param = 'email='+email+'&'+ajaxsecuritycode;
	           e.open("POST", 'joinmail.php', true);
	           e.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	           e.send(param);
	        }
        }
}
//fix page to title
/*addpagetitle=function(){var u=window.location.href;for(var i=2;i<=100;i++){var p='/page/'+i;if(u.length>p.length){var s=u.substring(u.length-p.length);if(s==p){var t=document.title+' Page '+i;document.title=t;break;};};};};addpagetitle();*/