
function CheckLogin()
{
	if(document.right.vEmail.value=='')
	{
		alert('Invalid Email or Password');
		document.right.vEmail.focus();
		document.right.vEmail.value='';
		return false;
	}
	else
	{
		if(document.right.vEmail.value != "" && isValidEmail(document.right.vEmail.value) == false	)
		{
			document.right.vEmail.focus();
			return false;
		}
	}

	if(document.right.vPassword.value=='')
	{
		alert('Invalid Email or Password');
		document.right.vPassword.focus();
		document.right.vPassword.value='';
		return false;
	}
	document.right.submit();
}

function CheckNewsLetter()
{
	if(document.right.mail.value=='E-mail' || document.right.mail.value=='')
	{
		alert('Inserisci e-mail');
		document.right.mail.focus();
		document.right.mail.value='';
		return false;
	}
	else
	{
		if(document.right.mail.value != "" && isValidEmail(document.right.mail.value) == false	)
		{
			document.right.mail.focus();
			return false;
		}
	}
	var mail='php/newsletter_a.php?mode=Add&mail='+document.right.mail.value;
	window.location.href=mail;
}

function isValidEmail(mailStr) 
{
	
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var mailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var usernamePat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=mailStr.match(mailPat);
	if (matchArray==null) 
	{
		alert("Email address seems blank or incorrect (check @ and .'s)");
		return false;
	}
	var username=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<username.length; i++) 
	{
		if (username.charCodeAt(i)>127) 
		{
			alert("Ths mail address contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (username.match(usernamePat)==null) 
	{
		alert("The mail address doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			alert("The domain name does not seem to be valid.");
			return false;
		}	
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		alert("Insert Valid E-Mail Address");
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2) 
	{
		alert("This address is missing a hostname!");
		return false;
	}	
	return true;
}
function Trim(s) 
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function EraseUser()
{
	if(document.right.vUsername.value=='Username')
	{
		document.right.vUsername.value='';
		return false;
	}
}
function ErasePass()
{

	if(document.right.vPassword.value=='********')
	{
			document.right.vPassword.value='';
			return false;
	}
}
function EraseEmail()
{
	if(document.right.mail.value=='E-mail')
	{
			document.right.mail.value='';
			return false;
	}
}
function Registered(e)
{
	if(e.keyCode==13)
	{
		return CheckNewsLetter();	
	}
}
function onBlurUSER(e)
{
	if(e.value=='')
	{
		e.value='Username';
	}
}
function onBlurPASS(e)
{
	if(e.value=='')
	{
		e.value='********';
	}
}
function onBlurEMAIL(e)
{
	if(e.value=='')
	{
		e.value='E-mail';
	}
}

function PassFocus(e)
{
	if(e.keyCode == 9)
	{
		document.right.vPassword.focus();
		return ErasePass();
	}
}
function EmailFocus(e)


{
	if(e.keyCode == 9)
	{
		document.right.mail.focus();
		return EraseEmail();
	}
}
function OnKeyLogin(e)
{
	if(e.keyCode == 13)
	{	
		return CheckLogin();
	}
}

function valid()
{
	if(document.forget.txtmail.value=="" || document.forget.txtmail.value=='E-mail')
	{
		alert('Insert e-mail.');
		document.forget.txtmail.value='';
		document.forget.txtmail.focus();
		return false;
	}
	else
	{
		if(document.forget.txtmail.value != "" && isValidEmail(document.forget.txtmail.value) == false	)
		{
			document.forget.txtmail.focus();
			return false;
		}
	}
	var mail1='php/prdd_login_a.php?mode=send&vEmail='+document.forget.txtmail.value;
	window.location.href=mail1;
}
function Trim(s) 
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function show()
{
	if(document.forget.txtuser.value=='Username')
		document.forget.txtuser.value='';
}
function show1()
{
	if(document.forget.txtmail.value=='E-mail')
		document.forget.txtmail.value='';
}
function show3(e)
{
	if(e.keyCode == 9)                                                                     
	{
		document.getElementById('tab_td').focus();
		return false;
	}
}
function show2(e)
{
	if(e.keyCode == 9)                                                                     
	{
		
		if(document.getElementById('txtmail').value=='E-mail')
			document.getElementById('txtmail').value='';
		document.getElementById('txtmail').focus();
		return false;
	}
}
			
function Blur(u)
{
	if(u.value=='')
		u.value='Username';
		
}
function Blur1(m)
{
	if(m.value=='')
		m.value='E-mail';
}




