$(document).ready(function(){

	var LANG;
	if( window.location.href.indexOf("/rus/") != -1 ){
		LANG = "rus";
	}else if( window.location.href.indexOf("/eng/") != -1 ){
		LANG = "eng";
	}else{
		LANG = "ukr";
	}
	
	// online-chat image
	substituteOnlineButton(LANG);
	
	init_panel();
	
	document.getElementById('regionselector').onchange = function(){
		gotoCountry();
	}
	
	$.ctrl = function(key, callback, args) {
    var code = (IsNumeric(key) ? parseInt(key) : key.toString().charCodeAt(0));
    if(LANG == 'rus'){
	var settings = {
          maxlen: 250,
            wText:  {
              Big: "Выдели текст с ошибкой меньшего размера.",
                NoSupport: "Ваш браузер не поддерживает возможность перехвата выделенного текста",
                Error: "Орфографическая ошибка в тексте",
                Send: "Отослать сообщение об ошибке редакторам? \n Ваш браузер останется на той же странице.",
                Mark: "<ошибка>",
                Url: "Страница: ",
                VarErr: "Статья: ",
                Err: "Ошибка:   "
            }
        };
	}else{
		var settings = {
	          maxlen: 250,
	            wText:  {
	              Big: "Виділи текст з помилкою меншого розміру.",
	                NoSupport: "Ваш браузер не підтримує можливість перехоплення виділеного тексту",
	                Error: "Орфографічна помилка в тексті",
	                Send: "Відіслати повідомлення про помилку редакторам? \n Ваш браузер залишиться на тій же сторінці.",
	                Mark: "<помилка>",
	                Url: "Сторінка: ",
	                VarErr: "Стаття: ",
	                Err: "Помилка:   "
	            }
	        };	
	}
	
	
    $(document).keydown(function(e) {
        if(!args) args=[]; // IE barks when args is null
        if(e.keyCode == code && e.ctrlKey) {
          var text = getSelectionText();
          var re = /\r|\n/gi;
          
          if (text == null) {
                    alert(settings.wText.NoSupport);
                    return;
                }
                
                text = text.toString().replace(re, " ");
                
                if (text.length > settings.maxlen) {
                    alert(settings.wText.Big);
                    return;
                }
                
                if (text == "") return;
          
          if (confirm(settings.wText.Error + "\n" + settings.wText.Mark + text + settings.wText.Mark + "\n\n" + settings.wText.Send)){
            args.push(text);
            callback.apply(this, args);
          }
          
          return false;
        }
    });
  };
  
	  function IsNumeric(n) {
	    return !isNaN(parseFloat(n)) && isFinite(n);
	  };
	
	  function getSelectionText(){
	    if (window.getSelection){
	        selectionTxt = window.getSelection();
	      }
	      else if (document.getSelection){
	        selectionTxt = document.getSelection();
	      }
	      else if (document.selection){
	        selectionTxt = document.selection.createRange().text;
	      }
	    
	      return selectionTxt;
	  };

		 	$.ctrl(13, function(text) {
			var url = window.location.href;
			var hostname = window.location.hostname;
			var string = {'text':text, 'url': url, 'hostname': hostname}
			
			$.ajax({
				type: "POST",
				url: "/misc/send_error2.php",
				dataType: "json",
				data: string,
				success: function(){
				}
				});
			window.location.reload(true);
			});

/*клавиатурная комбинация для отладки	*/
		
	$.ctrl(8, function(text) {
		$('div.pop_up').fadeIn(0);
	});	

/*END клавиатурная комбинация для отладки	*/

	
	/*на этих трех ссылках скрываем 2 блока*/
	if(location.href =='http://corp.mts.com.ua/rus/unlimited.php'){$('.grid tr').eq(0).fadeOut(0);}
	if(location.href =='http://corp.mts.com.ua/ukr/unlimited.php'){$('.grid tr').eq(0).fadeOut(0);}
	if(location.href =='http://corp.mts.com.ua/eng/unlimited.php'){$('.grid tr').eq(0).fadeOut(0);}
	/*END*/


	/*SEND-info-helper*/	
        function MakeWizard() {
            $("#SignupForm").formToWizard({ submitButton: 'SaveAccount' })
            $("#makeWizard").hide();
            $("#info").fadeIn(400);
        }	

		MakeWizard();
	
	$('#href').val(location.href);
	var s_i_data = {"name": false,
					"email":false,
					"phone1": false,
					"phone": false};
	
	$('#send-text input[name="name"], #send-text input[name="sername"], #send-text input[name="lastname"], #send-text input[name="email"], #send-text input[name="phone1"], #send-text input[name="phone"]').blur(function(){
	
		var name_field = $(this).attr('name');
	
		switch(name_field){
			case "email":
				var string = $('#send-text input[name="'+name_field+'"]').val();
				if(validate('email', string)){
					$('#send-text input[name="'+name_field+'"]').removeClass('red_border');
					s_i_data.email = true;
				}else{
					$('#send-text input[name="'+name_field+'"]').addClass('red_border');
					s_i_data.email = false;
				}
			break;
			case "phone1":
				var string = $('#send-text input[name="'+name_field+'"]').val();
				if(validate('onlyNumber', string)){
					$('#send-text input[name="'+name_field+'"]').removeClass('red_border');
					s_i_data.phone1 = true;
				}else{
					$('#send-text input[name="'+name_field+'"]').addClass('red_border');
					s_i_data.phone1 = false;
				}
			break;
			case "phone":
				var string = $('#send-text input[name="'+name_field+'"]').val();
				if(validate('onlyNumber', string)){
					$('#send-text input[name="'+name_field+'"]').removeClass('red_border');
					s_i_data.phone = true;
				}else{
					$('#send-text input[name="'+name_field+'"]').addClass('red_border');
					s_i_data.phone = false;
				}
			break;
			case "name":
				var string = $('#send-text input[name="'+name_field+'"]').val();
				if(validate('required', string, LANG)){
					$('#send-text input[name="'+name_field+'"]').removeClass('red_border');
					s_i_data.name = true;
				}else{
					$('#send-text input[name="'+name_field+'"]').addClass('red_border');
					s_i_data.name = false;
				}
			break;					
		}		
	});

	$('#SaveAccount').click(function(){
	var trig = 0;
	var what_info = $('#send-text textarea[name="what_info"]').val();
	var why_info = $('#send-text textarea[name="why_info"]').val();
	var propose_info = $('#send-text textarea[name="propose_info"]').val();
	var s_i_data_send = {"href":location.href,
						"what_info":what_info,
						"why_info":why_info,
						"propose_info":propose_info}
						
		$.each(s_i_data, function(key, value) { 
			switch(key){
				case "phone1":
					if($('#s_i_abonent_mts input').attr('checked')){
					  	if(value == false){
							$('#send-text input[name="'+key+'"]').addClass('red_border');
							trig++;
						}else{
							var kod = $('#s_i_abonent_mts_select option:selected').text();
							s_i_data_send.phone1 = kod+$('#send-text input[name="'+key+'"]').val();
						}
					}
				break;
				case "phone":
					if($('#s_i_not_abonent_mts input').attr('checked')){
					  	if(value == false){
							$('#send-text input[name="'+key+'"]').addClass('red_border');
							trig++;
						}else{
						var kod = $('#s_i_not_abonent_mts_select option:selected').text();
							s_i_data_send.phone = kod+$('#send-text input[name="'+key+'"]').val();
						}
					}
				break;
				case "name":
				  	if(value == false){
						$('#send-text input[name="'+key+'"]').addClass('red_border');
						trig++;
					}else{
						s_i_data_send.name = $('#send-text input[name="'+key+'"]').val();
					}
				break;
				case "sername":
				  	if(value == false){
						$('#send-text input[name="'+key+'"]').addClass('red_border');
						trig++;
					}else{
						s_i_data_send.sername = $('#send-text input[name="'+key+'"]').val();
					}
				break;
				case "lastname":
				  	if(value == false){
						$('#send-text input[name="'+key+'"]').addClass('red_border');
						trig++;
					}else{
						s_i_data_send.lastname = $('#send-text input[name="'+key+'"]').val();
					}
				break;
				case "email":
				  	if(value == false){
						$('#send-text input[name="'+key+'"]').addClass('red_border');
						trig++;
					}else{
						s_i_data_send.email = $('#send-text input[name="'+key+'"]').val();
					}
				break;				
			}
		});
		/*console.log(s_i_data_send);*/			
		if(trig>0){
			switch(LANG){
				case "rus":
					alert('Проверьте заполненность и корректность ввода информации в полях, отмеченных *')
				break;
				case "ukr":
					alert('Перевірте заповненість та коректність введення інформації у полях, відмічених *')
				break;
				case "eng":
					alert('Fields, marked * are obligatory for filling')
				break;				
			}				
		}else{
			$(this).unbind();
			switch(LANG){
				case "rus":
					alert('Благодарим Вас за содействие');
				break;
				case "ukr":
					alert('Дякуємо Вам за сприяння')
				break;
				case "eng":
					alert('Thank you for an assistance')
				break;				
			}
			$.ajax({
				type: "POST",
				url: "/misc/s_for_admins/s_i_data.php",
				dataType: "json",
				data: s_i_data_send,
				success: function(){
				}
				});
			window.location.reload(true);
				
		}
	});	
	/*END SEND-info-helper*/
});

