﻿/* Newsletter */
	function findPos(obj) {
		var curleft = curtop = 0;
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);

		return [curleft,curtop];
	}

	function OpenForm(obj){
		var nlsignup = document.getElementById('nl_signup');
		if (!nlsignup){return;}
		if (nlsignup.style.display == 'block'){
			nlsignup.style.display = 'none';
			return;
		}
		var coors = findPos(obj);
		nlsignup.style.left = (coors[0] + 55) + 'px';
		nlsignup.style.top = (coors[1] + obj.clientHeight - 7) + 'px';
		nlsignup.style.display = 'block';
		var email = document.getElementById('email');
		if (email) {email.focus();}		
	}
	
	function CloseForm(){
		var nlsignup = document.getElementById('nl_signup');
		if (!nlsignup){return;}
		nlsignup.style.display = 'none';
	}
	
	function Validate(){
		var email = document.getElementById('email');
		if (!email){
			window.alert('Can\'t find the email field.');
			return false;
		}
		
		if (!CheckEmail(email.value)){
			window.alert('Please enter a valid email address.');
			email.focus();
			return false;
		}
		
		return true;
	}

	function CheckEmail(email) {	
		var at="@";
		var dot=".";
		var lat=email.indexOf(at);
		var lstr=email.length;
		var ldot=email.indexOf(dot);
		if (email.indexOf(at)==-1)return false;
		if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr)return false;
		if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr)return false;
		if (email.indexOf(at,(lat+1))!=-1)return false;
		if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot)return false;
		if (email.indexOf(dot,(lat+2))==-1)return false;
		if (email.indexOf(" ")!=-1)return false;
		
		return true;
	} //CheckEmail	