// BEGIN CONFIGURATION
config =
{
	text :
	{
		 header : "Welcome to floseal.com"
		,intro : "The information on this website is intended for healthcare professionals only. Please certify that you are a healthcare professional by clicking the appropriate link below. If you are not a healthcare professional, we recommend <a href=\"http://www.baxter.com/baxter_worldwide.html\">www.baxter.com</a> for general information regarding Baxter."
		,choice_yes : "Yes, I am a healthcare professional"
		,choice_no : "No, I am not a healthcare professional"
	}

	,links :
	{
		 choice_yes : "http://floseal.com" // (not used)
		,choice_no : "http://www.baxter.com/baxter_worldwide.html"
	}

	,cookie_name : "flosealcom_hpo"
}
// END CONFIGURATION


hpo =
{
	 page_height : (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight
	,page_width : (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth
	,cookies_enabled : navigator.cookieEnabled

	,cookies :
	{
		set : function(in_name, in_value, in_path, in_expires)
		{
			if(hpo.cookies_enabled === true)
			{
				var new_cookie = escape(in_name) + "=" + escape(in_value);

				if(in_path.length > 0)
					new_cookie += ";path=" + in_path;

				if(in_expires > 0)
				{
					var expire_date = new Date();
					expire_date.setTime(expire_date.getTime() + (in_expires * 86400000));
					new_cookie += ";expires=" + expire_date.toGMTString();
				}
				
				document.cookie = new_cookie;
				return true;
			}

			return false;
		}

		,get : function(in_name)
		{
			if(hpo.cookies_enabled === true)
			{
				var cookie_item = document.cookie.split("; "), cookie_parts = "";
				for(var i=0, len=cookie_item.length; i < len; i++)
				{
					cookie_parts = cookie_item[i].split("=");
					if(cookie_parts[0] == in_name)
						return cookie_parts[1];
				}
			}

			return false;	
		}
	}

	,init : function()
	{
		var old_onload = window.onload;
		if(typeof window.onload == 'function')
		{
			window.onload = function()
			{
				old_onload();
				hpo.load();
			}
		}
		else
		{
			hpo.load();
		}
	}

	,load : function()
	{
		if(hpo.cookies.get(config.cookie_name) == false)
		{
			hpo.add_stylesheet();
			hpo.create_overlay_box();
			hpo.create_choice_box();
		}
	}

	,add_stylesheet : function()
	{
		var css_tag = document.createElement("link");
		css_tag.setAttribute("href", "/hpo/hpo.css");
		css_tag.setAttribute("rel", "stylesheet");
		css_tag.setAttribute("type", "text/css");
		document.getElementsByTagName("head")[0].appendChild(css_tag);
	}

	,create_overlay_box : function()
	{
		var body_tag = document.getElementsByTagName("body"), overlay_tag = document.createElement("div");
		overlay_tag.setAttribute("id", "div_overlay_box");
		body_tag[0].appendChild(overlay_tag);

		var overlay_box = document.getElementById("div_overlay_box");
		overlay_box.style.height = hpo.page_height + "px";
		overlay_box.style.width = hpo.page_width + "px";
	}

	,create_choice_box : function()
	{
		var overlay_tag = document.createElement("div");
		overlay_tag.setAttribute("id", "div_choice_box");
		document.getElementsByTagName("body")[0].appendChild(overlay_tag);

		var choice_box = document.getElementById("div_choice_box"), choice_box_content = "<h1>" + config.text.header + "</h1>";
		choice_box_content += "<p>" + config.text.intro + "</p>";
		choice_box_content += "<p><a href=\"#\" onclick=\"hpo.cookie_and_redirect(); return false;\" id=\"choice_yes\">" + config.text.choice_yes + "</a></p>";
		choice_box_content += "<p><a href=\"" + config.links.choice_no + "\" id=\"choice_no\">" + config.text.choice_no + "</a></p>";
		choice_box.innerHTML = choice_box_content;

		var choice_box_width = 400;
		choice_box.style.top = 125 + "px";
		choice_box.style.left = parseInt(hpo.page_width / 2) - parseInt(choice_box_width / 2) + "px";
		choice_box.style.width = choice_box_width + "px";
	}

	,cookie_and_redirect : function()
	{
		hpo.cookies.set(config.cookie_name, "true", "", 730);
		window.location.reload();
		return false;
	}
}

hpo.init();

