﻿function tsEMailForm(inPagePos)
{
	TSShowEMailPopup('ts_SignupDiv', 260, inPagePos);
}

function TSShowEMailPopup(inDivID, inW, inPagePos)
{
	var myHTMLData;
	myHTMLData = document.getElementById(inDivID).innerHTML;
	myHTMLData = myHTMLData.replace(/_repl/g, '');
	myHTMLData = myHTMLData.replace(/#pagepos#/g, inPagePos);
	overlib(myHTMLData, WIDTH, inW, CAPTION, " ", STICKY, CLOSECLICK, FGCOLOR, "#8FC5E2", BGCOLOR, "#1A3455", CLOSECOLOR, "#8FC5E2");
	setTimeout("document.getElementById('ltEMailSignup').focus()", 100);
}


function checkemail(str)
{
	var testresults;
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		testresults = true;
	else {
		alert("Please input a valid email address!");
		testresults = false;
	}
	return (testresults);
}

function doSignupSubmit(inAppend,inPagePos)
{
	var workAppend = '';
	if (inAppend != undefined) workAppend = inAppend;
	var signupLoc = document.domain;

	var currentInput;
	currentInput = document.getElementsByName("ltEMailSignup" + workAppend)[0];
	if (currentInput.value == "") {
		alert("Email Address is required.");
		currentInput.focus();
		return false;
	}

	var emailaddress = currentInput.value;
	if (checkemail(emailaddress) == false) {
		currentInput.value = ""
		currentInput.focus()
		return false
	}
	var signupURL = "http://www.travelscream.net/tripz/emailSignup.aspx?"
	signupURL += "email=" + currentInput.value
	signupURL += "&sitecode=" + signupLoc
	try { signupURL += "&fname=" + document.getElementById("ltEMailSignupName" + workAppend).value; } catch (e) { }
	try { signupURL += "&postcode=" + document.getElementById("ltEMailSignupZip" + workAppend).value; } catch (e) { }
	if (inPagePos != undefined) signupURL += "&pagepos=" + inPagePos;

	try {
		var fileref = document.createElement('script');
		fileref.setAttribute("type", "text/javascript");
		fileref.setAttribute("src", signupURL);
		if (typeof fileref != "undefined")
			document.getElementsByTagName("head")[0].appendChild(fileref);
		alert("Thank you for subscribing!");
		TSYWATrackAction('emailSignup', inPagePos);
	}
	catch (e) { }
	cClick();
}

