$(document).ready(function(){
//global vars
	var propertyform = $("#propertyform");
	var proprty_name = $("#proprty_name");
	var category = $("#category");
	var proprty_desc = $("#proprty_desc");
	
	var proprty_name_span = $("#proprty_name_span");
	var proprty_desc_span = $("#proprty_desc_span");
	var category_span = $("#category_span");

//On blur
	proprty_name.blur(validate_proprty_name);
	proprty_desc.blur(validate_proprty_desc);
	category.blur(validate_category);

//On key press
	proprty_name.keyup(validate_proprty_name);
	category.keyup(validate_category);
//On Submitting
	propertyform.submit(function(){
		if(validate_proprty_name() & validate_proprty_desc() & validate_category())
			return true
		else
			return false;
	});

//validation functions
	function validate_proprty_name()
	{
		if($("#proprty_name").val() == '')
		{
			proprty_name.addClass("error");
			proprty_name_span.text("Please Enter Title");
			proprty_name_span.addClass("message_error2");
			return false;
		}
		else{
			proprty_name.removeClass("error");
			proprty_name_span.text("");
			proprty_name_span.removeClass("message_error2");
			return true;
		}
	}
	
	function validate_proprty_desc()
	{
		if($("#proprty_desc").val() == '')
		{
			proprty_desc.addClass("error");
			proprty_desc_span.text("Please Enter Description");
			proprty_desc_span.addClass("message_error2");
			return false;
		}
		else{
			proprty_desc.removeClass("error");
			proprty_desc_span.text("");
			proprty_desc_span.removeClass("message_error2");
			return true;
		}
	}
	
	function validate_category()
	{
		var chklength = document.getElementsByName("category[]").length;
		var flag      = false;
		var temp	  ='';
		for(i=1;i<=chklength;i++)
		{
		   temp = document.getElementById("category_"+i+"").checked; 
		   if(temp == true)
		   {
				flag = true;
				break;
			}
		}
		if(flag == false)
		{
			category_span.text("Please select Category");
			category_span.addClass("message_error2");
			return false;
		}
		else{			
			category_span.text("");
			category_span.removeClass("message_error2");
			return true;
		}
	}	

});