/* slider_form*/


(function($) {
    $.fn.formToWizard = function(options) {
        options = $.extend({  
            submitButton: '',  
        }, options); 
        
        var element = this;

        var steps = $(element).find("fieldset");
        var count = steps.size();
        var submmitButtonName = "#" + options.submitButton;
        $(submmitButtonName).hide();

		var LANG;
		if( window.location.href.indexOf("/rus/") != -1 ){
			LANG = "rus";
		}else if( window.location.href.indexOf("/eng/") != -1 ){
			LANG = "eng";
		}else{
			LANG = "ukr";
		}
		
		switch(LANG){
			case "rus":
				var s_i_lang_prev = 'Назад ';
				var s_i_lang_next = 'Вперед ';
			break;
			case "ukr":
				var s_i_lang_prev = 'Назад ';
				var s_i_lang_next = 'Вперед ';
			break;
			case "eng":
				var s_i_lang_prev = 'Prev ';
				var s_i_lang_next = 'Next ';
			break;				
		}

		switch(LANG){
			case "rus":
				var s_i_lang_step = 'Шаг ';
			break;
			case "ukr":
				var s_i_lang_step = 'Крок ';
			break;
			case "eng":
				var s_i_lang_step = 'Step ';
			break;				
		}		
        // 2
        $(element).before("<ul id='s_i_steps'></ul>");

        steps.each(function(i) {
            $(this).wrap("<div id='step" + i + "'></div>");
            $(this).append("<p id='step" + i + "commands'></p>");
			
            // 2
            var name = $(this).find("legend").html();
						
            $("#s_i_steps").append("<li id='stepDesc" + i + "'>"+s_i_lang_step + (i + 1) + "<span>" + name + "</span></li>");

            if (i == 0) {
                createNextButton(i);
                selectStep(i);
            }
            else if (i == count - 1) {
                $("#step" + i).hide();
                createPrevButton(i);
            }
            else {
                $("#step" + i).hide();
                createPrevButton(i);
                createNextButton(i);
            }
        });

        function createPrevButton(i) {
            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Prev' class='s_i_prev'>< "+s_i_lang_prev+"</a>");

            $("#" + stepName + "Prev").bind("click", function(e) {
                $("#" + stepName).hide();
                $("#step" + (i - 1)).show();
                $(submmitButtonName).hide();
                selectStep(i - 1);
            });
        }

        function createNextButton(i) {	
            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='s_i_next'>"+s_i_lang_next+" ></a>");
            $("#" + stepName + "Next").bind("click", function(e) {
				if($(this).attr('id') == 'step0Next'){
					var string = $('#send-text textarea[name="what_info"]').val();
					if(validate('required', string, LANG)){
						$('#send-text textarea[name="what_info"]').removeClass('red_border');
					}else{
						$('#send-text textarea[name="what_info"]').addClass('red_border');
						switch(LANG){
							case "rus":
								alert('Проверьте заполненность и корректность ввода информации в полях, отмеченных *')
							break;
							case "ukr":
								alert('Перевірте заповненість та коректність введення інформації у полях, відмічених *')
							break;
							case "eng":
								alert('Fields, marked * are obligatory for filling')
							break;				
						}
						return false;
					}
				}
				
                $("#" + stepName).hide();
                $("#step" + (i + 1)).show();
                if (i + 2 == count)
                    $(submmitButtonName).show();
                selectStep(i + 1);
            });
        }

        function selectStep(i) {
            $("#s_i_steps li").removeClass("current");
            $("#stepDesc" + i).addClass("current");
        }
    }
})(jQuery); 


