var OutsideLinkMessage = "<div class=\'modalcontainer\'>" +
"<p>You are about to leave the LetsTalkIBS.com website and enter a website operated by an independent third party. The links to third-party websites contained on LetsTalkIBS.com are provided solely for your convenience. Takeda does not control the opinions, claims, or comments contained on any third-party website linked to, and your activities at those websites will be governed by the policies and practices of those third parties.</p><p>Please click \"Continue\" if you wish to be taken to this <nobr>non-Takeda</nobr> website.</p></div>";
//"<br>Please click \"OK\" if you wish to be taken to a website to learn about a possible prescription treatment option that might be available to you."
/* +
"<br>" +
"Links to other sites are provided as a convenience to the viewer.<br>" +
"<br>" +
"Pfizer Canada accepts no responsibility for the content of linked sites.</div>";*/

var OutsideLinkAmitiza = "<div class=\'modalcontainer\'>" +
"<p>You are about to leave the LetsTalkIBS.com website.</p><p>Please click \"OK\" if you wish to be taken to a website<br> to learn about a possible treatment option that<br> might be available to you.</p></div>";

var OutsideLinkBack = "Cancel"
var OutsideLinkProceed = "OK"
var ConfirmYes = "Yes"
var ConfirmNo = "No";

var Modal = {
	html : null,
	confirm : function(options) {
		var maskHeight = document.body.offsetHeight > document.viewport.getHeight() ? document.body.offsetHeight : document.viewport.getHeight();
		options.continueText = options.continueText === undefined ? "Continue" : options.continueText;
		this.close();//close if open
		this.html = document.createElement("div");
		document.body.appendChild(this.html);
		this.html = $(this.html);
		this.cancelText = options && options.cancelText ? options.cancelText : "Cancel";
		this.okText = options && options.okText ? options.okText : "Proceed";
		var modalClass = options.className ? options.className : 'modal-confirm';
		this.onOpen = options.onOpen || function() {}
		this.onClose = options.onClose || function() {}
		this.html.innerHTML = "\
			<div class='modal-container' id='modal-container'>\
				<div class='modal-mask' id='modal-mask'>" +
					/*@cc_on
					"<iframe frameborder='0' src='javascript:document.write(\"<html><body></body></html>\");document.close();'></iframe>" +
					@*/
				"</div>\
				<div class=" + modalClass + " id='modal-confirm'>\
					<div class='close'></div>\
					<div id='modal-content'>" + options.message + "</div>" +
					"<button id='modal-cancel-button' class='button modalButton'><span><span>" + options.cancelText + "</span></span></button>" +
					(options.continueText ? "<button id='modal-ok-button' class='button modalButton'><span><span>" + options.continueText +  "</span></span></button>" : "") +
				"</div>" +
			"</div>";
		this.onOpen();
		var y = document.documentElement.scrollTop;
		$("modal-container").setStyle({top : "0", left: "0"});
		$("modal-confirm").setStyle({
			top : ((document.viewport.getHeight() / 2) - ($("modal-confirm").getHeight()/2) + y) + "px",
			left : ((document.viewport.getWidth() / 2) - ($("modal-confirm").getWidth()/2)) + "px"
		})
		$("modal-mask").setStyle({
			height : maskHeight + "px",
			width : document.body.offsetWidth + "px"
		});
		if($("modal-cancel-button")){
			$("modal-cancel-button").observe("click", Modal.close.bind(Modal));
		}
		if($("modal-ok-button")){
			$("modal-ok-button").observe("click", function() {
				Modal.close();
				if(options.callback) options.callback();
			});
		}
	},
	close : function() {
		if (this.html) {
			this.html.remove();
			this.html = null;
			this.onClose();
		}
	}
}

function videoComplete(videoSource)
{
	pageTracker._trackPageview('/local/flash/FLV/IBS_Video.flv/complete');
}

function videoStart()
{
	pageTracker._trackPageview('/local/flash/FLV/IBS_Video.flv/start');
}

