/*jQuery(document).ready(function($)
 {
  $('img.tour_photo').each(function(){$(this).width($('TABLE#price_table').width()*0.32).height(150*($('TABLE#price_table').width()*0.32/250));});  
 }
);*/

jQuery(document).ready(function($){
  if(!opros){$('#opros_form_div').show();}
  
  $(".tour_list_header").click(function(){$("#tl_"+$(this).attr("id")).toggle(300);});
  
});

function send_opros()
 {
	$.post("http://www.holidaym.ru/orderonline/add_opros_tours_3.php", {o_ip:$('#o_ip').val(),o_tour:$('#o_tour').val(),o_email:$('#o_email').val(),o_phone:$('#o_phone').val(),o_prichina:$('#o_prichina').val(),o_svoya_prichina:$('#o_svoya_prichina').val(),o_other:$('#o_other').val(),o_other_text:$('#other_text').val()}, function(data){ $("#opros_form_div").html(data+'<div style="background:#66f;color:#fff;font-size:14px;margin:10px;padding:10px 5px;">Большое спасибо за высказанное мнение.<br>Мы обязательно примем его к сведению и постараемся быть максимально удобными для Вас!</div>');});
	
return false;
 }

/*
function inst_order()
 {
  $('.tpr').each(function()
   {
   	 if($(this).attr('qt')>0)
	  {
		$(this).parent().css('background-color','#afa');   
	  }
	 
   });  
 }
*/
function rc(ru)
 {
  
  $('.tpr').each(function()
   {
   	 var parts;
	 parts=$(this).attr('title').split('|');
	 if(ru>0)
   	  {
   	  	
		if(!prices[parts[1]]){prices[parts[1]]=$(this).text();}
   	  	$(this).text(number_format(prices[parts[1]]*course,0,',',' '));
   	  }
   	 else
   	  {
		if(prices[parts[1]]){$(this).text(number_format(prices[parts[1]],0,',',' '));}
		else{$(this).text(number_format($(this).text(),0,',',' '));}
	  }
   });
 }

function filter_price_table()
 {
  if(added_place>0){$('TABLE#price_table TD.rt_header').each(function(){$(this).attr('colspan',(num_rt_add+num_rt_main));});}
  else{$('TABLE#price_table TD.rt_header').each(function(){$(this).attr('colspan',(num_rt_add+num_rt_main-num_rt_add));});}$('TABLE#price_table TD.rt_header').each(function(){if(periods[$(this).attr('per')]>0){$(this).show();}else{$(this).hide();}});$('TABLE#price_table TD.tdp').each(function(){if(($(this).attr('main')==1 && periods[$(this).attr('per')]>0) || ($(this).attr('main')!=1 && added_place>0 && periods[$(this).attr('per')]>0)){$(this).show();}else{$(this).hide();}
  });
 }
function show_by_hs()
 {
 	$('TABLE#price_table TR.trp').each(function(){

        if($(this).attr('stars').search(/1\*/)!=-1){if(stars[1]>0){$(this).show();}else{$(this).hide();}}
        else if($(this).attr('stars').search(/2\*/)!=-1){if(stars[2]>0){$(this).show();}else{$(this).hide();}}
        else if($(this).attr('stars').search(/3\*/)!=-1){if(stars[3]>0){$(this).show();}else{$(this).hide();}}
        else if($(this).attr('stars').search(/4\*/)!=-1){if(stars[4]>0){$(this).show();}else{$(this).hide();}}
        else if($(this).attr('stars').search(/5\*/)!=-1){if(stars[5]>0){$(this).show();}else{$(this).hide();}}

    });
 }

function markdays(date, inMonth) {

    if (inMonth) {
        for (i = 0; i < dates.length; i++) {
            if (date.getMonth() + 1 == dates[i][0] &&
                    date.getDate() == dates[i][1]) {
                return {dateClass: 'activ_date',selectable: true};
            }}}
    return {selectable: false};
}



function find_pk_in_arr(pk,pk_ar){var i;var res=false;for(i=0;i<pk_ar.length;i++){if(pk==pk_ar[i]){return true;}}return res;} 
function show_quotes(tour_key,cur_date,cn_key){$("#show_quotes").hide();$("#q_loading").show();$.get("http://www.holidaym.ru/lib/php/get_quotes_by_tourkey_and_date.php",{tour:tour_key,cdate:cur_date,cn:cn_key},function(data){var pk_ar=data.split(",");$(".tdp").each(function(){
	  if($(this).parent().attr("class")=="trp"&& $(this).children().length>0){var p=$(this).children().attr("title").split("|");if(find_pk_in_arr(p[1],pk_ar)){$(this).css("background-color",$("#q_avalible").css("background-color"));}else{$(this).css("background-color",$("#q_onrequest").css("background-color"));}}});$("#q_loading").hide();$("#quotes_legend").show();});}

function number_format( number, decimals, dec_point, thousands_sep ) {    // Format a number with grouped thousands
    // 
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://crestidg.com)
 
    var i, j, kw, kd, km;
 
    // input sanitation & defaults
    if( isNaN(decimals = Math.abs(decimals)) ){
        decimals = 2;
    }
    if( dec_point == undefined ){
        dec_point = ",";
    }
    if( thousands_sep == undefined ){
        thousands_sep = ".";
    }
 
    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
 
    if( (j = i.length) > 3 ){
        j = j % 3;
    } else{
        j = 0;
    }
 
    km = (j ? i.substr(0, j) + thousands_sep : "");
    kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
    //kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
    kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");
 
 
    return km + kw + kd;
}
