        function currencychange(id,hotelname,tourid)
        {
         $.ajax({
         type: "GET",
         cache: false,
       url: '/hotel/currency/',
       success: function(msg){
            load_tourinfo(id,hotelname,tourid);
          }});
        }

        function agencyremoveroom(choice,priceid)
        {
         $.ajax({
         type: "GET",
         cache: false,
       url: '/agency/removeroom/' + choice + '/' + priceid + '/',
       success: function(msg){
            agencyshow(choice);
          }});
        }


        function agencyaddroom(choice,priceid)
        {
         $.ajax({
         type: "GET",
         cache: false,
       url: '/agency/addroom/' + choice + '/' + priceid + '/',
       success: function(msg){
            agencyshow(choice);
          }});
        }

        function agencyremovechoice(choice,priceid)
        {
         $.ajax({
         type: "GET",
         cache: false,
       url: '/agency/removechoice/' + choice + '/' + priceid + '/',
       success: function(msg){
            agencyshow(choice);
          }});
        }

        function agencydeletechoice(choice)
        {
            $.ajax({
         type: "GET",
         cache: false,
       url: '/booking/delete/' + choice + '/',
       success: function(msg){
            agencyshow(choice);
          }});
        }

        function agencyaddchoice(choice,priceid)
        {
                     $.ajax({
         type: "GET",
         cache: false,
       url: '/agency/addchoice/' + choice + '/' + priceid + '/',
       success: function(msg){
            agencyshow(choice);
          }});
        }

        function agencyshow(choice)
        {
       var target = '#agencypreset'+choice;
       $(target).load('/agency/booking/'+choice+'/');
        }

        function showhide(id)
        {
           var element = document.getElementById(id);
           if (element.style.display=="block")
             {
              element.style.display="none";
             }
             else
             {
              element.style.display="block";
             }
        }

        function booking_save(choice,priceid)
        {
         $.get('/hotel/booking/' + choice + '/' + priceid + '/');
        }

        function booking(choice,priceid)
        {
         booking_save(choice,priceid)
         var td = document.getElementById('td'+priceid);
         if (td.style.color!="blue")
             {
              td.style.color="blue";
              td.style.fontWeight="bold";
             }
             else
             {
               td.style.color="black";
               td.style.fontWeight="normal";
             }
        }

        function hoteltourdays(tourid,hotelid,hotelname,tourlist)
        {
             var days = document.getElementById('count'+tourid).value;
             var target = '#tourtable'+tourid;
             $(target).load('/hotel/tourtable/'+tourid+'/'+hotelid+'/'+ days +'/'+hotelname+'/'+tourlist+'/');
        }

        function tourinfoslider(tourid,total,uivalue)
        {

		  for (var i = 1; i <= total; i++)
			{
                            var col = document.getElementsByName('tour'+tourid+'col'+i );
                                	for (var a = 0; a < col.length; a++)
                                                {
                                                col[a].style.display="none";
                                                }
 
         
                       }

		  for (var j = uivalue; j <= uivalue+4; j++)
			{
          
                            var column = document.getElementsByName('tour'+tourid+'col'+j );
                                	for (var b = 0; b < column.length; b++)
                                                {
                                                column[b].style.display="table-cell";
                                                }


                       }

        }

	function animation(pic){

		$('#tvpicture').stop(true, true);

	        $("#tvpicture").fadeIn();		

  	          var e = document.getElementById('tvpicture');
//	          e.style.opacity = '1';
		  e.style.display = 'block';
                   var r = document.getElementById(pic);



                var totalscroll =  (550 - r.clientHeight) + "px";
	 	var halfscroll = (550 - r.clientHeight) / 2 + "px";

			$("#tvpicture").animate({top: totalscroll},14000).animate({left:"0px"}, 0);
			$("#tvpicture").animate({top: halfscroll},16000).animate({left:"0px"}, 0);
		
        }
	



	function presetshow() {
		document.getElementById('morepreset').style.display = 'block'; 
		}

	function presethide() {
        	document.getElementById('morepreset').style.display = 'none'; 
		}

            function guide_cities(regionid)
                {
                var e = document.getElementById('divregion'+regionid);
                if (e.innerHTML=='')
                    {
                          $.ajax({
                            type: "GET",
                            cache: false,
                            url: '/guide/cities/'+regionid,
                            success: function(msg){
                            $('#divregion'+regionid).html(msg);
                              }});
                    }
                            $.ajax({
                            type: "GET",
                            cache: false,
                            url: '/guide/region/'+regionid,
                            success: function(msg){
                            $('#privateitemcontainer').html(msg);
                              }});
                    toggle_vis('region'+regionid);
                }

        function guide_showcity(city)
        {
                                $.ajax({
                            type: "GET",
                            cache: false,
                            url: '/guide/city/'+city,
                            success: function(msg){
                            $('#privateitemcontainer').html(msg);
                              }});
        }

        function guide_regions(countryid)
                {
                var e = document.getElementById('divcountry'+countryid);
                if (e.innerHTML=='')
                    {
                          $.ajax({
                            type: "GET",
                            cache: false,
                            url: '/guide/regions/'+countryid+'/',
                            success: function(msg){
                            $('#divcountry'+countryid).html(msg);
                              }});
                    }
                            $.ajax({
                            type: "GET",
                            cache: false,
                            url: '/guide/country/'+countryid,
                            success: function(msg){
                            $('#privateitemcontainer').html(msg);
                              }});
                    toggle_vis('country'+countryid);
                }


        function guide_countries()
                {
                var e = document.getElementById('divguide');
                if (e.innerHTML=='')
                    {
                          $.ajax({
                            type: "GET",
                            cache: false,
                            url: '/guide/countries/',
                            success: function(msg){
                            $('#divguide').html(msg);
                              }});
                    }

                toggle_vis('guide');
                }

	function toggle_vis(id) {

	       var e = document.getElementById('div'+id);
	       var p = document.getElementById('img'+id);

	       if(e.style.display == 'block')
		{
                  e.style.display = 'none';
	          p.innerHTML="►";
		}
	      else
	        {
	          e.style.display = 'block';
	          p.innerHTML="▼";
		}

	    }


	function load_item(id,module)
		{
		  $('#privateitemcontainer').load('/'+module+'/show/'+id);
		}

        function nav_search(url)
                {
                  $('#privateitemcontainer').load(url);
                }


	function load_tv(id,hotelname)
		{
		$('#tvpicture').stop(true, true).fadeOut(function(){
  	        $('#tvpicture').load('/hotel/tvimage/'+hotelname+'/'+id);
    	          var e = document.getElementById('tvpicture');
	          e.style.top = '0px';
			});
		}

	function load_gmap(id,hotelname)
		{
	        $('#tv').load('/hotel/gmap/'+hotelname+'/'+id);
		}

	function load_options(id,hotelname,tourid)
		{
	        $('#hoteltabs').load('/hotel/options/'+hotelname+'/'+id+'?tourid='+tourid);
		}

	function load_info(id,hotelname,tourid)
		{
	        
	        $('#hoteltabs').load('/hotel/info/'+hotelname+'/'+id+'?tourid='+tourid);
		}

	function load_touroptions(id)
		{

	        $('#hoteltabs').load('/tour/options/'+id);
		}

	function load_tourinfo(id,hotelname,tourid)
		{
	        $('#hoteltabs').load('/hotel/tourinfo/'+hotelname+'/'+id+'/'+tourid);
		}

	function load_agencysearch(url)
		{

	        $('#agencysearchresults').load(url);
		}


	function load_tourhotelinfo(id)
		{
	    
	        $('#hoteltabs').load('/tour/tourhotelinfo/'+id);
		}


	function load_photo(id, hotelname)
		{
                  
	 $('#tv').load('/hotel/photo/'+hotelname+'/'+id);
		}

	function load_pager_left(url)
		{
   	        $('#tvimages').load(url);
		}

	function preset_item(id,prs)
		{
		  presethide();
		  var img = document.getElementsByName('triang');
		  var imgchoosen = document.getElementById('pic'+id);

		  for (var i = 0; i < img.length; i++) 
			{  
		  img[i].innerHTML="►";
		        }
		if(imgchoosen != undefined) 
			{
		  imgchoosen.innerHTML="▼";
		        }
		      
                  var termos = document.getElementsByName('tourspalink');	
                   for (var j = 0; j < termos.length; j++) 
                     { 

                       termos[j].style.color = '#939498';   
                     }
                    var linkchoosen = document.getElementById('tourspa'+id); 
                    if(linkchoosen != undefined) 
                    {
                    linkchoosen.style.color = '#0E7FBF';
                    }

 		      
		  $('#proposes').load('/preset/'+id+'?prs='+prs);

		}
                  
        function hotels_on_page(id)
              {
              var count = document.getElementById('count'+id);
              var hidd = document.getElementById('hiddcount');
              hidd.value = count.value;
              document.advsearch.submit();
              }
		
             function main_hotels_on_page(id)
              {
               var count = document.getElementById('count'+id);
               var hidd = document.getElementById('maincount');
               hidd.value = count.value;
               document.mainsearchform.submit();
             }


        function search_expand_all()
        {
          var menuheader = document.getElementsByName('menuheader');
      
      for (var i = 0; i < menuheader.length; i++) 
                        {  
                  menuheader[i].style.display = 'block';

                        }
          var imgheader = document.getElementsByName('imgheader');
      
      for (var i = 0; i < imgheader.length; i++) 
                        {  
                  imgheader[i].innerHTML="▼";

                        }                        
                        
                        
        }
         function search_minimize_all()
        {
          var menuheader = document.getElementsByName('menuheader');
      
      for (var i = 0; i < menuheader.length; i++) 
                        {  
                  menuheader[i].style.display = 'none';
                        }
                        
          var imgheader = document.getElementsByName('imgheader');
      
      for (var i = 0; i < imgheader.length; i++) 
                        {  
                  imgheader[i].innerHTML="►";

                        }                              

        }
 
        function clearForm(formname) {

          var elements = document.forms[formname].elements; 


          for(i=0; i<elements.length; i++) {
      
              field_type = elements[i].type.toLowerCase();
        
              switch(field_type) {
        
                case "text": 
                case "password": 
                case "textarea":
                case "hidden":
                        
                        elements[i].value = ""; 
                        break;
        
                case "radio":
                case "checkbox":
                        if (elements[i].checked) {
                                elements[i].checked = false; 
                        }
                        break;

                case "select-one":
                case "select-multi":
                        elements[i].selectedIndex = -1;
                        break;

                default:
                        break;
              }
          }
        }
        
       function show_refresh(id)
       {
           var refresh = document.getElementsByName('refresh');
      
      for (var i = 0; i < refresh.length; i++) 
                        {  
                  refresh[i].style.display = 'none';
                        }
                        
         var target = document.getElementById('refresh'+id);
         target.style.display = 'block';
       }

      function set_search_option(id)
      {
          
        var e = document.getElementById('item'+id);
              
        
       alert (event.x + '--' + event.target.y);

 
      }

      function set_search_stars(id,name)
      {   
        for (var i = 1; i <= 5; i++) 
                        {  
                            if (i <=id)
                            {
                           document.getElementById('img'+name+i).src = '/images/header/star.png';
                            }
                            else
                            {
                           document.getElementById('img'+name+i).src = '/images/header/star_black.png';  
                            }
                            
                            if(i==id)
                            {
                            document.getElementById(name+i).checked = true;
                            }
                            else
                            {
                            document.getElementById(name+i).checked = false; 
                            }
                          
                          
                        }
                        
      }

       function tourlist(){
 var countryid=document.getElementById('agency_countryto').value;
  $('#agtourlist').load('/agency/tourlist/'+countryid);
       var hotelsapi = $('#aghotels-list').data('jsp');
    hotelsapi.getContentPane().empty();
    hotelsapi.reinitialise();
           var citiessapi = $('#agcities-list').data('jsp');
    citiessapi.getContentPane().empty();
    citiessapi.reinitialise();
    var foodsapi = $('#agfoods-list').data('jsp');
    foodsapi.getContentPane().empty();
    foodsapi.reinitialise();
    var roomsapi = $('#agrooms-list').data('jsp');
    roomsapi.getContentPane().empty();
    roomsapi.reinitialise();
  $('#agency_stars').empty();
  }

 function citylist(){
  var citylist=document.getElementsByName('agency[citylist][]');
  for (var i=0; i < citylist.length; i++) citylist[i].checked = false;
  var tourlistid=document.getElementById('agency_tourlist').value;
          var citiessapi = $('#agcities-list').data('jsp');
          citiessapi.getContentPane().load('/agency/citylist/'+tourlistid,function(){citiessapi.reinitialise();});
          starlist();
    }

 function starlist(){
  var form = $("form").serialize();
  $.ajax({
   type: "POST",
   cache: false,
   url: "/agency/starlist/",
   data: form,
   success: function(msg){
     $('#agstarlist').html(msg);
      hotellist();
   }});}

 function hotellist(){
    var form = $("form").serialize();
 $.ajax({
   type: "POST",
   cache: false,
   url: "/agency/hotellist/",
   data: form,
   success: function(msg){
    var hotelsapi = $('#aghotels-list').data('jsp');
    hotelsapi.getContentPane().html(msg);
    hotelsapi.reinitialise();
     roomlist();
   }});}

 function roomlist(){
    var form = $("form").serialize();
  $.ajax({
   type: "POST",
   cache: false,
   url: "/agency/roomlist/",
   data: form,
   success: function(msg){
    var roomsapi = $('#agrooms-list').data('jsp');
    roomsapi.getContentPane().html(msg);
    roomsapi.reinitialise();
       foodlist();
   }});

   }

 function foodlist(){
    var form = $("form").serialize();
  $.ajax({
   type: "POST",
   cache: false,
   url: "/agency/foodlist/",
   data: form,
   success: function(msg){
    var foodsapi = $('#agfoods-list').data('jsp');
    foodsapi.getContentPane().html(msg);
    foodsapi.reinitialise();
   }});}


          function delete_row(rowid, choice, tourid)
          {
           var e = document.getElementById('row'+rowid);
            e.parentNode.removeChild(e);
            total_count(tourid);
            booking_save(choice,rowid);

            var table=document.getElementById('table'+tourid);
            if (table.rows.length <=3)
                {
                 var tour = document.getElementById('tour'+tourid);
                 tour.innerHTML = '';
                }
          }

function hotel_options(link)
{
$.fancybox ({

				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'href'			: link,
				'type'			: 'inline',
				'centerOnScroll'	: 'true'


})

}

function total_count(tourid)
{

 var col = document.getElementsByClassName('rooms'+tourid);
 var eur = document.getElementsByName('eur'+tourid);
 var rur = document.getElementsByName('rur'+tourid);
 var totaleur = 0;
 var totalrur = 0;
                                for (var a = 0; a < col.length; a++)
                                                {
                                               totaleur = totaleur + rtrim(eur[a].innerHTML) * col[a].value;
                                               totalrur = totalrur + rtrim(rur[a].innerHTML) * col[a].value;
                                                }
 var eursave = document.getElementById('totaleur'+tourid);
 var rursave = document.getElementById('totalrur'+tourid);
 eursave.innerHTML = totaleur;
 rursave.innerHTML = totalrur;
 
}

function rtrim(s)
{
 return s.replace(/ /g, '');
}

function sleep(msec) {

}
