var new_fieldname = "";

function initajax() {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp
}	

isset = function(e) {
    try {
       if (eval(e)) {}
    }
    catch(err) {
       return false;
    }
	if(eval(e) == undefined)
		return false
	else
	    return true;
}


function setDisplay(strShow,ly) {
	document.getElementById(ly).style.display=strShow;
}

function updateClick(clickedItem,offerID) {
	if(tract) {
		try {
			xmlhttp = initajax();
		    xmlhttp.open('GET', '/siteInc/clickCount.cfm?clickedItem='+clickedItem+'&site_ID='+siteID+'&offer_ID='+offerID+'&source_ID='+sourceID+'&session_ID='+sid+'&x='+Math.random(), true);
			xmlhttp.send(null)
			xmlhttp.close();
		} catch(e) {}
	}
}

function bannerClick(offerID) {
	document.getElementById('ck'+offerID).checked = true;
	setDisplay('block','div'+offerID);
	updateClick('BNR',offerID);
}

function linkClick(offerID) {
	document.getElementById('ck'+offerID).checked = true;
	setDisplay('block','div'+offerID);
	updateClick('LNK',offerID);
}

function boxClick(offerID) {
	if(document.getElementById('ck'+offerID).checked) {
		document.getElementById('ck'+offerID).checked = false;
		setDisplay('none','div'+offerID);
		updateClick('UBX',offerID);
	} else {
		document.getElementById('ck'+offerID).checked = true;
		setDisplay('block','div'+offerID);
		updateClick('BOX',offerID);
	}
}

function boxCheck(offerID) {
	if(document.getElementById('ck'+offerID).checked) {
		document.getElementById('ck'+offerID).checked = false;
		setDisplay('none','div'+offerID);
	} else {
		document.getElementById('ck'+offerID).checked = true;
		setDisplay('block','div'+offerID);
	}
}

function bannerDBLClick(offerID) {
	document.getElementById('ck'+offerID).checked = false;
	setDisplay('none','div'+offerID);
	updateClick('UBN',offerID);
}

function openWindow(url) {
     win = window.open(url,"windowName","scrollbars,resizable,copyhistory,height=500,width=500,left = 100,top = 100");
}

function doUnload(url){ 
	if ((window.event.clientX < 0) && (window.event.clientY < 0)){ 
//		window.open("thankyou.cfm","","fullscreen,status=yes,menubar=yes,scrollbars=yes");
		window.open(url,"unloadpop","status=yes,menubar=yes,scrollbars=yes");
	} 
}

function doCPCUnload(url){ 
	if ((window.event.clientX < 0) && (window.event.clientY < 0)){ 
//		window.open("thankyou.cfm","","fullscreen,status=yes,menubar=yes,scrollbars=yes");
		window.open(url,"CPCWindow","width=740,height=320,status=no,menubar=no,scrollbars=yes");
	} 
}

function doExitpop(url){ 
	if ((window.event.clientX < 0) && (window.event.clientY < 0)){ 
//		window.open("thankyou.cfm","","fullscreen,status=yes,menubar=yes,scrollbars=yes");
		window.open(url,"","width=552,height=415,status=no,menubar=no,scrollbars=no");
	} 
}

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].toLowerCase().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;
}


function echeck(str) {
//	var at="@"
//	var dot="."
//	var lat=str.indexOf(at)
//	var lstr=str.length
//	var ldot=str.indexOf(dot)

//	if (str.indexOf(at)<=0 || str.indexOf(at)==lstr || str.indexOf(at,(lat+1))!=-1 || str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot || str.indexOf(dot)<=0 || str.indexOf(dot)==lstr || str.indexOf(dot,(lat+2))==-1 || str.indexOf(" ")!=-1) {
//	   alert("Please Enter a Valid Email Address!")
//	   return false
//	} else
//		return true					
	return emailCheck(str);
}

function pop_window(url,width,height,x){
	if(height == undefined)
		height = 300;
	if(width == undefined)
		width = 400;
     win = window.open(url,'windowName','scrollbars,resizable,copyhistory,height='+height+',width='+width+',left = 100,top = 100');
}

