//handle the Ajax response ...
/*function handleResponse(transport)
{
   $('hello').innerHTML = transport.responseText;
}

//creates a prototype Ajax object, sends a request, and registers the callback function 'handleResponse'
function callAjax(s) 
{
   var myAjax = new Ajax.Request('index/getdata', 
                                   {method: 'post', parameters: {state: s}, 
                                   onComplete: handleResponse});
}*/

function postcomments()
{
	var vlid='';
	//Returns true if a text input has contents, false otherwise.
								
	if(!Form.Element.present('commentPostedBy'))
	{
		$('cmtby').addClassName('errormessage').update('Name Must Required!');
		vlid='false';
	}else
	{
		$('cmtby').update('');
	}
	
	if(!Form.Element.present('commentAuthorEmail'))
	{
		$('memail').addClassName('errormessage').update('Email Must Required!');
		vlid='false';
		
	}else if (echeck(Form.Element.getValue('commentAuthorEmail'))==false){
		$('memail').addClassName('errormessage').update('Invalid E-mail ID!');
		vlid='false';
	}else
	{
		$('memail').update('');
	}
	
	if(!Form.Element.present('commentDescription'))
	{
		$('mcmt').addClassName('errormessage').update('Comment Must Required!');
		vlid='false';
	}else
	{
		$('mcmt').update('');
	}
	
	if(vlid=='false')
	{
		return false;
	}
	//alert($('jgcomment').serialize());										
	var mAjax = new Ajax.Request('jgcomment/postcomment', 
	                                   {method: 'post', parameters: $('jgcomment').serialize(), 
	                                   onComplete: handleResponse1});                      
}


function handleResponse1(transport)
{
	//$('ajaform').innerHTML =transport.responseText;
	//alert(transport.responseText);
	if(transport.responseText=='success')
	{
		$('postsuccess').addClassName('sucess_msg').update('Your comment has been posted successfully, after approve the comment by admin, you will see your comment here!');
	}
	//clear the form elements
	Form.Element.clear('commentPostedBy');
	Form.Element.clear('commentAuthorEmail');
	Form.Element.clear('commentDescription');
	
	//it update the block content
	//var upt=new Ajax.Updater('comments', 'index/comments', { method: 'get' });	
	
}


function ajaxpage(page)
{
	//alert(page);
	var pyAjax = new Ajax.Request('jgcomment/comments', 
                                   {method: 'post', parameters: {state: page}, 
                                   onComplete: handleResponse2});
}

function handleResponse2(transport)
{
	$('comments').innerHTML = transport.responseText;
}

 // DHTML email validation script. 
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
 		 return true					
	}
//end of email validation
