/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

// add page form
function change_region(){
	// selected value
	var selected = document.getElementById("PropertyCityId").value;
	
//	var sel_array = document.getElementById("SelectRegions");	
//	!$(sel_array).children('option:all').remove();
	
	// set loading image
	ajax_loading_image('.ajax_loading_image');
	// ajax
	$.ajax({
		type: "POST",
		url: '/properties/update_select',
		data: "ajax=true&id="+selected,
		success: function(msg){
		//	console.log(msg); 
		
			$('.ajax_page_id').html(msg);
			// remove loading image
			ajax_remove_loading_image('.ajax_loading_image');
		}
	});
}

function change_region_select(){
	// selected value
	var selected = document.getElementById("PropertyCityId").value;
	
//	var sel_array = document.getElementById("SelectRegions");	
//	!$(sel_array).children('option:all').remove();
	
	// set loading image
	ajax_loading_image('.ajax_loading_image');
	// ajax
	$.ajax({
		type: "POST",
		url: '/properties/update_select_div',
		data: "ajax=true&id="+selected,
		success: function(msg){
		//	console.log(msg); 
		
			$('.ajax_page_id').html(msg);
			// remove loading image
			ajax_remove_loading_image('.ajax_loading_image');
		}
	});
}
//});

function init_region(){
	// selected value
	 isloaded=true;
    var selected = document.getElementById("PropertyCityId").value;

	// set loading image
	ajax_loading_image('.ajax_loading_image');
	// ajax
	$.ajax({
		type: "POST",
		url: '/properties/update_select',
		data: "ajax=true&id="+selected,
		success: function(msg){
			//console.log(msg);
			$('.ajax_page_id').html(msg);
			// remove loading image
			ajax_remove_loading_image('.ajax_loading_image');
		}
	});
}

// set a loading image
function ajax_loading_image(div) {
	$(div).html('<img src="/img/ajax_loading.gif" alt="Ajax Loading Image"/>');
}

// remove loading image
function ajax_remove_loading_image(div) {
	$(div).html('');
}

function moveFromTo(fromId, toId) { 
	!$('#'+fromId).children('option:selected').remove().appendTo($('#'+toId)); 
}

function moveAll(fromId, toId) { 
	!$('#'+fromId).children('option:all').remove().appendTo($('#'+toId)); 
}

function clean(selectField){
	 var selected = document.getElementById(selectField);
	 selected.value ='';
}
 
function change_picture()
{
   var neshto = imageName;
   document.getElementById("bigImage").src = "/img/properties/big/4a61f60a-5a30-47e6-b488-11cc68b0cc67.jpg";
}

function showForm(){
	$("#contactForm").slideDown("slow");
//	document.getElementById("#contactForm").open;

}

function closeForm(){
    $("#contactForm").slideUp("slow");
}

function submitForm(){
    	var name = document.getElementById("name").value;
		var email = document.getElementById("Email").value;
		var phone = document.getElementById("Phone").value;
		var message = document.getElementById("Message").value;
		var mailTo = document.getElementById("mailTo").value;
		var currentUrl = document.location.href;
		var captcha = document.getElementById("security_code").value;

		
		$.ajax({
		type: "POST",
		url: '/properties/send_mail',
		data: "ajax=true&name="+name+"&email="+email+"&message="+message+"&mailTo="+mailTo+"&currentUrl="+currentUrl+"&captcha="+captcha+"&phone="+phone,
		success: function(msg){ 
		//	  $("#messageSent").show("slow");
  			 // setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
			 location.reload(true);
		}
	});
	
}

