function mnboll(i,n) {
    if(document.getElementById("mn"+i)) {
       if(n==0) document.getElementById("mn"+i).style.display = 'none';
          else  document.getElementById("mn"+i).style.display = 'block';
    }
}
function getWeather() {
	var w = 99368;
    $("#wtext").html("");
    var w_xml = jQuery.ajax({
	type: "GET",
	url: "/mz_weather.php",
	data: "data=http://informer.gismeteo.ru/xml/"+w+"_1.xml&w="+w,
    async: true,
	complete: function(res,s) {
	   rxml = res.responseXML;
	   fc = rxml.getElementsByTagName("FORECAST")[0];
	   fres = "";
	   for(var i=0; i<fc.childNodes.length; i++) {
	      if(fc.childNodes[i].nodeName == "PHENOMENA") {
	        p1 = fc.childNodes[i].getAttribute("cloudiness");
	        p2 = fc.childNodes[i].getAttribute("precipitation");
	        if(p2<9) p1=p2;
	        if(p1>2) p1=1;
	        if(p1>5) p2=2;
	        fres = '<table border="0" cellspacing="0" cellpadding="0" width="160"><tr style="height:55px;"><td width="55px"><img src="/img/w/'+p1+'.gif" width="50" title="" boder="0"></td><td align="center" class="wtext">';
	      }
	      if(fc.childNodes[i].nodeName == "TEMPERATURE") {
          	tmin = parseInt(fc.childNodes[i].getAttribute("min"));
            	tmax = parseInt(fc.childNodes[i].getAttribute("max"));
            	$('.w_temp').each(function(){
            		tmin1 = tmin + parseInt($(this).attr("rel"));
            		tmax1 = tmax + parseInt($(this).attr("rel"));
            		fres = '<table border="0" cellspacing="0" cellpadding="0" width="150" style="margin-left:15px;margin-top:4px;"><tr style="height:55px;"><td width="55px"><img src="/img/w/'+p1+'.gif" width="50" title="" boder="0"></td><td align="right" class="wtext">';
  	            fres += '+' + tmin1.toString() + '..' + '+' + tmax1.toString() + ' &deg;C';
  	            fres += '</td></tr></table>';
  	            $(this).html(fres);
              });
              $('.w_water').each(function(){
              	tmin1 = tmin + parseInt($(this).attr("rel")) + 2;
            	tmax1 = tmax + parseInt($(this).attr("rel")) + 2;
            	fres = '<table border="0" cellspacing="0" cellpadding="0" width="150" style="margin-left:15px;margin-top:4px;"><tr style="height:55px;"><td width="55px"><img src="/img/w/sea.jpg" width="50" title="" boder="0"></td><td align="center" class="wtext">';
                fres += '+' + tmax1.toString() + ' &deg;C';
  	            fres += '</td></tr></table>';
  	            $(this).html(fres);
              });
              break;
	        }
	   }
	}
    });
}
k = 0;
function change_pic() {
   if(galr.length>1) {
     k1 = Math.round(Math.random()*(galr.length-1));
     while(k1==k) {
       k1 = Math.round(Math.random()*(galr.length-1));
     }
     k=k1;
     document.getElementById("galr1").innerHTML='<a href="/galery/"><IMG src="/common/galery'+galr[k]+'" width="180" height="135" border=0></a>';
     document.getElementById("galr1").style.display="block";
     setTimeout('document.getElementById("galr2").className="bpic3"',150);
     setTimeout('document.getElementById("galr2").className="bpic2"',300);
     setTimeout('document.getElementById("galr2").className="bpic1"',450);

     setTimeout('document.getElementById("galr1").className="bpic2"',700);
     setTimeout('document.getElementById("galr1").className="bpic3"',950);

     setTimeout('document.getElementById("galr2").innerHTML=document.getElementById("galr1").innerHTML;document.getElementById("galr2").className="bpic4";     document.getElementById("galr1").className="bpic1";          document.getElementById("galr1").style.display="none";',1300);
     setTimeout("change_pic();",Math.round(Math.random()*1000+3000));
   }
}
function vote_click(q,c) {
    document.getElementById("qbt_"+q).disabled = true;
    document.getElementById("qbt_"+q).value="Подождите";
    document.getElementById('qst_'+q).innerHTML = "";
    for(i=0;i<document.all("qcb_"+q).length;i++) {
       if(document.all("qcb_"+q)[i].checked) {
           a = document.all("qcb_"+q)[i].value;
           break;
       }
    }
    var w_query2 = 'q='+q+'&a='+a+'&c='+c+'&rnd='+Math.random();
    var w_res2 = jQuery.ajax({
        type: "GET",
	url: "/services/newvote.php",
	data: w_query2,
        async: true,
	complete: function(res,s) {
	   res2 = res.responseText;
           document.getElementById('qst_'+q).innerHTML = res2;
           document.getElementById("qbt_"+q).disabled = false;
	}
    });
}
function calc(param) {
    if(param!="") param = "_" + param;
    document.getElementById('calc_res').innerHTML = '<div><img src="/img/87.gif" width="10px"> пожалуйста, подождите..</div>';
    ca_id = (document.forms['calc_form'].ca_id) ? document.forms['calc_form'].ca_id.value : 0;
    c_priezd = (document.forms['calc_form'].c_priezd) ? document.forms['calc_form'].c_priezd.value : '';
    c_otezd = (document.forms['calc_form'].c_otezd) ? document.getElementById("c_otezd").value : '';
    cb_pens = 0;//(document.forms['calc_form'].cb_pens.checked) ? 1 : 0;
    cb_serf = 0;//(document.forms['calc_form'].cb_serf.checked) ? 1 : 0;
    c_cnt = (document.forms['calc_form'].c_cnt) ? document.forms['calc_form'].c_cnt.value : '';
    c_cntv = (document.forms['calc_form'].c_cntv) ? document.forms['calc_form'].c_cntv.value : '';
    c_cntk1 = (document.forms['calc_form'].c_cntk1) ? document.forms['calc_form'].c_cntk1.value : '';
    c_cntk2 = (document.forms['calc_form'].c_cntk2) ? document.forms['calc_form'].c_cntk2.value : '';
    c_cntpens = (document.forms['calc_form'].c_cntpens) ? document.forms['calc_form'].c_cntpens.value : '';
    c_cntserf = (document.forms['calc_form'].c_cntserf) ? document.forms['calc_form'].c_cntserf.value : '';
    for(i=0;i<document.forms['calc_form'].c_ntype.length;i++)
        if(document.forms['calc_form'].c_ntype[i].checked) c_ntype=document.forms['calc_form'].c_ntype[i].value;
    c_discount = 0;
    for(i=0;i<document.forms['calc_form'].c_discount.length;i++)
        if(document.forms['calc_form'].c_discount[i].checked) c_discount=document.forms['calc_form'].c_discount[i].value;
    var w_query2 = 'ca_id='+ca_id+'&c_priezd='+c_priezd+'&c_otezd='+c_otezd+'&c_ntype='+c_ntype+'&cb_pens='+cb_pens+'&cb_serf='+cb_serf+'&c_cnt='+c_cnt+'&c_cntv='+c_cntv+'&c_cntk1='+c_cntk1+'&c_cntk2='+c_cntk2+'&c_cntpens='+c_cntpens+'&c_cntserf='+c_cntserf+'&c_discount='+c_discount+'&c_currency=' + $('input[id^="currency_"]:checked').val() + '&c_grn=' + grv_rate + '&rnd='+Math.random();
    var w_res2 = jQuery.ajax({
        type: "POST",
	url: "/services/calc"+param+".php",
	data: w_query2,
        async: true,
	complete: function(res,s) {
	   res2 = res.responseText;
           window.setTimeout("document.getElementById('calc_res').innerHTML = '"+res2+"';",300);
	}
    });
}
function bron() {
	$('#calc_res').html('<div><img src="/img/87.gif" width="10px"> пожалуйста, подождите..</div>');
	$.get("/services/bron.php", { 'r' : Math.random(), 'number_type' : $('#number_type option:selected').val(), 'date_to' : $('#c_otezd').val(), 'date_from' : $('#c_priezd').val(), 'turist_a' : $('#turist_a').val(), 'turist_k' : $('#turist_k').val(), 'discount' : $('#discount').val(), 'currency' : $('input[id^="currency_"]:checked').val(), 'grn' : grv_rate }, function(res) {
		//window.setTimeout("$('#calc_res').html('"+res+"');",300);
		$('#calc_res').html(res);
	});
}
function bron_begin() {
	c = $('input[id^="brr_param_"]:checked').length;
	if(!c) {
		alert('Пожалуйста, выберите желаемый заезд');
		return;
	}
	$.post("/services/bron.php", { 'r' : Math.random(), 'action' : 'bron_begin', 'brr_name' : $('#brr_name').val(), 'brr_phone1' : $('#brr_phone1').val(), 'brr_email' : $('#brr_email').val(), 'brr_coment' : $('#brr_coment').val(), 'params' : $('input[id^="brr_param_"]:checked').val(), 'subscribe' : $('#brr_subscribe').attr('checked') ? 1 : 0  }, function(res) {
		if(res.indexOf("success")>=0) {
			res = res.split('#');
			if(res[1].length) window.location.href = '/bron/?s=1&bn=' + res[1]; else window.location.href = '/bron/?s=1';
		} else {
			alert(res);
		}
	});
}
rk = 0;
function rank_over(n) {
    if(!rk)
    for(i=1;i<6;i++) {
    	if(i<=n) {
    		$("#rank_im"+i).css('opacity',1);
        } else break;
    }
}
function rank_out(n) {
    if(!rk)
    for(i=1;i<6;i++) {
    	$("#rank_im"+i).css('opacity',0);
    }
}
function rank_click(n,im,c,t) {
    if(!rk) {
    rk = 1;
    var w_query2 = 't='+t+'&r='+n+'&i='+im+'&c='+c+'&rnd='+Math.random();
    var w_res2 = jQuery.ajax({
        type: "GET",
	url: "/services/newrank.php",
	data: w_query2,
        async: true,
	complete: function(res,s) {
	   res2 = res.responseText;
           document.getElementById('rankcont').innerHTML = res2;
	}
    });
    }
}