var ParseAnchors = function () {
	var ArchorArray = document.getElementsByTagName("a");
	for (var i=0; i<ArchorArray.length; i++) {
		var A = ArchorArray[i];
		if (String(A.href).indexOf("http") == 0 && String(A.target).indexOf("blank") > 0 && A.rel != "corporatesite") {
			// append token id
			if (typeof(tokenid)!="undefined") {
				var inner = A.innerHTML
				var u = A.href;
				if (u.indexOf("?") < 0)
					u += "?";
				if (u.indexOf("&tokenid")<0)
					u += "&tokenid=" + escape(tokenid);
				A.href = u;
				//IE automagically replaces innerHTML if it's close enough to href, when href is changed via js. This hack fixes that
				if (A.innerHTML != inner) A.innerHTML = inner.replace("http://", "").replace("/", "")
			}
		
		
			Event.observe(A, "click", function(e) {
				Event.stop(e);
				var ThisHref = this.href;
				var ThisRel = this.rel;
				var CallerId = this.id;
				
				pageTracker._trackEvent("Exit Links", "Popup", ThisHref.replace(this.search, ""));
				
				Modal.confirm({
					caller : this,
					cancelText : OutsideLinkBack,
					okText : OutsideLinkProceed,
					message : (ThisHref.indexOf("amitiza.com") > -1 ? OutsideLinkAmitiza : OutsideLinkMessage),
					continueText : (ThisHref.indexOf("amitiza.com") > -1 ? "OK" : "Continue"),
					callback : function() {
						if (CallerId == "amitiza") 
							pageTracker._trackPageview('/outboundlinks/new_treatment_options/www.amitiza.com/ibs/');
						
						pageTracker._trackEvent("Exit Links", "Exit", ThisHref.replace(this.caller.search, ""))
						window.open(ThisHref, "");
					}
				})
			}.bind(A))
		}

		if (typeof(pageTracker) != "undefined" && String(A.href).indexOf(siteroot + "local/files/") >= 0) {
			Event.observe(A, "click", function () {
				pageTracker._trackPageview(this.href);
				return false;
			});
		}
	}
}

Event.observe(window, "load" ,function() {
	ParseAnchors();
	$$("[href^=mailto:]").each(function(el) {
		el.observe("click", function(e) {
			pageTracker._trackEvent("Exit Links", "Mailto", el.href.replace("mailto:", ""))
		})
	})
	
	$$('.severityslider').each(function(el){
		
		var values = [0.06, 0.28, 0.49, 0.72,0.93];
		var defaultValueObject = el.getElementsByTagName("input");
		var defaultValue = defaultValueObject[0].value;
		
		new Control.Slider(el.down('.severityhandle'),el,{
			values:values,
			sliderValue: values[defaultValue - 1],
			onChange:function(val){
				var value;
				switch(val){
					case 0.06:
						value = 1;
						break;
					case 0.28:
						value = 2;
						break;
					case 0.49:
						value = 3;
						break;
					case 0.72:
						value = 4;
						break;
					case 0.93:
						value = 5;
						break;
				}
				el.down('.severityinput').value = value;
			}
		});
	});
	
	$$('.symptomexpander').each(function(el){
		Event.observe(el,"click",function(){
			var symptombody = el.up(".symptomcontainer").down(".symptombody")
			var symptomname = el.next("label").innerHTML.replace(':', '').replace(/ /g, '_').toLowerCase()
			if (el.checked){
				symptombody.removeClassName("symptomhidden")
				pageTracker._trackPageview('/describe_how_you_feel/' + symptomname)
			} else {
				symptombody.addClassName("symptomhidden")
			}
		});
	});
});
/* old GA call for dragdrop flash
var isDrapDropTracked = false;
var trackDragDrop = function() {
	if (!isDrapDropTracked) {
		pageTracker._trackPageview("/describe_how_you_feel/interact/");
		isDrapDropTracked = true;
	}
}
*/

var describe = function(tshirt, drop, description) {pageTracker._trackEvent(tshirt, drop, description);}

submitTracker = function(){
	//$("google-conversion-target").src = siteRoot() + "elements/submit_tracker.html";
}
printTracker = function(){
	$("google-conversion-target").src = siteRoot() + "elements/print_tracker.html";
}

AmitizaOutboundLink = function(){
	$("google-conversion-target").src = siteRoot() + "elements/amitiza_outbound_link.html";
}

var startVideo = function() {
	pageTracker._trackPageview('/local/flash/FLV/IBS_Video.flv/start');
	var so3 = new SWFObject(siteroot + "local/flash/letsTalkIbsPlayer_660x441.swf", "IBS_Video", "660", "441", "8", "#ffffff");
	$("modal-content").innerHTML = '<div id="homevideocontainer"></div><h3>Tips on Talking to a Healthcare Provider about IBS</h3><div class="clear"></div>'
	if ($("homevideocontainer")) so3.write("homevideocontainer");
}

var stopVideo = function() {
	if ($("homevideocontainer")) $("homevideocontainer").innerHTML = "";
}

var submitSym = function(listofpics){
	var picturelist = listofpics;
	document.getElementById('ImageLocations').value = listofpics;
}
