var jumptime = (function($) {

var customerName = "timeseg",
domain = "http://timeseg.jump-time.net/timeseg",
excludeAdParams = ["rsseg","qc","url","last","compare"],
imageUrl = "http://timeseg.jump-time.net/timeseg.gif",
scriptUrl = "http://beacon.jump-time.net/jt.js";
var publicAPI = {};
function getParams() {
return {
sup: "Health",
sec: s_time.prop16 || "",
ss: s_time.prop11 || "",
tag: s_time.prop12 || "health",
caid: adFactory.params.aid || "",
akv1: (adFactory.sitename || "") + "/" + (adFactory.zone || ""),
//akv2: adFactory.zone || "",
akv2: (function () {
    var params = [];
    for (param in adFactory.params) {
        if ($.inArray(param, excludeAdParams) < 0) {
            if (param.length > 1) {
                params.push(param + '=' + adFactory.params[param]);
            }
        }
    }
    return params.join('|');
})(),
ct: (function() {
var ptype = adFactory.params.ptype, ctype = adFactory.params.ctype;if(ptype && ctype) {
return ptype + '|' + ctype;} else if (ptype) {
return ptype;} else {
return ctype;}
})()
}
};
function track() {
var paramsObj = getParams();var params = customerName + '&' + $.param(paramsObj);if(typeof console !== "undefined") {
console.log('JumpTime Raw Data:');console.dir(paramsObj);console.log('JumpTime Url String:');console.dir(params);}
jt(domain,params,true);};
$.ajax({
type: "GET",
url: scriptUrl, 
dataType: "script",
cache: true,
success: track 
});
publicAPI.track = track;
return publicAPI;
})(jQuery);
function swapPreview(which) {
var previewImg = document.getElementById("previewImg");var imgSrc = which.href;if (previewImg && imgSrc) {
previewImg.src = imgSrc;return false;}
return true;}


// Used in Newsletter pages with forms

function swapPreview(which) {
	var previewImg = document.getElementById("previewImg");
	var imgSrc = which.href;
	if (previewImg && imgSrc) {
		previewImg.src = imgSrc;
		return false;
	}
	return true;
}

function isBlank(str) {
	return (!str || str == "");
}
function isValidEmail(str) {
	var filter  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})$/;
	return (filter.test(str));
}
function hasNewsletters() {
	var checks = document.getElementById("checkboxes");
	if (checks) {
		var inputs = checks.getElementsByTagName("input");
		for (var i=0; i < inputs.length; i++) {
			if (inputs[i].checked) {
				return true;
			}
		}
		return (inputs.length == 0);
	}
	return true;
}


function validateForm(which) {
	var error = "";
	if (!hasNewsletters()){
		error += "Please select at least one newsletter.\n\n";
	}
	if (which.email) {
		var email = which.email.value;
		if (isBlank(email)) {
			error += "Please enter an email address.\n\n";
		}
		else if (!isValidEmail(email)){
			error += "Invalid email address.  Address must be in the form 'name@domain.com'.\n\n";
		}
	}
	if (error != "") {
		alert(error);
		return false;
	}
	return true;
}

function validateForm2(which) {
	var errors = new Array(0);
	if (which.email) {
		var email = which.email.value;
		if (isBlank(email)) {
			errors.push("Please enter your new email address.");
		}
		else if (!isValidEmail(email)) {
			errors.push("Invalid email address.  Address must be in the form 'name@domain.com'.");
		}		
	}
	if (errors.length > 0) {
		var email_label = document.getElementById("email_label");
		if (email_label) {
			email_label.className = "error";
		}
		writeErrors(errors);
		return false;
	}
	return true;
}

function validateForm3(which) {
	var errors = new Array(0);
	if (which.email) {
		var email = which.email.value;
		if (isBlank(email)) {
			errors.push("Please enter your new email address.");
		}
		else if (!isValidEmail(email)) {
			errors.push("Invalid email address.  Address must be in the form 'name@domain.com'.");
		}		
	}
	if (errors.length > 0) {
		var email_label = document.getElementById("email_label");
		if (email_label) 
		writeErrors(errors);
		return false;
	}
	return true;
}

function writeErrors(errors) {
	var errorBox = document.getElementById("errorBox");
	if (errorBox) {
		var html = '<div class="errorMsg">';
		for (var i=0; i < errors.length; i++) {
			html += '<p>' + errors[i] + '</p>';
		}
		html += '</div>';
		errorBox.innerHTML = html;
	}
}

function initNForm() {
	var form = document.getElementById("fnews");
	if (form) {
		var anchors = form.getElementsByTagName("a");
		for (var i=0; i < anchors.length; i++) {
			if (anchors[i].parentNode.className == "preview") {
				anchors[i].onclick = function() {
					return swapPreview(this);
				}
			}
		}
	}
}

tii_callFunctionOnWindowLoad(function(event) {
	initNForm();
});

// function moved from home2.js - for dynamic lead and form validation


/* begin: Newsletter Signup Form Validation */
function isValidEmail(str) {
	var filter  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})$/;
	return (filter.test(str));
}

function validateSignup(form) {
	var error = "";
	var subCount = 0;
	for (var i=0; i < form.sub.length; i++) {
		if (form.sub[i].checked) {
			subCount += 1;
		}
	}
	if (subCount == 0) {
		error += "Please select at least one newsletter.\n";
	}
	if (!isValidEmail(form.email.value)){
		error += "Please enter a valid email address.\n";
	}
	if (error != "") {
		alert(error + "\nThank You,\nHealth.com");
		return false;
	}
	return true;
}
/* end: Newsletter Signup Form Validation */
