<!--hide this script from non-javascript-enabled browsers

//////////////////////////////////////////////////////////
//
// Afl Chemistry
//
// Produced by Presenting Science
//  www.PresentingScience.com
//
// Copyright (C) Royal Society of Chemistry &
//		 Presenting Science 2005
//
//////////////////////////////////////////////////////////


var label = "ShowWelcomePage=";	// The name of the cookie

/**
 * Redirect if welcome page is not required - called on load in redirect.htm
 */
 function doRedirect() {
	// This code added to immediately redirect a URL of the form www.aflchem.org/?34
	var name = unescape(parent.location.search.substring(1));
	if (name.length>0) {
		if (name.substr(0,1)=="0")
			name = name.substr(1);
		var resourceNo = 0;
		resourceNo = name;
		if (resourceNo>0 && resourceNo<=72) {		
			location = resourceNo > 9 ? "resources/"+resourceNo+"/index.htm" : "resources/0"+resourceNo+"/index.htm";
		}
		else
			location = "notfound.htm";
	}
	else {
		// Otherwise show welcome or contents page according to cookie
    	var welcomeCookie = readWelcomeCookie();
    	location = (welcomeCookie=="0")? "chapind.htm" : "home.htm";
	}
 }

/**
 * Update the checkbox from the cookie - called on load in home.htm
 */
function updateWelcomeCheckBox() {
    var welcomeCookie = readWelcomeCookie();
    document.form.WelcomePage.checked = (welcomeCookie=="0");
}

/**
 * Update the cookie from the checkbox - called when checkbox is clicked
 */
function updateWelcomeCookie() {
    var c = document.form.WelcomePage.checked? "0" : "1";
    writeWelcomeCookie(c);
}


/**
 * Extract and return the welcome cookie
 */
 function readWelcomeCookie() {
	 return readCookie(label);
 }
 
 function readCookie(l) {
    var c = document.cookie;
    var pos = c.indexOf(l);
    if (pos != -1) {
         var start = pos+label.length;
         var d = c.substring(start, c.length)
         var end = d.indexOf(";");
         if (end == -1) end = d.length;
         var h = d.substring(0, end);
         h = unescape(h);
         if (h.length>0) {
            return h;
        }
    }
    return "";
}
 
/**
 * Write the Welcome cookie
 */
 function writeWelcomeCookie(value) {
	 writeCookie(label, value);
 }
  
 function writeCookie(l, value) {
     var nextYear = new Date();
     nextYear.setFullYear(nextYear.getFullYear()+1);	// Will last for one year
     document.cookie = l+escape(value) + "; expires=" + nextYear.toGMTString();
 }

// stop hiding -->


