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 TTWin;
function OpenTTWin(url, width, height) {
        if (TTWin) TTWin.close();
        TTWin=window.open (url, "TTWin", "width="+width+",height="+height+",resizable=1,scrollbars=1");
        TTWin.focus();
}

var MapWin;
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();
}


//------- SHORT AJAX LIB -------------
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == 'Microsoft Internet Explorer'){
        ro = new ActiveXObject('Microsoft.XMLHTTP');
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
        
var request = createRequestObject();
var vId;

// nsPrgsBar.enable({deltaTime:50, imgSrc:'/i/loading.gif'});

function Load(id, action) {
    vId = id;
    request.open('get', action, true);
    request.onreadystatechange = handleResponse;
    request.send(null);
}

function handleResponse() {
    if(request.readyState == 4){
      if (request.status == 200){
         var response = request.responseText;
         document.getElementById(vId).innerHTML = response;
//         alert('obj:' + $('vId'))
      }
      else if (request.status == 404)
         alert("Request URL does not exist");
      else
         alert("Error: status code is " + request.status);
    }
}
//----------------------------------РЕДИРКЕТ!!!---------------------------------------
countryArr = [{name:'China',cid:50},{name:'Cuba',cid:3},{name:'Vietnam',cid:8},{name:'Greece',cid:7893},{name:'Dominicana',cid:809},{name:'Indonesia',cid:6221},{name:'Spain',cid:34},{name:'Italy',cid:80},{name:'Mauritius',cid:4},{name:'Malaysia',cid:603},{name:'Maldives',cid:960},
{name:'UA_Emirates',cid:222},{name:'Portugal',cid:351},{name:'Russia',cid:77},{name:'Seychelles',cid:345},{name:'Singapore',cid:665},{name:'Thailand',cid:53},{name:'Philippines',cid:7911},{name:'France',cid:37}];

//Найти id страны по ее названию в ссылке
function getStaticData(arr,kdata,datatype) { 
 for (var key in arr) { 
  if (kdata == arr[key].name){
   return arr[key][datatype];
  }
 }
} 

//адрес без домена
country0 = (document.location.href).substr(23);
//alert(country0);
pos = country0.indexOf("/");
//имя страны
country = country0.substring(0,pos);
//id страны
var givemeid = getStaticData(countryArr,country,'cid');
if (givemeid!=null) {
	info0 = country0.substr(pos+1);
	info_pos = info0.indexOf("_");
	//категория (отели, регионы, общая информация)
	info = info0.substring(0,info_pos);
	if (info != "") {
		info_id0 = info0.substr(info_pos+1);
		info_epos = info_id0.indexOf(".");
		info_id = info_id0.substring(0,info_epos);
		//id материала в категории	
		info_id = parseInt(info_id);
	}else{
		info_epos = info0.indexOf(".");
		info = info0.substring(0,info_epos);
		//id материала в категории	
		info_id = 0;
	}
	//alert("info= "+info);
	//alert("info_id= "+info_id);
	url = "http://ptsagency.ru";	
	//редирект в з-ти от категории	
	switch(info){
		case 'comb': a = "/cgi-bin/tours.cgi?country_id="+givemeid;break; 
		case 'exc': a = "/cgi-bin/countryinfo.cgi?country_id="+givemeid;break; 
		case 'flights': a = "/cgi-bin/countryinfo.cgi?country_id="+givemeid;break; 
		case 'info': a = "/cgi-bin/countryinfo.cgi?country_id="+givemeid;break; 
		case 'index': a = "/cgi-bin/countryinfo.cgi?country_id="+givemeid;break; 
		case 'hotel': a = "/cgi-bin/hotelinfo.cgi?hotel_id="+info_id;break;
		case 'hotels': a = "/cgi-bin/hotels.cgi?country_id="+givemeid;break; 
		case 'hotelprices': a = "/cgi-bin/hotelinfo.cgi?hotel_id="+info_id;break; 
		case 'region': a = "/cgi-bin/regioninfo.cgi?country_id="+givemeid+"&region_id="+info_id;break;
		default: a = "/cgi-bin/countryinfo.cgi?country_id="+givemeid;
	}
	newurl = url+a;	
}else{
	newurl = "http://www.ptsagency.ru/";	
}
//alert("newurl = "+newurl);
document.location.href = newurl;
//----------------------------------РЕДИРКЕТ!!!---------------------------------------