function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var searchs = " " + name + "=";
	var setStr = '';
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(searchs);
		if (offset != -1) {
			offset += searchs.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

coval=getCookie('ScreenWidth');
if (coval=='' || coval!=screen.width){
	var today = new Date();
	var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie("ScreenWidth", screen.width, expiry, '/', '', '');
}
if (coval=='' || coval!=screen.width){
	var today = new Date();
	var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie("ScreenWidth", screen.width, expiry, '/', '', '');
	if (screen.width>1260){
		var	cssdocument=document.createElement('link');
		cssdocument.href="/css/ctulu1280.css";
		cssdocument.setAttribute('type', 'text/css'); 	cssdocument.setAttribute('rel', 'stylesheet');
		var head = document.getElementsByTagName("head")[0] || document.documentElement;
        head.insertBefore( cssdocument, head.lastChild );
	}
	else if (screen.width<900){
		var	cssdocument=document.createElement('link');
		cssdocument.href="/css/ctulu800.css";
		cssdocument.setAttribute('type', 'text/css'); 	cssdocument.setAttribute('rel', 'stylesheet');
		var head = document.getElementsByTagName("head")[0] || document.documentElement;
        head.insertBefore( cssdocument, head.lastChild );
	}

}

function addLoadEvent(f) { var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (!f)f=function () {
				  for (var i = 1; i < emo_addresses.length; i++) {
					var id = '_emoaddrId' + i;
					var elem = document.getElementById(id);
					if (elem) {
					  if (elem.firstChild) {
						elem.removeChild(elem.firstChild);
					  }
					  elem.innerHTML = decrypt_string(i);
					}
				  }
				}
if (root){ 
	  if(root.addEventListener) root.addEventListener("load", f, false);
      else if(root.attachEvent) root.attachEvent("onload", f);
   } else {
      if(typeof window.onload == 'function') {
         var existing = window.onload;
         window.onload = function() {
            existing();
            f();
         }
      } else {
         window.onload = f;
      }
   }
}

// Decrypt all email addresses
function emo_replace() {
  for (var i = 1; i < emo_addresses.length; i++) {
    var id = '_emoaddrId' + i;
    var elem = document.getElementById(id);
    if (elem) {
      if (elem.firstChild) {
        elem.removeChild(elem.firstChild);
      }
      elem.innerHTML = decrypt_string(i);
    }
  }
}

// Manage decryption cache
var decryption_cache = new Array();
function decrypt_string(n) {
  var cache_index = "'"+n+"'";

  if(decryption_cache[cache_index])		// If this string has already been decrypted, just
    return decryption_cache[cache_index];	// return the cached version.

  if(emo_addresses[n])				// Is crypted_string an index into the addresses array?
    var crypted_string = emo_addresses[n];

  if(!crypted_string.length)			// Make sure the string is actually a string
    return "Error, not a valid index.";

  var decrypted_string = decode_base64(crypted_string);

  // Cache this string for any future calls
  decryption_cache[cache_index] = decrypted_string;

  return decrypted_string;
}

// Custom base 64 decoding
function decode_base64(data) {
  var tab = emo_addresses[0];
  var out = "", c1, c2, c3, e1, e2, e3, e4;
  for (var i = 0; i < data.length; ) {
    e1 = tab.indexOf(data.charAt(i++));
    e2 = tab.indexOf(data.charAt(i++));
    e3 = tab.indexOf(data.charAt(i++));
    e4 = tab.indexOf(data.charAt(i++));
    c1 = (e1 << 2) + (e2 >> 4);
    c2 = ((e2 & 15) << 4) + (e3 >> 2);
    c3 = ((e3 & 3) << 6) + e4;
    out += String.fromCharCode(c1);
    if (e3 != 64)
      out += String.fromCharCode(c2);
    if (e4 != 64)
      out += String.fromCharCode(c3);
  }
  return out;
}