function Validate()
{   
   var flag = true;
   var d = new Date();
   var year = d.getFullYear(); 
   var category = $("#selCategory").val();   
   if($("#selCategory").val() == '' || $("#selCategory").val()== null)
   {
   	
       $("#selCategoryError").html('Please select category'); 
       flag = false;
   }
   else
   {
       $("#selCategoryError").html(''); 
   }
   
   var subcat    = $("#selSubCategory"+category).val();
   var txtsubcat = $("#txtSubCategory").val();
   
   if((subcat == '' || subcat == null) && (txtsubcat == '' || txtsubcat == null))
   {       
       $("#selSubCategoryError").html('Please select sub-category');
       $("#selItemError").html(''); 
       flag = false; 
   }
   else
   {
       $("#selSubCategoryError").html(''); 
   }
  
   var item    = '';
   var txtitem = '';
  
   if((subcat != '' && subcat != null) || (txtsubcat != '' && txtsubcat != null))
   { 
	   item    = $('#selItem'+subcat).val();
	   txtitem = $('#txtItem').val();
	   
	   if((item == '' || item == null) && (txtitem == '' || txtitem == null))
	   {
	       $("#selItemError").html('Please select item');
	       $("#txtlItemError").html('Please enter item');
	       flag = false; 
	   } 
	   else
	   {
	       $("#selItemError").html(''); 
	       $("#txtlItemError").html('');
	   } 
   }
       
   if(trim($("#txtTitle").val()) == '')
   {
       $("#txtTitle").focus();
       $("#txtTitleError").html('Please enter the item title');
       flag = false; 
   }
   else if(!splCharacterValidation($("#txtTitle").val()))
   {
   	   $("#txtTitle").focus();
   	   $("#txtTitleError").html('Special characters not allowed');
       flag = false; 
   } 
   else
   {
       $("#txtTitleError").html(''); 
   } 
   
  /* if(trim($("#txtDetails").val()) == '')
   {
       $("#txtDetailsError").html('Please enter the description');
       flag = false;
   } 
   else
   {
       $("#txtDetailsError").html(''); 
   } */
   
   if(trim($("#txtImage").val()) != '')
   {
        fieldValue = trim($("#txtImage").val());
        fileTypes  = ['.jpg', '.gif', '.png', '.jpeg'];
        dots       = fieldValue.split(".")
        
        //get the part AFTER the LAST period.
        fileType = "." + dots[dots.length-1];
        fileType = fileType.toLowerCase();
   
        if(fieldValue == '')
        {
            $("#imageError").html("Please select image");
            flag = false;
        }
        else if(fileType != ".jpg" && fileType != ".gif" && fileType != ".png" && fileType != ".jpeg")
        {
            $("#imageError").html('Please upload valid type files');
            flag = false;
            
        }
        else
        {
            $("#imageError").html('');
        }
   	
   }
         
  /* if(trim($("#txtDeposit").val()) == '' || trim($("#txtDeposit").val()) == 0 )
   {
       $("#txtDepositError").html('Please enter the deposit amount');
       flag = false;
   }    */ 
   if(isNaN($("#txtDeposit").val()))
   {
      $("#txtDepositError").html('Please enter the valid deposit amount');
      flag = false;
   }  
   else
   {
      $("#txtDepositError").html('');       
   } 
   
  /*if(trim($("#txtRent").val()) == '' || trim($("#txtRent").val()) == 0 )
   {
       $("#txtRentError").html('Please enter the rental amount');
       flag = false;
   }*/     
   if(trim($("#txtRent").val()) != '')
   {
	   if(isNaN($("#txtRent").val()))
	   {
	      $("#txtRentError").html('Please enter the valid rental amount');
	      flag = false;
	   } 
	   else
	   {
	      $("#txtRentError").html('');       
	   } 
   }
   
   if(trim($("#txtApprox").val()) != '' || trim($("#txtApprox").val()) != 0 )
   {
	   if(isNaN($("#txtApprox").val()))
	   {
	      $("#txtApproxError").html('Please enter the valid approx. amount');
	      flag = false;
	   } 
	   else
	   {
	      $("#txtApproxError").html('');       
	   } 
   }	   
    
  /* if(parseFloat($("#txtRent").val()) >= parseFloat($("#txtDeposit").val()))
   {
   	  $("#txtRentError").html('Rental amount should be less than the deposit amount.');
      flag = false;
   }
   else
   {
      $("#txtDepositError").html('');       
   } */
   
   if(flag == false)
   {
       $("#selCategory").focus();       
   }
   else
   {       
       flag = true;       
   }

   return flag;

}

