jQuery(function() {
	jQuery('.pullLink').removeClass('hiddenLink');
});
jQuery(function() {
	jQuery('.hideLink').addClass('hiddenLink');
});
jQuery(function() {
	var sfid = getParameterByNameFromURL('sfid',location.href)
	if( sfid ) {
		var expires = new Date();
		expires.setDate(expires.getDate() + 30);
		document.cookie = "sfid =" +escape(sfid)+";expires=" + expires.toGMTString() + ";path=/;";
	}
	jQuery('a').click(function() {
		if( this.href.indexOf('.pdf') > 0 && typeof utEvtTag == 'function' ) {
			utEvtTag('ev=pdf_open&evdetail=' + escape(jQuery(this)[0].href));
		}
	});
});
jQuery( document ).ready( function(){
	var productArr = ["external","parent","new_popup","g2m_login","g2t_login","tos_popup","top","popup","g2m_pop","g2w_pop","g2t_pop"];
	jQuery.each( productArr, function(i) {
		switch (i) {
			case 0 : jQuery("a[rel='external']").click(function() {
							window.open(this.href);
							return false;
						});
						break;
			case 1 : jQuery("a[rel='parent']").click(function() {
							window.opener.location = this.href;
							window.close();
							return false;
						});
						break;
			case 2 : jQuery("a[rel='new_popup']").click(function() {
							var delim = (this.href.indexOf('?') >= 0) ? '&' : '?';
							var h = parseInt(getParameterByNameFromURL('height', this.href));
							var w = parseInt(getParameterByNameFromURL('width',  this.href));
							if (!h) { h = 400; }
							if (!w) { w = 500; }
							var features = "height=" + h + ",width=" + w + ",menubar=0,status=0,location=0,toolbar=0,scrollbars=yes,resizable=yes";
							newwindow=window.open(this.href , 'newPopup', features);
							return false;
						});
						break;
			case 3 : jQuery("a[rel='g2m_login']").click(function() {
							document.getElementById('mktgPixelImg').src = 'https://ad.doubleclick.net/activity;src=2870544;type=confi177;cat=g2m_l318;ord=1;num=1?';
						});
						break;
			case 4 : jQuery("a[rel='g2t_login']").click(function() {
							document.getElementById('mktgPixelImg').src = 'https://ad.doubleclick.net/activity;src=2870549;type=confi794;cat=g2t_l203;ord=1;num=1?';
						});
						break;
			case 5 : jQuery('a[rel="tos_popup"]').click(function() {
							var delim = (this.href.indexOf('?') >= 0) ? '&' : '?';
							var features = "height=653,width=992,menubar=0,status=0,location=0,toolbar=0,scrollbars=yes,resizable=yes";
							newwindow=window.open(this.href + delim + 'popup=true', 'tos_popup', features);
							return false;
						});
						break;
			case 6 : jQuery("a[rel='top']").click(function() {
							window.top.location = this.href;
						});
						break;
			default : jQuery("a[rel=" + productArr[i] + "]").click(function() {
							var delim = (this.href.indexOf('?') >= 0) ? '&' : '?';
							var h = parseInt(getParameterByNameFromURL('height', this.href));
							var w = parseInt(getParameterByNameFromURL('width',  this.href));
							if (!h) { h = 400; }
							if (!w) { w = 500; }
							var features = "height=" + h + ",width=" + w + ",menubar=0,status=0,location=0,toolbar=0,scrollbars=yes,resizable=yes";
							var productVar = ( i == 1 ) ? "" : productArr[i];
							newwindow=window.open(this.href + delim + 'popup=true#' + productVar, 'Popup', features);
							return false;
						});
		}
	});
	jQuery("a.annualPlan").click(function() {
		jQuery('.annualPlan').addClass('annualSelected');
		jQuery('.annualPrice').removeClass('hiddenContent');
		jQuery('.monthlyPrice').addClass('hiddenContent');
		jQuery('.monthlyPlan').addClass('monthlyDefault');
	});
	jQuery("a.monthlyPlan").click(function() {
		jQuery('.monthlyPrice').removeClass('hiddenContent');
		jQuery('.monthlyPlan').removeClass('monthlyDefault');
		jQuery('.annualPrice').addClass('hiddenContent');
		jQuery('.annualPlan').removeClass('annualSelected');
	});
	jQuery("a[rel='lightbox']").click(function() {
		var link = jQuery(this).attr("href")
		var h = parseInt(getParameterByNameFromURL('height', link));
		var w = parseInt(getParameterByNameFromURL('width',  link));
		if (!h) { h = 670; }
		if (!w) { w = 530; }
		if(link.indexOf("?")!=-1)
			link = link+"&popup=true&lb=true"
		else
			link = link+"?popup=true&lb=true"
		jQuery("#lightbox-border").addClass(jQuery(this).attr("title"));
		jQuery("#lightbox-border").prepend('<div class="lightbox-tl"><\/div><div class="lightbox-top"><\/div><div class="lightbox-tr"><\/div><div id="lightbox-close"><\/div><div class="clear-both"><\/div><div id="lightbox-content"><\/div>');
		jQuery("#lightbox-border").append('<div class="lightbox-bl"><\/div><div class="lightbox-bottom"><\/div><div class="lightbox-br"><\/div>');
		jQuery("#lightbox-content").addClass(jQuery(this).attr("class")).get(jQuery(this).attr("href"));
		if(jQuery(this).attr("href").indexOf("http") != "-1")
			jQuery("#lightbox-content").html("<iframe src='"+link+"' width='"+w+"' height='"+h+"' frameborder='0'><\/iframe>");
		else {
			jQuery("#lightbox-content").load(link, function(){
				jQuery("#lightbox-content a[rel='external']").each(function(){
					jQuery(this).click(function(){window.open(jQuery(this).attr('href')); return false;});
				});
			});
		}
		if( typeof utEvtTag == 'function' ) {
			utEvtTag('ev=lightbox_open&evdetail=' + escape(jQuery(this)[0].href));
		}
		jQuery("#lightbox-container").fadeIn(100);
		jQuery("#lightbox-close").hover(function(){ jQuery(this).css('cursor','pointer') });
		jQuery("div#lightbox-close").click(function() {
			lightboxClose();
		});
		return false;
	});
});
function checkAll(theObject) {
	theNodeList = theObject.form.elements[theObject.name];
	for( i=0;i<theNodeList.length;i++ )
		theNodeList[i].checked=theObject.checked
}