function qPay(prm){

	switch(prm){
		case "show":
			$("#pay-layer").fadeIn();
			$("#overlay-black").fadeIn();
		
		break;
		case "hide":
			$("#pay-layer").fadeOut();
			$("#overlay-black").fadeOut();
		break;
	}

}

function qSend(prm){

	switch(prm){
		case "show":
			$("#send-layer").fadeIn();
			$("#overlay-black-send").fadeIn();
		break;
		
		case "hide":
			$("#send-layer").fadeOut();
			$("#overlay-black-send").fadeOut();
		break;
	}

}

function s_i_abonent(prm){

	switch(prm){
		case "not_abonent_mts":
			$('#s_i_not_abonent_mts_select, .s_i_not_mts').removeAttr('disabled');
			$('#s_i_abonent_mts_select, .s_i_mts').attr('disabled', 'disabled');
			$('#s_i_abonent_mts_select, .s_i_mts').removeClass('red_border');
		break;
		
		case "abonent_mts":
			$('#s_i_abonent_mts_select, .s_i_mts').removeAttr('disabled');
			$('#s_i_not_abonent_mts_select, .s_i_not_mts').attr('disabled', 'disabled');
			$('#s_i_not_abonent_mts_select, .s_i_not_mts').removeClass('red_border');
		break;
	}		
}