function Validate_AddNewWish()
{   
   var flag = true;
   
   var d = new Date();
   var year = d.getFullYear();
   
   $('#selSubCategoryError').hide();
   $('#selItemError').hide();
   $("#txtItemError").hide();
   $("#txtSubCategoryError").hide();
   
   var category = $("#selCategory").val();   
   if($("#selCategory").val() == '' || $("#selCategory").val()== null)
   {   
       $("#selCategoryError").html('Please select category'); 
       flag = false;
   }
   else
   {
       $("#selCategoryError").html(''); 
   }
   
   var subcat    = $("#selSubCategory"+category).val();
   var txtsubcat = $("#txtSubCategory").val();
   
   if((subcat == '' || subcat == null) && (txtsubcat == '' || txtsubcat == null))
   {       
       $("#selSubCategoryError").html('Please select sub-category');
       $("#txtSubCategoryError").html('Please enter sub-category');
       $("#txtItemError").html('Please enter item');
       $('#selSubCategoryError').show();
       $("#txtItemError").show();
       $("#txtSubCategoryError").show();
       $("#selItemError").html(''); 
       flag = false; 
   }
   else
   {
       $("#selSubCategoryError").html(''); 
   }
  
   var item    = '';
   var txtitem = '';
  
   if((subcat != '' && subcat != null) || (txtsubcat != '' && txtsubcat != null))
   { 
	   item    = $('#selItem'+subcat).val();
	   txtitem = $('#txtItem').val();
	   
	   if((item == '' || item == null) && (txtitem == '' || txtitem == null))
	   {
	   	
		   /* if (txtsubcat == '')
		   {*/
			   $("#selItemError").html('Please select item');
		  /* }
	       $("#txtItemError").html('Please enter item');*/
	       $('#selItemError').show();
	       $("#txtItemError").show();
	       flag = false; 
	   } 
	   else
	   {
	       $("#selItemError").html(''); 
	       $("#txtlItemError").html('');
	   } 
   }

   if($("#txtTitle").val() == '' || $("#txtTitle").val() == "Specific Name, Brand, Size..")
   {
       $("#txtTitle").focus();
       $("#txtTitleError").html('Please enter the item title');
       flag = false; 
   }
   else if(!splCharacterValidation($("#txtTitle").val()))
   {
       $("#txtTitle").focus();
       $("#txtTitleError").html('Special characters not allowed');
       flag = false; 
   } 
   else
   {
       $("#txtTitleError").html(''); 
   } 
   
   if(flag == false)
   {
       $("#selCategory").focus();       
   }
   else
   {       
       flag = true;       
   }

   return flag;

}

function trim(stringToTrim) 
{
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}
 
function splCharacterValidation(val)
{
    var flag1 = 0;  
    //var iChars = "*|,\":<>[]{}=_!^+?`\;()@$#%";
    var iChars = "%<>";
     for(var i = 0; i < val.length; i++) 
     {
        if(iChars.indexOf(val.charAt(i)) != -1)
        {
            flag1 = 1;
        }
     }
     
     if (flag1 == 0)
        return true;
     else
        return false;
}
    

function checkAreaCode(code)
{
    if(code.length > 3 || isNaN(code))
    {
        return false;        
    }    
    else
    {
        return true;
    } 
}


