function CreateCookie(name, value, expiredays)
{
var todayDate = new Date();
todayDate.setDate(todayDate.getDate() + expiredays);
document.cookie = name + " = " + value + "; expires=" + 
todayDate.toGMTString() + ";";
}

function ReadCookie(cookiename)
{
var numOfCookies = document.cookie.length;
var nameOfCookie = cookiename + "=";
var cookieLen = nameOfCookie.length;
var x=0;
while (x <= numOfCookies)
{
var y = (x + cookieLen);
if (document.cookie.substring(x, y) == nameOfCookie)
return(ExtractCookieValue (y));
x = document.cookie.indexOf(" ", x) + 1;
if (x == 0)
break;
}
return null;
}

function ExtractCookieValue(val)
{
if ((endOfCookie = document.cookie.indexOf(";", val)) == -1)
{
endOfCookie = document.cookie.length;
}
return unescape(document.cookie.substring(val, endOfCookie));
}

function GoodBye()
{
if (confirm("Before you leave, please take a moment and fill out our survey to make our website better"))
{
alert("Thank you!");
window.open("http://192.168.1.241/everdrysurvey.html");
}
else
{
alert("See you again Good Luck!");
return false;
}
}

function MainGoodBye()
{
var userCookie = ReadCookie("_everdrynco");
if (userCookie == null)
{
// user is here at first time
//propose to visit site
GoodBye();
//create coockie key (30 days)
CreateCookie("_everdrynco", 1, 30);
}
} 
