//àêöèÿ äëÿ åâðîñåòè
function show_action() {
	document.getElementById('actiontext').style.display = 'block';
}
function hide_action() {
	document.getElementById('actiontext').style.display = 'none';
}

function chTable() {
	if (document.getElementById('boxGPRS').style.display == 'block') {
		document.getElementById('boxGPRS').style.display = 'none';
		document.getElementById('boxPrice').style.display = 'block';
	} else {
		document.getElementById('boxGPRS').style.display = 'block';
		document.getElementById('boxPrice').style.display = 'none';
	}
}


var tariffsType = 'voice';
function select_tariff(obj, exrate) {

//	if(tariffsType=="gprs") {
//		document.getElementById('gprsrates').style.display='block';
//		document.getElementById('prices').style.display='none';

//		document.getElementById('prices_gprs_btn').className='selected'; 
//		document.getElementById('prices_gprs_btn').style.border="dashed 1px #F65206";

//		document.getElementById('prices_voice_btn').className=''; 
//		document.getElementById('prices_voice_btn').style.border="none";

		showGprsRates(obj.value);
//		return;
//	} else {
//		document.getElementById('gprsrates').style.display='none';
//		document.getElementById('prices').style.display='block';

//		document.getElementById('prices_voice_btn').className='selected';
//		document.getElementById('prices_voice_btn').style.border="dashed 1px #F65206";
//		document.getElementById('prices_gprs_btn').className=''; 
//		document.getElementById('prices_gprs_btn').style.border="none";
//	}

	var data = tariff_data[obj.value];

	document.getElementById('st_in').innerHTML = '<strong>' + data[0] + '</strong>';
	document.getElementById('st_out').innerHTML = data[1];
	document.getElementById('mts_in').innerHTML = data[2];
	document.getElementById('mts_out').innerHTML = data[3];
	document.getElementById('mf_in').innerHTML = data[4];
	document.getElementById('mf_out').innerHTML = data[5];
	document.getElementById('bl_in').innerHTML = data[6];
	document.getElementById('bl_out').innerHTML = data[7];

	document.getElementById('st_in_nis').innerHTML = '<strong>' + data[10] + '</strong>';
	document.getElementById('st_out_nis').innerHTML = data[11];

	if(obj.value!=142 && obj.value!=184 && obj.value!=177) {
		try {
			pageTracker._trackEvent("tariffs", "getTariff", lang + "/tariffs/" + obj.options[obj.selectedIndex].text);
		} catch(err) {}
	}
	
//	document.getElementById('mi_in').innerHTML = data[8];
//	document.getElementById('mi_out').innerHTML = data[9];
}

function select_gprs(obj) {
	var html = '<table class="price"><tr><td colspan="2" class="price_td">Öåíà (ó.å./1 Ìb)</td></tr>';
	for (i = 0; i < gprs_data[obj.value].length; i++) {
		html += '<tr><td class="comp"><strong>' + gprs_data[obj.value][i][0] + '</strong></td><td class="inn">' + gprs_data[obj.value][i][1] + '</td></tr><tr class="hr"><td colspan="2"></td></tr>';
	}
	html += '</table>'
	document.getElementById('gprs_place').innerHTML = html;
}

function open_map(id) {
	var w = 310;
	var h = 330;
	window.open('/buy/point/' + id + '/', '_blank', 'top=' + ((screen.availHeight / 2) - (h / 2)) + 'px, left=' + ((screen.availWidth / 2) - (w / 2)) + 'px, width=' + w + ', height=' + h + ', directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no');
}

function update_region() {
	r_id = form.regions_select.value;
	if (form.city_select.length > 0) {
		while (form.city_select.length > 0) {
			form.city_select.options[0] = null;
		}
	}
	for (i = 0; i < citys_data[r_id].length; i++) {
		form.city_select.options[i] = new Option(citys_data[r_id][i][1], citys_data[r_id][i][0]);
	}
	update_city();
}

