
// cookies.js
// Derived from the Bill Dortch code at http://www.hidaho.com/cookies/
var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

function getCookieVal (offset) {
       var endstr = document.cookie.indexOf (";", offset);
       if (endstr == -1) { endstr = document.cookie.length; }
       return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
       var arg = name + "=";
       var alen = arg.length;
       var clen = document.cookie.length;
              
       var i = 0;
       while (i < clen) {
           var j = i + alen;
           if (document.cookie.substring(i, j) == arg) {
                   return getCookieVal (j);
           }
           i = document.cookie.indexOf(" ", i) + 1;
           if (i == 0) break;
       }
       return null;
}

function DeleteCookie (name,path,domain) {
       if (GetCookie(name)) {
               document.cookie = name + "=" +
               ((path) ? "; path=" + path : "") +
               ((domain) ? "; domain=" + domain : "") +
               "; expires=Thu, 01-Jan-70 00:00:01 GMT";
               }
}

function SetCookie (name,value) {
  document.cookie = name + "=" + escape (value) + "; path=/;";
}

// this method is intended to be called on the form submit.  it saves their current position in the signup process.
//pass in the name of the screen you're on as the first argument.
function saveWizard (s) {
	SetCookie("lang", s);
	checkCookieForLanguage();
	return true;
}
  

//This function, called as soon as the page loads, it tests for the existence of the cookie,
// creates it if it does not exist, and adjusts the classes accordingly
function checkCookieForLanguage() {

	if ( GetCookie("lang") ) {
		
		// this is where we open language specific spans
		setStyleByClass('SPAN','french','display','none');
		setStyleByClass('SPAN','english','display','none');
		setStyleByClass('SPAN',GetCookie("lang"),'display','inline');
		
	} else {

		SetCookie("lang", default_language);
		checkCookieForLanguage();
	}
	
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

window.onload = checkCookieForLanguage;

