var G_sizes_window;
var G_sizes_opened=false;
function winOpen(url,window_name,features){
  if(G_sizes_opened){G_sizes_window.close();}
  G_sizes_window = window.open(url,window_name,features);
  G_sizes_opened = true;

}

/*START OPTIN JS*/
var G_rtn; //global for debugging
function G_OptinSubscribe(list){
	var optin = document.getElementById("optin-container");
	var frm = document.getElementById("optin-form");
	optinButtonText("sending...");
	var email = frm.email.value;
	var regex = /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/;
	if(!regex.exec(email)){
		document.getElementById("optin-message").innerHTML="Your email does not appear to be valid. Please double check it and try re-sending.";
	}else{
		var url = "/whatcounts/optin.php?list="+list+"&email="+escape(email);
		ajax.send(url,"G_OptinSubscribeCallBack");
	}
}

function G_OptinSubscribeCallBack(){
	G_rtn = ajax.responseText;
	var display = document.getElementById("optin-message");

	if(G_rtn.indexOf("SUCCESS")+1){
		//document.getElementById("optin-form").style.display="none";
		display.innerHTML = "<br /><br />Thank you, you are now subscribed to receive emails when new product is added.";
		optinButtonText("subscribe");
	}else{
		optinButtonText("send again");
		display.innerHTML = "Sorry, there was an error while trying to add your email to our list.<br /><br />This could simply be because you are already subscribed to this list.<br /><br />If you are not already subscribed, please let us know at <a href=\"mailto:customerservice@paper-source.com \">customerservice@paper-source.com </a>";
	}
}
function optinButtonText(txt){
	document.getElementById("optin-button").innerHTML=txt;
}
/*END OPTIN JS*/