jQuery.fn.validate = function() {
	var val=this;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		val.submit(function(){
			var i=0;
			$('.error_string').hide();
			$v=val.find('.required');//alert($v);
			$v.each(function(){
				$t=$(this);
				$name=$t.attr('title');
				$left=($t.offset().left+$t.width()+20)+'px';
				$top=($t.offset().top)+'px';
				if($t.attr('type')=='checkbox') {
						if($t.attr('checked')==false){
						i++;
						$('body').append('<div class=error_string style="left:'+$left+';top:'+$top+';">'+$name+' should be checked</div>');
						}
				}
				else if($t.val()==''){
						i++;
						$('body').append('<div id="comment_id" class=error_string style="left:'+$left+';top:'+$top+';">'+$name+' can\'t be empty</div>');
					}
				else if($t.attr('type')=='radio'){
					if($t.attr('checked')==false){
					i++;
						$('body').append('<div id="comment_id" class=error_string style="left:'+$left+';top:'+$top+';">Select '+$name+' option</div>');
					}
				}
			});
			$v=val.find('.email');
			$v.each(function(){
				$t=$(this);
				$name=$t.attr('title'); 
				$left=($t.offset().left+$t.width()+20)+'px';
				$top=($t.offset().top)+'px';
				if($t.val()=='') {
					i++;
					$('body').append('<div class=error_string style="left:'+$left+';top:'+$top+';">'+$name+' can\'t be empty</div>');
				}
				else if(reg.test($t.val()) == false) {
					i++;
					$('body').append('<div class=error_string style="left:'+$left+';top:'+$top+';">'+$name+' is not a valid email</div>');
				}
			});
			if(i==0)
			{
			$origin=$('#origin').val();
			$destination=$('#destination').val();
			$origin1=$('#origin1').val();
			$destination1=$('#destination1').val();	
				if($origin!=null || $origin1!=null){
					if(($destination==$origin) || (($destination1==$origin1) && ($destination1!='' || $origin1!='')))
				{
					alert("Source and Destination field can not be same");
					return false;
				}
				else
					return true;
				}
			}
			else{
				 return false;
				 					 
			}
		});
		$('input,select,img').click(function(){
			$k=$('.error_string').length;
			for($i=0;$i<$k;$i++)
			{
				$('.error_string').remove();
			}
		});
};
