var ROOT="http://www.vitaly-company.ru/";
function hello(){
	var a;
	var b;
	a=document.getElementById(1);
	b=document.getElementById(2);

	 $.post("test.php",{ name: a.value }, function(data){$("#result").html(data);});
}

function test(id){
	$("#mes"+id).html('<img valign="middle" src="upload.gif">');
	$.post("ajax.php", { id: id }, function(data){ $("#mes"+id).html(data);});
}
function easy(type,id_item){
	$("#report").html('<img valign="middle" src="http://www.vitaly-company.ru/images/upload.gif">');
	$.post("http://www.vitaly-company.ru/files/ajax.php", { type: type, id_item: id_item }, function(data){ $("#report").html(data);});
}
function open_new(id) {
	window.open(ROOT+'forms/redact.php?id='+id,'mail','scrollbars,resizable,width=500,height=500');
	void(0);
}

(function($){
  // очищаем select
  $.fn.clearSelect = function() {
	  return this.each(function(){
		  if(this.tagName=='SELECT') {
		      this.options.length = 0;
		      $(this).attr('disabled','disabled');
		  }
	  });
  }
  // заполняем select

  $.fn.fillSelect = function(dataArray) {
	  return this.clearSelect().each(function(){
		  if(this.tagName=='SELECT') {
			  var currentSelect = this;
			  $.each(dataArray,function(index,data){
				  var option = new Option(data.text,data.value,data.selected);
				  if($.support.cssFloat) {
					  currentSelect.add(option,null);
				  } else {
					  currentSelect.add(option);
				  }
			  });
		  }
	  });
  }


})(jQuery);

jQuery(document).ready(function(){


// ADMIN SELECT

  // выбор города
  function adjustCity(){
  	var countryValue = jQuery('#country').val();
  	var tmpSelect = jQuery('#city');
  	if(countryValue.length == 0) {
  		tmpSelect.attr('disabled','disabled');
  		tmpSelect.clearSelect();
  		adjustHotel();
  	} else {
  		jQuery.getJSON(ROOT+'files/SelectCity.php',{country:countryValue},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); adjustHotel(); });

  	}
  };
  // выбор отеля
  function adjustHotel(){
  	var countryValue = jQuery('#country').val();
  	var cityValue = jQuery('#city').val();
  	var tmpSelect = jQuery('#hotel');
  	if(countryValue.length == 0||cityValue.length == 0) {
  		tmpSelect.attr('disabled','disabled');
  		tmpSelect.clearSelect();
  	} else {
  		jQuery.getJSON(ROOT+'files/SelectHotel.php',{country:countryValue,city:cityValue},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); });
  	}
  };

  jQuery('#country').change(function(){
  	adjustCity();
  }).change();
  jQuery('#city').change(adjustHotel);
  jQuery('#hotel').change(function(){
  	if(jQuery(this).val().length != 0) {  }
  });


//USER SELECT DATE

function adjustMonth_Year(){
  var lenValue = jQuery('#len').val();
  var tmpSelect = jQuery('#my');

  if(lenValue.length == 0) {
    tmpSelect.attr('disabled','disabled');
    tmpSelect.clearSelect();
    adjustDay();
  } else {
    jQuery.getJSON(
      ROOT+'files/SelectMY.php',
      {len:lenValue},
      function(data) {
        tmpSelect.fillSelect(data).attr('disabled','');
        adjustDay();
    });
  }
};

function adjustDay(){
  var lenValue = jQuery('#len').val();
  var myValue = jQuery('#my').val();
  var tmpSelect = jQuery('#day');

  if(lenValue.length == 0||myValue.length == 0) {

    tmpSelect.attr('disabled','disabled');
    tmpSelect.clearSelect();
  } else {
    jQuery.getJSON(
      ROOT+'files/SelectDay.php',
      {len:lenValue,my:myValue},
      function(data) {
        tmpSelect.fillSelect(data).attr('disabled','');
    });
  }
};

jQuery('#len').change(function(){
  adjustMonth_Year();
}).change();
jQuery('#my').change(adjustDay);
jQuery('#day').change(function(){
  if(jQuery(this).val().length != 0) { }
});


