
//using Cookie Util Function from Wrox Press Professional Javascript for Web Developers
//Chapter 19 of 2009 edition.  Get, Set, and UnSet are all methods and addressed by
// CookieUtil.get("blah") for example.  Javascript cookie handling stinks and I like this 
//better than all of the other canned cookie managment scripts out there because it uses methods 
// instead of super complicated text parsing.  Cheers.

var CookieUtil = {

    get: function (name){
        var cookieName = encodeURIComponent(name) + "=",
            cookieStart = document.cookie.indexOf(cookieName),
            cookieValue = null;

    if (cookieStart > -1){
        var cookieEnd = document.cookie.indexOf(";", cookieStart)
        if (cookieEnd == -1){
            cookieEnd = document.cookie.length;
        }
        cookieValue = decodeURIComponent(document.cookie.substring(cookieStart
                      + cookieName.length, cookieEnd));
}

         return cookieValue;
},

set: function (name, value, expires, path, domain, secure) {
    var cookieText = encodeURIComponent(name) + "=" +
                     encodeURIComponent(value);

    if (expires instanceof Date) {
        cookieText += "; expires=" + expires.toGMTString();

}

    if (path) {
        cookieText += "; path=" + path;
    }

    if (domain) {
        cookieText += "; domain=" + domain;
    }

    if (secure) {
        cookieText += "; secure";
    }

    document.cookie = cookieText;
},

unset: function (name, path, domain, secure){
    this.set(name, "", new Date(0), path, domain, secure);
  }
};



//enable cookies
CookieUtil.set("cookiesenabled", "yes");

     


//check for cookies
                           

//any javascript can go in here

//do a cookie check to see if the user has been shown the survey before
//if no then generate random number and maybe display survey.

if (CookieUtil.get("cookiesenabled") == "yes" && CookieUtil.get("Cat_Seen_It")!="true")
{  
var RandomNumber=Math.floor(Math.random()*5);
var RandomNumber=4;
 	//if (RandomNumber !=4) {document.cookie = "Cat_Seen_It=true";}
	if (RandomNumber ==4) {document.cookie = "Cat_Seen_It=true";} 
 }

//OK--they haven't seen it.  Check the random number.  Right now it is set to 4 to ensure the survey is shown to 10% of 
//visitors.  Move it up if more displays are needed.  If they are shown the survey then set the
//cookie to expire at survey's end.



//if (RandomNumber == 4 && CookieUtil.get("Cat_Seen_It")!="true")
	//{
	//window.open("http://library.state.or.us/content_includes/survey_ask_Catalog.html","Window1","menubar=yes,width=430,height=360,toolbar=yes,scrollbars=yes");
//	document.cookie = "Cat_Seen_It=true; expires= Tue, 30-Mar-2010 00:00:01 GMT";
	//}	

