//function simple_tooltip(target_items, name){
// $(target_items).each(function(i){
//							   
//							 alert($(this).attr('title'));
//		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
//		var my_tooltip = $("#"+name+i);
//
//		$(this).removeAttr("title").mouseover(function(){
//				my_tooltip.css({opacity:0.8, display:"none"}).stop().fadeIn(400);
//		}).mousemove(function(kmouse){
//				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
//		}).mouseout(function(){
//				my_tooltip.stop().fadeOut(400);
//		});
//	});
//}

// START TOOLTIP

var tooltip_counter = 0;
function simple_tooltip(target_items, name){

    var bodyWdith = $("body").outerWidth();
	//alert(target_items);	
//    alert($(target_items).length);
     $(target_items).each(function(i){
				 			   
          tooltip_counter = tooltip_counter + 1;
          if(($(this).attr('title').length) > 0) {

             if(tooltip_counter == 0) {
                remove_elements('.' + name);
             }

              $("body").append("<div class='"+name+"' id='"+name+tooltip_counter+"'><p>"+$(this).attr('title')+"</p></div>");
              var my_tooltip = $("#"+name+tooltip_counter);
              var my_tooltipW = my_tooltip.outerWidth();
              var my_tooltipH = my_tooltip.outerHeight();
              $(this).removeAttr("title").mouseover(function(){
															
                    my_tooltip.css({opacity:0.8, display:"none"}).stop().fadeIn(400);
              }).mousemove(function(kmouse){
                    if(my_tooltipW+kmouse.pageX+5 > bodyWdith) {
                        my_tooltip.css({left:bodyWdith-my_tooltipW, top:kmouse.pageY-my_tooltipH+70});
                    } else {
                        my_tooltip.css({left:kmouse.pageX+5, top:kmouse.pageY-my_tooltipH+70});
                    }
              }).mouseout(function(){
                    my_tooltip.stop().fadeOut(400);
              });
         }
     });
}

// END TOOLTIP


/*DIALOG
*/

