

var IE = false;

if (navigator.appName.indexOf('Microsoft Internet Explorer') != -1) {IE = true}

var Price = 0;


// Класс авто, Время суток и Продолжительность поездки при поездке по городу

var CityClass = 3;
var CityTime = '12:00';
var CityLength = 1;
var CityMode = false;



// Смена картинок

function ChangeImage (id, url, active) {

    var foto = document.getElementById('foto-' + id);
    
    var a0 = document.getElementById('foto-' + id + '-0');
    var a1 = document.getElementById('foto-' + id + '-1');
    var a2 = document.getElementById('foto-' + id + '-2');
    
    var a2 = document.getElementById('foto-' + id + '-2');
    
    a0.className = 'thumb';
    a1.className = 'thumb';
    a2.className = 'thumb';
    
    active.className = 'thumb active';
    
    foto.src = url;
}


// Смена классов в списке автомобилей

function ChangeClass (active) {

    var li3 = document.getElementById('selector-3');
    var li4 = document.getElementById('selector-4');
    var li341 = document.getElementById('selector-341');
    
    var div3 = document.getElementById('content-3');
    var div4 = document.getElementById('content-4');
    var div341 = document.getElementById('content-341');
    
    var pl3 = document.getElementById('price-3');
    var pl4 = document.getElementById('price-4');
    var pl341 = document.getElementById('price-341');
    
    li3.className = '';
    li4.className = '';
    li341.className = '';
    
    div3.style.display = 'none';
    div4.style.display = 'none';
    div341.style.display = 'none';
    
    pl3.style.display = 'none';
    pl4.style.display = 'none';
    pl341.style.display = 'none';

    var main_ill = document.getElementById('main-ill');
    
    if (active == 3) {
    
        li3.className = 'active';
        div3.style.display = 'block';
        pl3.style.display = 'block';
        if (main_ill) {main_ill.style.backgroundImage = 'url(/images/header_ill_01.jpg)'}
    }
    
    
    if (active == 4) {
    
        li4.className = 'active';
        div4.style.display = 'block';
        pl4.style.display = 'block';
        if (main_ill) {main_ill.style.backgroundImage = 'url(/images/header_ill_03.jpg)'}
    }

    if (active == 341) {
    
        li341.className = 'active';
        div341.style.display = 'block';
        pl341.style.display = 'block';
        if (main_ill) {main_ill.style.backgroundImage = 'url(/images/header_ill_03.jpg)'}
    }
}


// Показываем текуще время

function UpdateTime (separator) {

    var time = new Date();
    
    separator = separator == ':' ? separator = ' ' : separator = ':';
    
    var content = document.getElementById('clock');
    
    var hh = time.getHours();
    var mm = time.getMinutes();
    
    if (mm < 10) {mm = '0' + mm}
    
    if (content) 
        content.innerHTML = hh + separator + mm;
    
    setTimeout(function () {UpdateTime(separator)}, 500);
}

setTimeout(UpdateTime, 0);



// Смена типов поездки на главной

var TypeIndex = 'air';

function ChangeType (active) {

    var li_air = document.getElementById('type-air');
    var li_city = document.getElementById('type-city');
    
    li_air.className = '';
    li_city.className = '';
    
    TypeIndex = active;
        
    var t1 = document.getElementById('form-map');            
    var t2 = document.getElementById('form-city-directions');            
    var t3 = document.getElementById('form-air');
                
    var t4 = document.getElementById('form-table');            
    var t5 = document.getElementById('order');            
                    
    if (active == 'air')
    {
        li_air.className = 'active';
        if (t1) {t1.style.display = 'block'}
        if (t2) {t2.style.display = 'none'}
        if (t3) {t3.style.display = 'block'}
        if (t4) {t4.style.display = 'block'}
        if (t5) {t5.style.display = 'none'}

        CityMode = false;
            
        UpdatePrice();
        UpdatePriceAir();        
        
    }
  
    if (active == 'city')
    {
        li_city.className = 'active';
        if (t1) {t1.style.display = 'none'}
        if (t2) {t2.style.display = 'block'}
        if (t3) {t3.style.display = 'none'}
        if (t4) {t4.style.display = 'none'}
        if (t5) {t5.style.display = 'block'}

        CityMode = true;
        
        
        CalculatePrice();
    }
}


// Обновление маршрута



