function getCookie(name)
{
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
				return unescape(dc.substring(begin, end).split('+').join(' '));
		}
	}
	return null;
}

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
}

function getSubCookie( uName, name )
{
	uValue = getCookie( uName )

	if (uValue != null) {
		var flag = uValue.indexOf( name+'=' )
		if( flag != -1 ) {
			flag += name.length + 1
			end = uValue.indexOf( '&', flag )
			if( end == -1 ) end = uValue.length
			return uValue.substring( flag, end )
		}
	}
}

function delCookie (name,path,domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) + 
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function frequent () {
}

function frequent2 () {
	//document.master.q.focus();
	var visits = getSubCookie('WebsiteActivity', 'SessionCount')
	var request = getCookie('Request')
	var ema = getCookie('Email')
	if (((visits == 4 || visits == 8 || visits == 16 || visits == 32 || visits == 64 || visits == 128) && (ema == null || ema == "") && (request != 'Declined')) || (window.location.search == '?prompt')) {
	//if (visits > 50) {
		mym = prompt('We notice you have been to the site ' + visits + ' times. If you would like to contact us, please enter your email address (we keep it private).','Email address here');
		if ((mym == null) || (mym == '') || (mym == 'Email address here')) {
			var declined = new Date();
			declined.setTime(declined.getTime() + 21600000);
			setCookie('Request', 'Declined', declined, '/', 'connors.com');
			return;
		} else {
		var AtSym	= mym.indexOf('@')
		var Period	= mym.lastIndexOf('.')
		var Space	= mym.indexOf(' ')
		var Length	= mym.length - 1
		}
		if ((AtSym < 1) ||
			(Period <= AtSym+1) ||
			(Period == Length ) ||
			(Space	!= -1))
			{	
				EmailOk = false;
				alert('Please enter a valid e-mail address!');
				frequent();
			} else {

				var accepted = new Date();
				accepted.setTime(accepted.getTime() + 1209600000);
				var expiration = new Date();
				expiration.setTime(1293857999520);
				setCookie('Request', 'Accepted', accepted, '/', 'connors.com');
				setCookie('Email', mym, expiration, '/', 'connors.com');
				alert('Thank you, ' + mym + '.\n\nWe sincerely appreciate the opportunity to talk with you. You can expect an email from us within the next day or two. You can start a discussion with us on the following screen, or call us immediately at 1-212-219-9188.');
				location.replace("http://private.connors.com/capture.asp?e=" + escape(mym));
			}
	}
}

function IsEmailValid(FormName,ElemName)
{
var EmailOk	= true
var Temp	= document.forms[FormName].elements[ElemName]
var AtSym	= Temp.value.indexOf('@')
var Period	= Temp.value.lastIndexOf('.')
var Space	= Temp.value.indexOf(' ')
var Length	= Temp.value.length - 1		// Array is from 0 to length-1

if ((AtSym < 1) ||				// '@' cannot be in first position
	(Period <= AtSym+1) ||			// Must be atleast one valid char btwn '@' and '.'
	(Period == Length ) ||			// Must be atleast one valid char after '.'
	(Space	!= -1))				// No empty spaces permitted
	{	
		EmailOk = false;
		alert('Please enter a valid e-mail address!');
		Temp.focus();
	}
return EmailOk
}

function MyEmail() {
	//First, we need to do a loop up to the number of elements on 
	var moveOn = true;
	var i = 0;
	while (i < document.forms.length) {
		var z = 0;
		while (z < document.forms[i].elements.length) {
			if (document.forms[i].elements[z].name == "Email" || document.forms[i].elements[z].name == "email" || document.forms[i].elements[z].name == "From" || document.forms[i].elements[z].name == "from" || document.forms[i].elements[z].name == "E" || document.forms[i].elements[z].name == "e" || document.forms[i].elements[z].name == "txtFrom") {
				if (IsEmailValid(i,z) == true) {
					var expiration = new Date();
					expiration.setTime(1293857999520);
					setCookie('Email', document.forms[i].elements[z].value, expiration, "/", "connors.com");
					moveOn = true;
				} else {
					moveOn = false;
				}
			}
			z++
		}
		i++
	}
	return moveOn;
}

