/* ##### 
Display dialog that invites visitors to enter their email address.
Email address is submitted, and a cookie is set to prevent the dialog from appearing next time.
Visitor can cancel and continue to publication, but cookie isn't set.
###### */

/* cookie variables */
var c_name="zinioRegister";
var expiredays = 365;
var cookieValue = 1;
var exdate=new Date();

/* form validation variables */
var error;
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/

function register() {

//show the registration dialog if a cookie is not present
if(document.cookie.indexOf(c_name)==-1) showRegistration();

}


function showRegistration() {

// Generate and display a JavaScript prompt dialog
var theEmail = prompt("Enter your email address and get the latest iPhone updates from Zinio","")

/* OK button */

//if the field is entry, return an error and try again
if (theEmail=="") {
	//validation
	alert("Please enter a valid email address");
	register();
	return false;
	}

//if an entry exists
else if (theEmail!=null) {


if (!(emailFilter.test(theEmail))) { 
	alert("Please enter a valid email address");
	register();
	return false;
	}

if (theEmail.match(illegalChars)) {
	alert("The email address contains illegal characters");
	register();
	return false;
	}

	//submit form
	var domain = "http://www.zinio.com/";
	var serviceUrl = "/nsservice?Service=addEmailToList";
	var url = domain + "nsservices?Service=addSubscriber&Email=" + theEmail + "&type=iphone";
	frame = document.createElement("IFRAME");
	frame.style.display = "none";
	frame.src = url;
	document.body.appendChild(frame);

	//write cookie
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(cookieValue)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

	//confirmation message
	alert('Thanks, your email has been added to our iPhone list');

	}

/* Cancel button */
else {
	return;
	}
	
	
}