function UpdatePath () {

    var list1 = document.getElementById('list-from');
    var list2 = document.getElementById('list-to');

    var a = document.getElementById('path-info-from');
    if (a) a.innerHTML = list1.options[list1.selectedIndex].text;

    var b = document.getElementById('path-info-to');
    if (b) b.innerHTML = list2.options[list2.selectedIndex].text;

    var c = document.getElementById('input-from');
    if (c) c.value = list1.options[list1.selectedIndex].text;

    var d = document.getElementById('input-to');
    if (d) d.value = list2.options[list2.selectedIndex].text;
}

var SelectFrom = 0;
var SelectTo = 0;


// Сабытия на выподающие списки мст на главной


function List1Onchange (t) {

            SelectFrom = t.options[t.selectedIndex].value || 0;
            ShowOrder();
            UpdatePath();
            
            if (Price == 0 && SelectTo > 0 && SelectFrom > 0 && SelectFrom != SelectTo) {ChangeType('city');}           
}

function List2Onchange (t) {

            SelectTo = t.options[t.selectedIndex].value || 0;
            ShowOrder();
            UpdatePath();
            
            if (Price == 0 && SelectTo > 0 && SelectFrom > 0 && SelectFrom != SelectTo) {ChangeType('city');}
}




// Загрузка списков мест в выподающие списки


function UpdatePlaceList1 () {

    if (PAGE['type'] != 10) {return false;}

    var list = document.getElementById('list-from');

    if (list) {
       
        list.options.length = 1;
    
    	for (var i = 0; i < PLACE.length; i++) (function()
    	{    	
        	list.options.length++;
        	
        	list.options[list.options.length-1].text = PLACE[i].header;
        	list.options[list.options.length-1].value = PLACE[i].id;
        		
    	})();
    }
    
    else {setTimeout('UpdatePlaceList1();', 100)}	
}



function UpdatePlaceList2 () {

    if (PAGE['type'] != 10) {return false;}

    var list = document.getElementById('list-to');

    if (list) {
       
        list.options.length = 1;
    
    	for (var i = 0; i < PLACE.length; i++) (function()
    	{    	
        	list.options.length++;
        	
        	list.options[list.options.length-1].text = PLACE[i].header;
        	list.options[list.options.length-1].value = PLACE[i].id;
	
    	})();
    }
    
    else {setTimeout('UpdatePlaceList2();', 100)}	
}


setTimeout('UpdatePlaceList1();', 0);
setTimeout('UpdatePlaceList2();', 0);


// Щелчек по карте на главной странице


function MapClick (id) {
    
    var list1 = document.getElementById('list-from');
    var list2 = document.getElementById('list-to');

    if (SelectFrom > 0 && SelectTo > 0)
    {
        SelectFrom = 0;
        SelectTo = 0;
        if (list1) {list1.selectedIndex = 0}
        if (list2) {list2.selectedIndex = 0}
    }



    if (SelectTo == 0 && SelectFrom > 0)
    {
        SelectTo = id;
        
        for (var i = 0; i < list2.options.length; i++) (function()
        {    	
            if (list2.options[i].value == id) list2.selectedIndex = i	
        })();
    }


    if (SelectFrom == 0)
    {
        SelectFrom = id;
        
        for (var i = 0; i < list1.options.length; i++) (function()
        {    	
            if (list1.options[i].value == id) list1.selectedIndex = i	
        })();
    } 

    UpdatePath();
    ShowOrder();
    
    
    if (Price == 0 && SelectTo > 0 && SelectFrom > 0 && SelectFrom != SelectTo) {ChangeType('city');}

}


// Показать или спрятать блок с заказом.



function ShowOrder () {

    var hint = document.getElementById('hint');
    var order = document.getElementById('order');

    if (SelectTo > 0 && SelectFrom > 0 && SelectFrom != SelectTo)
    {
        if (hint) hint.style.display = 'none';
        if (order) order.style.display = 'block';
    }
    else
    {
        if (hint) hint.style.display = 'block';
        if (order) order.style.display = 'none';
    }
    
    UpdatePrice();
    UpdatePriceAir();
}


// Меняем класс автомобиля  в заказе

var Class = 3;

