//onload calling of functions
$(document).ready(function() {

	$("#top_nav li").hover( 
		function(){
			
			$(this).find("ul").show();
			
		},
		
		function(){
			
			$(this).find("ul").hide();
			
		}
	);
	
	
	
		
});


function checkLogin(){
	user = $("#uname").val();
	pass = $("#upass").val();
	
	$("#mess").hide();
	
	if( user=='' || pass=='' ){
		$("#mess").show();
		$("#mess").html("Please complete username and passward.");
		return false;
	}
	
	return true;
}

function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function checkEmail(emial){
	var str=emial;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		return true;
	else
		return false;
}

function checkRequired(){
	
	document.getElementById('commess').style.display = 'none';
	
	var status = document.getElementById('loggedin').value;
	var comment = trim(document.getElementById('comment').value);
	
	if( status=='no' ){
		var name = trim(document.getElementById('author1').value);
		var email = trim(document.getElementById('email').value);
		
		if( name=='' || email=='' ){
			//alert('Please complete the required fields (Name, Email).');
			document.getElementById('commess').innerHTML = 'Please complete the required fields (Name, Email).';
			document.getElementById('commess').style.display = 'block';
			return false;
		}
		else if( comment=='' ){
			//alert('Please type a Comment.');
			document.getElementById('commess').innerHTML = 'Please type a Comment.';
			document.getElementById('commess').style.display = 'block';
			return false;
		}
		else if( !checkEmail(email) ){
			//alert('Please enter a valid email address.');
			document.getElementById('commess').innerHTML = 'Please enter a valid email address.';
			document.getElementById('commess').style.display = 'block';
			return false;
		}
	}
	else{
		if( comment=='' ){
			//alert('Please type a Comment.');
			document.getElementById('commess').innerHTML = 'Please type a Comment.';
			document.getElementById('commess').style.display = 'block';
			return false;
		}
	}
	
	
	return true;
	
}

