﻿// textsizer
function makeCookie(Name,Value,Expiry,Path,Domain,Secure){ 
    if (Expiry!= null) { 
        var datenow = new Date(); 
        datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry)); 
        Expiry = datenow.toGMTString(); 
    } 

    Expiry = (Expiry!= null)? '; expires='+Expiry : ''; 
    Path = (Path!= null)?'; path='+Path:''; 
    Domain = (Domain!= null)? '; domain='+Domain : ''; 
    Secure = (Secure!= null)? '; secure' : ''; 

    document.cookie = Name + '=' + escape(Value) + Expiry + Path + Domain + Secure; 
} 

function readCookie(Name) { 
    var cookies = document.cookie; 
    if (cookies.indexOf(Name + '=') == -1) return null; 
    var start = cookies.indexOf(Name + '=') + (Name.length + 1); 
    var finish = cookies.substring(start,cookies.length); 
    finish = (finish.indexOf(';') == -1)? cookies.length : start + finish.indexOf(';'); 
    return unescape(cookies.substring(start,finish)); 
} 

function setActiveStyleSheet(pTitle) { 
    var vLoop, vLink; 
    for(vLoop=0; (vLink = document.getElementsByTagName("link")[vLoop]); vLoop++) { 
        if(vLink.getAttribute("rel").indexOf("style")!= -1 && vLink.getAttribute("title")) { 
            vLink.disabled = true; 
            if(vLink.getAttribute("title") == pTitle) vLink.disabled = false; 
        } 
    } 
}

function resetStyle() {
    var vLoop, vLink; 
    for(vLoop=0; (vLink = document.getElementsByTagName("link")[vLoop]); vLoop++) { 
        if(vLink.getAttribute("rel").indexOf("style")!= -1 && vLink.getAttribute("title")) { 
            vLink.disabled = true; 
        } 
        // write cookie
    makeCookie('style', 'reset', 90, '/'); 
    } 
} 

function selectStyle (vCookieName, vSelection) { 
    // write cookie
    makeCookie(vCookieName, vSelection, 90, '/'); 
    // set active stylesheet 
    setActiveStyleSheet(vSelection);
} 

// ensure that the stylesheets are disabled
var vLoop, vLink; 
for(vLoop=0; (vLink = document.getElementsByTagName("link")[vLoop]); vLoop++) { 
    if(vLink.getAttribute("rel").indexOf("style")!= -1 && vLink.getAttribute("title")) { 
        vLink.disabled = true;
    } 
}

// activate stylesheet if required
if (document.cookie.indexOf('style')!=-1) { 
    css = readCookie('style'); 
    // set active stylesheet
    if (css != 'reset') {
        setActiveStyleSheet(css); 
    }
}




