//Custom JavaScript Functions by Shawn Olson
//Copyright 2006-2008
//http://www.shawnolson.net
//If you copy any functions from this page into your scripts, you must provide credit to Shawn Olson & http://www.shawnolson.net
//*******************************************


function changeCss(theClass, element, value)
{
    //Last Updated on May 21, 2008
    //documentation for this script at
    //http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
    var cssRules;
    if (document.all) {
        cssRules = 'rules';
    } else if (document.getElementById) {
        cssRules = 'cssRules';
    }
    var added = false;
    for (var S = 0; S < document.styleSheets.length; S++){
        for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
            if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
                if(document.styleSheets[S][cssRules][R].style[element]){
                    document.styleSheets[S][cssRules][R].style[element] = value;
                    added=true;
                    break;
                }
            }
        }

        if(!added){
            if(document.styleSheets[S].insertRule){
                document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
            } else if (document.styleSheets[S].addRule) {
                document.styleSheets[S].addRule(theClass,element+': '+value+';');
            }
        }
    }
}

// End of Shawn Olson's code

function setCookie(name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function switchCurrency(curr)
{
    changeCss('.curr_uah', 'display', 'none');
    changeCss('.curr_usd', 'display', 'none');
    changeCss('.curr_eur', 'display', 'none');
    changeCss('.curr_' + curr, 'display', 'block');

    changeCss('.switch_uah', 'border', 'none');
    changeCss('.switch_uah', 'background-color', 'transparent');
    changeCss('.switch_usd', 'border', 'none');
    changeCss('.switch_usd', 'background-color', 'transparent');
    changeCss('.switch_eur', 'border', 'none');
    changeCss('.switch_eur', 'background-color', 'transparent');
    changeCss('.switch_' + curr, 'border', '1px solid #ccc');
    changeCss('.switch_' + curr, 'background-color', '#dedede');

    setCookie('additional_currency', curr, '', '/');
}