function ChangeClassOrder (active) {

    CityClass = active;

    CalculatePrice();

    var li3 = document.getElementById('class-order-3');
    var li4 = document.getElementById('class-order-4');
    
    var list3 = document.getElementById('auto-list-3');
    var list4 = document.getElementById('auto-list-4');
    
    Class = active;

    var Input = document.getElementById('form-class');
    
    if (active == 3)
    {
        li3.className = 'active left';
        li4.className = 'right';
        list3.style.display = 'block';
        list4.style.display = 'none';
        if (Input) {Input.value = 'Эконом класс'}
    }
    
    if (active == 4)
    {
        li3.className = 'left';
        li4.className = 'active right';
        list3.style.display = 'none';
        list4.style.display = 'block';
        if (Input) {Input.value = 'Бизнес класс'}
    }
    
    UpdatePrice();
    UpdatePriceAir();
}


// Подщет цены


function UpdatePrice (active) {

if (PAGE['type'] == 10 && TypeIndex == 'air') {

    var p;

	for (var i = 0; i < PRICE.length; i++) (function()
	{    	
	if (PRICE[i].from == SelectFrom && PRICE[i].to == SelectTo && PRICE[i]['class'] == Class) {p = PRICE[i].price}
	})();

    p = p ? p : 0;

    var p1 = document.getElementById('show-price');
    var p2 = document.getElementById('show-price-2');
    
    if (p1) p1.innerHTML = p;
    if (p2) p2.innerHTML = p;
    
    var Input = document.getElementById('form-price');
    if (Input) {Input.value = p}
    
    Price = p;
    
    //  (p == 0) {ChangeType('city');}
    
}
}



// Переключение вкладок в-из аэроопорта



function ChangeFromTo (active) {

    var li_from = document.getElementById('air-from');
    var li_to = document.getElementById('air-to');
    var fromto = document.getElementById('fromto');
    
    li_from.className = '';
    li_to.className = '';
        
    if (active == 'from')
    {
        li_from.className = 'active';
        if (fromto) fromto.innerHTML = 'Куда';
        AirTargetInvert = false;
    }
  
    if (active == 'to')
    {
        li_to.className = 'active';
        if (fromto) fromto.innerHTML = 'Откуда';
        AirTargetInvert = true;
    }
    
    UpdatePriceAir();
}

// Показать вкладки шерметьево 1 или 2


function ShowSVO () {

    if (PAGE['page'] == 66) {
    
        var tab = document.getElementById('svo');
        
        if (tab) {tab.style.display = 'block'; UpdatePriceAir();}
        
        else {setTimeout('ShowSVO();', 100);}
    }
}

ShowSVO();


// Переключение вкладок с шереметьевом

function ChangeSVO (active) {

    var li1 = document.getElementById('svo1');
    var li2 = document.getElementById('svo2');
    
    li1.className = '';
    li2.className = '';
        
    if (active == '1')
    {
        li1.className = 'active';
        AirTarget1 = 9;
    }
  
    if (active == '2')
    {
        li2.className = 'active';
        AirTarget1 = 173;
    }
    
    UpdatePriceAir();
}



// Загрузка списка пунктов назначения в странице аэропорта

var SelectFromTo = 0;

function UpdatePlaceListAir () {

    var list = document.getElementById('list-air');

    if (list)
    {

        list.onchange = function ()
        {
            AirTarget2 = list.options[list.selectedIndex].value || 0;
            UpdatePriceAir();
        };
        
        list.options.length = 1;
    
    	for (var i = 0; i < PLACE.length; i++) (function()
    	{   
    	
    	var ok = true;
    	   	
    	   	if (PAGE['page'] == 68 && PLACE[i].id == 7) {ok = false}
    	   	if (PAGE['page'] == 67 && PLACE[i].id == 8) {ok = false}
    	   	if (PAGE['page'] == 66 && PLACE[i].id == 9) {ok = false}
    	   	if (PAGE['page'] == 66 && PLACE[i].id == 173) {ok = false}
    	   	
    	   	if (ok)
    	   	{
            	list.options.length++;
    
            	list.options[list.options.length-1].text = PLACE[i].header;
            	list.options[list.options.length-1].value = PLACE[i].id;
			}
    	})();
    	
    	UpdatePriceAir();
    }
    else
    {
    setTimeout('UpdatePlaceListAir();', 100);
    }	
}

setTimeout('UpdatePlaceListAir();', 0);


// Подщет цены для страницы аэропорта


