var dtalk_account_id=23;
var dtalk_template_set_id = 42;
var dtalk_online_operators=6;

//var agent=navigator.userAgent.toLowerCase();
//var is_iphone = (agent.indexOf('iphone')!=-1);
//if (is_iphone) {
//	document.location = '/mobile/index.php';
//}


function defined (cn) { 
	return (typeof window[cn] !== 'undefined');
}

dtalk_department_online_operators = {40 : 3,41 : 2,784 : 6};

function DtalkOpenChat () {
	var dtalk_url = 'http://www.gotalk.ru/entrance?account_id=' + dtalk_account_id; 
	if (defined ('dtalk_template_set_id')) { 
		dtalk_url += '&template_set_id=' + dtalk_template_set_id; 
	} if (defined ('dtalk_department_id')) {
		dtalk_url += '&department_id=' + dtalk_department_id; 
	} if (defined ('dtalk_department_fix')) {
		dtalk_url += '&department_fix'; 
	} if (defined ('dtalk_local_visitor_id')) { 
		dtalk_url += '&dtalk_local_visitor_id=' + escape (dtalk_local_visitor_id); 
	} 
	
	window.open (dtalk_url,'_blank','width=600,height=550,location=0,menubar=0,resizable=0,scroolbars=0,status=0,titlebar=0,toolbar=0,hotkeys=0');
};
 
if (defined ('dtalk_department_fix') && defined ('dtalk_department_id')) dtalk_online_operators = dtalk_department_online_operators[dtalk_department_id];


	menu = new Array('hl', 'hm', 'hp', 'ak');
	menuT = new Array('ab', 'pr', 'at');
	
	var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
	var url = location.href.substring(dir.length,location.href.length+1);
	var page = url.substring(0, url.lastIndexOf('.'));
	var tarify = location.href.substring(location.href.indexOf('tarify'), location.href.lastIndexOf('/')+1);
	var beeline = location.href.substring(location.href.lastIndexOf('beeline'), location.href.lastIndexOf('beeline')+7 );
	var mts = location.href.substring(location.href.lastIndexOf('mts'), location.href.lastIndexOf('mts')+3 );
	var skylink = location.href.substring(location.href.lastIndexOf('skylink'), location.href.lastIndexOf('skylink')+7 );
	var dealers_page = url.substring(0, url.lastIndexOf('?'));
	var region = url.substring(url.lastIndexOf('?')+1, 50);

	
function ShowIndex(subM){
		$("#"+subM).parent('li').addClass('active');
	}

function DrWebBuy(location) {
    if (confirm("Вы уверены, что хотите приобрести Dr. Web?")) {
        document.location = location;
    }
}
function KavBuy(location) {
	if (confirm("Вы уверены, что хотите приобрести Касперский антивирус?")) { 
	document.location = location;
	}
}
function PandaBuy(location) {
	if (confirm("Вы уверены, что хотите приобрести данный продукт?")) {
	document.location = location;
	}
}
function RealIPBuy() {
var _buy = $("#q_mod #order");
	var _cancel = $("#q_mod #cancel");
	if ($('#confirm:checked').val() !== undefined) {
			$('#order').css('background', '#d60316');
		} else {
			$('#order').css('background', '#d2d2d2');
		}
	// if (confirm("Вы уверены, что хотите приобрести данную услугу?")) {
	    // document.location = "https://customer.radugainternet.ru/?md:string=Service&asid:digit=6&smd:string=AddStep1";
	// }
	positionCenter($("#q_mod"));
	$("#q_mod").fadeIn('slow');
	
	
	$('#confirm').change(function(){
		if ($('#confirm:checked').val() !== undefined) {
			$('#order').css('background', '#d60316');
			$(_buy).click(function(e){
				e.preventDefault();
				document.location = "https://customer.radugainternet.ru/?md:string=Service&asid:digit=6&smd:string=AddStep1";
			});
		}  
		else {
			$('#order').css('background', '#d2d2d2');
			$(_buy).click(function(e){
				e.preventDefault();
			});
		}
	});
	
	$(_cancel).click(function(e){
		e.preventDefault();
		$("#q_mod").fadeOut('slow');
	});	
}


