var SepWin;
function OpenSepWin(url, width, height, alt) {
   if (SepWin) SepWin.close();
   if (alt) 
      WinHeight = height+20;
   else{
      alt='';
      WinHeight = height;
   }
      
   SepWin=window.open (url, 'SepWin', 'width='+width+',height='+WinHeight+',resizable=0');
   SepWin.document.open();
   SepWin.document.writeln("<HTML><BODY leftmargin=0 topmargin=0><img src="+url+" width="+width+" height="+height+" border=0><br><center>"+alt+"</center></BODY></HTML>");
   SepWin.document.title = alt;
   SepWin.document.close();
   SepWin.focus();
}




var gb = (((navigator.appName == "Netscape") && 
         (parseInt(navigator.appVersion) >= 3 )) || 
         ((navigator.appName == "Microsoft Internet Explorer") && 
         (parseInt(navigator.appVersion) >= 4 ))); 
var layers=new Array('Country', 'Tour', 'Services', 'Spravka', 'Search', 'Descripts', 'HotelsC', 'ToursC', 'C-Hotels', 'C-Services', 'C-Guidebook', 'Weather', 'city-hotels', 'Dops', 'Des', 'Res', 'Hot', 'Ser', 'Dop');
var sh=0;
var Timer;

function fix() { if (gb) clearTimeout(Timer);}
function set() { 
   if (gb) Timer = setTimeout('if (sh==1) HideLayers()', 500);
}
//\'HideLayers(div);\'
function HideLayers() {
    if (gb) {
       for (i=0; i<layers.length; i++) 
           if (document.all[layers[i]]) document.all[layers[i]].style.visibility='hidden';
       if (ExtraDiv && document.all[ExtraDiv]) document.all[ExtraDiv].style.visibility='hidden';
       sh=0;
    }
}
var ExtraDiv;
function Show(LayerName) {
    if (gb) {
        clearTimeout(Timer);
        HideLayers(LayerName);
        ExtraDiv = LayerName;
        if (document.all[LayerName]) document.all[LayerName].style.visibility='visible';
        sh=1;
    }
}

var chvis=0;
function ch_vis(lname) {
    if (document.all[lname].style.visibility=='hidden') {document.all[lname].style.visibility='visible'; chvis=1;}
    else {document.all[lname].style.visibility='hidden'; chvis=0;}
}

var pdt='';
function pd(id) {
    if (document.all[pdt]) {document.all[pdt].style.visibility='hidden';}
    if (pdt!=id) {document.all[id].style.visibility='visible'; pdt=id;} else { pdt='';}
}

function choose(id,num) {
    id.value=num.name;
    document.all[pdt].style.visibility='hidden';
    pdt='';
}

function ba(days) {
    document.f1.ba1.value=days;
    document.f1.ba2.value=days;
    document.f1.ba3.value=days;
    document.f1.ba4.value=days;
    document.f1.ba5.value=days;
    document.f1.ba6.value=days;

    document.f1.ba11.value=days*324;
    document.f1.ba12.value=days*324*1.4;
    document.f1.ba13.value=days*324*0.8;
    document.f1.ba14.value=days*324*0.5;

    days=days*1.25;
    document.f1.ba21.value=days*324;
    document.f1.ba22.value=days*324*1.4;
    document.f1.ba23.value=days*324*0.8;
    document.f1.ba24.value=days*324*0.5;

    days=days*0.9;
    document.f1.ba31.value=days*324;
    document.f1.ba32.value=days*324*1.4;
    document.f1.ba33.value=days*324*0.8;
    document.f1.ba34.value=days*324*0.5;

    days=days*1.25;
    document.f1.ba41.value=days*324;
    document.f1.ba42.value=days*324*1.4;
    document.f1.ba43.value=days*324*0.8;
    document.f1.ba44.value=days*324*0.5;

    days=days*1.1;
    document.f1.ba51.value=days*324;
    document.f1.ba52.value=days*324*1.4;
    document.f1.ba53.value=days*324*0.8;
    document.f1.ba54.value=days*324*0.5;

    days=days*1.25;
    document.f1.ba61.value=days*324;
    document.f1.ba62.value=days*324*1.4;
    document.f1.ba63.value=days*324*0.8;
    document.f1.ba64.value=days*324*0.5;
}


function hide_b(ln) {
    document.all[ln+"s"].style.display='none';
}

function g_show_b(ln) {
    if (document.all[ln+"h"].style.display == 'none') { document.all[ln+"s"].style.display='block'; }
}

function show_b(LayerName) {
    clearTimeout(DivTimer);
    if (document.all[LayerName].style.display == 'block') {
       document.all[LayerName].style.display='none';
    }
    else {document.all[LayerName].style.display='block';}
}