function update_city() {
	c_id = form.city_select.value;
	if (c_id == 19) {
		document.getElementById('district_text').innerHTML = 'Âûáåðèòå áëèæàéøóþ ñòàíöèþ ìåòðî:';
	} else {
		document.getElementById('district_text').innerHTML = 'Âûáåðèòå ðàéîí:';
	}
	
	if (form.district_select.length > 0) {
		while (form.district_select.length > 0) {
			form.district_select.options[0] = null;
		}
	}
	
	for (i = 0; i < districts_data[c_id].length; i++) {
		form.district_select.options[i] = new Option(districts_data[c_id][i][1], districts_data[c_id][i][0]);
	}
	update_district();

	var html = '';
	if (shops_data[c_id]) {
		html += '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="logo_table">';
		for (i = 0; i < shops_data[c_id].length; false) {
			html += '<tr>';
			for (u = 0; u < 3; u++) {
				if (shops_data[c_id][i]) {
					var logo_id = shops_data[c_id][i];
						
						html += '<td><img src="/img/shop_logos/' + logo_id + '.gif" alt="' + citys_data[logo_id] + '" width="104" height="26"></td>';
				} else {
					html += '<td>&nbsp;</td>';
				}
				i++;
			}
			html += '</tr>';
		}
		html += '</table>';
	}
	document.getElementById('cityLogosPlace').innerHTML = html;
	
	if (districts_data[c_id].length == 1) {
		document.getElementById('districtSlect').style.display = 'none';
	} else {
		document.getElementById('districtSlect').style.display = '';
	}
}

function update_district() {
	points_place.innerHTML = '<p>Îæèäàíèå...</p>';
	
	// map_point.style.display = 'none';

	r_id = form.regions_select.value;
	c_id = form.city_select.value;
	d_id = form.district_select.value;
	var url = '/js/ajax_answer.php';
	var pars = 'op=get_points&regions_id=' + r_id + '&city_id=' + c_id + '&district_id=' + d_id;
	var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete: update_district_result});

}
function update_district_result(originalRequest) {
	points_place.innerHTML = originalRequest.responseText;
}

function update_map(src, href) {
	if (src == '' || href == '') {
		// alert('Êàðòà ê äàííîé òî÷êå ïðîäàæ îòñóòñòâóåò.');
		map_point.style.display = 'none';
	} else {
		var html = '<iframe width="290" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' + src + '"></iframe><br /><small><a href="' + href + '" style="color:#0000FF;text-align:left">Ïðîñìîòðåòü óâåëè÷åííóþ êàðòó</a></small>';
		map_point.style.display = '';
		map_point.innerHTML = html;
	}
}

function showBranches(city, lang) {
	var url="ajaxBranches.php?";
	url = url + "&city=" + encodeURIComponent(city);
	url = url + "&lang=" + encodeURIComponent(lang);


	var xmlhttp = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
	xmlhttp.open("GET", url, true);

	document.getElementById('brancheslist').innerHTML="";
	document.getElementById('ajaxload').innerHTML='<img src=images/ajaxload.gif align=center>';

	xmlhttp.onreadystatechange=function() {	if (xmlhttp.readyState==4) {
		setTimeout("document.getElementById('ajaxload').innerHTML='';document.getElementById('brancheslist').innerHTML='" + xmlhttp.responseText + "';", 700);
	}}
	xmlhttp.send(null);

}



function showGprsRates(country_id) {

	var url="./ajaxGPRS.php?";
	url = url + "&country_id=" + encodeURIComponent(country_id);

	var xmlhttp = (typeof(XMLHttpRequest) != "undefined") ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
	xmlhttp.open("GET", url, true);

//	document.getElementById('gprsrates').style.display='block';
//	document.getElementById('prices').style.display='none';
	document.getElementById('gprsrates').innerHTML="";
	document.getElementById('gprsrates').innerHTML='<img src=images/ajaxload.gif align=center>';

	xmlhttp.onreadystatechange=function() {	if (xmlhttp.readyState==4) {
		try{document.getElementById('ajaxload').innerHTML='';}catch(e){};
		document.getElementById('gprsrates').innerHTML=xmlhttp.responseText;
	}}
	xmlhttp.send(null);

}
