function sendForm(html, link){
 var txttour_name = $("#tour_name").text();
 var txtname = $("#name").val();
 var txtemail = $("#email").val();
 var txtphone = $("#phone").val();
 var txtcountry = $("#country").val();
 var txttime = $("#time").val();
 var txtnumber = $("#number").val();
 var txtwishes = $("#wishes").val();
 var txtlink = link;
 if(txtemail == "" || txtemail == " "){
 	$("#form #email").css({'border' : 'solid 1px red'})
 	return false;
 }
 
 $.post(html+".php", 
	{tour_name: txttour_name,
	 name: txtname,
	 email: txtemail,
	 phone: txtphone,
	 country: txtcountry,
	 time: txttime,
	 number: txtnumber,
	 wishes: txtwishes,
	 link: txtlink}, function(resp){
		$("#rp").replaceWith(resp);
		$("#close2").bind('click', function(){cancelForm()});
	}
 );
}


function cancelForm(){
	$("#form").hide();
	$("#form").remove();
	$("#bg").fadeOut('slow');
}


function addForm(html, link){
	if($("#popap_div").length == 0) $("body").prepend("<div id='popap_div'></div>");
	var y = !y ? 100 : y;
	var dir = !dir ? "" : dir;
	var html = "js_includ/"+html;
	$.get(html+".html", function(resp){
		$('#popap_div').after(resp);
		var frmOrder = $("#form");
		var ScrollRight = document.documentElement.scrollTop+y; //(document.documentElement.scrollTop)+($(frmOrder).height()/2);
		var ScrollBottom = ((document.body.clientWidth/2))-$(frmOrder).width()/2;
		$("#form #tour_name").text($("#nametour").text());
		frmOrder.css({
			position: 'absolute', 
			left: ScrollBottom, 
			top: ScrollRight, 
			'z-index' : 96, 
			display: 'none'
		});
		$("#formbtt").bind('click', function(){
			sendForm(html, link);
		});
		$("#cur_btt").bind('click', function(){
			cur_calc();
		});
		$("#close").bind('click', function(){
			cancelForm()
		});
		$("body").prepend("<div id='bg'></div>");
		$h = $("#content").height();
		$("#bg").css({
			'background-color' : '#000000', 
			'width' : '100%',
			'height' : $h+"px",
			'position' : 'absolute',
			'z-index' : 90,
			'opacity' : 0
		});
		$("#bg").fadeTo('slow', 0.2);
		frmOrder.show();
		return false;
	});
};



function cur_calc(){
	var rates = new Array();
	rates[0] = 1;
	rates[1] = $("#insert_rate_USD_1263542730").text();
	rates[2] = $("#insert_rate_RUB_1263542730").text();
	rates[3] = $("#insert_rate_EUR_1263542730").text();
	rates[4] = $("#insert_rate_GBP_1263542730").text();
	var price_from = $("#form #price_from").attr("value");
	var cur_from =  $("#form #cur_from").val();
	var cur_to = $("#form #cur_to").val();
	if (price_from != undefined && price_from > 0 && rates[cur_to] > 0) {
		var price_to = price_from * rates[cur_from] / rates[cur_to];
		price_to = price_to.toFixed(2);
		$("#form #price_to").attr("value", price_to);
	}
	return false;
}

