function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//Custom functions
/*
function loginlink() {
	if (getMLTCookie('username') && getMLTCookie('id'))
	{
		if(getMLTCookie('username')!='connors')
		{
			if(document.location.href.toString().indexOf('my_account.asp') > 0 )
			{
				document.write('<a href="/hits.asp">Return to controls</a> &nbsp;&nbsp;');
			}
			else
			{
				document.write('<a href="https://www.hittail.com/my_account.asp">My Account</a>  &nbsp;&nbsp;');
			}
		}
		if (document.location.href.toString().indexOf('.asp') > 0)
		{
			document.write('<a href="https://www.hittail.com/login.asp">Logout: ' + getMLTCookie('username') + '</a>');
		} else {
			document.write('<a href="/hits.asp">Return to controls</a>');
		}
	} else {
		document.write('<a href="https://www.hittail.com/login.asp">Login</a>');
	}
}
*/
//This is the loginlink function for multiple logins

function loginlink() {
	var mystats;
	var myaccount;
	var login;
	var logout;
	var register;

	switch(getMLTCookie('lang'))
	{
	case 'de':
		mystats = 'Meine Stats'; //'Meine Statistiken'
		myaccount = 'Mein Konto';
		login = 'Login';
		logout = 'Logout';
		register = 'Anmelden';
		break ;   
	case 'nl':
		mystats = 'Mijn Stats'; //Mijn Statistieken
		myaccount = 'Mijn Account';
		login = 'Login';
		logout = 'Logout';
		register = 'Registreer';
		break;
	case 'fr':
		mystats = 'Mes Stats';
		myaccount = 'Mon Compte';
		login = 'Login';
		logout = 'Logout';
		register = 'S\'Inscrire';  //'Inscrivez-vous';
		break;
	case 'it':
		mystats = 'Le mie stats'; //Le mie statistiche
		myaccount = 'Il mio account';
		login = 'Login';
		logout = 'Logout';
		register = 'Registrarsi';
		break;
	default:
		mystats = 'My Stats';
		myaccount = 'My Account';
		login = 'Login';
		logout = 'Logout';
		register = 'Register';
	}
	// Webinar
	//	document.write('<a href="#" onclick="openWebinar();">Webinar</a> &nbsp;&nbsp;');
	if (getMLTCookie('username') && getMLTCookie('id'))
	{
		if(getMLTCookie('username')!='connors')
		{
			if(document.location.href.toString().indexOf('my_account.asp') > 0 )
			{
				document.write('<a class="blue" href="http://www.hittail.com/hits.asp">'+mystats+'</a> &nbsp;&nbsp;');
			}
			else
			{
				document.write('<a class="blue" href="https://www.hittail.com/my_account.asp">'+myaccount+'</a>  &nbsp;&nbsp;');
			}
		}
		if (document.location.href.toString().indexOf('.asp') > 0)
		{
			//document.write('<a href="https://www.hittail.com/login.asp">Logout: ' + getMLTCookie('username') + '</a>');
			document.write('<a class="blue" href="https://www.hittail.com/login.asp">'+logout+'</a>');
			if(document.location.href.toString().indexOf('my_account') < 1 && document.location.href.toString().indexOf('subscribe') < 1 && document.location.href.toString().indexOf('cancel') < 1 && document.location.href.toString().indexOf('contact') < 1 && document.location.href.toString().indexOf('hittail-plus') < 1 && document.location.href.toString().indexOf('hittail-premium') < 1 && document.location.href.toString().indexOf('hittail-basic') < 1 && document.location.href.toString().indexOf('bloggers') < 1 && document.location.href.toString().indexOf('publishers') < 1 && document.location.href.toString().indexOf('marketers') < 1)
			{
				objSelect = document.getElementById('multiLogin');
				allSites = new String(getMLTCookie("multiple"));
				allSites2 = new String(getMLTCookie("multiple2"));
				allSites3 = new String(getMLTCookie("multiple3"));

				//allSites = allSites + allSites2;
				
				if(allSites!='' && allSites != 'null')
				{
					if(allSites2!='' && allSites2 != 'null')
					{
						allSites = allSites + allSites2;
					}
					if(allSites3!='' && allSites3 != 'null')
					{
						allSites = allSites + allSites3;
					}
					siteArr = allSites.split(",");
					siteArr.sort();
					for(i=0;i<siteArr.length;i++)
					{
						if (siteArr[i] != 'null' && siteArr[i] !='')
						{
								
							objOption = document.createElement("option");
							objOption.text = siteArr[i];
							objOption.value = siteArr[i];
							if(getMLTCookie("site")==siteArr[i])
							{
								objOption.selected = true;
								selIndex = i-1;
							}
							objSelect.options.add(objOption);
						}
					}
					document.getElementById('selectSpan').style.display = 'inline';
					changeSite(getMLTCookie("site"), selIndex);
				}
			}
		} else {
		
			//we need to check if it's a Forum page
			if (document.location.href.toString().indexOf('forum.hittail.com') > 0) 
				{
				document.write('<a class="blue" href="http://www.hittail.com/hits.asp">'+mystats+'</a>');
				}
				else
				{
				document.write('<a class="blue" href="/hits.asp">'+mystats+'</a>');
				}
		}
	} else {
		if ( (document.location.href.toString().indexOf('pricing') > 0) || (document.location.href.toString().indexOf('what') > 0) || (document.location.href.toString().indexOf('faq') > 0) || (document.location.href.toString().indexOf('terms') > 0) || (document.location.href.toString().indexOf('about') > 0) || (document.location.href.toString().indexOf('privacy') > 0) || (document.location.href.toString().indexOf('demo') > 0) || (document.location.href.toString().indexOf('how') > 0) || (document.location.href.toString().indexOf('who') > 0) || (document.location.href.toString().indexOf('blog') > 0))
		{
		document.write('<a class="blue" href="https://www.hittail.com/register.asp">'+register+'</a>  &nbsp;&nbsp;');
		document.write('<a class="blue" href="https://www.hittail.com/login.asp">'+login+'</a>');
		}
		else
		{
		//new homepage - no Register link
		//document.write('<a class="blue" href="https://www.hittail.com/register.asp">'+register+'</a>  &nbsp;&nbsp;');
		document.write('<a class="blue" href="https://www.hittail.com/login.asp">'+login+'</a>');
		}
	}
}