function skyGabberBuy() {
	if (confirm("Вы уверены, что хотите приобрести данный продукт?\nСтоимость продукта: 500 руб.")) {
	    document.location = "https://customer.radugainternet.ru/?md:string=Service&asid=19&smd=Buy";
	}
}
function RCBuy() {
	if (confirm("Вы уверены, что хотите приобрести Raduga-Connect?")) {
	    document.location = "https://customer.radugainternet.ru/?md:string=Service&asid:digit=201&smd:string=AddStep1";
	}
}
function OutpostBuy(location) {
	if (confirm("Вы уверены, что хотите приобрести данный продукт?")) {
	document.location = location;
	}
}

function positionCenter(obj){
		var _abs_m = $(window).height() / 2 - $(obj).height() / 2;
		var _abs_c = $(window).width() / 2 - $(obj).width() / 2;
		$(obj).css({'top': _abs_m,'left': _abs_c});
	}
		
var modal_cont = $("<div id='q_mod'>", 
	{
		'left': '0',
		'background': '#FFF'
	}
);

$.fn.modalwin = function(content){
	var _href = $(this).attr('href');
	$(modal_cont).html(content);
} 





function checkMac(a) {

    var pat;
    var str = a.value;
    addstr = "";

    switch (str.length) {
        case 1:
			if(str.match(/[а-яА-Я]/)) alert("Вам необходимо сменить раскладку клавиатуры");
			pat = /^[0-9a-fA-F]$/;
        break;
		case 2:
			addstr = ":";
			pat = /^[0-9a-fA-F]{2}$/;
        break;
        case 3: case 6: case 9: case 12: case 15:
			pat = /^([0-9a-fA-F]{2}:){1,5}$/;
        break;
        case 4: case 7: case 10: case 13: case 16:
			pat = /^([0-9a-fA-F]{2}:){1,5}[0-9a-fA-F]$/;
        break;
        case 5: case 8: case 11: case 14: case 17:
        if (str.length < 17) addstr = ":";
			pat = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){0,5}$/;
        break;
        default:
			pat = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/;	
        if (str.length > 17) {
            alert("Превышение количества символов!");
        }
        break;
    }
    if(str.match(pat)){
        str     = str.toUpperCase();
        a.value = str + addstr;
    }else{
        a.value = str.replace(/.{1}$/, "");
    }
}



  
  function proverka() {
    var _anketa = document.forms.anketa;
    msg = "Не указаны следующие обязательные поля:\n\n"
    error= 0 ;


    if (_anketa.name.value == ''){
    msg += "- ФИО\n";
    error = 1;
     }
    if (_anketa.region.value == ''){
    msg += "- Регион\n";
    error = 1;
    }
    if (_anketa.address.value == ''){
    msg += "- Адрес\n";
    error = 1;
    }
    if (_anketa.personal_info.value == ''){
    msg += "- Как с вами связаться\n";
    error = 1;
    }

    if (_anketa.mail.value == ''){
    msg += "- Email\n";
    error = 1;
    }

    if (_anketa.problemdescription.value == ''){
    msg += "- Примечание\n";
    error = 1;
    }



    if (error == 0) {
    document.forms.anketa.submit();
    }  else  {
                window.alert (msg);
                                                }
}

