﻿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 selectStyle (vCookieName, vSelection, lng)
{ 
    //WRITE COOKIE 
    makeCookie(vCookieName, vSelection, 90, '/'); 
    //ACTIVE SELECTED ALTERNAT STYLE SHEET 
    setActivestylesheet(vSelection);
    
//    renderInfoExponorImage(vSelection, lng, rootK);
} 

//function renderInfoExponorImage (vSelection, lng, root)
//{
//    if (vSelection == 'customDefault')
//    {
//        if (lng == 'pt-PT')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_customDefault.gif'; }
//        if (lng == 'es-ES')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customDefault.gif'; }
//        if (lng == 'en-US')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customDefault.gif'; }
//    }
//    if (vSelection == 'customSpring')
//    {
//        if (lng == 'pt-PT')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_customSpring.gif'; }
//        if (lng == 'es-ES')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customSpring.gif'; }
//        if (lng == 'en-US')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customSpring.gif'; }
//    }
//    if (vSelection == 'customSummer')
//    {
//        if (lng == 'pt-PT')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_customSummer.gif'; }
//        if (lng == 'es-ES')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customSummer.gif'; }
//        if (lng == 'en-US')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customSummer.gif'; }
//    }
//    if (vSelection == 'customOutumn')
//    {
//        if (lng == 'pt-PT')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_customOutumn.gif'; }
//        if (lng == 'es-ES')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customOutumn.gif'; }
//        if (lng == 'en-US')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customOutumn.gif'; }
//    }
//    if (vSelection == 'customWinter')
//    {
//        if (lng == 'pt-PT')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_customWinter.gif'; }
//        if (lng == 'es-ES')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customWinter.gif'; }
//        if (lng == 'en-US')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customWinter.gif'; }
//    }
//    if (vSelection == 'customAlternate')
//    {
//        if (lng == 'pt-PT')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_customAlternate.gif'; }
//        if (lng == 'es-ES')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customAlternate.gif'; }
//        if (lng == 'en-US')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customAlternate.gif'; }
//    }
//    if (vSelection != 'customDefault' && vSelection != 'customSpring' && vSelection != 'customSummer' && vSelection != 'customOutumn' && vSelection != 'customWinter' && vSelection != 'customAlternate')
//    {
//        if (lng == 'pt-PT')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_customDefault.gif'; }
//        if (lng == 'es-ES')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customDefault.gif'; }
//        if (lng == 'en-US')
//        { document.images['imgInfoExponor'].src = root + 'App_Themes/SiteFeira/_images/info_exponor_international_customDefault.gif'; }
//    }
//}

if (document.cookie.indexOf('style=')!=-1)
{ 
    css = readCookie('style'); 
    //activate SELECTED STYLE SHEET 
    setActivestylesheet(css); 
}
else
{
    setActivestylesheet('customDefault');
}