function fpr(h,v,s) {
	$(".fp_button").attr("disabled",true).addClass("fp_button_disabled");
	$("#fpwait").css("visibility","visible");
	$("#fp_x").val(parseInt($("#fp_x").val())+h);
	$("#fp_y").val(parseInt($("#fp_y").val())+v);
	$("#fp_s").val(parseInt($("#fp_s").val())+s);
	$("#fpim").delay(300).queue(function(){$("#fpim").attr('src','/fp/'+$("#fp_n").val()+'?i='+$("#fp_i").val()+'&f='+$("#fp_f").val()+'&x='+$("#fp_x").val()+'&y='+$("#fp_y").val()+'&s='+$("#fp_s").val()).load(function(){$(".fp_button").attr("disabled",false).removeClass("fp_button_disabled");$("#fpwait").css("visibility","hidden");$.dequeue(this);})});
}
function fpd() {
	window.location.href = '/fp/'+$("#fp_n").val()+'?i='+$("#fp_i").val()+'&f='+$("#fp_f").val()+'&x='+$("#fp_x").val()+'&y='+$("#fp_y").val()+'&s='+$("#fp_s").val()+'&get=1';
}
function fpp() {
	$(".fp_button").attr("disabled",true).addClass("fp_button_disabled");
	$("#fpwait").css("visibility","visible");
	$.get('/fp/'+$("#fp_n").val()+'?i='+$("#fp_i").val()+'&f='+$("#fp_f").val()+'&x='+$("#fp_x").val()+'&y='+$("#fp_y").val()+'&s='+$("#fp_s").val()+'&get=2', {}, function(res) {
		res = res.split('#');
		if(res[0]=='ok') {
			window.location.href = '/send/?fp=' + res[1];
		} else {
			
		}
		$(".fp_button").attr("disabled",false).removeClass("fp_button_disabled");
		$("#fpwait").css("visibility","hidden");
	});
}
function fpstop() {
	$.dequeue($("#fpim"));
	$(".fp_button").attr("disabled",false).removeClass("fp_button_disabled");$("#fpwait").css("visibility","hidden");
}