// DOM Ready
$(document).ready(function(){
	var _sbarw = $("#right_col").height();
	$("#left_col").css("min-height", _sbarw);
	var modal = 0;
	var abs_middle = $(window).height() / 2 - $("#modal_inner").height() / 2;
	var abs_center = $(window).width() / 2 - $("#modal_inner").width() / 2;
	var page_group = page.substr(0, 9);
	
	var curr_pglink = $("#right_col a[href="+page+".php]");
	var parentUl = $(curr_pglink).parent().parent('ul');
	var grandparentUl = $(parentUl).parent().parent('ul');
	$(curr_pglink).css('color','#D60316');
	$(curr_pglink).next('ul').show();
	if($("ul.sublist").find($(curr_pglink))){
		$(parentUl).show().addClass('unmuted');
		if($(grandparentUl)){
			$(grandparentUl).show();
		}
	}
	
	$('#marva_wrapper').hover(function(){
		$(this).animate({
			'right': '-10px'
		}, 600);
	}, function(){
		$(this).animate({
			'right': '-325px'
		}, 600);
	});
	
	$(".accord").bind('click', function(){
		$('.unmuted').slideUp('fast').removeClass('unmuted');
		$(this).next('ul').slideDown('fast').addClass('unmuted');
	});
	
	
	
	$(".supp").click(function(){
		var _url = $(this).find('a').attr('href');
		document.location = _url;
	});
	
	if(page == 'di-traffic'){
	$(".view_table").toggle(function(){	
				$('#h_table').fadeIn('fast');
				}, function(){
					$('#h_table').fadeOut('fast');
				});	
	}
	
	
	if(page == 'realip'){
		$('body').append($(modal_cont));
	}
	
	
	 
	if ($.browser.msie && $.browser.version.substr(0,1)<=8) {
		$("#usergate_form fieldset:even").css('background', '#FFF');
		$("#tariffs_tbl tr:even td, .b_table tr:even td").css('background', '#F8F8F8');
		$('.button, .mission, .boxes_x3, .button_buy, .supp').corner({
			 tl: { radius: 10 },
			 tr: { radius: 10 },
			 bl: { radius: 10 },
			 br: { radius: 10 }
		 });
		 $("#usergate_form").corner({
			 tl: { radius: 10 },
			 tr: { radius: 10 },
			 bl: { radius: 0 },
			 br: { radius: 0 }
		 });
		$("#top_nav li a").corner({
				 tl: { radius: 0 },
				 tr: { radius: 0 },
				 bl: { radius: 10 },
				 br: { radius: 10 }
		});
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$("#main_nav li a").each(function(){
			var _cw = $(this).width() + 20;
			$(this).parent().css('width', _cw);
		});
                }
	}
	
	
	var macFieldId = "#mac1, #mac2";
	$("#login").focus();
    // $.mask.definitions['~']='[abcdefABCDEF0123456789]';
    // $("#mac1").mask('~~:~~:~~:~~:~~:~~');
	// $("#mac2").mask('~~:~~:~~:~~:~~:~~');
	// $("#cellphone, #mobile").mask('(999) 999-99-99');
    
    $("#mac1").change(function () {
        $("#mac1").val($("#mac1").val().toUpperCase());
    });
	$("#mac2").change(function () {
        $("#mac2").val($("#mac2").val().toUpperCase());
    });
	
	$("#sl_modem").hover(function(e){
		$("#skymodem_desc").fadeIn('slow');
	},
	function(e){
		$("#skymodem_desc").fadeOut('slow');
	});
	
	$("a.modal").toggle(function(e){
		e.preventDefault();
		$("#maket").fadeIn('slow');
	}, function(){
		$("#maket").fadeOut('slow');
	});
	
	if(modal == 1){
		$(documanet).click(function(){
			$("#modal").fadeOut('slow');
		});
	}
	
	//New tarifs - August 2010
	var tar = tarify.indexOf('tarify');
	if(tar >= 0){
		$('a').css('text-decoration', 'none');
		$('h1.active').click(function(){
			location.href = 'index.php';
		});
	}
	
	//tabs on tarifs pages
	$(".tab_btn1").click(function(){
	  $(this).addClass('red').siblings('.tab_btn2').removeClass('red');
	  $('#tab1').show().siblings("#tab2").hide();
	});

	$(".tab_btn2").click(function(){
	  $(this).addClass('red').siblings('.tab_btn1').removeClass('red');
	  $('#tab2').show().siblings("#tab1").hide();
	});
	
	
	//expandable list
	var _exp_kids = $("#exp_tree li").children();
	$(_exp_kids).hide();
	if(_exp_kids.length > 0){
		$(_exp_kids).parent().addClass('expandable');
	}
	$(".expandable").toggle(
	function(e){
		$(this).addClass('expanded');
		$(this).children().show();
		e.stopPropagation();
		}, 
	function(e){
		$(this).removeClass('expanded');
		$(this).children().hide();
		e.stopPropagation();
	});
	$(".expanded").children().click(function(){
		return false;
	});
	
	if(page == 'gorodok'){
		$("#hl").click(function(){
			window.location.href = "index.php";
		});
	}
	
	if($("#hp_banners").children().length > 1){
		$("#hp_banners").slideshow(4);
	} else {
		$(".hp_banner").show();
	}
	
	
	//terminology
	if(page == 'dealers-model' || page == 'init-model' || page == 'business-model' || page == 'calculate' || page == 'test-drive' || page == 'tarifs' || page == 'small-gorodok'){

		$(".italic").hover(function(e){
			var termin = $(this).attr('rel');
			var p = $(this).position();
			var x =  e.pageX+20;
			var y =  e.pageY-130;
			$("."+termin).show('300').css('top', y).css('left', x);
		},
		function(){
			var termin = $(this).attr('rel');
			$("."+termin).hide('300');
		});
	}
	
	$("a[rel=lightbox]").lightBox();
	if(page_group == 'buy-rikor' || page == 'buy-dibox-lite'){
		$("#equip_request").validation();
		$("#equip_request").validate();
		$("#entity").click(function(){
			$("#iyr_data").fadeIn('slow');
			$("#iyr_data input").attr('validation', 'required');
			$("#equip_request").validation();
			$("#equip_request").validate();
		});
		$("#individual").click(function(){
			$("#iyr_data").fadeOut('slow');
			$("#iyr_data input").attr('validation', '');
			$("#equip_request").validation();
			$("#equip_request").validate();
		});
		
	}
	
	
	if(page == 'request-service' || page == 'Admin1274865275'){
		$("#equip_request").validation();
		$("#equip_request").validate();
	}
	
	
	
	if(page == 'cooperation'){
		$("#equip_request").click(function(){
			$(this).validation();
		});
	}
	
	if(page == 'support'){
		$("#sup_menu").fadeIn('fast');
	}
	
	
	if(region == 'rg=piter'){
		var zaplatka = '<div><div><h3 class="bold">ИП Черемис Сергей Михайлович</h3><p>Адрес: <span>188401, Ленинградская область, Волосовский район, п. Волосово, Ленинградская ул., дом 15, ТК "Виктория"</span><br/>Телефон: <span>(921)318 57 09</span></p></div></div><div class="dotted">&nbsp;</div>';
		var _cont = $("#left_col");
		$(_cont).append(zaplatka);
	}
	
	if(page == 'gorodok-ras4ety'){
	
		var def_abs = 100;
			$.fn.calculate = function(){
				var day = $(this).find('.day').val();
				var night = $(this).find('.night').val();
				var down = $(this).find('.down').val();
				var up = $(this).find('.up').val();
				var res_day_down = $(this).find('.res_day_down');
				var res_day_up = $(this).find('.res_day_up');
				var res_night_down = $(this).find('.res_night_down');
				var res_night_up = $(this).find('.res_night_up');
				var day_val = '0.'+day.substr(0, day.lastIndexOf('%'));
				var night_val = '0.'+night.substr(0, night.lastIndexOf('%'));
				
				
				$(res_day_down).text(def_abs * day_val * down);
				$(res_day_up).text(def_abs * day_val * up);
				$(res_night_down).text(def_abs * night_val * down);
				$(res_night_up).text(def_abs * night_val * up);
			};
			$('#monthly_stats tr').keyup(function(){
			$(this).calculate();
			});
	}
	
	
	if(dealers_page == 'dealers' || page == 'dealers'){
		$("#select option[value="+region+"]").attr('selected', 'selected');
		$("#showform").toggle(function(){
			$(".funnel").fadeIn("slow");
		}, function(){
			$(".funnel").fadeOut("slow");
		});
		$("#content").css('margin-bottom', '130px')
	}

	
	if(page == 'ditraffic' || page == 'di-traffic'){
	if($('#tariffs_tbl').length > 0){$('#tariffs_tbl tr:last td:first').addClass('view_table');};
			$(".view_table").toggle(function(){	
				$('#h_table').fadeIn('fast');
				}, function(){
					$('#h_table').fadeOut('fast');
				});	
	};
	if(page == 'dipaid'){
		$(".t_range > td").css('width','170px');
	}
	
	if(page == 'certificate-of-mass-media'){
		//$("#dialog").jqm({ajax: 'http://radugainternet.ru/js-2010/y_maps.html',
		//trigger: 'h1'
		//});
	}
	
	if(page == 'page_') {

        $('form a').click(function(){
			var _opt = $(this).attr('class');
			var _form = $(this).parents("form");
			var _pl =  $(_form).find("input[class='platform']");
			
			$(_pl).attr('value', _opt);
			$(_form).submit();
			
			return( false );
		});
	};
	if ($.browser.msie && $.browser.version.substr(0,1)<=8) {
		$(".sat_grid, .button_buy, .round").corner({
			 tl: { radius: 10 },
			 tr: { radius: 10 },
			 bl: { radius: 10 },
			 br: { radius: 10 }
		 });
	}
	 	 
	 $("ul#tariffs_nav li").click(function(){
		var _kids = $(this).children('a').attr('href');
		window.location.href = _kids;
	 });
	 
	 $(".families").click(function(){
		var _url = $(this).find('a').attr('href');
		document.location = _url;
	});
	
	$(".regFiz").click(function(){
		$("#Block1:hidden:first").fadeIn("slow");
		$("#Block2").css('display','none');
	});

	$(".regIyr").click(function(){
		$("#Block2:hidden:first").fadeIn("slow");
		$("#Block1").css('display','none');
	}); 
	
	$("#tar_mts ul").hide();
	$("#tar_beeline ul").hide();
	$("#tar_skylink ul").hide();
	$("a.bee").toggle(function(){
		$("#tar_beeline > ul").show("fast")},
	function (){
		$("#tar_beeline > ul").hide("fast");
	});
	$("a.mts").toggle(function(){
		$("#tar_mts > ul").show("fast")},
	function(){
		$("#tar_mts > ul").hide("fast");
	});
	$("a.tele2").toggle(function(){
		$("#tar_tele2 > ul").show("fast")},
	function(){
		$("#tar_tele2 > ul").hide("fast");
	});
	$("a.skylink").toggle(function(){
		$("#tar_skylink > ul").show("fast")},
	function(){
		$("#tar_skylink > ul").hide("fast");
	});
	
	if(beeline == 'beeline'){
		$("#tar_beeline ul").show("fast");
		$("#tar_mts ul").hide("fast");
		$("#tar_skylink ul").hide("fast");
	}
	
	if(mts == 'mts'){
		$("#tar_mts ul").show("fast");
		$("#tar_beeline ul").hide("fast");
		$("#tar_skylink ul").hide("fast");
	}
	
	if(skylink == 'skylink'){
		$("#tar_skylink ul").show("fast");
		$("#tar_beeline ul").hide("fast");
		$("#tar_mts ul").hide("fast");
	}
	
	// if(getCookie('operator') == 'beeline'){
		// $("#tar_beeline ul").show("fast");
	// };
	// if (getCookie('operator') == 'mts'){
		// $("#tar_mts ul").show("fast");
	// };
	// if (getCookie('operator') == 'tele2'){
		// $("#tar_tele2 ul").show("fast");
	// }
	
	$(".ex_coll h3").toggle(function(e){
		e.stopPropagation();
		$(this).siblings('.togg').fadeIn('fast')},
	function(e){
		e.stopPropagation();
		$(this).siblings('.togg').fadeOut('fast');
		
	});
});