function ValidateEmailForm(){
	var emailID=document.formemail.email
	if(isset('document.formemail.agree')) {
		if(!document.formemail.agree.checked) {
			alert('In order to continue, you must agree to the privacy policy and terms & conditions of this site.');
			return false
		}
	}
	if ((emailID.value==null)||(emailID.value=="")||(emailID.value.indexOf('www.')!=-1)){
		alert("Please Enter a Valid Email Address!");
		emailID.focus();
		return false
	} else if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false
	} else
		return true
 }
 
function autotab(original,destination){
	if(original.name.indexOf('Phone') < 0)
		if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
			destination.focus();
}

function nocertify() {
	document.memberform.address.value = '';
	document.memberform.HPhone1.value = '';
	document.memberform.HPhone2.value = '';
	document.memberform.HPhone3.value = '';
	alert('You must enter your correct phone number and address to receive your guaranteed reward.\nEntering any incorrect contact information will void your reward.');
}

function checkMemberForm() {
	var message = "";
	var emailID;
	
	if(isset('document.memberform.certify'))
		if(!document.memberform.certify[0].checked)
			message += 'You must enter your correct phone number and address to receive your guaranteed reward.\nEntering any incorrect contact information will void your reward.\n\n'

	if(document.memberform.fname.value.length == 0)
		message += 'Please enter your First Name\n'
	else if(document.memberform.fname.value.length < 3)
		message += 'Please enter your full First Name\n';

	if(document.memberform.lname.value.length == 0)
		message += 'Please enter your Last Name\n'
	else if(document.memberform.lname.value.length < 3)
		message += 'Please enter your full Last Name\n';

	if(isset('document.memberform.email')) {
		emailID = document.memberform.email
		if ((emailID.value==null)||(emailID.value=="")||(emailID.value.indexOf('www.')!=-1)){
			message += 'Please Enter a Valid Email Address\n';
		} else if (echeck(emailID.value)==false){
			message += 'Please Enter a Valid Email Address\n';
		}
	}

	if(document.memberform.HPhone1.value.length != 3 || document.memberform.HPhone2.value.length != 3 || document.memberform.HPhone3.value.length != 4 || document.memberform.HPhone1.value.indexOf(' ') != -1 || document.memberform.HPhone2.value.indexOf(' ') != -1 || document.memberform.HPhone3.value.indexOf(' ') != -1 || document.memberform.HPhone1.value < 200 || document.memberform.HPhone1.value > 999 || document.memberform.HPhone2.value < 000 || document.memberform.HPhone2.value > 999 || document.memberform.HPhone2.value == 555 || document.memberform.HPhone3.value < 0000 || document.memberform.HPhone3.value > 9999)
		message += 'The home phone number you entered may be incorrect or disconnected.\n\n';

	if(document.memberform.WPhone1.value.length != 3 || document.memberform.WPhone2.value.length != 3 || document.memberform.WPhone3.value.length != 4 || document.memberform.WPhone1.value.indexOf(' ') != -1 || document.memberform.WPhone2.value.indexOf(' ') != -1 || document.memberform.WPhone3.value.indexOf(' ') != -1 || document.memberform.WPhone1.value < 200 || document.memberform.WPhone1.value > 999 || document.memberform.WPhone2.value < 000 || document.memberform.WPhone2.value > 999 || document.memberform.WPhone2.value == 555 || document.memberform.WPhone3.value < 0000 || document.memberform.WPhone3.value > 9999)
		message += 'The work phone number you entered may be incorrect or disconnected.\n\n';
	
	if(document.memberform.address.value.length == 0)
		message += 'Please enter your Street Address\n';

	if(document.memberform.city.value.length == 0)
		message += 'Please enter your City\n'
	else if(document.memberform.city.value.length < 3)
		message += 'Please enter your full City\n';

	if(document.memberform.state.selectedIndex == 0)
		message += 'Please select your State\n';

	if(document.memberform.zipcode.value == "")
		message += 'Please enter your Zip Code\n';
	
	if(!document.memberform.Age[0].checked && !document.memberform.Age[1].checked)
		message += 'Please tell us if you have any children under the age of 5 years\n';

	if(!document.memberform.Pool[0].checked && !document.memberform.Pool[1].checked)
		message += 'Please tell us if you currently have an in-ground backyard pool\n';

	if(!document.memberform.SafetyDevice[0].checked && !document.memberform.SafetyDevice[1].checked)
		message += 'Please tell us if you currently have, or use, any type of pool safety device\n';

	if(!document.memberform.ninetyDays[0].checked && !document.memberform.ninetyDays[1].checked)
		message += 'Please tell us if you plan on installing a child safety fence within the next 90 days\n';

	if(!document.memberform.ownHome[0].checked && !document.memberform.ownHome[1].checked)
		message += 'Please tell us if you currently own or your home\n';

	if(!document.memberform.safety[0].checked && !document.memberform.safety[1].checked)
		message += 'Please tell us if you are concerned about water safety\n';
	
	if (message != '') {
		alert("The following form field(s) were incomplete or incorrect:\n\n" + message + "\n\n Please complete or correct the form and submit again.");
		return false
	} else {
		return true
	}
}