function validate(prm, str, LANG){
	switch(prm){
		case "required":
			var result= /^[а-яА-Яa-zA-ZіІїЇєЄ0-9\,\.\!\?\s]+$/.test(str)	
			return result;		
		break;
			
		case "onlyLetter":
			var result= /^[а-яА-Яa-zA-ZіІїЇєЄ]+$/.test(str)	
			return result;
		break;
		
		case "onlyNumber":
			var result= /^[0-9]+$/.test(str)
			return result;			
		break;
				
		case "email":
			var result= /^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/.test(str)
			return result;			
		break;
		
		case "telephone":
			var result= /^[0-9\-\(\)]+$/.test(str)
			return result;			
		break;		
	}	
}

function iHalper(prm){

	switch(prm){
		case "show":
			
			$("#ihalper-info").show("normal");
		
		break;
		
		case "hide":
		
			$("#ihalper-info").hide("normal");
			
		break;
	}

}

function substituteOnlineButton(LANG){
	var ONLINE_IMAGE = $("#sc2LTA > a > img");
	var rb = false;

	if(ONLINE_IMAGE && LANG != ""){

		$(ONLINE_IMAGE).attr("src", "/img/tmpl/online-support_"+LANG+".png");

		rb = true
	}
	
	return rb;
}

function telephone_format_close(){
	$("#bn_telephone_format").hide();
	$.cookie("TF_STATUS", "closed", { path: '/'});
}

function init_panel(){
	var sidebar = "";
	$.get("/misc/panel.php", function(data){
	  sidebar = data;
		if(sidebar)
			$("body").append(sidebar);
	});

}

function gotoCountry() {
	var dropdown = document.getElementById('regionselector');

	//window.open(dropdown[dropdown.selectedIndex].value, "redirect");
	window.location.href = dropdown[dropdown.selectedIndex].value;
}

