function determineSubmit() { // driver
	var isFilled = allFilled();
	if (isFilled != "") {
		return isFilled;
	}
	else {
		return "";
	}
}

function allFilled () { // when necessary fields are empty, return an error message to alert user
	var error = "";
	if (document.dpe.fname.value == "")			{ error = "Please enter your first name"; }
	else if (document.dpe.lname.value == "")		{ error = "Please enter your last name"; }
	else if (!isValidEmail(document.dpe.email.value))	{ error = "Your email address should follow this format: someone@somewhere.[com,org,mil,net,biz,tv,etc.]"; }
	else if (document.dpe.age.selectedIndex == 0)		{ error = "Please select your age range"; }
	return error;
}

function isValidEmail(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;					
}

/* COOKIE */

var SIOC_PE = WM_readCookie( "sioc_print_edition" );
domainArray = location.hostname.split( '.' );
thisdomain = ( domainArray.length > 1 ) ? '.' + domainArray[domainArray.length-2] + '.' + domainArray[domainArray.length-1] : '';

function WM_readCookie( name ) {
	if ( document.cookie == '' ) { // there's no cookie, so go no further
		return false;
	} else { // there is a cookie
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
		var NN2Hack = firstChar + name.length;
		if ( (firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=') ) { // if you found the cookie
			firstChar += name.length + 1; // skip 'name' and '='
			lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
			if (lastChar == -1) lastChar = theBigCookie.length;
			return unescape( theBigCookie.substring(firstChar, lastChar) );
		} else { // If there was no cookie of that name, return false.
			return false;
		}
	}
} // WM_readCookie

function setCookie(name,value) {
	var expires = '';
	var date = new Date(2006,6,1,0,0,0);
	expires = '; expires=' + date.toGMTString();
	document.cookie = name+'='+value + expires +
	                  '; path=/; domain=.' + cookieDomain();
}

function WM_killCookie( name, path, domain ) {
	var theValue = WM_readCookie( name ); // We need the value to kill the cookie
	if ( theValue ) {
		document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
	}
} // WM_killCookie

function cookieDomain() {
	var d;
	var parts = window.location.hostname.split('.');
	if (parts[parts.length-1].length == 2) {
		// Domains like cnn.co.jp should retain 3 parts
		d =	parts[parts.length-3] + '.' +
			parts[parts.length-2] + '.' +
			parts[parts.length-1];
	}
	else {
		// Other domains like cnn.com should retain 2 parts
		d =	parts[parts.length-2] + '.' +
			parts[parts.length-1];
	}
	//alert(d);
	return d;
}

function set() {
  setCookie('sioc_print_edition', 'isregistered');
}
