$(document).ready(function(){
						   
	//+++++++++++++++++++++++++++++++++++++++++ START : Login Check +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	$("#f_login").submit(function(){		
		var start_point=1;
		var obj=$(".login_dv tr:nth-child("+start_point+") td:nth-child(2) input");
		while(obj.attr("type")!="submit")
		{
			if(obj.val()==""){
				//alert("Please enter "+obj.closest("td").prev("td").html());	
				obj.after("<div class='err_msg'>Please enter "+obj.closest("td").prev("td").html()+"</div>");
				obj.focus();
				return false;
			}
			start_point++;
			obj=$(".login_dv tr:nth-child("+start_point+") td:nth-child(2) input");
		}
	});
	//+++++++++++++++++++++++++++++++++++++++++ END : Login Check +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
	//+++++++++++++++++++++++++++++++++++++++++ START : Admin Panel +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	$("#admin_panel a").hover(function(){
			$(this).closest("table").addClass("backchobi");
			//$(".master_tr table").not(".backchobi").fadeTo('slow', 0.5);
	},function(){
			$(this).closest("table").removeClass("backchobi");
			//$(".master_tr table").fadeTo("fast", 1.0);
	});
	
	$(".foldable span").click(function(){
			var part=$(this).attr("id").split("id_");
			if($(this).attr("class")=="effecton")
			{
				$(this).removeClass("effecton");
				$("."+part[1]+" table").fadeIn("slow");
			}
			else
			{
				$(this).addClass("effecton");
				$("."+part[1]+" table").fadeOut("slow");
			}
	})
	//+++++++++++++++++++++++++++++++++++++++++ END : Admin Panel +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
	//+++++++++++++++++++++++++++++++++++++++++ START : Grid Action +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	$(".grid").hover(function(){
	if($(this).find("td").attr("class")=="data_text")
	$(this).find("td").removeClass("data_text").addClass("data_text_over");
	else
	$(this).find("td").removeClass("data_text_1").addClass("data_text_over_1");
	
		},function(){
			if($(this).find("td").attr("class")=="data_text_over")
			$(this).find("td").removeClass("data_text_over").addClass("data_text");
			else
			$(this).find("td").removeClass("data_text_over_1").addClass("data_text_1");
	});

	//+++++++++++++++++++++++++++++++++++++++++ END   : Grid Action +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
	//+++++++++++++++++++++++++++++++++++++++++ START : Action Master Add +++++++++++++++++++++++++++++++++++++++++++++++++++++++
	$("#f_actionmasteradd").live('submit',function(){		
		var start_point=1;
		var obj=$(".actionadd_dv tr:nth-child("+start_point+") td:nth-child(4) *");
		while(obj.attr("type")!="submit")
		{
			if(obj.val()=="" && obj.closest("td").attr("class")!="nocheck"){
				var iddyn=obj.attr("id")+"_err";
				//alert("Please enter "+obj.closest("td").prev("td").prev("td").html());
				if($("#"+iddyn).attr("class")!="err_msg")
				{
					obj.after("<div id='"+iddyn+"' style='display:none' class='err_msg'>Please enter "+obj.closest("td").prev("td").prev("td").html()+"</div>");
					$(".err_msg").fadeIn("slow");
				}
				obj.focus();
				return false;
			}
			start_point++;
			obj=$(".actionadd_dv tr:nth-child("+start_point+") td:nth-child(4) *");
		}
	});
	//+++++++++++++++++++++++++++++++++++++++++ END : Action Master Add +++++++++++++++++++++++++++++++++++++++++++++++++++++++
		//+++++++++++++++++++++++++++++++++++++++++ START : Unit Master Add +++++++++++++++++++++++++++++++++++++++++++++++++++++++
	$("#f_unitmasteradd").live('submit',function(){		
		var start_point=1;
		var obj=$(".unitadd_dv tr:nth-child("+start_point+") td:nth-child(4) *");
		while(obj.attr("type")!="submit")
		{
			if(obj.val()=="" && obj.closest("td").attr("class")!="nocheck"){
				var iddyn=obj.attr("id")+"_err";
				//alert("Please enter "+obj.closest("td").prev("td").prev("td").html());
				if($("#"+iddyn).attr("class")!="err_msg")
				{
					obj.after("<div id='"+iddyn+"' style='display:none' class='err_msg'>Please enter "+obj.closest("td").prev("td").prev("td").html()+"</div>");
					$(".err_msg").fadeIn("slow");
				}
				obj.focus();
				return false;
			}
			start_point++;
			obj=$(".unitadd_dv tr:nth-child("+start_point+") td:nth-child(4) *");
		}
	});
	//+++++++++++++++++++++++++++++++++++++++++ END : Unit Master Add +++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
	//+++++++++++++++++++++++++++++++++++++++++ START : Property Master Add +++++++++++++++++++++++++++++++++++++++++++++++++++++++
	$("#f_propertymasteradd").live('submit',function(){		
		var start_point=1;
		var obj=$(".actionadd_dv tr:nth-child("+start_point+") td:nth-child(4) *");
		while(obj.attr("type")!="submit")
		{
			if(obj.val()=="" && obj.closest("td").attr("class")!="nocheck"){
				var iddyn=obj.attr("id")+"_err";
				//alert("Please enter "+obj.closest("td").prev("td").prev("td").html());
				if($("#"+iddyn).attr("class")!="err_msg")
				{
					obj.after("<div id='"+iddyn+"' style='display:none' class='err_msg'>Please enter "+obj.closest("td").prev("td").prev("td").html()+"</div>");
					$(".err_msg").fadeIn("slow");
				}
				obj.focus();
				return false;
			}
			start_point++;
			obj=$(".actionadd_dv tr:nth-child("+start_point+") td:nth-child(4) *");
		}
	});
	
	$("#location_type_id").change(function(){
		$.post("../process/createdropdown.php", { id_val: $(this).val(), def_id: "category_id", id: "property_type_id", table: "propertytypes", field: "type_name" },
		   function(data){
			 //alert("Data Loaded: " + data);
			 $("#property_type_id").closest("td").html(data);
		 });
	});
	
	
	$("#state_id").change(function(){
		$.post("../process/createdropdown.php", { id_val: $(this).val(), def_id: $(this).attr("id"), id: "city_id", table: "cities", field: "city_name" },
		   function(data){
			 //alert("Data Loaded: " + data);
			 $("#city_id").closest("td").html(data);
		 });
	});
	//+++++++++++++++++++++++++++++++++++++++++ END : Property Master Add +++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
	//+++++++++++++++++++++++++++++++++++++++++ START : Enquiry Master Search +++++++++++++++++++++++++++++++++++++++++++++++++++
	$("#f_srchenq").submit(function(){
		if($("#st_date").val()=="") {
			if($("#err_id_1").attr("class")!="err_msg") {
				$("#st_date").after("<div id='err_id_1' style='display:none' class='err_msg'>Enter Start Date</div>");
				$(".err_msg").fadeIn("slow");
			}
			$("#st_date").focus();
			return false;
		}
		if($("#end_date").val()=="") {
			if($("#err_id_2").attr("class")!="err_msg") {
				$("#end_date").after("<div id='err_id_2' style='display:none' class='err_msg'>Enter End Date</div>");
				$(".err_msg").fadeIn("slow");
			}
			$("#end_date").focus();
			return false;
		}
	});
	//+++++++++++++++++++++++++++++++++++++++++ END : Enquiry Master Search +++++++++++++++++++++++++++++++++++++++++++++++++++++
	//+++++++++++++++++++++++++++++++++++++++++ START : Property Master (Display)  ++++++++++++++++++++++++++++++++++++++++++++++
	$(".display_flag_class").click(function(){
			//$(this).attr('checked', false);
			var ids=$(this).attr("id");
			var part=ids.split("_");
			var flag=($(this).is(':checked'))?('1'):('0');
			//alert(flag);
			$.post("../process/displaydefaultset.php", { id: part[1], display_status:flag }, function(data){
				//alert(data);
				var part_res=data.split("__");
				if(parseInt(part_res[1])==1) return true;
				else if(parseInt(part_res[1])==2) { $("#"+ids).attr('checked', false); alert("Already four property assigned"); }
				else $("#"+ids).attr('checked', false);
		    });
	});
	//+++++++++++++++++++++++++++++++++++++++++ End : Property Master (Display)  ++++++++++++++++++++++++++++++++++++++++++++++
	
	$(".checksurity").live('click',function(){
			if(confirm('Sure you want to delete?')) return true;
			else return false
	})

//+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_ CUSTOMER FORM _+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+
	
	//+++++++++++++++++++++++++++++++++++++++++ START : Enquery Form  ++++++++++++++++++++++++++++++++++++++++++++++
	$("#enquiry_type").live("click",function(){
			var buyer=$("#buyer_form").html();
			var saler=$("#saler_form").html();
			$("#buyer_form").html(saler);
			$("#saler_form").html(buyer);
	});
	
	$(window).load(function(){
		if(parseInt($("#enquiry_flag_box").val())==1){ return true; }
		else {
			//$("#enquiry_type[:value=2]").attr('checked',true);
			var presetValue = 2;
			$("[name=enquiry_type]").filter("[value="+presetValue+"]").attr("checked",true);

			var buyer=$("#buyer_form").html();
			var saler=$("#saler_form").html();
			$("#buyer_form").html(saler);
			$("#saler_form").html(buyer);
		}
	});
	//+++++++++++++++++++++++++++++++++++++++++ End : Enquery Form  ++++++++++++++++++++++++++++++++++++++++++++++++
	
});