function PrintVersion(){
	if (document.print_form){
		PR=window.open("","wndPrint","alwaysRaised=yes,left=0,top=0,height=500,width=730,menubar=yes,toolbar=yes,resizable=yes,status=yes,scrollbars=yes");
		document.print_form.submit();
	}else{
		alert("No print version for this page!");
	}
}

function sSearch(lang){

var error	= Array();
	error["ukr"] = "Введіть слова для пошуку";
	error["rus"] = "Введите слова для поиска";
	error["eng"] = "Enter search words";
var text	= Array();
	text["ukr"]	= "пошук";
	text["rus"] = "поиск";
	text["eng"] = "search";

	if(document.srch.search_words.value == '' || document.srch.search_words.value  == text[lang]){
		alert(error[lang]);
	}else{
		document.srch.submit();
	}
}

function loadPoll(id){
	//alert(get_cookie('poll_complete'))
	if(!get_cookie('poll_complete_3')){
		wo('poll.php', 600, 600, 1);
	}
}
function loadVote(id){
	if(!get_cookie('vote_'+id)){
		wo('wap_quest.php',600,750,1);
	}
}
function setSkipPoll(id)
{

 var edate = new Date();
 edate.setTime(edate.getTime() + 365 * 24 * 60 * 60 * 1000);
 set_cookie('poll_'+id, "Y" ,edate,null,null,null); 

  window.close();  

}
// Atention!!! Link on this function insert into FCk-editor!!!--------------------------
function wo(_wurl,_ww,_wh,_wscrl){

/***************
	wurl: window URL
	wh: window height
	ww: window width
	wsr: scrollbars 1 - yes, 0 - no
***************/
 if(screen.width){
  wpos_x = (screen.width-_ww)/2;
  if (wpos_x < 0){ wpos_x = 0;}
  wpos_y = (screen.height-_wh)/2;
  if (wpos_y < 0){ wpos_y = 0;}
 }else{
  wpos_x = 0;
  wpos_y = 0;
 }
// if(_wscrl==undefined){ _wscrl = 0;}
 wind_desc=window.open(_wurl,"","alwaysRaised=0,top="+wpos_y+",left="+wpos_x+",height="+_wh+",width="+_ww+",menubar=0,resizable=1,scrollbars="+_wscrl+",status=1");
 wind_desc.focus();
}
///-------------------------------------------------------------------------------------

///-----Sliding-text-----------------------------------------------------
/* EXAMPLE
	fullInfo(ID, BLOCK HEIGHT, SPEED, SPEEDUP);
*/

var bHeight = new Array();
var i = new Array();
var condition = new Array;
var blocked = new Array();
var sVal; 

function move(id,opHeight,speed,speedup){

	bHeight[id] = 1;
if(!i[id])
	i[id] = bHeight[id];

if(speed <= 0)
	speed = 1;

	blocked[id] = 1;
	if(!condition[id]){
		if(i[id] < opHeight){

			if(speedup > 0){
				i[id] += speed * speedup * ((opHeight-i[id])/opHeight)
				i[id] = Math.round(i[id] * 40) / 40;
				if(i[id] > (opHeight-1))
					i[id] = opHeight;
			}else{
				i[id] = i[id] + speed
			}

			if(i[id] > opHeight)
				i[id] = opHeight;
			
			//document.getElementById('trace').innerHTML += i[id] + "<br>";

			document.getElementById(id).style.height = i[id]+'px';
			setTimeout("move('"+id+"',"+opHeight+","+speed+","+speedup+")",50);
		}else{
			
			condition[id] = condition[id]?0:1;
			blocked[id] = 0;
		}
	
	}else{
		if(i[id] > bHeight[id]){
			
			if(speedup > 0){
				i[id] -= speed * speedup * (i[id]/opHeight)
				i[id] = Math.round(i[id] * 40) / 40;
				if(i[id] < (bHeight[id]+1))
					i[id] = bHeight[id];
			}else{
				i[id] = i[id] - speed;
			}			
			//document.getElementById('trace2').innerHTML += i[id] + "<br>";

			if(i[id] < bHeight[id])
				i[id] = bHeight[id];
			document.getElementById(id).style.height = i[id]+'px';
			setTimeout("move('"+id+"',"+opHeight+","+speed+","+speedup+")",50);	
		}else{
			condition[id] = condition[id]?0:1;
			blocked[id] = 0;
		}
	}

}


