function fontsizeup() {
  active = getActiveStyleSheet('text')
  switch (active) {
    case 'text--' : 
      setActiveStyleSheet('text-')
      break
    case 'text-' : 
      setActiveStyleSheet('text')
      break
    case 'text' : 
      setActiveStyleSheet('text+')
      break
    case 'text+' : 
      setActiveStyleSheet('text++')
      break
    case 'text++' : 
      setActiveStyleSheet('text+++')
      break
    case 'text+++' :
      break
    default :
      setActiveStyleSheet('text')
      break
  }
}

function fontsizedown() {
  active = getActiveStyleSheet('text')
  switch (active) {
    case 'text+++' : 
      setActiveStyleSheet('text++')
      break
    case 'text++' : 
      setActiveStyleSheet('text+')
      break
    case 'text+' : 
      setActiveStyleSheet('text')
      break
    case 'text' : 
      setActiveStyleSheet('text-')
      break
    case 'text-' : 
      setActiveStyleSheet('text--')
      break
    case 'text--' : 
       break
    default :
      setActiveStyleSheet('text')
      break
  }
}
function textonly() {
  active = getActiveStyleSheet('image')
  switch (active) {
    case 'image+' : 
      setActiveStyleSheet('image-')
      break
    default :
      setActiveStyleSheet('image+')
      break
  }
}
function show_mobile() {
  active = getActiveStyleSheet('mobile')
  switch (active) {
    case 'mobile-' : 
      setActiveStyleSheet('mobile+')
      break
    default :
      setActiveStyleSheet('mobile-')
      break
  }
}
function show_normal() {
  active = getActiveStyleSheet('mobile')
  switch (active) {
    case 'mobile-' : 
      setActiveStyleSheet('mobile-')
      break
    default :
      setActiveStyleSheet('mobile-')
      break
  }
  active2 = getActiveStyleSheet('image')
  switch (active2) {
    case 'image-' : 
      setActiveStyleSheet('image+')
      break
    default :
      setActiveStyleSheet('image+')
      break
  }
  active3 = getActiveStyleSheet('text')
  switch (active3) {
    case 'text--' : 
      setActiveStyleSheet('text')
      break
    case 'text-' : 
      setActiveStyleSheet('text')
      break
    case 'text' : 
      setActiveStyleSheet('text')
      break
    case 'text+' : 
      setActiveStyleSheet('text')
      break
    case 'text++' : 
      setActiveStyleSheet('text')
      break
    case 'text+++' : 
      setActiveStyleSheet('text')
      break
    default :
      setActiveStyleSheet('text')
      break
  }
}


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.getAttribute("title").substr(0,4)==title.substr(0,4)) {
      a.disabled = true
      if(a.getAttribute("title") == title) a.disabled = false
    }
  }
}

function getActiveStyleSheet(type) {
  var i, a
  for(i=0;(a = document.getElementsByTagName("link")[i]);i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled && a.getAttribute("title").substr(0,4)==type.substr(0,4)) return a.getAttribute("title")
  }
  return null
}

// function getPreferredStyleSheet() {
//   return ('text')
// }

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
}

window.onload = function(e) {  
 
 
  var cookie = readCookie('mobile_style')

  var image = cookie ? cookie : 'mobile'
  if (image == 'null') {
    image = 'mobile-'
  }
  var cookie = readCookie('image_style')
  var image = cookie ? cookie : 'image'
  if (image == 'null') {
    image = 'image+'
  }
  var cookie = readCookie('text_style')
  var text = cookie ? cookie : 'text'
  if (text == 'null') {
    text = 'text'
  }
  setActiveStyleSheet(mobile)
  setActiveStyleSheet(image)
  setActiveStyleSheet(text)
}

window.onunload = function(e) {

  var mobile = getActiveStyleSheet('mobile')
  var image = getActiveStyleSheet('image')
  var text = getActiveStyleSheet('text')
  
  createCookie("mobile_style", mobile, 31)
  createCookie("image_style", image, 31)
  createCookie("text_style", text, 31)
}
 
 var cookie = readCookie('mobile_style')
 
 var mobile = cookie ? cookie : 'mobile'
 
  if (mobile == 'null') {
    mobile = 'mobile-'
  }
  
  active = getActiveStyleSheet('mobile')

  var cookie = readCookie('image_style')
  var image = cookie ? cookie : 'image'
  if (image == 'null') {
    image = 'image+'
  }
  var cookie = readCookie('text_style')
  var text = cookie ? cookie : 'text'
  if (text == 'null') {
    text = 'text'
  }
  setActiveStyleSheet(mobile)
  setActiveStyleSheet(image)
  setActiveStyleSheet(text)
