// JavaScript Document
// only show if cookie was not saved before

if((!GetCookie("VDaddBOX")) && ( -1 == document.cookie.search(/MessShown/i))) {
	showBox();
} 


// for orientation on x purposes
var boxWidth = 365; //Remeber to change this variable according to the box new Size according

//show box on load or on any change of screen size or scrolling
function showBox() {
	// must calculate initial box position 
	//window.onload = initBoxPosition;
	window.onscroll = updateBoxPosition;
	window.onresize = updateBoxPosition;
}
function hideBox() {
	setBoxPosition(0, -500); //box is still in memory but out of sight
	window.onload = null;
	window.onscroll = null;
	window.onresize = null;
}

//initial box position

var boxYPos = 250; // set to 250 for low res screens

function initBoxPosition() {
	setBoxPosition(document.body.clientWidth/2 - boxWidth/2, boxYPos);
}
function updateBoxPosition() {	
	var y = document.body.clientHeight/2;
	if(document.documentElement.scrollTop) {
		// mozilla
		y = document.documentElement.scrollTop+boxYPos;
	}
	else {
		// safari/IE
		y = document.body.scrollTop+boxYPos;
	}
	setBoxPosition(document.body.clientWidth/2 - boxWidth/2, y);
}


function setBoxPosition(x, y) {
	var ratings = document.getElementById("BoxPop").style;
	if(ratings.posTop) {
		// IE
		ratings.posTop = y;
		ratings.posLeft = x;
	} else {
		ratings.top = y + "px";
		ratings.left = x + "px";
	}
}

// Set cookie for a year
function neverAgain() {
	hideBox();
	SetCookie("VDaddBOX", "hide", 365);
	return true;
}

//set cookie for a day
function closeBox() {
	hideBox();
	setCookie2();
	
}

//Create one entry cookie
function setCookie2(){
document.cookie = 'MessShown';
}


//create cookie according to given parameters
function SetCookie(sName, sValue, days) {
	var expDate = new Date();
	expDate.setDate(expDate.getDate() + days);
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + expDate.toGMTString() + "; path=/;";
	return true;
}


//brakeout the cookie string and look for a specific value
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return false;
}

//reset cookies by changing the date as expired
function DelCookie(sName)
{
  document.cookie = sName + "=asdf; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

function imageChange(){
document.images["continue"].src = "images/buttonStayFrenchOver.jpg";
}

function imageChangeOut(){
document.images["continue"].src = "images/buttonStayFrench.jpg";
}

window.onload=function(){
if((!GetCookie("VDaddBOX")) && ( -1 == document.cookie.search(/MessShown/i))) {
	initBoxPosition();
	}
}