//EOF
});
//добавление инпутов в форму
function addInput(name) {
	var id = document.getElementById("default-id").value;
  id++;
  $("#"+name).append('<div id="div-' + id + '"><input name="' + name + '[]" id="' + name + '[]" type="text" size="80"><a href="javascript:{}" onclick="removeInput(\'' + id + '\')">dell</a></div>');
  document.getElementById("default-id").value = id;
}

function addPeople(name) {

	var id = document.getElementById("default-id").value;
  id++;
	var id_name='#'+name;
  jQuery(id_name).append('<tr><td><input type="text" name="fio[]" size="30" value="" /> </td><td><input type="text" name="bd[]" size="12" value="" />  </td><td><input type="text" name="number[]" size="20" value="" /></td><td><input type="text" name="srok[]" size="12" value="" /></td></tr>');
  document.getElementById("default-id").value = id;
  document.getElementById("people").style.display="block";
}

function addSpecial(name) {
	var id = document.getElementById("default-id").value;
  id++;
  $("#"+name).append('<div id="div-' + id + '"><br><table wight="100%" class="tour_table" border="0" cellpadding="0" cellspacing="0"><th>Название</th><th>Начало</th><th>Окончание</th><tr><td><input name="special_name[]" id="special_name[]" type="text" size="40"></td><td><input name="special_start[]" id="special_start_'+id+'" class="date-pick" type="text" size="10" ></td><td><input name="special_end[]" id="special_end_'+id+'" class="date-pick" type="text" size="10" ></td></tr><th colspan="3">Описание</th><tr><td colspan="3"><textarea name="special_text[]" id="special_text[]" cols="50" rows="5" ></textarea></td></tr><a href="javascript:{}" onclick="removeInput(\'' + id + '\')">Удалить</a></div><br>');
  document.getElementById("default-id").value = id;
}

function addFile(name) {
	var id = document.getElementById("default-id").value;
  id++;
  $("#"+name).append('<div id="div-' + id + '"><input type="file" name="' + name + '[]" id="' + name + '[]" /><br><input name="name_'+name +'[]" id="name_'+name +'[]" type="text" size="30" /><a href="javascript:{}" onclick="removeInput(\'' + id + '\')">dell</a></div>');
  document.getElementById("default-id").value = id;
}
function addLive(name) {
	var id = document.getElementById("default-id").value;
  id++;
  $("#"+name).append('<div id="div-' + id + '"><input name="desc_price[]" id="desc_price[]" type="text" size="30" value="Цены на размещение 1 чел./ночь"/><input type="hidden" name="check_live[]" id="check_live[]" value="' +id + '"><input type="hidden" name="check_tour_price[]" value="' +name + '"><a href="javascript:{}" onclick="addLive2(\'' + id + '\')">Добавить</a> <a href="javascript:{}" onclick="removeInput(\'' + id + '\')">dell</a><br></div><br>');
  document.getElementById("default-id").value = id;
}
function addLive2(id) {
	var live = document.getElementById("default-live").value;
  live++;
  $("#div-"+id).append('<div id="live-' + live + '"><input name="name_price[]" id="name_price[]" type="text" size="30" /> <input name="start_price[]" id="start_price_'+live+'" class="date-pick" type="text" size="10" /> <input name="end_price[]" id="end_price_'+live+'" class="date-pick" type="text" size="10" /> <input name="price[]" id="price[]" type="text" size="10" /><input type="hidden" name="check_live[]" id="check_live[]" value="' +id + '"><a href="javascript:{}" onclick="removeLive(\'' + live + '\')">dell</a></div>');
  document.getElementById("default-live").value = live;
}
function addLive3(id) {
	var live = document.getElementById("default-live").value;
  live++;
  $("#price-parent-"+id).append('<div id="live-' + live + '"><input name="name_price_id[]" id="name_price_id[]" type="text" size="30" /> <input name="start_price_id[]" id="start_price_id_'+live+'" class="date-pick" type="text" size="10" /> <input name="end_price_id[]" id="end_price_id_'+live+'" class="date-pick" type="text" size="10" /> <input name="price_id[]" id="price_id[]" type="text" size="10" /><input type="hidden" name="check_id[]" id="check_id[]" value="' +id + '"><a href="javascript:{}" onclick="removeLive(\'' + live + '\')">dell</a></div>');
  document.getElementById("default-live").value = live;
}