function help_toggle()
{
	if(document.getElementById("help").style.display == 'none' || document.getElementById("help").style.display == null || document.getElementById("help").style.display == '')
	{
		document.getElementById("help").style.display = 'block';
		document.getElementById("close_help_span").style.display = 'inline';
		document.getElementById("help_span").style.display = 'none';
		document.getElementById("myTable").style.display = 'none';
	}
	else
	{
		document.getElementById("help").style.display = 'none';
		document.getElementById("close_help_span").style.display = 'none';
		document.getElementById("help_span").style.display = 'inline';
		document.getElementById("myTable").style.display = 'block';
	}
	
}


function changeSite(site, selIndex)
{
	setMLTCookie('site', site, 'expires', '/', 'hittail.com' );
	if(document.location.href.toString().indexOf('chart.asp')>0)
	{
		//call chart reload function
		getChart();
		getStats();
	}
	else
	{
		//document.getElementById("myTable").innerHTML = '<div class="loading">Loading data... Please wait<br/><img src="/images/loading.gif" />';
		getTableData('noaction', '', '', '', '');
	}
	document.getElementById('multiLogin').selectedIndex  = selIndex;
	if(document.location.href.toString().indexOf('keywords.asp')>0)
	{
		getSavings();
	}
	if(document.location.href.toString().indexOf('keywords_aw.asp')>0)
	{
		getSavings();
	}
}

