﻿
/*
*   Release notes
*   ----------------------------------------------------------------
*   Name: styleswitcher - used for the template creator
*   Authors: www.alistapart.com / Paul Sowden
*   Version: 2.0
*   Last modified: 2 Oct 2008 by Tinna
*
*   Note: This file is maintained in the .NET solution "ecShop".
*   Do not modify it directly on the server.
*                                            
*   Naming conventions:                                
*   - global variables: _xxxXXXX
*   - functions: xxxXXX()
*
*   Last modified:
*   Changed comment sections to be chrome compatible 
*/


function mediumFontSize()

{

	var titleOfActiveStyle = getActiveStyleSheet("fontsize");

	setActiveStyleSheet("Size:9pt","fontsize");

}


/*function decreaseFontSize()

{

	var titleOfActiveStyle = getActiveStyleSheet("fontsize");

	if(titleOfActiveStyle == null)	

		titleOfActiveStyle = "Size:9pt";

		

	if(titleOfActiveStyle == "Size:10pt")

		setActiveStyleSheet("Size:9pt","fontsize");

	if(titleOfActiveStyle == "Size:9pt")

		setActiveStyleSheet("Size:8pt","fontsize");



}



function increaseFontSize()

{

	var titleOfActiveStyle = getActiveStyleSheet("fontsize");

	if(titleOfActiveStyle == null)	

		titleOfActiveStyle = "Size:9pt";	

		

	if(titleOfActiveStyle == "Size:8pt")	

		setActiveStyleSheet("Size:9pt","fontsize");

	if(titleOfActiveStyle == "Size:9pt")

		setActiveStyleSheet("Size:10pt","fontsize");



}*/


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;
}

function loadStyleSheet() {
    var cookie = readCookie("style");
    title = cookie;

    if(cookie == null || cookie == "null") {
        title = getPreferredStyleSheet();
    }
    setActiveStyleSheet(title);
}

//Used for the template creator - not necessary for standard ecshop functionality
//This function dynamically adds available CSS skins to the <head> tag
//so it's possible to change skins with the Template creator
function appendStyleSheets(array, names) {
    /*var headContainer = document.documentElement.firstChild;
        
    if(headContainer) {
        for(var i = 0; i < array.length; i++) {
            var link = document.createElement("link");
            link.setAttribute("rel","alternate stylesheet");
            link.setAttribute("href", array[i]);
            link.setAttribute("type", "text/css");
            link.setAttribute("media", "screen");
            link.setAttribute("title", names[i]);
            
            headContainer.appendChild(link);
        }
    }*/
}

function loadEvent(func) {	    
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
        window.onload = func;
	} else {
        window.onload = function(){
		oldonload();
		func();
		}
	}
}

loadEvent(loadStyleSheet);

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

function isStyleSheetType(str,type) {

  if(str == ""){
   return true; 
  }
  else if(type == "fontsize" && str.match(/^Size/)){
  return true;
  }
  else if (type == "weight" && str.match(/\Font/)){
  return true;
  }
  else if (type == "contrast" && str.match(/^Back/)){
  return true;
  }
  return false;
}

window.onload = function(e) {
 var title = "";
 var cookie = readCookie("style");
 var title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title,"fontsize"); 
 cookie = readCookie("wstyle");
 title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title,"weight");
 cookie = readCookie("cstyle");
 title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title,"contrast");

}

window.onunload = function(e) {
 var title = getActiveStyleSheet("fontsize");
 createCookie("style", title, 365);
 var title = getActiveStyleSheet("weight");
 createCookie("wstyle", title, 365);
 var title = getActiveStyleSheet("contrast");
 createCookie("cstyle", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"fontsize");
var cookie = readCookie("cstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"contrast");
var cookie = readCookie("wstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title,"weight");




var min=57;
var max=67;
function increaseFontSize() {
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("%",""));
      } else {
         var s = 62;
      }
      if(s!=max) {
         s += 5;
      }
      p[i].style.fontSize = s+"%"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("%",""));
      } else {
         var s = 62;
      }
      if(s!=min) {
         s -= 5;
      }
      p[i].style.fontSize = s+"%"
   }   
}