var AirTarget1; // пункт назначения определяемый страницей
var AirTarget2; // пункт назначения выбираемый из списка

var AirTargetInvert = false;


if (PAGE['page'] == 66) {AirTarget1 = 9}
if (PAGE['page'] == 67) {AirTarget1 = 8}
if (PAGE['page'] == 68) {AirTarget1 = 7}


function UpdatePriceAir () {

if (PAGE['type'] == 40) {

    var p;

    var t1 = AirTarget1;
    var t2 = AirTarget2;

    var temp;
    
    if (AirTargetInvert) {temp = t1; t1 = t2; t2 = temp}

	for (var i = 0; i < PRICE.length; i++) (function()
	{    	
    	if (PRICE[i].from == t1 && PRICE[i].to == t2 && PRICE[i]['class'] == Class) {p = PRICE[i].price}
	})();

    p = p ? p : 0;

    var p1 = document.getElementById('show-price');
    var p2 = document.getElementById('show-price-2');
    
    if (p1) p1.innerHTML = p;
    if (p2) p2.innerHTML = p;
    
    var t11 = document.getElementById('path-info-from');
    var t22 = document.getElementById('path-info-to');
    
    var t33 = document.getElementById('input-from');
    var t44 = document.getElementById('input-to');
    
       
	for (var i = 0; i < PLACE.length; i++) (function()
	{    	
        if (t11 && PLACE[i].id == t1) t11.innerHTML = PLACE[i].header;
        if (t22 && PLACE[i].id == t2) t22.innerHTML = PLACE[i].header; 	

        if (t33 && PLACE[i].id == t1) t33.value = PLACE[i].header;
        if (t44 && PLACE[i].id == t2) t44.value = PLACE[i].header; 	

	})();
	          
    var Input = document.getElementById('form-price');
    if (Input) {Input.value = p}
    
    Price = p;
    
}
}


// Сделать форму отправки заявки


function MakeOrderForm () {

    var form = document.getElementById('order-form');
    var phone = document.getElementById('order-phone');
    
    if (form && phone)
    {
        form.onsubmit = function ()
        {
            if  (phone.value == '') {
            
                alert('Необходимо указать телефон');
                
                return false;
            }
        }
    }
    
    else {setTimeout('MakeOrderForm();', 1000)};
}

setTimeout(MakeOrderForm, 0);



// Рассчет стоимости поездки при поездки по городу


function CalculatePrice() {

// CityClass
// CityTime
// CityLength

var p = 0;


var DN = 'd';

if (CityTime == '0:00') {DN = 'n'}
if (CityTime == '0:30') {DN = 'n'}
if (CityTime == '1:00') {DN = 'n'}
if (CityTime == '1:30') {DN = 'n'}
if (CityTime == '2:00') {DN = 'n'}
if (CityTime == '2:30') {DN = 'n'}
if (CityTime == '3:00') {DN = 'n'}
if (CityTime == '3:30') {DN = 'n'}
if (CityTime == '4:00') {DN = 'n'}
if (CityTime == '4:30') {DN = 'n'}
if (CityTime == '5:00') {DN = 'n'}
if (CityTime == '5:30') {DN = 'n'}
if (CityTime == '6:00') {DN = 'n'}
if (CityTime == '6:30') {DN = 'n'}
if (CityTime == '7:00') {DN = 'n'}
if (CityTime == '21:30') {DN = 'n'}
if (CityTime == '22:00') {DN = 'n'}
if (CityTime == '22:30') {DN = 'n'}
if (CityTime == '23:00') {DN = 'n'}
if (CityTime == '23:30') {DN = 'n'}

var H = Math.ceil(CityLength / 60);

if (CityClass == 3 && DN == 'n')
{    
    p = 100 + Math.round(CityLength * 10); 		
    if (p < 300) p = 300;
}

if (CityClass == 3 && DN == 'd')
{    
    p = 100 + Math.round(CityLength * 9); 		
    if (p < 280) p = 280;
}



if (CityClass == 4)
{    
    p = 100 + (H * 700); 		
    if (p < 800) p = 800;
}

if (CityMode) {

    var p1 = document.getElementById('show-price');
    var p2 = document.getElementById('show-price-2');
    
    if (p1) p1.innerHTML = p;
    if (p2) p2.innerHTML = p;
    
    var Input = document.getElementById('form-price');
    if (Input) {Input.value = p}
}



return p;

}