function changeSiteAndReload(site, selIndex)
{


	setMLTCookie('site', site, 'expires', '/', 'hittail.com' );
	if(document.location.href.toString().indexOf('chart.asp')>0)
	{
		//call chart reload function
		getChart();
		getStats();
	}
	else
	{
		//document.getElementById("myTable").innerHTML = '<div class="loading">Loading data... Please wait<br/><img src="/images/loading.gif" />';
		getTableData('noaction', '', '', '', '');
	}
	document.getElementById('multiLogin').selectedIndex  = selIndex;
	if(document.location.href.toString().indexOf('keywords.asp')>0)
	{
		getSavings();
	}
	if(document.location.href.toString().toLowerCase().indexOf('hits.asp')>0)
	{
		window.open(window.location.pathname + '?changedsite=true', '_parent');
	}
	if(document.location.href.toString().toLowerCase().indexOf('keywords.asp')>0)
	{
		getSavings();
		window.open(window.location.pathname + '?changedsite=true', '_parent');
	}
	if(document.location.href.toString().toLowerCase().indexOf('suggestions.asp')>0)
	{
		window.open(window.location.pathname + '?changedsite=true', '_parent');
	}
	if(document.location.href.toString().toLowerCase().indexOf('todo.asp')>0)
	{
		window.open(window.location.pathname + '?changedsite=true', '_parent');
	}
}

function changeSiteCookie(site)
{
	setMLTCookie('site', site, 'expires', '/', 'hittail.com' );
}

function changeSite1(site, selIndex)
{
	setMLTCookie('test', '1', '', '/', 'hittail.com' );
	setMLTCookie('site', site, '', '/', 'hittail.com' );
	//alert(site);
	//setMLTCookie1('site', site, '/', 'hittail.com');
	if(document.location.href.toString().indexOf('chart.asp')>0)
	{
		//call chart reload function
		getChart();
		getStats();
	}
	else
	{
		document.getElementById("myTable").innerHTML = '<div class="loading">Loading data... Please wait<br/><img src="/images/loading.gif" />';
		getTableData('noaction', '', '', '', '');
	}
	document.getElementById('multiLogin').selectedIndex  = selIndex;
}

// Language support functions

function switch_lang()
{
	lang = getMLTCookie('lang');
	if(lang && lang != '' && lang != 'en')
	{
		langElements = getElementsByClass(lang, document, "span");
		enElements = getElementsByClass("en", document, "span");
		//alert(langElements.length);
		//alert(enElements.length);
		for(i=0; i<langElements.length; i++)
		{
			langElements[i].style.display = 'inline';
		}
		for(i=0; i<enElements.length; i++)
		{
			enElements[i].style.display = 'none';
		}
	}
}
function setLanguage(lang)
{
	//alert(lang);
	setMLTCookie ('lang', lang, '', '/', 'hittail.com', '');
	return false;
}

function getElementsByClass(searchClass,node,tag) 
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function setMLTCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function setMLTCookie1(name, value, path, domain) {
  var curCookie = name + "=" + escape(value) +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "");
  alert(curCookie);
  document.cookie = curCookie;
}

function getMLTCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/*function delCookie (name,path,domain) {
	if (getMLTCookie(name)) {
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) + 
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}*/