function pricep(s) {
	s1 = "";
	s = s.toString();
	for(i1=3;i1<s.length+3;i1+=3) {
		i2 = s.length-i1;
		if(i2<0) {i3=3+i2; i2=0;} else i3=3;
		s1 = s.substring(i2,i2+i3) + " " + s1;
	}
	return s1;
}

cur = 1;
function gr2ru() {
	$('.grv_link').addClass("val_link");
    $('.grv_link').click(function(){
    	if(cur==1) {
    		$('.reprice').each(function(){
	    		p = Math.ceil((parseInt($(this).html().replace(' ','')) / grv_rate));
	    		$(this).attr("rel",$(this).html());
	    		if(p>0) $(this).html(pricep(p) + ' грн'); else $(this).html(' - ');
	    		if($(this).attr("href")!=undefined) $(this).attr("href",$(this).attr("href").replace("&cur=1","&cur=2"));
	    	});
    		cur = 2;
	    	$('.rub_link').addClass("val_link");
	    	$('.grv_link').removeClass("val_link");
    	}
    });
    
    $('.rub_link').click(function(){
    	if(cur==2) {
	   		$('.reprice').each(function(){
	    		$(this).html($(this).attr("rel"));
	    		if($(this).attr("href")!=undefined) $(this).attr("href",$(this).attr("href").replace("&cur=2","&cur=1"));
	    	});
	   		cur = 1;
	    	$('.grv_link').addClass("val_link");
	    	$('.rub_link').removeClass("val_link");
    	}
   });
}

galr = '';
$(document).ready(function (){
     //$(document).pngFix();
	 $('#number_type').change(function(){
		 $('div[id^="maxplace_"]').hide(); 
		 $('div[id="maxplace_'+$(this).val()+'"]').show();
	 });
     getWeather();
     setTimeout("change_pic();",Math.round(Math.random()*1000+3000));
     $(".tip4").click(function() {
    	 $.fancybox({
 			'padding'		: 0,
 			'autoScale'		: false,
 			'transitionIn'	: 'none',
 			'transitionOut'	: 'none',
 			'title'			: this.title,
 			'width'			: 600,
 			'height'		: 338,
 			'overlayOpacity': 0.9,
 			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
 			'type'			: 'swf',
 			'swf'			: {
 				'wmode'		: 'transparent',
 				'allowfullscreen'	: 'true'
 			}
 		});
 		return false;
     });
     
     $('.vkl').click(function(event) {
    	 event.preventDefault();
    	 window.location.href = 'http://morezovet.ru/pp/2002';
     });
     
     gr2ru();
     
     
     
});