function addDates(name) {
	var id = document.getElementById("default-id").value;
  id++;
  $("#"+name).append('<div id="div-' + id + '">продолжительность - <input name="dates_day[]" id="dates_day-'+id+'"  type="text" size="20" /><input type="hidden" name="check_dates[]"  value="' +id + '"><a href="javascript:{}" onclick="addDates2(\'' + id + '\')">Добавить</a> <a href="javascript:{}" onclick="removeInput(\'' + id + '\')">dell</a><br></div><br>');
  document.getElementById("default-id").value = id;
}

function addDates2(id) {
	var dates = document.getElementById("default-dates").value;
  dates++;
  $("#div-"+id).append('<div id="dates-' + dates + '">дата начала тура - <input name="date[]" id="date-'+dates+'" class="date-pick" type="text" size="20" /> нет мест - <input id="places[]" name="places[]" value="1" type="checkbox"><input type="hidden" name="check_dates[]" value="' +id + '"><a href="javascript:{}" onclick="removeDates(\'' + dates + '\')">dell</a></div>');
  document.getElementById("default-dates").value = dates;
  addMyPicker();
}

function addDates3(id) {
	var dates = document.getElementById("default-dates").value;
  dates++;
  $("#date-parent-"+id).append('<div id="dates-' + dates + '">дата начала тура - <input name="date_id[]" id="date-'+dates+'" class="date-pick" type="text" size="20" /> нет мест - <input id="places_id[]" name="places_id[]" value="1" type="checkbox"><input type="hidden" name="check_date_id[]" value="' +id + '"><a href="javascript:{}" onclick="removeDates(\'' + dates + '\')">dell</a></div>');
  document.getElementById("default-dates").value = dates;
    addMyPicker();
}

function removeInput(id) {
	$("#div-" + id).remove();
}

function removeLive(live) {
	$("#live-" + live).remove();
}
function removeDates(dates) {
	$("#dates-" + dates).remove();
}
function removeItem(type,id) {
	$("#"+type+"-"+id).html('<img valign="middle" src="http://www.vitaly-company.ru/images/upload.gif">');
	void(2);
	$.post("http://www.vitaly-company.ru/files/removeItem.php", { type: type, id: id }, function(data){ $("#"+type+"-"+id).html(data);});

}
function change_price(id) {
	var objSel = document.getElementById("period-"+id);
	if ( objSel.selectedIndex != -1){
		var price=objSel.options[objSel.selectedIndex].value;
	}

	var obj = document.getElementById('price-'+id);
	obj.innerHTML=price;
}
function change_hotels(name) {
	var objSel = document.getElementById("hotels");
	if ( objSel.selectedIndex != -1){
		var hotels=objSel.options[objSel.selectedIndex].value;
	}

	jQuery("#"+name).html('<img valign="middle" src="http://www.vitaly-company.ru/images/upload.gif">');
	jQuery.post("http://www.vitaly-company.ru/files/ajax.php", { hotels: hotels, type: "hotels" }, function(data){ jQuery("#"+name).html(data);});
}

function change_dates(name) {
	var objSel = document.getElementById("dates");
	if ( objSel.selectedIndex != -1){
		var dates=objSel.options[objSel.selectedIndex].value;
	}

	jQuery("#"+name).html('<img valign="middle" src="http://www.vitaly-company.ru/images/upload.gif">');
	jQuery.post("http://www.vitaly-company.ru/files/ajax.php", { dates: dates, type: "dates" }, function(data){ jQuery("#"+name).html(data);});
}

function Calendar(name) {
	//alert(name);
	$("#"+name).attachDatepicker();

}

function showhide(id1,id2){
 var a;
 var b;
 a=document.getElementById(id1);
 b=document.getElementById(id2);
 a.style.display="none";
 b.style.display="block";
}