function checkMemberForm_nextGen() {
	var message = "";
	var emailID;

	if(isset('document.memberform.salutation')) {
		if(document.memberform.salutation.selectedIndex == 0)
			message += 'Please select your salutation\n';	
	}
	
	if(document.memberform.fname.value.length == 0)
		message += 'Please enter your First Name\n'
	else if(document.memberform.fname.value.length < 3)
		message += 'Please enter your full First Name\n';

	if(document.memberform.lname.value.length == 0)
		message += 'Please enter your Last Name\n'
	else if(document.memberform.lname.value.length < 3)
		message += 'Please enter your full Last Name\n';

	if(isset('document.memberform.email')) {
		emailID = document.memberform.email
		if ((emailID.value==null)||(emailID.value=="")||(emailID.value.indexOf('www.')!=-1)){
			message += 'Please Enter a Valid Email Address\n';
		} else if (echeck(emailID.value)==false){
			message += 'Please Enter a Valid Email Address\n';
		}
	}

	if(document.memberform.HPhone1.value.length != 3 || document.memberform.HPhone2.value.length != 3 || document.memberform.HPhone3.value.length != 4 || document.memberform.HPhone1.value.indexOf(' ') != -1 || document.memberform.HPhone2.value.indexOf(' ') != -1 || document.memberform.HPhone3.value.indexOf(' ') != -1 || document.memberform.HPhone1.value < 200 || document.memberform.HPhone1.value > 999 || document.memberform.HPhone2.value < 000 || document.memberform.HPhone2.value > 999 || document.memberform.HPhone2.value == 555 || document.memberform.HPhone3.value < 0000 || document.memberform.HPhone3.value > 9999)
		message += 'The home phone number you entered may be incorrect or disconnected. \n\n To receive your guaranteed cash you must enter your valid working phone number. \n\n If the number you entered is your correct working phone number\n re-enter the phone number and address so we can send you guaranteed cash.\n\n';

	if(document.memberform.address.value.length == 0)
		message += 'Please enter your Street Address\n';

	if(document.memberform.city.value.length == 0)
		message += 'Please enter your City\n'
	else if(document.memberform.city.value.length < 3)
		message += 'Please enter your full City\n';

	if(document.memberform.state.selectedIndex == 0)
		message += 'Please select your State\n';

	if(document.memberform.zipcode.value == "")
		message += 'Please enter your Zip Code\n';

	if(isset('document.memberform.agree')) {
		if(!document.memberform.agree.checked) {
			alert('In order to continue, you must agree to the privacy policy and terms & conditions of this site.');
			return false
		}
	}
	
	if (message != '') {
		alert("The following form field(s) were incomplete or incorrect:\n\n" + message + "\n\n Please complete or correct the form and submit again.");
		return false
	} else {
		return true
	}
}

function showoffer(oid) {
	if(document.getElementById('lnk'+oid).style.display == '' && !document.getElementById('continuebutton').disabled) {
		document.getElementById('if'+oid).src=document.getElementById('if'+oid).src;
		document.getElementById('od'+oid).style.display = '';
		document.getElementById('continuebutton').disabled = true;
	}
}

function closeoffer(oid) {
	document.getElementById('od'+oid).style.display = 'none';
	document.getElementById('continuebutton').disabled = false;
}

function gup(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function allowdec() {
	if((event.keyCode >= 48 && event.keyCode <= 57) || event.keyCode == 46) {return true} else {return false}
}

function allowint() {
	if((event.keyCode >= 48 && event.keyCode <= 57)) {return true} else {return false}
}
