var CH=(navigator.userAgent.indexOf('Chrome')!=-1);
var SF=(navigator.userAgent.indexOf('Safari')!=-1 && !CH);
var OP=(navigator.userAgent.indexOf('Opera')!=-1);
var IE=(navigator.userAgent.indexOf('MSIE')!=-1 && !OP);
var FF=(navigator.userAgent.indexOf('Firefox')!=-1);
var MZ=(navigator.userAgent.indexOf('Gecko')!=-1 && !SF && !CH);
var onloadExec=new Array();
function getById(id) {
    return document.getElementById(id);
}


var stylesheetId=0;
function stylesheet() {
    var f=true;
    if (!document.styleSheets[stylesheetId]) { f=false; }
    else if (document.styleSheets[stylesheetId].title!='dynamic') { f=false; }
    if (!f) {
        for (i=0;i<document.styleSheets.length;i++) {
            if (document.styleSheets[i].title=='dynamic') { stylesheetId=i; break; }
        }
    }
    return (IE) ? document.styleSheets[stylesheetId].rules : document.styleSheets[stylesheetId].cssRules;
}


var tariffColorTimer=0;
var tariffColorTimeout=15;
var tariffColorStep=0.05;
var sheet=false;
var tariffCurrent='';
function ShowTarriffsPlan(sel) {
	if (sel!=undefined) {
		getById('TarriffPlan').value=sel;
	}
	if (getById('TarriffPlan').value==tariffCurrent) { return; }
	tariffCurrent=getById('TarriffPlan').value;
	var spl=getById('TariffsTable').className=getById('TarriffPlan').value;

	//if (IE) { return; }

	if (sheet===false) { sheet=stylesheet(); }
	var spl=spl.substr(2);
	clearTimeout(tariffColorTimer);
	sheet[0].style.backgroundColor = sheet[spl].style.backgroundColor;
	if (!IE) { sheet[0].style.opacity=1; }
	else {
		sheet[0].style.filter='alpha(opacity="100")';
	}
	tariffColorTimer=setTimeout('tariffColor('+spl+')',tariffColorTimeout*2);
}
function tariffColor(spl) {
	//var sheet=stylesheet();
	if (!IE) { var opac=Number(sheet[0].style.opacity)-tariffColorStep; }
	else {
		var opac=sheet[0].style.filter;
		var s=opac.indexOf('"');
		opac=Number(opac.substring(s+1, opac.indexOf('"',s+1)))-tariffColorStep*100 *2;

	}
	if (opac>0) {
		if (!IE) { sheet[0].style.opacity=opac; }
		else {
			sheet[0].style.filter='alpha(opacity="'+opac+'")';
		}
		tariffColorTimer=setTimeout('tariffColor('+spl+')',tariffColorTimeout);
	}
	else {
		if (!IE) { sheet[0].style.opacity=0; }
		else {
			sheet[0].style.backgroundColor = '';
			sheet[0].style.filter='alpha(opacity="0")';
		}
	}
}

function tariffSetHover(obj) {
	var rel=obj.getAttribute('rel');
	var trs=getById('TariffsTable').rows;
	for (i=0;i<trs.length;i++) {
		var trRel=trs[i].getAttribute('rel');
		if (trRel) {
			if (trRel==rel) { if (trs[i].className.indexOf('mark_red')!=-1) { trs[i].className+=' markhover'; } else { trs[i].className+=' hovered'; } }
			else { trs[i].className=trs[i].className.replace(/hovered|markhover/g,''); }
		}
	}
}
function tariffUnsetHover() {

	var trs=getById('TariffsTable').rows;
	for (i=0;i<trs.length;i++) {
		var trRel=trs[i].getAttribute('rel');
		if (trRel) {
			trs[i].className=String(trs[i].className).replace(/hovered|markhover/g,'');
		}
	}
}

