//
// retrieve and read the cookie
//
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 ""
}

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

//
// Launch the survey box
//
function startSurvey()
{
    // set cookie now, might break
    state=true
    setCookie('survey',state,365);

    // and thunderbirds are go!
    GB_showCenter("BioMed Website Visitor Survey", "http://www.biomedhtc.org.uk/survey.htm", 500, 650);
}

//
// check for cookie
//
function checkCookie()
{
    // Check that cookies are enabled first
    var tmpcookie = new Date();
    chkcookie = (tmpcookie.getTime() + '');
    document.cookie = "chkcookie=" + chkcookie + "; path=/";
    if (document.cookie.indexOf(chkcookie,0) < 0) {
        // user has cookies disabled
        // safer to do nothing?
    } else {
        state=getCookie('survey');
        // check if we have a survey cookie
        if (state!=null && state!="")
        {
            // visitor has already "seen" the survey prompt
            // do not bug them again
        } else {
            // we have a new victim
			// launch the survey
            startSurvey();
        }
    }
}
