var OutsideLinkMessage = "<div class=\'modalcontainer\'><center>" +
"<p>You are about to leave the LetsTalkConstipation.com website and enter a website operated by an independent third party. The links to third-party websites contained on LetsTalkConstipation.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 non-Takeda website.</p></center></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\'><center>" +
"<p>You are about to leave the LetsTalkConstipation.com website.</p><p>Please click \"OK\" if you wish to be taken to a website to learn about a possible treatment option that might be available to you.</p></center></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 ? options.continueText : "Continue";
		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 : "Back";
		this.okText = options && options.okText ? options.okText : "Proceed";
		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='modal-confirm' id='modal-confirm'>\ <div class='close'></div>\
					" + options.message + "\
					<div class='popupPosition'>\
					<button id='modal-cancel-button' class='button modalButton'><span><span>Cancel</span></span></button>\
					<button id='modal-ok-button' class='button modalButton'><span><span>" + options.continueText +  "</span></span></button>\
					</div>\
				</div>\
			</div>\
		";
		var y = window.pageYOffset || document.documentElement.scrollTop;
		$("modal-container").setStyle({top : "0", left: "0"});
		$("modal-confirm").setStyle({
			top : ((document.viewport.getHeight() / 2) - 100 + y) + "px",
			left : ((document.viewport.getWidth() / 2) - 200) + "px"
		})
		$("modal-mask").setStyle({
			height : maskHeight + "px",
			width : document.body.offsetWidth + "px"
		});
		$("modal-cancel-button").observe("click", Modal.close.bind(Modal));
		$("modal-ok-button").observe("click", function() {
			Modal.close();
			options.callback();
			if (options.caller.id == "amitiza") {
				pageTracker._trackPageview('/outboundlink' + (location.pathname.replace(siteroot, "/").replace(".ssx", "")) + 'www.amitiza.com/cic/');
				AmitizaOutboundLink();
			}
		});
	},
	close : function() {
		if (this.html) {
			this.html.remove();
			this.html = null;
		}
	}
}


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) {
			Event.observe(A, "click", function(e) {
				Event.stop(e);
				var ThisHref = this.href;
				var ThisRel = this.rel;
				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() {
						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();
});

/* 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);}

document.observe("dom:loaded", function() {
	setTimeout(function(){if($("noflash")) $("noflash").removeClassName("hidden")} ,600)
	
	var flashvars = {};
	var params = {'wmode':'transparent'};
	var attributes = {};
   if($("homepageflashcontainer")) 
   		swfobject.embedSWF(siteroot + "local/flash/constipation_937x235.swf", "homepageflashcontainer", "937", "235", "8.0.0","", flashvars, params, attributes);
   if($("flashcontent")) 
   		swfobject.embedSWF(siteroot + "local/flash/CIC_Website_dragdrop_700x500_v7.swf", "flashcontent", "850", "410", "8.0.0","", flashvars, params, attributes);
   
	//Flash functions to get the layout of the symptoms
	//my personal problem is the porcupine with broken glass
	 js2as = function() {
		getMovieName("mymovie").callASfunction();
	}

	getMovieName = function(movieName) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName]
		}
		else {
			return document[movieName]
		}
	}

	submitSym = function(listofpics){
		var picturelist = listofpics;
		$('ImageLocations').value = listofpics;
	}
	
	if($('StomachFeeling')){
		$$('.severityslider').each(function(el){
			new Control.Slider(el.down('.severityhandle'),el,{
				values:[0.06, 0.28, 0.49, 0.72,0.93],
				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('/living/how_you_feel/' + symptomname)
				} else {
					symptombody.addClassName("symptomhidden")
				}
			});
		});
	}
	
});


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";
}