var copytoclipB=1
function copytoclip(theField) {
	var tempvalB=eval('document.'+theField)
	tempvalB.focus()
	tempvalB.select()
	if (document.all&&copytoclipB==1){
		therange=tempvalB.createTextRange()
		therange.execCommand('Copy')
		window.status='Contents highlighted and copied to clipboard!'
		setTimeout('window.status=\'\'',2400);
	}
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


function changeImg(img, source)
{
	img.src = source;
}

function breakout_of_frame()
{
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}

function showCode(codetype)
{
	if(codetype == 'secure')
	{
		document.getElementById('toCopy').value = '<script src="https://'+getMLTCookie("id")+'.hittail.com/mlt_secure.js" type="text/javascript"></script>';
	}
	else
	{
		document.getElementById('toCopy').value = '<script src="http://'+getMLTCookie("id")+'.hittail.com/mlt.js" type="text/javascript"></script>';
	}
	return false;
}

function chooseCost(type, formName, urlVal)
{

var promoEnd = new Date(2008, 5, 30);
var today = new Date();

var milli_d1 = promoEnd.getTime();
var milli_d2 = today.getTime();
var diff = milli_d1 - milli_d2;

	switch(formName)
	{
		case 'basic_high':
			amountMonthly = "49.95";
			itemMonthly = "basic_high_monthly";
			amountAnnual = "499.95";
			itemAnnual = "basic_high_annual";
			break;

		case 'plus_low':
			/*if(Date()>'5/1/2007')
			{
				amountMonthly = "4.95";
				itemMonthly = "plus_low_monthly_promo";
				amountAnnual = "49.95";
				itemAnnual = "plus_low_annual_promo";
			}
			else
			{*/
				amountMonthly = "9.95";
				itemMonthly =  "plus_low_monthly";
				amountAnnual = "99.95";
				itemAnnual = "plus_low_annual";
			//}
			break;

		case 'plus_high':
			amountMonthly = "99.95";
			itemMonthly = "plus_high_monthly";
			amountAnnual = "999.95";
			itemAnnual = "plus_high_annual";

			break;

		case 'premium_low':

			if(diff > 0)
			{	
				//positive diff value indicates that the Promotion End date is in the future
				amountMonthly = "19.95";
				itemMonthly = "premium_low_monthly_promo";
				amountAnnual = "199.95";
				itemAnnual = "premium_low_annual_promo_charter";
				itemNameMonthly = "HitTail Premium Monthly Promo - " + urlVal;
				itemNameAnnual = "HitTail Premium Annual Promo - " + urlVal;
			}
			else
			{
				//Negative diff value means the Promotion is over
				amountMonthly = "29.95";
				itemMonthly = "premium_low_monthly";
				amountAnnual = "299.95";
				itemAnnual = "premium_low_annual";
				itemNameMonthly = "HitTail Premium Monthly - " + urlVal;
				itemNameAnnual = "HitTail Premium Annual - " + urlVal;
			}

			break;
	
	}
	
	f = document.forms[formName];
	
	if(type=='monthly')
	{
		f.a3.value = amountMonthly;
		f.item_number.value = itemMonthly;
		f.t3.value = "M";
		if (formName == 'premium_low')
		{
			f.item_name.value = itemNameMonthly;
		}
		
		//alert("form: " + formName + ", amount: " + amountMonthly + ", name: " + itemMonthly);
	}
	else
	{
		f.a3.value = amountAnnual;
		f.item_number.value = itemAnnual;
		f.t3.value = "Y";
		if (formName == 'premium_low')
		{
			f.item_name.value = itemNameAnnual;
		}
		//alert("form: " + formName + ", amount: " + amountAnnual + ", name: " + itemAnnual);
	}
	
	return false;

}

function copyBuffer()
{
	var tempvalB=eval('document.getElementById("toCopy")');
	tempvalB.focus()
	tempvalB.select()
	if (document.all&&copytoclipB==1){
		therange=tempvalB.createTextRange()
		therange.execCommand('Copy')
		window.status='Contents highlighted and copied to clipboard!'
		setTimeout('window.status=\'\'',2400);
	}
}

function openWebinar()
{
	window.open('http://www.hittail.com/webinar.asp','','width=650,height=500,resizable=yes,scrollbars=yes,location=no');
}


function chooseCostTemp(type, formName)
{
	switch(formName)
	{
		case 'basic_high':
			amountMonthly = "49.95";
			itemMonthly = "basic_high_monthly";
			amountAnnual = "499.95";
			itemAnnual = "basic_high_annual";
			break;

		case 'plus_low':
			amountMonthly = "4.95";
			itemMonthly = "plus_low_monthly_promo";
			amountAnnual = "49.95";
			itemAnnual = "plus_low_annual_promo";
			break;

		case 'plus_high':
			amountMonthly = "99.95";
			itemMonthly = "plus_high_monthly";
			amountAnnual = "999.95";
			itemAnnual = "plus_high_annual";

			break;
	
	}
	
	f = document.forms[formName];
	
	if(type=='monthly')
	{
		f.a3.value = amountMonthly;
		f.item_number.value = itemMonthly;
		f.t3.value = "M";
		//alert("form: " + formName + ", amount: " + amountMonthly + ", name: " + itemMonthly);
	}
	else
	{
		f.a3.value = amountAnnual;
		f.item_number.value = itemAnnual;
		f.t3.value = "Y";
		//alert("form: " + formName + ", amount: " + amountAnnual + ", name: " + itemAnnual);
	}
	
	return false;

}