function fullInfo(id,opHeight,speed,speedup){

$("#"+id).slideToggle();

/*if(condition[id] !=1){
	condition[id] = 0;
	i[id] = bHeight[id];
}

if(!blocked[id])
	move(id,opHeight,speed,speedup);*/
}
///----------------------------------------------------------------------

///--for-covermap-------------
/*function opdesc(country){
	
	if(country == "Ukraine"){
		document.location.replace("covering_uk.php");
	}else{
		wopen("covermap_popup.php?roaming_country="+country+"","covermap",550,500,1);
	}
}*/
///-/for-covermap-------------

function wopen(_wurl,_wn,_ww,_wh,_wscrl){

/***************
	wurl: window URL
	wh: window height
	ww: window width
	wsr: scrollbars 1 - yes, 0 - no
***************/
 if(screen.width){
  wpos_x = (screen.width-_ww)/2;
  if (wpos_x < 0){ wpos_x = 0;}
  wpos_y = (screen.height-_wh)/2;
  if (wpos_y < 0){ wpos_y = 0;}
 }else{
  wpos_x = 0;
  wpos_y = 0;
 }
// if(_wscrl==undefined){ _wscrl = 0 
 if(_wn==""){ _wn = "w_test";}
 wind_desc = window.open(_wurl,_wn,"alwaysRaised=0,top="+wpos_y+",left="+wpos_x+",height="+_wh+",width="+_ww+",menubar=0,resizable=1,scrollbars="+_wscrl+",status=1");
 wind_desc.focus();
}


/*	CROSS LINKs------------------------------------*/
function cross(link){
	
	var URL = document.URL;
	//alert("URL: "+URL)
	var reg1 = /^http:\/\//;
	var reg2 = /^.*\/light\/+./i;
	var reg21= /\/light\//i;
	var reg3 = /http:\/\/+[^\/]*\/+/i

	if(reg1.test(link)){
		//alert("http://")
		if(reg2.test(URL)){
			//alert("LIGHT")
			
			if(reg2.test(link)){
				location.replace(link)
			}else{
				var arr=reg3.exec(link)
				link = link.replace(arr[0],arr[0]+"light/")
				//alert(link)
				location.replace(link)
			}
		
		}else{
			//alert("not LIGHT")
			if(reg2.test(link)){
				link = link.replace(reg21, "/");
				//alert(link)
				location.replace(link)
			}else{
				location.replace(link)
			}
		}
	}else{
		location.replace(link)
		//alert("in site")
	}

}

/*	/CROSS LINKs-----------------------------------*/



/* ---------------Copyrights---------------------*/
//var TEXT = Array(2,15,25,1,14);
var TEXT = Array(9,14,6,15);
var NUM = 0;
function copy(letter){
	//alert(letter)	
	if(letter == TEXT[NUM]){
		NUM++;
		if(NUM == TEXT.length){
			alert('');
		}
	}else{
		NUM = 0;
	}
}
/*-----------------------------------------------*/

function sendsms(){
	wopen('sendsms.php','sendsms',650,720,1);
}


 function DoSubmit(nlog){   if(nlog==1){    document.WebLoginForm.submit();   }else{    document.NonSubViewMsgForm.submit();   }  } 

/*	COOKIE	------------------------------------*/
function get_cookie(Cname){
/* example
get_cookie("COOKIE NAME")

*/
 var result = null;
 var myCookie = " " + document.cookie + ";";
 var searchName = " " + Cname + "=";
 var startOfCookie = myCookie.indexOf(searchName);
 //alert(startOfCookie);
 var endOfCookie;
 if(startOfCookie != -1){
  startOfCookie += searchName.length;
  endOfCookie = myCookie.indexOf(";",startOfCookie);
  result = unescape(myCookie.substring(startOfCookie,endOfCookie));
 }
 return result;
}

