function overlay() {
	HomePageOverlay.init("welcome-message");
	HomePageOverlay.loadContent($('#welcome-message').html());
	
}

var HomePageOverlay = {
	offsetToTop : 0,
	offsetOfElement : 0,
	popupID : '',
	status : false,

	init: function(id) {
		var obj = this;

		$('<div id="overlay"></div>').appendTo('body');
		$('#overlay').css({
			height: $(document).height() + 'px',
			width: $(window).width() + 'px'
		});

		this.popupID = (id !== '') ? id : 'PopupDefault';

		//$(window).scroll(this._offset);
		$(window).resize(function(){
			$('#overlay').css({
				height: $(document).height() + 'px',
				width: $(window).width() + 'px'
			});

			obj._offset();
		});

		this.status = true;

		$('<div class="popup"></div>').attr('id', this.popupID).appendTo('body');

		
	},

	loadContent: function(e) {
		$('div.popup').html(e).show();
		this._offset();
	},

	close: function(evtfunc) {
		$('div.popup').remove();
		$("#overlay").remove();

		this.status = false;

		$(document).unbind('keydown', evtfunc);

		return false;
	},

	loadMessage: function() {
		$('div.popup').html('<p class="tcenter"><strong>Loading... please wait.</strong></p>')
		$('div.popup').show();

		this._offset();
	},

	_offset: function() {
		$('div.popup').css('top','0' + 'px');
	}
};


function getCookie(c_name)
{

if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));

    }
  }
return "";
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function openOverLay(){
var cookieVal = getCookie('advisorCookie');
var emptyString = "";
var cookieValFinal = trim(cookieVal,emptyString)
if (cookieValFinal == "")
	{
		
		overlay();
		
	}

}

/* To set Advisor cookies */
function setCookieAdvisor()
	{
		
		var expiredays=30;
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+30);
		document.cookie='advisorCookie'+ "=" +escape('accepted')+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ';path=/';
		
	
	}

/* To set Consumer cookies */

function setCookieConsumer()
	{
		
		var expiredays=30;
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+30);
		document.cookie='consumerCookie'+ "=" +escape('accepted')+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ';path=/';
	
	}
	
function acceptRedirect() 
	{
	
	
	setCookieAdvisor('true','www.sunlife-uk.com',30);
	HomePageOverlay.close();

	}

function declineRedirect() {
	
	
	window.location.href='http://www.sloc.co.uk/slfuk/Consumer';
	
}

function checkAllCookies()
{

	var advisorCookieVal = getCookie('advisorCookie');
	var consumerCookieVal = getCookie('consumerCookie');
	var emptyString = "";
	var advisorCookieValFinal = trim(advisorCookieVal,emptyString);
	var consumerCookieValFinal = trim(consumerCookieVal,emptyString);
	if(document.location.href.indexOf("Accept") < 0)
	{
		if( consumerCookieValFinal != "")
		{
			var consumerURL = "http://www.sloc.co.uk/slfuk/Consumer";
	  		window.location = consumerURL;
		}
		else if(advisorCookieValFinal != "")
		{
		
			var advisorURL = "https://www.sunnet.sunlife.com/signin/ukpublic/e/home.wca";
			window.location = advisorURL;
		
		}
	}

}

function checkCookieAdvisor(url){
	

	setCookieAdvisor('true','www.sunlife-uk.com',30);
	window.location.href='https://www.sunnet.sunlife.com/signin/ukpublic/e/home.wca';
	
}