// JavaScript Document

function login(showhide){
  if(showhide == "show"){
      document.getElementById('paywallLoginSignupHomeDiv').style.display="block"; /* If the function is called with the variable 'show', show the login box */
  }else if(showhide == "hide"){
      document.getElementById('paywallLoginSignupHomeDiv').style.display="none"; /* If the function is called with the variable 'hide', hide the login box */
  }
}


function checkLogin(error){
	alert(error);
  if(error == "noname"){
      login('show');
  }else 
      login('hide');
}

/* --------------------------------------------------------------------------  */
/* Functions to care of focus control on text boxes used across all the pages */

function controlOnFocus(me, defaultValue)
{
	if (me.value == defaultValue)
    me.value = "";
}
               
function controlOnBlur(me, defaultValue)
{
	if (me.value == "")
    me.value = defaultValue;
}

/* --------------------------------------------------------------------------  */


/* ------------------------------------------------------------------------------------------------------------------------------------------------------------------------  */
/* Functions to care form validation / popup / form submit for the marketing ad at the bottom of the home page */

function pop_conf () {
    var browser_name = navigator.appName;
	var width = 450;
	var height = 573;
	if (browser_name.indexOf("WebTV") != -1) return null;
	if (parseInt(navigator.appVersion) >= 4 )
	{xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}

	args = "width=" + width + ",";
	args += "height=" + height + ",";
	args += "location=0" + ","
	args += "menubar=0" + ","
	args += "resizable=0" + ","
	args += "scrollbars=1" + ","
	args += "status=0" + ","
	args += "titlebar=0" + ","
	args += "toolbar=0" + ","
	args += "hotkeys=0" + ","
	args += "screenx=" + xposition + ",";
	args += "screeny=" + yposition + ",";
	args += "left=" + xposition + ",";
	args += "top=" + yposition;

	var name = document.botform.cds_name.value;
	var address1 = document.botform.cds_address_1.value;
	var address2 = document.botform.cds_address_2.value;
	var city = document.botform.cds_city.value;
	var state = document.botform.cds_state.value;
	var zip = document.botform.cds_zip.value;
	var email = document.botform.cds_email.value;
	
	var error = validateform(name, address1, address2, city, state, zip, email);
	
	if (error){
		alert(error);}
	else{

		if (address2 == "Address (Line 2)"){address2 = "";}
	
		var fields = "cds_name=" + name + "&cds_address_1=" + address1 + "&cds_address_2=" + address2 +"&cds_city=" + city + "&cds_state=" + state + "&cds_zip=" + zip + "&cds_email=" + email;
	
		var conf_page = "popup_confirmation.asp?";
		var conf_page = conf_page + fields;
		
		var demo_window = window.open(conf_page, "main", args);
			demo_window.focus();
	}
}

function validateform(name, address1, address2, city, state, zip, email)
{
    var error = '';
	var descriptionType = '';

	if ((name == "") || (name == "Name"))
	{ error = error + 'Please enter Full Name.\n' }
	
	if ((address1 == "") || (address1 == "Address (Line 1)"))
	{error = error + 'Please enter Address.\n'; }
	
	if ((city == "") || (city == "City")) 
	{error = error + 'Please enter City.\n'; }

	if ((state == "") || (state == "Name")) 
	{error = error + 'Please enter State.\n'; }

	if ((zip == "") || (zip == "Zip Code")) 
	{error = error + 'Please enter Zip.\n'; }
	
	if ((email == "") || (email == "E-mail (required)"))
	{error = error + 'Please enter Email.\n'; }

	if (!isEmail(email))
	{error = error + 'Please enter valid Email.\n'; }

	if(error) {
	error = 'The following error(s) occurred:\n'+error;}
	else {error = ''; }
	
	return error;
}

function isEmail(str) {
	  // are regular expressions supported?
	  var supported = 0;
	  if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	  }
	  if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  return (!r1.test(str) && r2.test(str));
}

function collectcdsb(link)
{

//pull data from the CDS form to send to the Prepop Gateway
var name = document.botform.cds_name.value;
var address1 = document.botform.cds_address_1.value;
var address2 = document.botform.cds_address_2.value
var city = document.botform.cds_city.value;
var state = document.botform.cds_state.value;
var zip = document.botform.cds_zip.value;
var email = document.botform.cds_email.value;

var error = validateform(name, address1, address2, city, state, zip, email);

if (error){
	alert(error);}
else{
	if (address2 == "Address (Line 2)"){address2 = "";}

	var fields = "&cds_name=" + name + "&cds_address_1=" + address1 + "&cds_address_2=" + address2 +"&cds_city=" + city + "&cds_state=" + state + "&cds_zip=" + zip + "&cds_email=" + email;
	var cdslink = link + fields
	
	window.open(cdslink, "window");
	}

}
/* -------------------------------------------------------------------------------------------------------------------------------------------------------------------  */