function unCheck(theObject) {
	var flag=true
	theNodeList = theObject.form.elements[theObject.name];
	for( i=0;i<theNodeList.length-1;i++ )
		if(!theNodeList[i].checked) {
			flag=false;
			break;
		}
	theNodeList[theNodeList.length-1].checked = flag;
}
function preFillElements(theObject, flag) {
	if(flag) {
		for(i=0;i<theObject.length;i++) {
			theTarget = document.getElementById(theObject[i][0]);
			(flag == "prefill" && ( theTarget.value == theObject[i][1] ) ) ? eventHandlerClass('add', theTarget, flag) : clearElement(theTarget, theObject[i][1]);
		}
	}
	return true;
}
function clearElement(theObject, defaultText, refill) {
	theAction = ( refill && ( ( theObject.value == ""	) || ( theObject.value == defaultText ) ) ) ? 'add' : 'remove';
	eventHandlerClass( theAction, theObject, 'prefill' );
	if( refill && theObject.value == "" )
		theObject.value = defaultText;
	else if( theObject.value == defaultText )
		theObject.value = "";
}
function eventHandlerClass(theAction,theObj,class1,class2) {
	switch( theAction )	{
		case 'add':
			if(!eventHandlerClass('check',theObj,class1)){theObj.className+=theObj.className?' '+class1:class1;}
			break;
		case 'remove':
			var rep = theObj.className.match(' '+class1) ? ' ' + class1 : class1;
			theObj.className = theObj.className.replace(rep, '');
			break;
		case 'check':
			return new RegExp('\\b'+class1+'\\b').test(theObj.className)
			break;
	}
}
function getParameterByNameFromURL(name, url) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(url);
	if(results == null) {
		return "";
	}
	else {
		return results[1];
	}
}
function utEvtTag(sEvt) {
	try {
		bO=objCopy(utag.handler.o);
		pageVal=utag.handler.CONCAT("/",1,"",[bO.locale,bO.product,bO.section,bO.sub_section,bO.content_type,bO.template,bO.pageset,bO.conversion_type,bO.conversion_currency,bO.plan,bO.plan_tier]);
		mylc=escape(document.URL+((document.URL.indexOf('?')>0)?'&':'?')+'ni_title='+pageVal);
		ntptEventTag('lc=' + mylc + '&' +sEvt);
	} catch (e) {}
}
function objCopy(obj){
	var objCopy={};
	for(var i in obj){
		objCopy[i]=obj[i];
	}
	return objCopy
}
function lightboxClose(){
		jQuery("#lightbox-container").fadeOut(100, function(){
		jQuery("#lightbox-border").removeClass().html("");
		jQuery("#lightbox-container").hide();
	});
}

