function validateForm()
{
	
	var title = document.getElementById('bookTitle').value;
	if(Trim(title) == "")
	{
		alert("Please specify title of book.");
		document.getElementById('bookTitle').focus();
		return false;
	}

	var basicDescription = document.getElementById('basicDescription').value;
	if(Trim(basicDescription) == "")
	{
		alert("Please specify basic description of book.");
		document.getElementById('basicDescription').focus();
		return false;
	}

	var fullDescription = document.getElementById('fullDescription').value;
	if(Trim(fullDescription) == "")
	{
		alert("Please specify full description of book.");
		document.getElementById('fullDescription').focus();
		return false;
	}

	var imagePrefilled = document.getElementById('imageName').value;

	var image = document.getElementById('image').value;
	if(imagePrefilled == "" )
	{
		if(Trim(image) == "")
		{
			alert("Please specify cover image of book.");
			//document.getElementById('fullDescription').focus();
			return false;
		}
	}
	
	if(image != "")
	{	
		document.getElementById('imageName').value ='';
		arrExt = image.split(".");

		if(arrExt.length >1)
		{
			ext = arrExt[1].toLowerCase();
			
			if(ext !="jpg" && ext !="gif" && ext !="jpeg" ) {
				alert("Please upload an image with JPG or GIF extensions only.");
				return false;
			}
		}
		else
		{
			alert("Please specify valid image path.");
			return false;
		}
	}
	if(!isCategorySelected())
	{
		alert("Please select atleast one category.");
		return false;
	}

	var publishStartDate = document.getElementById('publishStartDate').value;
	if(Trim(publishStartDate) == "")
	{
		alert("Please specify start date for book display.");
		//document.getElementById('publishStartDate').focus();
		return false;
	}
/*
	var publishEndDate = document.getElementById('publishEndDate').value;
	if(Trim(publishEndDate) == "")
	{
		alert("Please specify end date for book display.");
		//document.getElementById('publishStartDate').focus();
		return false;
	}
*/
	return true;
}

function confirmDelete(id,imageName)
 {
	 if(confirm("Are you sure, you want to delete this booking?"))
	 {
		window.location="index.php?module=application&action=bookSumm&mode=del&img="+imageName+"&delId="+id;
		return true;
	 }
	 else
		 return false;
 }
 
 
function isCategorySelected()
{
	var length=document.frmApplication['category[]'].length;
	for(i = 0 ; i < length ; i ++)
	{
		if(document.frmApplication['category[]'][i].checked == true )
			return true;
	}
	return false;

}

function checkMaxLimit(field,maxlimit)
{
	 var fieldValue	=	Trim(field.value);
	
	 var arrWord	=	fieldValue.split(/\s+/); // split the sentence into an array of words
	 var fieldLength = arrWord.length;

	
	
	if (fieldLength > maxlimit) // if too long...trim it!
	{
		
		var a		=	fieldValue.length;
		var newArr	=	arrWord.slice(0,maxlimit);
		
		field.value =	newArr.join(' ');
		//alert(field.value);
		
	}
	
}

function cancelForm()
{
	if(document.getElementById('refNo').value == '' )
		window.location =	'index.php';
	else
		window.location	=	'index.php?module=application&action=bookSumm';
}
function Trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
