var old_fromfull='';
var old_tofull='';
var old_Fromfull='';
var old_Tofull='';

var now = new Date();  
 
window.CP_dateFormat = "dd/MM/yyyy";
 now.setDate(now.getDate()+2*365-(now.getMonth()+1)*30);;
 


function unseen(id){
	document.getElementById(id).style.display="none";
}
function seen(id){
	document.getElementById(id).style.display="block";
}
 

var  povtor=0;

 function Sumthing(num1) {
// свойства объекта
this.openWin = num1;
this.leftwaitframe= new Sumthing1(num1);

}

function Sumthing1(num1) {
// свойства объекта
this.nezagruz1 = num1;

}

var    popupWin = new Sumthing(false);
var winopen =false;
window.onerror=myOnError;

function myOnError(msg, url, lno) {
//ident = window.setTimeout(" CheckCode();  ", 1350); alert("  перезагруз") ;
   
   // alert ("Поймали ошибку "+msg+' '+url+' '+lno);
	return false;
	z=101;
   return true
}
var firsttime=1;

function  CheckCode() 
{


   if   (document.getElementsByName("date_type")[0].checked) 
	{
		document.forms[0]["date_type"].value="exactly";
		sc("tridnya",0)
	}
	else if (document.getElementsByName("date_type")[1].checked) 
	{
		document.forms[0]["date_type"].value="1-3";
		sc("tridnya",1)
	}
 	else   
	{
		document.forms[0]["date_type"].value="about";
		sc("tridnya",1)
	}
  if ((document.forms[0]["From"].value=='')&&(document.forms[0]["To"].value==''))
  {
     alert ("Аэропорты вылета и прилета введены неверно.\n Попробуйте ввести названия снова");
	 document.forms[0]["FromFull"].focus();
	 return false;
  }
  if  (document.getElementById("From").value=='') 
  {
     alert ("Аэропорт вылета введен неверно. Попробуйте ввести название снова");
	 document.getElementById("FromFull").focus();
	 return false;
  }
  if  (document.getElementById("To").value=='') 
  {
     alert ("Аэропорт прилета  введен неверно. Попробуйте ввести название снова");
	 document.getElementById("ToFull").focus();
	 return false;
  } 
 
  if  (document.getElementById("in").value.length<8) 
  {
     alert ("Укажите дату отправления");	 
	 return false;
  } 
 
 
	for  (i=0; i<5; i++)	 
	{
       //alert ( document.forms[0].elements[i].name+' '+document.forms[0][document.forms[0].elements[i].name].value);
		if ((document.forms[0].elements[i].name!='') && (document.forms[0].elements[i].name!='hotels') )    document.forms[1][document.forms[0].elements[i].name].value=document.forms[0][document.forms[0].elements[i].name].value;
 
   }
 

    // ident1892 = window.setTimeout(" document.forms[1].submit();", 550+((1-firsttime)*200)); 

	windowname='w'+Math.floor( Math.random( ) * (10000) );



	if ((navigator.appVersion.indexOf('Chrome')>0)  || (navigator.appName=="Microsoft Internet Explorer")) 	{
			document.forms['Form1'].submit(); 
			if (document.getElementById('hotels').checked ) 
			jConfirm(
						   'Запускаем в новой вкладке быстрый поиск отелей по 39 системам бронирования.',
						   	'Подтверждение поиска отеля',
						   function(b){

								   if (b){
										   searchHotels('ok');
								   }
		
						   }
						   
			)	
	}
	else
	if (navigator.appName=='Netscape') { 
	  $("#Form1").attr('target', windowname);
	  ident191 = window.setTimeout("aa=window.open('',windowname,'width=1040,height='+$(document).width()+',resizable=1,status=1,scrollbars=1');;", 250); 
	  ident192 = window.setTimeout("document.forms['Form1'].submit();", 550); 

	  searchHotels(''); 
	}
	
	if  (navigator.appName=='Opera')	{
	searchHotels('');
	document.forms['Form1'].submit(); 

 		    

	}

	   return false;
}

