/*   Web Page Name : nl.js										*/
/*      Created By : Jacky Fang		Created Date :	02/14/2003	*/
/*     Modified By : Jacky on 04/07/2003						*/
/* 	        Reason : Add the Zip code validation				*/

function mySubmit() {
	if (validated()) {
		pop = "No";
		document.NLSignUp.target = "_blank";
		document.NLSignUp.submit();
//		setTimeout("top.close()",500)
	}
}

function validated() {
	// Email
	if (document.NLSignUp.Email.value == "") {
		alert("Field \"Email\" is missing.");
		document.NLSignUp.Email.focus();
		return false
	}

	re = new RegExp("([A-Za-z0-9_.-]){2,}@([A-Za-z0-9_.-]){2,}\.([A-Za-z0-9_.-]){2,}")
	if (document.NLSignUp.Email.value.match(re) == null) {
		alert("I'm sorry, but your email address does not appear to be valid");
		document.NLSignUp.Email.focus();
		return false
	}

	// Old Email for Return Path
	if (typeof(document.NLSignUp.OldEmail) != "undefined") {
		if (document.NLSignUp.OldEmail.value != "" && document.NLSignUp.OldEmail.value.match(re) == null) {
			alert("I'm sorry, but your \"OldEmail\" address does not appear to be valid");
			document.NLSignUp.OldEmail.focus();
			return false
		}
	}

	// First Name
	if (document.NLSignUp.FirstName.value == "") {
		alert("Field \"FirstName\" is missing.");
		document.NLSignUp.FirstName.focus();
		return false
	}

	// Last Name
	if (document.NLSignUp.LastName.value == "") {
		alert("Field \"LastName\" is missing.");
		document.NLSignUp.LastName.focus();
		return false
	}

	// Birth Date
	if (typeof(document.NLSignUp.mm) != "undefined") {
		if (document.NLSignUp.yy.selectedIndex == "0") {
			alert("I'm sorry, but your birth year is missing.");
			document.NLSignUp.yy.focus();
			return;
		}
		if (document.NLSignUp.mm.selectedIndex == "0") {
			alert("I'm sorry, but your birth month is missing.");
			document.NLSignUp.mm.focus();
			return;
		}
		month = document.NLSignUp.yy.options[document.NLSignUp.yy.selectedIndex].value + document.NLSignUp.mm.options[document.NLSignUp.mm.selectedIndex].value
		if (month > document.NLSignUp.mm.options[0].value) {
			alert("I'm sorry, you are not old enough to subscribe this newsletter. Please check back later.");
			return false;
		}
	}

	// Age
	if (typeof(document.NLSignUp.age) != "undefined") {
		if (document.NLSignUp.age.options[document.NLSignUp.age.selectedIndex].value == "") {
			alert("Field \"Age Range\" is missing.");
			document.NLSignUp.age.focus();
			return false
		}
	}

	// Gender
	if (!(document.NLSignUp.Gender[0].checked || document.NLSignUp.Gender[1].checked)) {
		alert("Field \"Gender\" is missing.");
		document.NLSignUp.Gender.focus();
		return false;
	}

	// Country
	if (document.NLSignUp.Country.options[document.NLSignUp.Country.selectedIndex].value == "") {
		alert("Field \"Country\" is missing.");
		document.NLSignUp.Country.focus();
		return false;
	}

	// Zip Code
	if (document.NLSignUp.zip.value == "") {
		alert("Field \"Zip\" is missing.");
		document.NLSignUp.zip.focus();
		return false;
	}
	else {
		if (document.NLSignUp.Country.options[document.NLSignUp.Country.selectedIndex].value == "U.S.") {
			if (document.NLSignUp.zip.value.length != 5 || document.NLSignUp.zip.value.search(/\d{5}/) != 0) {
				alert("Invalid Zip Code for U.S.");
				document.NLSignUp.zip.focus();
				return false;
			}
		}
		else if (document.NLSignUp.Country.options[document.NLSignUp.Country.selectedIndex].value == "Canada") {
			if (!((document.NLSignUp.zip.value.length==6 && document.NLSignUp.zip.value.search(/([a-z]\d){3}/gi)==0)
					|| (document.NLSignUp.zip.value.length==7 && document.NLSignUp.zip.value.search(/[a-z]\d[a-z] \d[a-z]\d/gi)==0))) {
				alert("Invalid Postal Code for Canada.");
				document.NLSignUp.zip.focus();
				return false;
			}
		}
	}

	// Profession
	if (typeof(document.NLSignUp.InSchool) != "undefined") {
		if (document.NLSignUp.InSchool.checked) {
			if (document.NLSignUp.school.options[document.NLSignUp.school.selectedIndex].value == "") {
				alert("Field \"Profession\" is missing.");
				document.NLSignUp.school.focus();
				return false
			}
		}
		else {
			if (document.NLSignUp.profession.options[document.NLSignUp.profession.selectedIndex].value == "") {
				alert("Field \"Profession\" is missing.");
				document.NLSignUp.profession.focus();
				return false
			}
		}
	}

	// Industry
	if (typeof(document.NLSignUp.industry) != "undefined") {
		if (document.NLSignUp.industry.options[document.NLSignUp.industry.selectedIndex].value == "") {
			alert("Field \"Industry\" is missing.");
			document.NLSignUp.industry.focus();
			return false
		}
	}

	// Job Title
	if (typeof(document.NLSignUp.jobtitle) != "undefined") {
		if (document.NLSignUp.jobtitle.options[document.NLSignUp.jobtitle.selectedIndex].value == "") {
			alert("Field \"Job Title\" is missing.");
			document.NLSignUp.jobtitle.focus();
			return false
		}
	}

	// Income
	if (typeof(document.NLSignUp.income) != "undefined") {
		if (document.NLSignUp.income.options[document.NLSignUp.income.selectedIndex].value == "") {
			alert("Field \"Income Level\" is missing.");
			document.NLSignUp.income.focus();
			return false
		}
	}

	// Legalized
	if (!(document.NLSignUp.Legalized.checked || document.NLSignUp.Legalized.value == "yes")) {
		alert("I'm sorry, but you must agree to our Privacy Policy.");
		document.NLSignUp.Legalized.focus();
		return false
	}

	return true
}

function popup(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function AuthorIcon1(url,vara,x,y) {
	var options = "toolbar=no,scrollbars=no,resizable=no,width=" + x + ",height=" + y;
	msgWindow=window.open(url + vara,"WinkOpen",options);
}

function AuthorIcon2(url,x,y) {
	var options = "toolbar=no,scrollbars=yes,resizable=no,width=" + x + ",height=" + y;
	msgWindow=window.open(url,"WinjOpen",options);
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr;
	for (i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++)
		x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document;
	if(d.images) {
		if(!d.MM_p)
			d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0) {
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
	}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;
	if (!d)
		d=document;
	if ((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if (!(x=d[n])&&d.all)
		x=d.all[n];

	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	if (!x && d.getElementById)
		x=d.getElementById(n);
	return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null) {
			document.MM_sr[j++]=x;
			if(!x.oSrc)
				x.oSrc=x.src;
			x.src=a[i+2];
		}
}
