 /*
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

 /*
 * Fees control function's
 */

var siteRes;
var feesLeg;
var oldFees;

$(document).ready(function(){ 
$("#private").click(function (e)  { 
	feesLeg='p';
	ShowFees();
	return false;
});
$("#legal").click(function (e)  {
	feesLeg='l';
	ShowFees();
	return false;
});

$("#resident").click(function (e)  { 
	siteRes='r';
	ShowFees();
	SwitchResidental();
	return false;
});
$("#nonresident").click(function (e)  { 
	siteRes='n';
	ShowFees();
	SwitchResidental();
	return false;
});

$("#resswitch").click(function (e)  { 
if (siteRes=='n') {
	siteRes='r';
	ShowFees();
} else {
	siteRes='n';
	ShowFees();
}
	SwitchResidental();
	return false;
});

//initial after load
ShowFeesFromCookie();
});

function SwitchResidental(){
if (siteRes=='n') { //nonresident
	$('#resident').removeClass("on");
	$('#nonresident').addClass('on');
	$('#resswitchimg').attr("src", '/images/switch_right.gif');
} else {
	$('#nonresident').removeClass("on");
	$('#resident').addClass('on');
	$('#resswitchimg').attr("src", '/images/switch_left.gif');
}
}

function ShowFees(){
$('#fees_'+oldFees).css('display','none');
$('#fees_'+feesLeg+siteRes).css('display','');
if (feesLeg=='p') {
	$('#legal').removeClass('on');
	$('#private').addClass("on");
} else {
	$('#private').removeClass("on");
	$('#legal').addClass('on');
}
oldFees=feesLeg+siteRes;
$.cookie("Legal", feesLeg, { expires: 31 });
$.cookie("Resident", siteRes, { expires: 31 });
}

function ShowFeesFromCookie() {
siteRes=$.cookie("Resident");
//alert (siteRes);
if (siteRes!="n") if (siteRes!="r") siteRes="n";
//alert (siteRes);

feesLeg=$.cookie("Legal");
//alert (feesLeg);
if (feesLeg!='l') if (feesLeg!='p') feesLeg="l";
//alert (feesLeg);

oldFees=feesLeg+siteRes;
SwitchResidental();
ShowFees();
//$('#swfees').css("display","");\
//MakeTabTop();
//alert ('click on resident');
//$('#resident').click();
}

function MakeTabTop(){
var k="";
var tmpout='<li id="private"><a href="#">\u0427\u0430\u0441\u0442\u043D\u044B\u0439\u043A \u043B\u0438\u0435\u043D\u0442</a></li>';
tmpout+='<li id="legal"><a href="#">\u041A\u043E\u0440\u043F\u043E\u0440\u0430\u0442\u0438\u0432\u043D\u044B\u0439 \u043A\u043B\u0438\u0435\u043D\u0442</a></li>';
tmpout+='<li class="switch">';
tmpout+='<span>\u041A\u043B\u0438\u0435\u043D\u0442 \u0438\u0437:</span>';
k=""; if (siteRes=='r') k='class="on" ';
tmpout+='<a id="resident" '+k+'href="#">\u041B\u0430\u0442\u0432\u0438\u0438</a>';
tmpout+='<a href="#" id="resswitch"><img  id="resswitchimg" src="/images/switch_right.gif" alt="" /></a>';
k=""; if (siteRes=='n') k='class="on" ';
tmpout+='<a id="nonresident" '+k+'href="#">\u0417\u0430\u0440\u0443\u0431\u0435\u0436\u044C\u044F</a></li>';
alert(tmpout);
$('#swfees').html(tmpout);
}


