


function startPopUp(waitTime, pageToDisplay, divName, display2)
{
$('#msg1').notificationmsg({period: 2500});
$('#closebutton').click(function(){ $('#'+divName).notificationmsg('hide'); });
advert(waitTime, pageToDisplay, divName, display2);
}







function advert(waitTime, pageToDisplay, divName, display2)
{
    setTimeout("showPop(\""+pageToDisplay+"\", \""+divName+"\", \""+display2+"\")",waitTime)
//1;
}

function showPop(pageToDisplay, divName,display2)
{

if(display2 == 'popDisplayedCTA')
	{
var animStyle = 'slide';

var cookie = getCookie("popDisplayedCTA");
if(!cookie)//if cookie not found
	{
	setSessionCookie("popDisplayedCTA","Next_Page"); // we save Next_Page to indicate that the popup should open in the next page
	}
else if (cookie == "Next_Page") //now we display the cookie.
{
 $.ajax({
                    type: "GET",
                    url: pageToDisplay,
                    contentType: "text/html; charset=utf-8",
                    dataType: "html",
                    timeout: 1000,

                    success: function(html) {
                        $("#modalbody").html(html);
                        $('#'+divName).notificationmsg({animation:animStyle, period: 0});
                        $('#'+divName).notificationmsg('show'); 
			setCookie("popDisplayedCTA","OK",2); 
	//		setSessionCookie("popDisplayed1","OK");// this is the new session cookie! F Barclays.
						},
                    error: function(xhr,msg,e){
                   }
	})
}

	}
	else
	{
var animStyle = 'slide';

var cookie = getCookie("popDisplayed1");
if(!cookie)//if cookie not found
	{
	setSessionCookie("popDisplayed1","Next_Page"); // we save Next_Page to indicate that the popup should open in the next page
	}
else if (cookie == "Next_Page") //now we display the cookie.
{
 $.ajax({
                    type: "GET",
                    url: pageToDisplay,
                    contentType: "text/html; charset=utf-8",
                    dataType: "html",
                    timeout: 1000,

                    success: function(html) {
                        $("#modalbody").html(html);
                        $('#'+divName).notificationmsg({animation:animStyle, period: 0});
                        $('#'+divName).notificationmsg('show'); 
			setCookie("popDisplayed1","OK",2); 
	//		setSessionCookie("popDisplayed1","OK");// this is the new session cookie! F Barclays.
						},
                    error: function(xhr,msg,e){
                   }
	})
}
	}
	
}

function startPopUp2(waitTime, pageToDisplay, divName)
{
$('#info_msg1').notificationmsg({period: 2500});
$('#info_closebutton').click(function(){ $('#'+divName).notificationmsg('hide'); });
advert2(waitTime, pageToDisplay, divName);
}







function advert2(waitTime, pageToDisplay, divName)
{
    setTimeout("showPop2(\""+pageToDisplay+"\", \""+divName+"\")",waitTime)
//1;
}

function showPop2(pageToDisplay, divName)
{
var animStyle = 'slide';

 $.ajax({
                    type: "GET",
                    url: pageToDisplay,
                    contentType: "text/html; charset=utf-8",
                    dataType: "html",
                    timeout: 1000,

                    success: function(html) {
                        $("#info_modalbody").html(html);
                        $('#'+divName).notificationmsg({animation:animStyle, period: 0});
                        $('#'+divName).notificationmsg('show');
                        setCookie("popDisplayed1","OK",2);
                                                },
                    error: function(xhr,msg,e){
                   }
        })

}                



function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+";path=/"+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

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 setSessionCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+";path=/";
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}