function show_CM(ln) {
    if (document.all[ln+"s"].style.display == 'none') {
//        document.all[ln].style.display='none';
        document.all[ln+"s"].style.display='block';
        document.all[ln+"h"].style.display='none';
    }
    else {
//        document.all[ln].style.display='block';
        document.all[ln+"s"].style.display='none';
        document.all[ln+"h"].style.display='block';
    }
}

function changeall(ii) {
    if (document.all['dbl'+ii]) {document.all['dbl'+ii].style.display = 'none';}
    if (document.all['sgl'+ii]) {document.all['sgl'+ii].style.display = 'none';}
    if (document.all['trpl'+ii]) {document.all['trpl'+ii].style.display = 'none';}
    if (document.all['chld'+ii]) {document.all['chld'+ii].style.display = 'none';}
}

function changeblock(b,i) {

/*    if (document.all[b+i].style.display == 'block') { document.all[b+i].style.display = 'none';}
    else if (document.all[b+i].style.display == 'none') {
        document.all[b+i].style.display = 'block';
    }
 */
   if (document.all[b].style.display == 'block') { document.all[b].style.display = 'none';}
   else if (document.all[b].style.display == 'none') {
        document.all[b].style.display = 'block';
   }
}

function oncloseLB(){
    document.all['closeLB'].style.visibility = 'visible';
}
function plus(LayerName) {
    if (document.all[LayerName].style.display == 'block') {return 'url(/img/lim.gif)';}
    else {return 'url(/img/lip.gif)';}
}

var MapWin;
function OpenMap1(url, width, height, title) {
        if (MapWin) { MapWin.close(); }
        MapWin=window.open ("", title, "width="+width+",height="+height+",resizable=0");
        MapWin.document.open();
        MapWin.document.writeln("<HTML><head><title>"+title+"</title></head><BODY leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false'><img src="+url+" width="+width+" height="+height+" border=0></BODY></HTML>");
        MapWin.document.close();
        MapWin.focus();
}

function OpenMap(url, width, height, scroll) {
     if (!scroll) scroll = 0;
     if (MapWin) {MapWin.close();}
     MapWin=window.open (url, "MapWin", "width="+width+",height="+height+",resizable=1, scrollbars="+scroll);
     MapWin.focus();
}



function OpenRec(url, width, height) {
        if (MapWin) { MapWin.close(); }
        var widthWin=width+20;
        MapWin=window.open ("", "Photos", "width="+widthWin+",height=600,resizable=0,scrollbars=1");
        MapWin.document.open();
        MapWin.document.writeln("<HTML><head><title>Фотографии</title></head><BODY leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false'><img src="+url+" width="+width+" height="+height+" border=0></BODY></HTML>");
        MapWin.document.close();
        MapWin.focus();
}

var BookWin;
function OpenWin(url, width, height) {
        if (BookWin) { BookWin.close();}
        BookWin=window.open (url, "Book", "width="+width+",height="+height+",resizable=1,scrollbars=1");
        BookWin.focus();
}



//################################################################################
//################################################################################
var lcountry_id;
function LoadCountries(city_id){
  $('Countries').innerHTML = 'Идет загрузка...';
  $('AviaCountries').innerHTML = 'Идет загрузка...';
  Load({update:'Countries', data:{from_city_id:city_id}}, '/cgi-bin/countries.cgi');
  Load({update:'AviaCountries', data:{from_city_id:city_id}}, '/cgi-bin/countries.cgi');
  LoadRegions(0);
} 
function LoadRegions(country_id){
  lcountry_id = country_id;
  $('AviaRegions').innerHTML = 'Идет загрузка...';
  $('Regions').innerHTML = 'Идет загрузка...';
  $('NeardatesOuter').style.display = 'block';
  $('Neardates').innerHTML = 'Идет загрузка...';
  Load({update:'Neardates', data:{country_id:country_id}}, '/cgi-bin/neardates.cgi', 1);
  Load({update:'Regions', data:{country_id:country_id}}, '/cgi-bin/regions.cgi', 1);
  Load({update:'AviaRegions', data:{country_id:country_id}}, '/cgi-bin/regions.cgi', 1);
  LoadTourTypes(0);
} 
function LoadTourTypes(region_id){
  $('TourTypes').innerHTML = 'Идет загрузка...';
  Load({update:'TourTypes', data:{country_id:lcountry_id, region_id:region_id}}, '/cgi-bin/tourtypes.cgi', 1);
} 

function UpdateCountrySelect(country_id){
  $('country_id').value = country_id;
  LoadRegions(country_id);
} 

function LoadSubheader(country_id){
  $('country_id').value = country_id;
  Load({update:'Main', data:{country_id:country_id}}, '/cgi-bin/subheader.cgi');
} 