function  searchHotels()
{
	var name='To'; 
	if (trim(document.forms[0].elements[name+'Full'].value)!='') {

		var v=trim(document.forms[0].elements[name+'Full'].value);
	//alert (v.substr(v.length-4,1));
		if ((v.lastIndexOf(" ")>0)&&(v.substr(v.length-4,1)==" "))
		{
			//alert ('change');
			v=v.substr(v.lastIndexOf(" ")+1,3);
			document.forms[0].elements[name].value=v;
		}
		   //alert (document.forms[0].elements[name].value);
		} 
	name='From'; 
	if (trim(document.forms[0].elements[name+'Full'].value)!='') {
		var v=trim(document.forms[0].elements[name+'Full'].value);
		if ((v.lastIndexOf(" ")>0)&&(v.substr(v.length-4,1)==" "))
		{
			//alert ('change');
			v=v.substr(v.lastIndexOf(" ")+1,3);
			document.forms[0].elements[name].value=v;
		}
		//alert (document.forms[0].elements[name].value);
		} 
	tfl=document.getElementById('ToFull').value ;

	if (document.getElementById('hotels').checked )
	{
 
		checkin1=document.getElementById('in').value;
 		checkin=checkin1.substr(0,checkin1.indexOf('/'));
		checkin1=checkin1.substr(checkin1.indexOf('/')+1,10);
		checkin=checkin1.substr(checkin1.indexOf('/')+1,10)+'-'+checkin1.substr(0,checkin1.indexOf('/'))+'-'+checkin;
 
 		checkout1=document.getElementById('out').value;
 		checkout=checkout1.substr(0,checkout1.indexOf('/'));
		checkout1=checkout1.substr(checkout1.indexOf('/')+1,10);
		checkout=checkout1.substr(checkout1.indexOf('/')+1,10)+'-'+checkout1.substr(0,checkout1.indexOf('/'))+'-'+checkout;
		if (checkout=="--")
		{
			checkin1=document.getElementById('in').value;
			checkoutday=checkin1.substr(0,checkin1.indexOf('/'));
			checkoutday++;
			checkin1=checkin1.substr(checkin1.indexOf('/')+1,10);
			checkoutyear=checkin1.substr(checkin1.indexOf('/')+1,10);
			checkoutmonth=checkin1.substr(0,checkin1.indexOf('/'));
 
			if ((checkoutday==31)&&((checkoutmonth==4)||(checkoutmonth==6)||(checkoutmonth==9)||(checkoutmonth==11))) {checkoutday=1;  checkoutmonth++;}
			if ((checkoutday==29)&&(checkoutmonth==2)) {checkoutday=1; checkoutmonth++;}
			if ((checkoutday==32)&&((checkoutmonth==1)||(checkoutmonth==3)||(checkoutmonth==5)||(checkoutmonth==7)||(checkoutmonth==8)||(checkoutmonth==10)||(checkoutmonth==12))) {checkoutday=1; checkoutmonth++;}
			if (checkoutmonth==13) {checkoutmonth==1;checkoutyear++;}
			checkout=checkoutyear+'-'+checkoutmonth+'-'+checkoutday;
			 
		}
		var to1=document.getElementById('To').value;
		document.forms[2].to.value=to1;
		if (to1.indexOf('(')>0) document.forms[2].to.value=to1.substr(0,to1.indexOf('('));

		if (tfl.indexOf('(')>0) tfl=tfl.substr(0,tfl.indexOf('('));
		document.forms[2].fileName.value=encodeURI(tfl);
		document.forms[2].checkin.value=checkin;
		document.forms[2].checkout.value=checkout;
		
		
 
        //                                       document.getElementById('hotelForm').submit();
		$('#my-submit').click(); 
 
	} 

		
	 
 	return true;
}
 
	 
	
	 
function  winClose()
{
   alert ("winclose");
	 if (winopen) { if (!(popupWin.closed)) popupWin.close(); }
}
 
	
function alrts()
{

  if ((!(alert1==''))&&(!(alert2=='')))
  {
     alert ("Аэропорты вылета и прилета "+alert1+" и "+alert2+" не найдены.\n Попробуйте ввести названия снова");
	 document.getElementById("FromFull").focus();
	 return;
  }
  if (!(alert1==''))
  {
     alert ("Аэропорт вылета "+alert1+" не найден. Попробуйте ввести название снова");
	 document.getElementById("FromFull").focus();
	 return;
  }
   if (!(alert2==''))
  {
     alert ("Аэропорт прилета "+alert2+" не найден. Попробуйте ввести название снова");
	 document.getElementById("ToFull").focus();
	 return;
  } 
}
var alert1='';	
var alert2='';	
 

function sc(name,s){
	 document.cookie = name+"="+s+"; path=/;";
	 //alert ("установили "+name+"="+s+"; path=/;");
	 return true;
}


 
var selfscrollflag=0;
function selfscroll(an)
{
	if (selfscrollflag==0)  
	{
		self.scroll(1,120);
		selfscrollflag=1;
		an.innerHTML='скрыть опции';
	}
	else
	{
		self.scroll(1,-130);
		selfscrollflag=0;
		an.innerHTML='дополнительные опции';
		document.getElementById('dopopcii').style.display='none'
	}	
		
}
  
function trim(string) {
  return string.replace(/(^\s+)|(\s+$)/g, "");
}
 
 
function focus_city_name(obj,flag) {
  if(flag=='from') {
    old_fromfull=trim(obj.value);
  } else {
    old_tofull=trim(obj.value);
  }
  return true;
}










 
