// JavaScript Document
function valid_nl ( myform, myaction ) {
	if (trim(myform.name.value) == ''){
		alert ('Please provide your Name.');
		myform.name.focus();
		return false;
	}
	if (trim(myform.email.value) == '' || !email_validate(trim(myform.email.value))){
		alert ('Please provide a valid E-mail Address.');
		myform.email.focus();
		return false;
	}

	if ( myaction == 'unsub' || myaction == 'snup' ) {
		myform.req.value = myaction;
		myform.submit();
	}
	
}

function valid_cnt ( myform ) {
	if (trim(myform.name.value) == ''){
		alert ('Please provide your Name.');
		myform.name.focus();
		return false;
	}
	if (trim(myform.phone.value) == ''){
		alert ('Please provide your Phone Number.');
		myform.phone.focus();
		return false;
	}
	if (trim(myform.email.value) == '' || !email_validate(trim(myform.email.value))){
		alert ('Please provide a valid E-mail Address.');
		myform.email.focus();
		return false;
	}

	myform.req.value = '1';
	myform.submit();
}

function email_validate(myEmail){
	//mac ie does not seem to like regular expressions
	if (macie_sniff())
		return true;
	//it doesn't even like slash notation in a script
	//var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var filter = new RegExp("^([\\w-]+(?:\\.[\\w-]+)*)@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(?:\\.[a-z]{2})?)$");
	if (filter.test(myEmail.toLowerCase()))
		return true;
	return false;
}

function textCounter(field, maxlimit) {
	if (field.value.length > maxlimit) {
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	} 
}

function macie_sniff(){
	var agt=navigator.userAgent.toLowerCase();
	var is_mac    = (agt.indexOf("mac")!=-1);
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));	
	if (is_mac && is_ie)
		return 1;
	return 0;
}

function trim(myString){
	if (macie_sniff())
		return myString;
	myString = myString.replace(/\r/g, " ");
	//There are regex switchs for printing /nonprinting characters 
	//but they stripped some characters either needed or left some not wanted,
	//thats why the following replacement exists.
	myString = myString.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
	myString = myString.replace(/'/g, "");
	myString = myString.replace(/ +/g, " ");  
	myString = myString.replace(/^\s/g, "");
	myString = myString.replace(/\s$/g, "");	
	if (myString == ' '){myString = ''};
	return myString;
}