function set_cookie(Cname,Cvalue,expires,path,domain,secure){
/* example
 var edate = new Date();
 edate.setTime(edate.getTime() + 365 * 24 * 60 * 60 * 1000);
 set_cookie("COOKIE NAME","VALUE",edate,null,null,null);

*/


 var expString = ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
 var pathString = ((path == null) ? "" : ("; path=" + path));
 var domainString = ((domain == null) ? "" : ("; domain=" + domain));
 var secureString = ((secure == true) ? "; secure" : "");
 document.cookie = Cname + "=" + escape (Cvalue) + expString + pathString + domainString + secureString;
}

function clear_cookie(Cname){
/*
	 clear_cookie("COOKIE NAME")

*/

 var ThreeDays = 3 * 24 * 60 * 60 *1000;
 var expDate = new Date();
 expDate.setTime (expDate.getTime() - ThreeDays);
 document.cookie = Cname + "=ImOutOfHere; expires=" + expDate.toGMTString();
}


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;
    }
};


/*	/COOKIE	------------------------------------*/

function rand(id)
      {
          var now=new Date()
          var num=(now.getSeconds())%4
          var num=num+1
		  var lang
		  var ban1_src
		  var ban1_href
		  var ban2_src
		  var ban2_href
			  if(id == 1){lang="ukr"}
			  if(id == 2){lang="rus"}
			  if(id == 3){lang="eng"}
		  if(num == 1){
			  ban1_src="http://www.umc.ua/img/" + lang + "/search_ban.jpg";
			  ban2_src="http://www.umc.ua/img/" + lang + "/calc_ban.jpg";
			  ban1_href="http://www.umc.ua/" + lang + "/search.php";
			  ban2_href="http://www.umc.ua/" + lang + "/calc.php";
		  }
		  if(num == 2){
			  ban1_src="http://www.umc.ua/img/" + lang + "/calc_ban.jpg";
			  ban2_src="http://www.umc.ua/img/" + lang + "/roam_ban.jpg";
			  ban1_href="http://www.umc.ua/" + lang + "/calc.php";
			  ban2_href="http://www.umc.ua/" + lang + "/covermap.php";
		  }
		  if(num == 3){
			  ban1_src="http://www.umc.ua/img/" + lang + "/roam_ban.jpg";
			  ban2_src="http://www.umc.ua/img/ukr/informer_bnr_inner.gif";
			  ban1_href="http://www.umc.ua/" + lang + "/covermap.php";
			  ban2_href="/" + lang + "/informer.php";
		  }
		  if(num == 4){
			  ban1_src="http://www.umc.ua/img/ukr/informer_bnr_inner.gif";
			  ban2_src="http://www.umc.ua/img/" + lang + "/search_ban.jpg";
			  ban1_href="/" + lang + "/informer.php";
			  ban2_href="http://www.umc.ua/" + lang + "/search.php";
		  }
		  window.document.getElementById("ban1").src=ban1_src;
		  window.document.getElementById("ban2").src=ban2_src;
		  window.document.getElementById("href1").href=ban1_href;
		  window.document.getElementById("href2").href=ban2_href;

      }
	  
/*  RENDOM FOOTER */	
function setFirstVisit()
{
 var edate = new Date();
 edate.setTime(edate.getTime() + 365 * 24 * 60 * 60 * 1000);
 set_cookie('first_visit', 'footer'+number ,edate,null,null,null); 
}
 

/* Popup */

function mtsPopup(a) {
	if (a == true) {
		document.getElementById('mts_ban').style.display = 'block';
		var fz = new SWFObject("/flash/popup/popup.swf", "popup", "320", "240", "high", "#ffffff", true);
		fz.addParam("wmode", "opaque");
		fz.addParam("allowscriptaccess", "always");
		fz.write("mts_ban");
	} else {
		document.getElementById('mts_ban').style.display = 'none';
	}
}
