var ext_int = '<div class="qi_msg"><h2>By clicking on the link below, you will leave <a href="http://www.anemiacaretools.com" title="">http://www.AnemiaCareTools.com</a>.</h2><p>Clicking on the link below will take you to a Web site to which our site\'s <a href="privacy_policy.aspx" title="">Privacy Policy</a> does not apply. You are solely responsible for your interactions with that Web site. The links are provided for informational purposes only and do not represent an endorsement, direct or implied, of the Web sites to which you will be directed.</p><br/><p><a href="#" title="Continue" class="btn_callout qi_targeturl">Continue</a> <a href="#" title="Cancel" class="btn_callout qi_cancel">Cancel</a></p></div>';

ext_int = '<div class="qi_msg"><h2>You Are Now Leaving AnemiaCareTools.com</h2><p>By clicking &quot;Okay&quot; below, you will be taken to <a href="http://www.esa-apprise.com" target="_blank">www.esa-apprise.com</a>, a Web site that may contain links or references to other Web sites to which our <a href="privacy_policy.aspx">Privacy Policy</a> may not apply. We encourage you to read the Privacy Policy of every Web site you visit. Our Privacy Policy is located at <a href="privacy_policy.aspx">www.anemiacaretools.com/privacy_policy.aspx</a>.<br/>You are solely responsible for your interactions with such Web sites.</p><br/><p><a href="#" title="Okay" class="btn_callout qi_targeturl">Okay</a> <a href="#" title="Cancel" class="btn_callout qi_cancel">Cancel</a></p></div>';

var ext_int2 = '<div class="qi_msg"><h2>You Are Now Leaving AnemiaCareTools.com</h2><p>By clicking &quot;Okay&quot; below, you will be taken to THEURL, a Web site that may contain links or references to other Web sites to which our <a href="privacy_policy.aspx">Privacy Policy</a> may not apply. We encourage you to read the Privacy Policy of every Web site you visit. Our Privacy Policy is located at <a href="privacy_policy.aspx">www.anemiacaretools.com/privacy_policy.aspx</a>.<br/>You are solely responsible for your interactions with such Web sites.</p><br/><p><a href="#" title="Okay" class="btn_callout qi_targeturl">Okay</a> <a href="#" title="Cancel" class="btn_callout qi_cancel">Cancel</a></p></div>';


$(document).ready(function(){
	
	//$('a[rel=external]').attr('target','_blank');
	$('.ext').each(function(){
		$(this).qi_dialog({type: 'ext', msg: ext_int, mask_opacity: .5, fn_launch: function(){
			$('.qi_msg a[target=_blank]').each(function(){
				$(this).qi_dialog({call: 'click', type:'ext'});
			});
		}});
	});
	$('.ext2').each(function(){
		var turl = $(this).attr('href');
		var turl2 = turl.replace('http://', '').replace('https://', '');
		
		var tindex = turl2.indexOf('/');
		if (tindex > 0) turl2 = turl2.substring(0, turl2.indexOf('/'));
		//console.log(turl2);
		tindex = turl2.indexOf('#');
		if (tindex > 0) turl2 = turl2.substring(0, turl2.indexOf('#'));
		//console.log(turl2);
		tindex = turl2.indexOf('?');
		if (tindex > 0) turl2 = turl2.substring(0, turl2.indexOf('?'));
		//console.log(turl2);
		
		$(this).qi_dialog({type: 'ext', msg: ext_int2.replace('THEURL', '<a href="' + turl + '" target="_blank">' + turl2 + '</a>'), mask_opacity: .5, fn_launch: function(){
			$('.qi_msg a[target=_blank]').qi_dialog({call: 'click', type:'ext'});
		}});
	});
	$('a[target=_blank]').not('.ext').not('.ext2').each(function(){
		$(this).qi_dialog({call: 'click', type:'ext'});
	});
	
	if ($('#rightcol').height() < 220){
		$('#rightcol').css({height: 220});
	}
	
	$('.costcalculator').click(function(){
		if(!$.browser.safari){ //if its not a Safari
			window.open($(this).attr('href'), "new_window", 'directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=yes,toolbar=no,width=480,height=530');
			return false;
		}
	});
});
