//<!---------------------------------+
//  Check_Title Script
//  Date : 19.03.09
//  Created by: Sheik
// --------------------------------->

$(document).ready(function()
{
	$("#title").blur(function()
	{
		
	title=$("#title").val();
	sid=$('#sub_topic_select').val();
	mid=$('#maintopicid_add').val();
	
	if(mid == "")
	{
		mid=$('#maintopicid_edit').val();
	}
	

		//remove all the class add the messagebox classes and start fading
		if(title!= "" && title!='Enter Title...')
		{
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		
		url="classes/title_availability.php?mid="+mid+"&sid="+sid+"&tit="+title;
		//alert(url);
		//check the username exists or not from ajax
		$.post(url,{ title:$(this).val() } ,function(data)
		 {
		data=trim(data);
       	  if(data=='no') //if username not avaiable
		  {
			  document.getElementById('exists').value='1';
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('This Title Already exists').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  else
		  {
			  document.getElementById('exists').value='0';
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<img src="../images/accept.png" style="vertical-align:text-bottom;"/>Valid Title').addClass('messageboxok').fadeTo(900,1);	
			});
		  }
				
        });
 			 }else {document.getElementById("msgbox").style.display='none';document.getElementById('exists').value='0';}
	});
});