//-----------------ЦЕНОВЫЕ ТАБЛИЦЫ---------------------------------------------
function GetTourPrices(){
document.priceform.submit();
/*  Load({update : 'Main', 
        prgsMsg: 'Загрузка...', 
        data:{ group_id:$(group_id).value, 
               tour_id:$(tour_id).value, 
               hotel_id:$(hotel_id).value, 
               tour_date:$(tour_date).value,
               nday:$(nday).value, 
               airline_id:$(airline_id).value,
               price_type:$(price_type).value,
               currency:$(currency).value,
               board_id:$(board_id).value, 
               stars:$(stars).value,
               quote:$(quote).value,
               quote0:$(quote0).value,
               quote2:$(quote2).value,
               roomcategory_id:$(roomcategory_id).value
             }}, 
         '/cgi-bin/tourprices.cgi');
*/
}

//-----------------КАЛЕНДАРЬ--------------------------------------------
function Calendar(){
  Load({update : 'Main', 
        prgsMsg: 'Загрузка...', 
        data:{ vector:$(vector).value, 
               tour_id:$(tour_id).value, 
               group_id:$(group_id).value, 
               month_id:$(month_id).value, 
               year:$(year).value
             }}, 
         '/cgi-bin/tourdates.cgi');
}


function ShowDiv(id, target_div){
//alert(id);
   if (!target_div) target_div = 'Main';
//  alert('SOURCE '+id)
//  alert('target '+target_div)
   if (document.getElementById(target_div) && document.getElementById(id))
      document.getElementById(target_div).innerHTML = document.getElementById(id).innerHTML;
/*   var content = document.getElementById(id).innerHTML;
   document.getElementById(id).innerHTML = '';
   document.getElementById(target_div).innerHTML = content;
   if (prev_div_id && document.getElementById(prev_div_id)) {
      document.getElementById(prev_div_id).innerHTML = prev_div_content;
   }   
   prev_div_id = id;
   prev_div_content = content;
   */
}

function ShowItem(id){
   document.getElementById('Main').innerHTML = '<div id=subitems></div><div id=content></div>';
   var subitems_div = 'subitems_'+id;
   if (document.getElementById(subitems_div)) ShowDiv(subitems_div, 'subitems');
   if (document.getElementById(id)) ShowDiv(id, 'content');
}

function ClearDivs(){
  $('Subheader').innerHTML='';
  $('Main').innerHTML='';
}

function GetCountryInfo(id){
   ClearDivs();
   Load({update:'Subheader', onComplete : function(text, xml) {ShowItem(0)}, evalScripts: true, prgsMsg: 'Загрузка...', data:{country_id:id}}, '/cgi-bin/subheader.cgi');
   UpdateCountrySelect(id);
}

function getDate() 
{ 
 // displays date as 'Month d, yyyy' 
 var datestr, curdate = ""; 
 datestr = new Date(); 
 month = new Array( 
  "January","February","March", 
  "April","May","June", 
  "July","August","September", 
  "October","November","December" 
  ); 


 m = datestr.getMonth(); 
 curdate += month[m] + " "; 
 curdate += datestr.getDate() + ", "; 
 curdate += datestr.getFullYear(); 
 return curdate; 
} 

//--------Показывать хинт у тега <a> title -----
var HelpTitle;
function showTitle(oA, xshift, yshift ){
  HelpTitle = oA.title;
  oA.title = '';
  showTip(HelpTitle, xshift, yshift);
}

function hideTitle (oA){
  hideTip()
  if (oA) oA.title = HelpTitle;
}

//--------Показывать хинт у обычного текста---------
function showTip(text, xshift, yshift ) {
    if (text && text!='') {
        var which = document.createElement("DIV"); 
        if (!xshift) xshift = -150;
        if (!yshift) yshift = 15;
        which.style.top =  window.event.clientY + yshift + document.body.scrollTop;
//        alert (window.event.clientY);
//        alert (document.body.scrollTop);
        which.style.left = window.event.clientX + xshift - document.body.scrollLeft;
        which.className = "Help";
        var it = document.body.appendChild(which); 
        it.id = "tipHelp"; 
    
        which.innerHTML = '<center>'+text+'</center>';
    }
}

function hideTip() {
        if (document.all['tipHelp']) {
           document.all['tipHelp'].style.visibility = "hidden";
           document.body.removeChild(document.all['tipHelp']);
        }
}


function OpenPrint(div, width, height) {
        if (!width) width = 800;
        if (document.getElementById(div)) {
           var widthWin=width+20;
           var MapWin=window.open ("", "Print", "width="+widthWin+",height=600,resizable=0,scrollbars=1,menubar=1");
           MapWin.document.open();
           MapWin.document.writeln("<HTML><head><link rel='stylesheet' type='text/css' href='/print_2007.css'><link rel='stylesheet' type='text/css' href='/calendar.css'><title>Форма для печати</title></head><BODY>"+document.getElementById(div).innerHTML+"</BODY></HTML>");
           MapWin.document.close();
           MapWin.focus();
        }
}