//SHOW BLOCK
function show(id){
 var a,b,c,id2,id3;
 id2="plus_"+id;
 id3="minus_"+id;
 a=document.getElementById(id);
 b=document.getElementById(id2);
 c=document.getElementById(id3);
 a.style.display="block";
 b.style.display="none";
 c.style.display="inline";
}
//END SHOW BLOCK

//HIDE BLOCK
function hide(id){
 var a,b,c,id2,id3;
 id2="plus_"+id;
 id3="minus_"+id;
 a=document.getElementById(id);
 b=document.getElementById(id2);
 c=document.getElementById(id3);
 a.style.display="none";
 b.style.display="inline";
 c.style.display="none";
}
//END HIDE BLOCK

//open_close
function open_close(id,act){
 var a,b,c,id1,id2,id3;

 id1="day_"+id;
 a=document.getElementById(id1);
 if (act==1){
	a.style.height="100%";
	id2="show_"+id;
	b=document.getElementById(id2);
	b.style.display="none";

	id3="hide_"+id;
	c=document.getElementById(id3);
	c.style.display="block";
 }
 if (act==2){
	a.style.height="45px";
	id2="show_"+id;
	b=document.getElementById(id2);
	b.style.display="block";

	id3="hide_"+id;
	c=document.getElementById(id3);
	c.style.display="none";

 }
}
//END open_close


// Start Changing Currecy

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function change_currency(name,kurs)
{
	var new_cur;

	var all_eur = getElementsByClass('price_eur');
	var all_price = getElementsByClass('price');

	var cur_cur = document.getElementById(name);
	var main_rate = document.getElementById('main_rate');
	var curr_name=getElementsByClass('curr_name');

	for(i=0; i<curr_name.length; i++){
		curr_name[i].style.background="#FFFFFF";
	}
	cur_cur.style.background="#33CCFF";
	kurs=main_rate.value/kurs;
	var thePrice;
	for(i=0; i<all_eur.length; i++){
		if (name=='RUR') name='руб.';
		thePrice = all_eur[i].innerHTML;
		if (parseFloat(thePrice)) new_cur=Math.round(parseFloat(thePrice)*kurs);
		else new_cur = all_eur[i].innerHTML;
	 	all_price[i].innerHTML = new_cur;
		all_price[i].style.display="block";
		all_eur[i].style.display="none";
	}

}
// End Changing Currecy

//TABS
function tabs(id){
	var a,b;
	var all_tab_button = getElementsByClass('tab_button');
	for(i=0; i<all_tab_button.length; i++){
	 	all_tab_button[i].style.background = "#FFFFFF";
	}
	var all_tabs = getElementsByClass('tabs');
	for(i=0; i<all_tabs.length; i++){
	 	all_tabs[i].style.display = "none";
	}

	id1="stars"+id;
	id2="stars_button"+id;
	a=document.getElementById(id1);
	b=document.getElementById(id2);
	a.style.display="block";
	b.style.background="#EEEEEE";
}


//END OF TABS

function confirmDelete() {
    return confirm("Вы подтверждаете удаление?");
}

function booking_fast(){	var IsValid = true;
	document.getElementById("NameERR").innerText = "";
	document.getElementById("phoneERR").innerText = "";
	document.getElementById("NameERR").innerHTML = "";
	document.getElementById("phoneERR").innerHTML = "";
	if (document.getElementById("name").value == "") {
	    document.getElementById("NameERR").innerText = "Введите имя";
		document.getElementById("NameERR").innerHTML = "Введите имя";
	    IsValid = false;
 	}

	if (document.getElementById("phone").value == "") {
	    document.getElementById("phoneERR").innerText = "Введите телефон";
		document.getElementById("phoneERR").innerHTML = "Введите телефон";
	    IsValid = false;
	}

    if (IsValid) {		name=document.getElementById("name").value;
		phone=document.getElementById("phone").value;
		comment=document.getElementById("info").value;
		$("#booking").html('<img valign="middle" src="http://www.vitaly-company.ru/images/upload.gif">');
		$.post("http://www.vitaly-company.ru/files/post.php", { name_form: name, phone_form: phone, info_form: comment, type: "booking_form", booking_fast: 1 }, function(data){ $("#booking").html(data);});
	}
	return false;


}