$(function() {
		
		   var validcap = '0';		
		   /*START dialog revezvation fields
		   */
			
			var full_name = $("#full_name");
			phone = $("#phone");
			phone_calc = $("#phone_calc");
			email = $("#email");
			email_calc = $("#email_calc");
			calendarrez_1 = $("#calendarrez_1");
			calendarrez_2 = $("#calendarrez_2");
			roomsid_rez = $("#roomsid_rez");
			adultsid_rez = $("#num_adults_rez");
			adultsid_rez2 = $("#num_adults_rez2");
			adultsid_rez3 = $("#num_adults_rez3");
			childsid_rez = $("#childsid_rez");
			childsid_rez2 = $("#childsid_rez2");
			childsid_rez3 = $("#childsid_rez3");
			captcha_code = $("#captcha_code");
			message = $("#message");
			sel_date = $("#sel_date");
			hotel_name = $("#hotel_name");
			h_id = $("#h_id");
			
			// CHILD FIELDS
			chld_1 = $("#chld_1"); chld_2 = $("#chld_2"); chld_3 = $("#chld_3"); chld_4 = $("#chld_4"); chld_5 = $("#chld_5"); chld_6 = $("#chld_6"); chld_7 = $("#chld_7"); chld_8 = $("#chld_8"); chld_9 = $("#chld_9"); chld_10 = $("#chld_10"); chld_11 = $("#chld_11"); chld_12 = $("#chld_12");
			
			/*END dialog revezvation fields
			  START dialog inquery fields
		   */
		    var full_name_inq = $("#full_name_inq");
			phone_inq = $("#phone_inq");
			email_inq = $("#email_inq");
			about_inq = $("#about_inq");
			message_inq = $("#message_inq");
			captcha_code_inq = $("#captcha_code_inq");
			/*END dialog inquery fields
		   */
			
			
			//coment = $("#coment")
			allFields = $([]).add(full_name).add(email).add(calendarrez_1).add(calendarrez_2).add(roomsid_rez).add(adultsid_rez).add(childsid_rez).add(message).add(captcha_code).add(phone).add(full_name_inq).add(phone_inq).add(email_inq).add(about_inq).add(message_inq).add(captcha_code_inq);
			tips = $("#validateTips");

		//function updateTips(t) {
//			tips.text(t).effect("highlight",{},1500);
//		}

function checkLength(o,min) {
			
			if (o.val().length <= min ) {
				if(o==calendarrez_1 || o==calendarrez_2){
					o.addClass('send_err_ui_date');
				}else if(o==sel_date){
					$('#selectsel_date').addClass('send_err_ui_sel');
				}else if(o==hotel_name){
					$('#selecthotel_name').addClass('send_err_ui_sel');
				}else if(o==phone){
					o.addClass('send_err_ui_phone_mail');
				}else if(o==message_inq){
					o.addClass('send_err_ui_mess');
				}else{
					o.addClass('send_err_ui');
				}

				if(o==calendarrez_1){
					$("#calendarrez_1err").html('Моля, въведете дата на заминаване!');
				}
				
				if(o==calendarrez_2){
					$("#calendarrez_2err").html('Моля, въведете дата на връщане!');
				}
				
				if(o==full_name){
					$("#nameerr").html('Моля, въведете име!');
				}
				
				if(o==phone || o==phone_calc){
					$("#phoneerr").html('Моля, въведете телефон!');
				}
				
				if(o==sel_date){
					$("#dateerr").html('Изберете дата на заминаване!');
				}

				if(o==hotel_name){
					$("#hotelnameerr").html('Изберете име на хотела!');
				}
				
				
				 	//$("#emailerr").html('');
//					$("#emailerr").append('???? ????????? email-a!');
				 
				//updateTips(validname_length + n + validname_must+min+validname_char);
				return false;
			} else if( o==calendarrez_1 || o==calendarrez_2 ) {
				var date_string_1 = calendarrez_1.val();
				date_string_1 = date_string_1.toString();
				var date_string_arr_1 = date_string_1.split("-");
				var d_1 = new Date(date_string_arr_1[2], date_string_arr_1[1], date_string_arr_1[0], 0, 0, 0, 0);
				var d_1_ms = d_1.getTime();
				
				var date_string_2 = calendarrez_2.val();
				date_string_2 = date_string_2.toString();
				var date_string_arr_2 = date_string_2.split("-");
				var d_2 = new Date(date_string_arr_2[2], date_string_arr_2[1], date_string_arr_2[0], 0, 0, 0, 0);
				var d_2_ms = d_2.getTime();
				
				if( d_1_ms > d_2_ms ) {
					$("#calendarrez_2err").html('Датата на връщане трябва да е по-късна от датата на заминаване!');
					calendarrez_2.addClass('send_err_ui_date');
					return false;
				} else {
					$("#calendarrez_2err").html('');
					calendarrez_2.removeClass('send_err_ui_date');
					return true;
				}
			} else {
				if(o==calendarrez_1 || o==calendarrez_2){
					if(o==calendarrez_1){
						$("#calendarrez_1err").html('');
					}
					
					if(o==calendarrez_2){
						$("#calendarrez_2err").html('');
					}
					o.removeClass('send_err_ui_date');
				}else if(o==sel_date){
					$("#dateerr").html('');
					$('#selectsel_date').removeClass('send_err_ui_sel');
				}else if(o==hotel_name){
					$("#hotelnameerr").html('');
					$('#selecthotel_name').removeClass('send_err_ui_sel');
				}else if(o==phone){
					$("#phoneerr").html('');
					o.removeClass('send_err_ui_phone_mail');
				}else if(o==message_inq){
					o.removeClass('send_err_ui_mess');
				}else{
					$("#nameerr").html('');
					$("#phoneerr").html('');
					o.removeClass('send_err_ui');
				}
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {
			if ( !( regexp.test( o.val() ) ) ) {
				if(o==email) {
					$("#emailerr").html('Невалиден email!');
					o.addClass('send_err_ui_phone_mail');
				}else if(o==email_calc) {
					$("#emailerr").html('Невалиден email!');
					o.addClass('send_err_ui');
				} else {
					o.addClass('send_err_ui');
				}
				return false;
			} else {
				if(o==email) {
					$("#emailerr").html('');
					o.removeClass('send_err_ui_phone_mail');
				}else if(o==email_calc) {
					$("#emailerr").html('');
					o.removeClass('send_err_ui');
				} else {
					o.removeClass('send_err_ui');
				}
				return true;
			}

		}
		
			function checkCaptch(from) {
				//alert(from);
					var bValid = true;
					allFields.removeClass('send_err_ui');
					allFields.removeClass('send_err_ui_date');
					allFields.removeClass('send_err_ui_mess');
					if(from=='tour'){
						var captchdata = captcha_code.val();
						var captchelem = "#captcha_code";
						var captcherrelem = "#captcherror";
						var captchimd = "cpt_img";
						bValid = bValid && checkLength(full_name, 5);
						bValid = bValid && checkLength(phone, 3);
						bValid = bValid && checkRegexp(email, /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b/, "");
						bValid = bValid && checkLength(sel_date, 1);
					}else if(from=='hotel'){
						var captchdata = captcha_code.val();
						var captchelem = "#captcha_code";
						var captcherrelem = "#captcherror";
						var captchimd = "cpt_img";
						bValid = bValid && checkLength(full_name, 5);
						bValid = bValid && checkLength(phone, 3);
						bValid = bValid && checkRegexp(email, /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b/, "");
						bValid = bValid && checkLength(calendarrez_1, 0);
						bValid = bValid && checkLength(calendarrez_2, 0);
					}else if(from=='calc'){
						var captchdata = captcha_code.val();
						var captchelem = "#captcha_code";
						var captcherrelem = "#captcherror";
						var captchimd = "cpt_img";
						bValid = bValid && checkLength(full_name, 5);
						bValid = bValid && checkLength(phone_calc, 3);
						bValid = bValid && checkRegexp(email_calc, /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b/, "");
					}else if(from=='rez'){
						var captchdata = captcha_code.val();
						var captchelem = "#captcha_code";
						var captcherrelem = "#captcherror";
						var captchimd = "cpt_img";
						bValid = bValid && checkLength(full_name, 5);
						bValid = bValid && checkLength(phone, 3);
						bValid = bValid && checkRegexp(email, /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b/, "");
						bValid = bValid && checkLength(sel_date, 1);
						bValid = bValid && checkLength(hotel_name, 1);
					}else if(from=='inq'){
						var captchdata = captcha_code_inq.val();
						var captchelem = "#captcha_code_inq";
						var captcherrelem = "#captcherror_inq";
						var captchimd = "cpt_img_inq";
						bValid = bValid && checkLength(full_name_inq, 5);
						bValid = bValid && checkLength(phone_inq, 3);
						bValid = bValid && checkRegexp(email_inq,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
						bValid = bValid && checkLength(about_inq, 0);
						bValid = bValid && checkLength(message_inq, 0);
					}
					
					
//					bValid = bValid && checkLength(from_mail,0);
//					bValid = bValid && checkLength(friend_name,0);
					//bValid = bValid && checkLength(email,0);
					//bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com");
					
					
			 $.ajax({
				   type: "POST",
				   url: my_url + "templates/captch_ajax.php",
				   data: "captcha_code="+ captchdata,
				   success: function(msg){

					if(msg=='1'){
						var imgnew = new Image();
						imgnew.src = my_url + 'templates/captcha.php?' + Date();
						document.getElementById(captchimd).src = imgnew.src;
						validcap = '0';
						$(captchelem).addClass('send_err_ui_c');
						$(captcherrelem).html('');
						$(captcherrelem).append('Моля, въведете кода!');
					}else if(msg=='0'){
						validcap = '1';
						$(captchelem).removeClass('send_err_ui_c');
						$(captcherrelem).html('');

						if (bValid) {
                                                    $("#reserve_package").serialize();
							var theofferid = window.offer_id;
							if(from=='rez'){
							
								 $.ajax({
									   type: "GET",
									   url: my_url + "templates/rezerv_ajax.php",
									   data: "full_name="+ full_name.val() + "&date_id="+ sel_date.val() + "&rooms="+ roomsid_rez.val() + "&adults="+ adultsid_rez.val() + "&adults2="+ adultsid_rez2.val() + "&adults3="+ adultsid_rez3.val()  + "&childs="+ childsid_rez.val() + "&childs2=" + childsid_rez2.val() + "&childs3=" + childsid_rez3.val() + "&message="+ message.val()+ "&email="+ email.val() +"&id="+ theofferid  +"&phone="+ phone.val() + "&chld[]=" + chld_1.val() + "&chld[]=" + chld_2.val() + "&chld[]=" + chld_3.val() + "&chld[]=" + chld_4.val() + "&chld[]=" + chld_5.val() + "&chld[]=" + chld_6.val() + "&chld[]=" + chld_7.val() + "&chld[]=" + chld_8.val() + "&chld[]=" + chld_9.val() + "&chld[]=" + chld_10.val() + "&chld[]=" + chld_11.val() + "&chld[]=" + chld_12.val() + "&h_id=" + hotel_name.val() + "&type=" + from,
									   success: function(msg){
										   $('.sendcvform').hide();
										   $('#success').show();
										   setTimeout(function(){$('.dialog').dialog('close');},2000);
										  
									   }
									});
							} else if( from=='tour' ) {
								 $.ajax({
									   type: "GET",
									   url: my_url + "templates/ajax_tour_rez.php",
									   data: "full_name="+ full_name.val() + "&date_id="+ sel_date.val() + "&adults="+ adultsid_rez.val() + "&adults2="+ adultsid_rez2.val() + "&adults3="+ adultsid_rez3.val()  + "&childs="+ childsid_rez.val() + "&childs2=" + childsid_rez2.val() + "&childs3=" + childsid_rez3.val() + "&message="+ message.val()+ "&email="+ email.val() +"&id="+ theofferid  +"&phone="+ phone.val() + "&chld[]=" + chld_1.val() + "&chld[]=" + chld_2.val() + "&chld[]=" + chld_3.val() + "&chld[]=" + chld_4.val() + "&chld[]=" + chld_5.val() + "&chld[]=" + chld_6.val() + "&chld[]=" + chld_7.val() + "&chld[]=" + chld_8.val() + "&chld[]=" + chld_9.val() + "&chld[]=" + chld_10.val() + "&chld[]=" + chld_11.val() + "&chld[]=" + chld_12.val() + "&type=" + from,
									   success: function(msg){
										   $('.sendcvform').hide();
										   $('#success').show();
										   setTimeout(function(){$('.dialog').dialog('close');},2000);
										  
									   }
									});
							} else if(from=='hotel'){
							
								var date1 = calendarrez_1.val();
								var date2 = calendarrez_2.val();
								date1 = date1.toString();
								date2 = date2.toString();
							
								 $.ajax({
									   type: "GET",
									   url: my_url + "templates/ajax_hotel_rez.php",
									   data: "full_name="+ full_name.val() + "&calendarrez_1="+ date1 + "&calendarrez_2="+ date2 + "&rooms="+ roomsid_rez.val() + "&adults="+ adultsid_rez.val() + "&adults2="+ adultsid_rez2.val() + "&adults3="+ adultsid_rez3.val() + "&childs="+ childsid_rez.val()+ "&message="+ message.val()+ "&email="+ email.val() +"&id="+ theofferid  +"&phone="+ phone.val() + "&type=" + from + "&childs2=" + childsid_rez2.val() + "&childs3=" + childsid_rez3.val() + "&chld[]=" + chld_1.val() + "&chld[]=" + chld_2.val() + "&chld[]=" + chld_3.val() + "&chld[]=" + chld_4.val() + "&chld[]=" + chld_5.val() + "&chld[]=" + chld_6.val() + "&chld[]=" + chld_7.val() + "&chld[]=" + chld_8.val() + "&chld[]=" + chld_9.val() + "&chld[]=" + chld_10.val() + "&chld[]=" + chld_11.val() + "&chld[]=" + chld_12.val() + "&h_id=" + h_id.val(),
									   success: function(msg){
										   $('.sendcvform').hide();
										   $('#success').show();
										   setTimeout(function(){$('.dialog').dialog('close');},2000);
									   }
									});
							} else if( from == 'calc' ) {
							
								rooms = $("#frm_num_rooms");
								adultsid_rez = $("#frm_num_adults1");
								adultsid_rez2 = $("#frm_num_adults2");
								adultsid_rez3 = $("#frm_num_adults3");
								childsid_rez = $("#frm_num_childs1");
								childsid_rez2 = $("#frm_num_childs2");
								childsid_rez3 = $("#frm_num_childs3");
								childs1 = $("#frm_childs1");
								childs2 = $("#frm_childs2");
								childs3 = $("#frm_childs3");
								transport_id = $("#frm_transp_id");
								date_id = $("#frm_opid"); // op = offer_prices
								date = $("#date");
								date2 = $("#date2");
								phone = $("#phone_calc");
								email = $("#email_calc");
								room_info1 = $("#room_info1");
								room_info2 = $("#room_info2");
								room_info3 = $("#room_info3");
							
								 $.ajax({
									   type: "GET",
									   url: my_url + "templates/ajax_calc_rez.php",
									   data: "full_name="+ full_name.val() + "&date_id="+ date_id.val() + "&date="+ date.val() + "&date2="+ date2.val() + "&rooms="+ rooms.val() + "&adults="+ adultsid_rez.val() + "&adults2="+ adultsid_rez2.val() + "&adults3="+ adultsid_rez3.val()  + "&childs="+ childsid_rez.val() + "&childs2=" + childsid_rez2.val() + "&childs3=" + childsid_rez3.val() + "&message="+ message.val()+ "&email="+ email.val() +"&id="+ theofferid  +"&phone="+ phone.val() + "&transport_id=" + transport_id.val() + "&childsy1=" + childs1.val() + "&childsy2=" + childs2.val() + "&childsy3=" + childs3.val() + "&type=" + from + "&room_info1=" + room_info1.val() + "&room_info2=" + room_info2.val() + "&room_info3=" + room_info3.val(),
									   success: function(msg){
										   $('.sendcvform').hide();
										   $('#success').show();
										   setTimeout(function(){$('.dialog').dialog('close');},2000);
										  
									   }
									});
							} else if(from=='inq'){
								$.ajax({
									   type: "POST",
									   url: my_url + "templates/dial_frm_submit.php",
									   data: "full_name_inq="+ full_name_inq.val() + "&phone_inq="+ phone_inq.val() + "&email_inq="+ email_inq.val() + "&about_inq="+ about_inq.val() + "&message_inq="+ message_inq.val(),
									   success: function(msg){
										   //alert(msg);
										  $('.sendcvform_inq').hide();
										   $('#success_inq').show();
										  setTimeout(function(){$('.dialog_inq').dialog('close');},2000);
										 if(($('#selectnum_childs2').html()!=null || $('#selectnum_childs2').html()!='0') && $('#selectnum_childs2').html()>'2'){
														$('#selectnum_childs2').html('0');
														$('#childsid2').val('0');
														$('option:selected', '#num_childs2').removeAttr('selected');
														
														
											}
											if(($('#selectnum_childs').html()!=null || $('#selectnum_childs').html()!='0') && $('#selectnum_childs').html()>'2'){
													$('#selectnum_childs').html('0');
													$('#childsid').val('0');
													$('option:selected', '#num_childs').removeAttr('selected');
													$("#ch_r").remove();
											}
											if(($('#selectnum_childs3').html()!=null || $('#selectnum_childs3').html()!='0') && $('#selectnum_childs3').html()>'2'){
													$('#selectnum_childs3').html('0');
													$('#childsid3').val('0');
													$('option:selected', '#num_childs3').removeAttr('selected');
												
											}
									  
									   }
									});
								
							}
								
						} else {							
							$('div[role="dialog"]').each(function() {
								if( $(this).css('display') == 'block' ) {
									var top = parseInt($(this).css('top'));
								}
							});
							// I'll try it again later ;(
							//$("body").scrollTop(top);
							//$("body").attr({ scrollTop: top });
						}
					}
				   }
				});
			// alert(validcap);
		
		}
		$(".dialog_video").dialog({
			resizable: false,			
					bgiframe: true,
					autoOpen: false,
					width:670,
					height: 490,
					zIndex: 6999,
					modal: true

			
			
		});
		$(".dialog").dialog({
					resizable: false,			
					bgiframe: true,
					autoOpen: false,
					width:308,
					height: 800,
					zIndex: 6999,
					modal: true,

			close: function() {
				allFields.val('').removeClass('send_err_ui');
				allFields.val('').removeClass('send_err_ui_date');
				allFields.val('').removeClass('send_err_ui_c');
				$("#nameerr").html('');
				$("#phoneerr").html('');
				$("#captcherror").html('');
				$("#roomsid_rez").val('');
				$("#childsid_rez").val('');
				$("#adultsid_rez").val('');
				//alert($("#selectnum_rooms_rez").html());
				$("#selectnum_rooms_rez").remove();
				$("#selectnum_adults_rez").remove();
				$("#selectnum_childs_rez").remove();
				Custom.clear;
				//alert($("#roomsid_rez").val());
				//$("#selectnum_rooms_rez").html('1');
//				$("#selectnum_childs_rez").html('1');
			}
		});
		
		$(".dialog_inq").dialog({
					resizable: false,			
					bgiframe: true,
					autoOpen: false,
					width:308,
					height: 800,
					zIndex: 6999,
					modal: true,

			close: function() {
				allFields.val('').removeClass('send_err_ui');
				allFields.val('').removeClass('send_err_ui_mess');
				allFields.val('').removeClass('send_err_ui_c');
				$("#captcherror_inq").html('');
				$("#full_name_inq").val('');
				$("#phone_inq").val('');
				$("#email_inq").val('');
				$("#about_inq").val('');
				$("#message_inq").val('');
				
				if(($('#selectnum_childs2').html()!=null || $('#selectnum_childs2').html()!='0') && $('#selectnum_childs2').html()>'2'){
							$('#selectnum_childs2').html('0');
							$('#childsid2').val('0');
							$('option:selected', '#num_childs2').removeAttr('selected');
							
							
				}
				//alert($('#selectnum_childs').html());
				if(($('#selectnum_childs').html()!=null || $('#selectnum_childs').html()!='0') && $('#selectnum_childs').html()>'2'){
						$('#selectnum_childs').html('0');
						$('#childsid').val('0');
						$('option:selected', '#num_childs').removeAttr('selected');
						$("#ch_r").remove();
				}
				if(($('#selectnum_childs3').html()!=null || $('#selectnum_childs3').html()!='0') && $('#selectnum_childs3').html()>'2'){
						$('#selectnum_childs3').html('0');
						$('#childsid3').val('0');
						$('option:selected', '#num_childs3').removeAttr('selected');
					
				}
			}
		});
		 var ButtonText = "";
		 var Button = "";
		 var buttons = {};
		 
		 
		//$(".dialog").parent().scrollFollow({speed: 10}); 
		$(".dialog_inq").parent().scrollFollow({speed: 10}); 
		$(".dialog_video").parent().scrollFollow({speed: 10}); 
		 $('#send').click(function() {
			var role = $(this).attr('role');
			checkCaptch(role);
		});
		 $('#close').click(function() {

				$('.dialog').dialog('close');
		});
		 $('#send_inq').click(function() {
					checkCaptch('inq');
								
		});
		$('#close_inq').click(function() {
									  
				
				$('.dialog_inq').dialog('close');
				
		});

		
		

});


function dialog_open(from, id){
	
					if(from!='video'){
					if(id=='0'){
						var imgnew = new Image();
						imgnew.src = my_url + 'templates/captcha.php?' + Date();
						document.getElementById('cpt_img_inq').src = imgnew.src;
						window.offer_id = id;
						$('.sendcvform_inq').show();
						$('#success_inq').hide();
						//alert($("#selectnum_childs2").html());
						if(($("#selectnum_childs3").html()=='0' || $("#selectnum_childs3").html()>'2' || $("#selectnum_childs3").html()==null) && ($("#selectnum_childs2").html()=='0' || $("#selectnum_childs2").html()>'2' || $("#selectnum_childs2").html()==null) && ($("#selectnum_childs").html()=='0' || $("#selectnum_childs").html()>'2' || $("#selectnum_childs").html()==null)){
							
							$('#alertage').hide();
							$("#calculchilds_js").html('');
						}
						if(($('#selectnum_childs').html()!=null || $('#selectnum_childs').html()!='0') && $('#selectnum_childs').html()>'2'){
							
							$("#ch_r").remove();
						}
						if(($('#selectnum_childs2').html()!=null || $('#selectnum_childs2').html()!='0') && $('#selectnum_childs2').html()>'2'){
							
							$("#ch_r_2").remove();
						}
						if(($('#selectnum_childs3').html()!=null || $('#selectnum_childs3').html()!='0') && $('#selectnum_childs3').html()>'2'){
							
							$("#ch_r_3").remove();
						}
						
						
						$('.dialog_inq').dialog('open');
						
					}else{
						var imgnew = new Image();
						imgnew.src = my_url + 'templates/captcha.php?' + Date();
						document.getElementById('cpt_img').src = imgnew.src;
		
						
						window.offer_id = id;
						$('.sendcvform').show();
						$('#success').hide();
						$( "#calendarrez_1" ).datepicker({
							changeMonth: true,
							changeYear: true,
							dateFormat: 'dd-mm-yy',
							showAnim: 'slideDown',
							onClose: function() {
								$(this).blur();
							}
						});
						$( "#calendarrez_2" ).datepicker({
							changeMonth: true,
							changeYear: true,
							dateFormat: 'dd-mm-yy',
							showAnim: 'slideDown',
							onClose: function() {
								$(this).blur();
							}
						});
						//alert($("#adultsid_rez").val());
						Custom.init();
						//$('#rezerv').val('1');
						//$(this).addClass("ui-state-default_active"); 
	
					$('.ui-dialog').css('background-image', 'url(' + my_url + 'im/rezerv_top.png)');
					$('.dialog').dialog('open');	
					}
				}else{
					//$('.dialog_video_' + id).dialog('open');
					//$('.dialog').html('');
					$('.ui-dialog').css('background-image', 'url(' + my_url + 'im/rezerv_top_video.png)');
					 $.ajax({
					   type: "POST",
					   url: my_url + "templates/video_ajax.php",
					   data: "id="+ id,
					   success: function(msg){
							$('.dialog_video').dialog('open');
							$('.dialog_video').html(msg);
							$(".dialog_video").data("width.dialog", 670);
							$(".dialog_video").data("height.dialog", 490);
							$('#close_video').click(function() {
								$('.dialog_video').dialog('close');
							});
					   }
					})
				}
				
}

function dialog_load_hotels(sel_val) {
	 $.ajax({
	   type: "POST",
	   url: my_url + "templates/ajax_load_hotels.php",
	   data: "date_id=" + sel_val,
	   success: function(msg){
			$('#selecthotel_name').html('-');
			$('#hotel_name').html(msg);
	   }
	})
}
/*DIALOG
*/
