// Homepage Image Preloader
function preloadFontSizeImages() {
	// If so, get to loading the images
	image1 = new Image();
	image1.src = "http://www.att.net/images/icon_font_large.gif";
	image2 = new Image();
	image2.src = "http://www.att.net/images/icon_font_large_on.gif";
	image3 = new Image();
	image3.src = "http://www.att.net/images/icon_font_med.gif";
	image4 = new Image();
	image4.src = "http://www.att.net/images/icon_font_med_on.gif";
	image5 = new Image();
	image5.src = "http://www.att.net/images/icon_font_small.gif";
	image6 = new Image();
	image6.src = "http://www.att.net/images/icon_font_small_on.gif";
}
// setActiveStyleSheet('small'); return false;
function prepFontSize() {
	// Make sure these methods are supported and quit if they aren't
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	//Test to make sure the font_size cell is present
	if (!document.getElementById("font_size")) return false;
	
	// Get ahold of the font size images
	var fontSizeCell = document.getElementById("font_size");
	var fontSizeImgs = fontSizeCell.getElementsByTagName("img");
	
	// Attach the behavior to the onclick event
	fontSizeImgs[0].onclick = function() {
		fontSizeImgs[0].setAttribute("src","http://www.att.net/images/icon_font_small_on.gif");
		fontSizeImgs[1].setAttribute("src","http://www.att.net/images/icon_font_med.gif");
		fontSizeImgs[2].setAttribute("src","http://www.att.net/images/icon_font_large.gif");
		setActiveStyleSheet('small'); return false;
	}
	fontSizeImgs[1].onclick = function() {
		fontSizeImgs[0].setAttribute("src","http://www.att.net/images/icon_font_small.gif");
		fontSizeImgs[1].setAttribute("src","http://www.att.net/images/icon_font_med_on.gif");
		fontSizeImgs[2].setAttribute("src","http://www.att.net/images/icon_font_large.gif");
		setActiveStyleSheet('default'); return false;
	}
	fontSizeImgs[2].onclick = function() {
		fontSizeImgs[0].setAttribute("src","http://www.att.net/images/icon_font_small.gif");
		fontSizeImgs[1].setAttribute("src","http://www.att.net/images/icon_font_med.gif");
		fontSizeImgs[2].setAttribute("src","http://www.att.net/images/icon_font_large_on.gif");
		setActiveStyleSheet('large'); return false;
	}
}
function setFontImage() {
	var cookie = GetCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	// Get ahold of the font size images
	var fontSizeCell = document.getElementById("font_size");
	var fontSizeImgs = fontSizeCell.getElementsByTagName("img");
	
	if(title == 'small') {
	fontSizeImgs[0].setAttribute("src","http://www.att.net/images/icon_font_small_on.gif");
	fontSizeImgs[1].setAttribute("src","http://www.att.net/images/icon_font_med.gif");
	fontSizeImgs[2].setAttribute("src","http://www.att.net/images/icon_font_large.gif");
	}
	if(title == 'default') {
	fontSizeImgs[0].setAttribute("src","http://www.att.net/images/icon_font_small.gif");
	fontSizeImgs[1].setAttribute("src","http://www.att.net/images/icon_font_med_on.gif");
	fontSizeImgs[2].setAttribute("src","http://www.att.net/images/icon_font_large.gif");
	}
	if(title == 'large') {
	fontSizeImgs[0].setAttribute("src","http://www.att.net/images/icon_font_small.gif");
	fontSizeImgs[1].setAttribute("src","http://www.att.net/images/icon_font_med.gif");
	fontSizeImgs[2].setAttribute("src","http://www.att.net/images/icon_font_large_on.gif");
	}
}
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  
}
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
//function createCookie(name,value,days) {
// if (days) {
//    var date = new Date();
//    date.setTime(date.getTime()+(days*24*60*60*1000));
//    var expires = "; expires="+date.toGMTString();
//  }
//  else expires = "";
//  document.cookie = name+"="+value+expires+"; path=/";
//}
//function readCookie(name) {
//  var nameEQ = name + "=";
//  var ca = document.cookie.split(';');
//  for(var i=0;i < ca.length;i++) {
//    var c = ca[i];
//    while (c.charAt(0)==' ') c = c.substring(1,c.length);
//    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
//  }
//  return null;
//}
//  onload="cookieForms('open', 'connectform')" onunload="cookieForms('save', 'connectform')"
//window.onload = function(e) {
function init_fontsize() {
  var cookie = GetCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  preloadFontSizeImages();
  prepFontSize();
  setFontImage();
  //cookieForms('open', 'connectform')
}
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  var exp_date = new Date();
  var domain2_index = document.domain.lastIndexOf(".");
  var domain2 = document.domain.substr(domain2_index);
  var shortened_domain_name = document.domain.substr(0,domain2_index);
  var domain1_index = shortened_domain_name.lastIndexOf(".");
  var domain1 = shortened_domain_name.substr(domain1_index);
  var cookie_domain = domain1 + domain2;

  // set style cookie expiration to 1 year
  exp_date.setTime(exp_date.getTime() + (365 * 24 * 60 * 60 * 1000));
  SetCookie("style", title, exp_date, '/', cookie_domain);
  //cookieForms('save', 'connectform')
}
var cookie = GetCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
