$(document).ready(function() {
	$("#cmbPropertyGroup").change(function() {
		if(this.value!="")
		{
			$("#cmbPropertyType").append($("<option>Loading...</option>"));
			PropertyGroup = this.value;
			$("#hidPropertyGroup").val(PropertyGroup)
			ShowPropertyType(PropertyGroup);
		}
		else
		{
			$("#cmbPropertyType").html("");
			$("#cmbPropertyType").append($("<option></option>").val("").html("-- Select Property Type --"));
			$("#cmbPropertyType").attr("disabled","disabled");
		}
    });
	
	$("#cmbPropertyType").change(function() {
		if(this.value!="")
		{
			$("#divPropertyFeatures").html("");
			ShowPropertyFeatures(this.value);
		}
		else
		{
			$("#divPropertyFeatures").html("");
		}
    });
});
	
function ShowPropertyType(PropertyGroup)
{
/*	var temp = $.ajax({
        type: "POST",
        url: "URL.asmx/CheckIfInstanceIsInitilized",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {
                IsInitialized = result.d;
        },
        error: function(xmlHttpRequest, status, err) {
                alert(xmlHttpRequest.statusText + " " + xmlHttpRequest.status + " : " + xmlHttpRequest.responseText);
        }

    });*/

	$.ajax({
			type: "GET",
			url: "property_ajax.php",
			data: ({Action : 'ShowPropertyType', PropertyGroup: PropertyGroup}),
			async: false,
			dataType: "json",
			success: function(json) {
				var strOptions = '';
				for (var i = 0; i < json.length; i++) 
				{
			        strOptions += '<option value="' + json[i].optionValue + '">' + json[i].optionDisplay + '</option>';
				}
				$("#cmbPropertyType").removeAttr('disabled');
				$("#cmbPropertyType").html(strOptions);
			},
			error: function(xmlHttpRequest, status, err) {
				alert(xmlHttpRequest.statusText + " " + xmlHttpRequest.status + " : " + xmlHttpRequest.responseText);
			}
    });

/*	var PropertyType = $.ajax({
					  url: "property_ajax.php?Action=ShowPropertyType&PropertyGroup="+PropertyGroup,
					  async: false
					 }).responseText;
	$("#divPropertyType").html(PropertyType);*/
}

function ShowPropertyState(CountryID)
{
	$.ajax({
			type: "GET",
			url: "property_ajax.php",
			data: ({Action : 'ShowPropertyState', CountryID: CountryID}),
			async: false,
			dataType: "json",
			success: function(json) {
				var strOptions = '';
				for (var i = 0; i < json.length; i++) 
				{
			        strOptions += '<option value="' + json[i].optionValue + '">' + json[i].optionDisplay + '</option>';
				}
				$("#cmbPropertyState").removeAttr('disabled');
				$("#cmbPropertyState").html(strOptions);
				
				$("#cmbPropertyState").change(function() {
					if(this.value!="")
					{
						$("#cmbPropertyCity").append($("<option>Loading...</option>"));
						StateID = this.value;
						ShowPropertyCity(StateID);
					}
					else
					{
						$("#cmbPropertyCity").html("");
						$("#cmbPropertyCity").append($("<option value''>-- Select State --</option>"));
						$("#cmbPropertyCity").attr("disabled","disabled");
					}
				});
			},
			error: function(xmlHttpRequest, status, err) {
				alert(xmlHttpRequest.statusText + " " + xmlHttpRequest.status + " : " + xmlHttpRequest.responseText);
			}
    });
}

function ShowPropertyCity(StateID)
{
	$.ajax({
			type: "GET",
			url: "property_ajax.php",
			data: ({Action : 'ShowPropertyCity', StateID: StateID}),
			async: false,
			dataType: "json",
			success: function(json) {
				var strOptions = '';
				for (var i = 0; i < json.length; i++) 
				{
			        strOptions += '<option value="' + json[i].optionValue + '">' + json[i].optionDisplay + '</option>';
				}
				$("#cmbPropertyCity").removeAttr('disabled');
				$("#cmbPropertyCity").html(strOptions);
			},
			error: function(xmlHttpRequest, status, err) {
				alert(xmlHttpRequest.statusText + " " + xmlHttpRequest.status + " : " + xmlHttpRequest.responseText);
			}
    });
}

function ShowPropertyFeatures(PropertyType)
{
	var TransactionType = $("#cmbTransactionType").val();
	$.ajax({
			type: "GET",
			url: "property_ajax.php",
			data: ({Action : 'ShowPropertyFeatures', PropertyType: PropertyType, TransactionType: TransactionType}),
			async: false,
			dataType: "html",
			success: function(html) {				
				$("#divPropertyFeatures").html(html);
				
				$("#cmbPropertyCountry").change(function() {
					if(this.value!="")
					{
						$("#cmbPropertyState").append($("<option>Loading...</option>"));
						CountryID = this.value;
						ShowPropertyState(CountryID);
					}
					else
					{
						$("#cmbPropertyState").html("");
						$("#cmbPropertyState").append($("<option value''>-- Select State --</option>"));
						$("#cmbPropertyState").attr("disabled","disabled");
					}
				});
			},
			error: function(xmlHttpRequest, status, err) {
				alert(xmlHttpRequest.statusText + " " + xmlHttpRequest.status + " : " + xmlHttpRequest.responseText);
			}
    });
}

function toggleSpecification(val)
{
	if(val=='S')
	{
		$("#divSingleProperty").css("display", "block"); 
		$("#divMultipleProperty").css("display", "none"); 
	}
	else
	{
		$("#divMultipleProperty").css("display", "block");
		$("#divSingleProperty").css("display", "none"); 
	}
}

function toggleRentalIncome(isChecked)
{
	if(isChecked==true)
		$("#txtRentalIncome").css("display", "inline");
	else
		$("#txtRentalIncome").css("display", "none");
}