var cntCommentPlace; 
var cntStatVoteNo;
var cntBorderControl;
var cntStatResult;
var cntErrorPlace;
//var cntStatus; //test
var AjaxCommentObject = {      
     handleSuccess:function(o){            
         this.processResult(o);            
     },   
   
     handleFailure:function(o){            
         document.getElementById(cntStatResult).innerHTML= o.status + " " + o.statusText;   
     },   
   
     processResult:function(o){      
		//document.getElementById(cntStatus).style.display='none';	
			var rootComment = o.responseXML.documentElement;                            
			var oComment = rootComment.getElementsByTagName('comments')[0].firstChild.nodeValue;   
			document.getElementById(cntCommentPlace).style.color='#ffffff';
			document.getElementById(cntCommentPlace).display='block';
			document.getElementById(cntCommentPlace).innerHTML='';
			document.getElementById(cntCommentPlace).innerHTML=oComment ;						
			
			var fontAnim = new YAHOO.util.ColorAnim(cntCommentPlace, { color: { to: '#333333' } });  			
			fontAnim.animate();							   
     }   
     ,   
   
     startRequest:function(){            
     }
           
 };   
   
 var callbackComment =   
 {   
     success:AjaxCommentObject.handleSuccess,   
     failure:AjaxCommentObject.handleFailure,   
     scope: AjaxCommentObject   
 };   
   
 
 
 function display_comments(DealID, CommentPlace)
{

	cntCommentPlace=CommentPlace;		
	document.getElementById(cntCommentPlace).innerHTML='<img src=images/ajax-l.gif style=padding:5px>';	
	var transaction = YAHOO.util.Connect.asyncRequest('GET', 'util_getcomments.aspx?pid=' + DealID + '&ctr=' + CommentPlace, callbackComment); 
 
 }
 
 
 
 var AjaxAddCommentObject = {      
     handleSuccess:function(o){            
         this.processResult(o);            
     },   
   
     handleFailure:function(o){            
         alert(o.status + " " + o.statusText);
     },   
   
     processResult:function(o){      
		
        var rootComment = o.responseXML.documentElement;  
       
        
        if (rootComment.getElementsByTagName('error')[0].firstChild!=null){         
			document.getElementById(cntErrorPlace).innerHTML=rootComment.getElementsByTagName('error')[0].firstChild.nodeValue;
			var fontAnim = new YAHOO.util.ColorAnim(cntErrorPlace, { color: { to: '#f00000' } });           
			fontAnim.animate();		
        }else{        			
			var oComment = rootComment.getElementsByTagName('comments')[0].firstChild.nodeValue;   
			var oNewID = rootComment.getElementsByTagName('newpostid')[0].firstChild.nodeValue;   
			var cntNewPost='divComment_' + oNewID;
			document.getElementById(cntCommentPlace).style.color='#ffffff';
			document.getElementById(cntCommentPlace).display='block';
			document.getElementById(cntCommentPlace).innerHTML=oComment;						
			var fontAnim = new YAHOO.util.ColorAnim(cntCommentPlace, { color: { to: '#333333' } });           
			fontAnim.animate();		
			/*document.getElementById(cntNewPost).style.border='1px solid #AACC00';
			var borderAnim = new YAHOO.util.ColorAnim(cntNewPost , { borderColor: { to: '#FFFFFF' } });           
			borderAnim.duration=2;
			borderAnim.animate();*/
			
			document.getElementById(cntErrorPlace).style.color='#ffffff';
			document.getElementById(cntErrorPlace).innerHTML='Thank you for comment!';		
			var fontStatusAnim = new YAHOO.util.ColorAnim(cntErrorPlace, { backgroundColor: { to: '#AACC00' } });           
			fontStatusAnim.animate();		
			
			
		}  			   
     }   
     ,   
   
     startRequest:function(){    
     }
           
 };   
   
 var callbackAddComment =   
 {   
     success:AjaxAddCommentObject.handleSuccess,   
     failure:AjaxAddCommentObject.handleFailure,   
     scope: AjaxAddCommentObject   
 };  

function add_comment(DealID, CommentPlace, CommentBody, CommentAuthor, WVIText, WVIString, ErrorPlace)
{
		
	cntErrorPlace=ErrorPlace;
	
	var strError;	
	var cntCommentBody=document.getElementById(CommentBody);	
	var cntWVIText=document.getElementById(WVIText);	
	var bIsError;	
	var strAuthor=document.getElementById(CommentAuthor).value;
	
	document.getElementById(cntErrorPlace).style.color='#666666';
	document.getElementById(cntErrorPlace).style.backgroundColor='#ffffff';
	
	document.getElementById(cntErrorPlace).innerHTML='<img src=images/ajax-l.gif>';
	
	if (validate_required(cntCommentBody)==false){		
		document.getElementById(cntErrorPlace).innerHTML ='<br/>* Comment cannot be empty';	
		bIsError=true;
	}

	if (validate_required(cntWVIText)==false){
		document.getElementById(cntErrorPlace).innerHTML  =document.getElementById(cntErrorPlace).innerHTML  + '<br/><br/>* Word verification cannot be empty<br/>';	
		bIsError=true;
	}
	
	if(bIsError==true){
		var fontAnim = new YAHOO.util.ColorAnim(cntErrorPlace, { color: { to: '#f00000' } });           
		fontAnim.animate();			
	}else{
	
		var transaction = YAHOO.util.Connect.asyncRequest('GET', 'util_addcomments.aspx?pid=' + DealID + '&wvi=' + cntWVIText.value + '&wvistr=' + WVIString + '&auth=' +  strAuthor + '&body=' +  cntCommentBody.value , callbackAddComment); 
	
	}
		
 }



function add_comment_fb(DealID, CommentPlace, CommentBody, ErrorPlace)
{
		
	cntErrorPlace=ErrorPlace;
	
	var strError;	
	var cntCommentBody=document.getElementById(CommentBody);	
	var bIsError;	
	
	document.getElementById(cntErrorPlace).style.color='#666666';
	document.getElementById(cntErrorPlace).style.backgroundColor='#ffffff';
	
	document.getElementById(cntErrorPlace).innerHTML='<img src=images/ajax-l.gif>';
	
	if (validate_required(cntCommentBody)==false){		
		document.getElementById(cntErrorPlace).innerHTML ='<br/>* Comment cannot be empty';	
		bIsError=true;
	}
	
	if(bIsError==true){
		var fontAnim = new YAHOO.util.ColorAnim(cntErrorPlace, { color: { to: '#f00000' } });           
		fontAnim.animate();			
	}else{
	
		var transaction = YAHOO.util.Connect.asyncRequest('GET', 'util_addcomments.aspx?pid=' + DealID + '&body=' +  cntCommentBody.value + '&ctr=' + CommentPlace, callbackAddComment); 
	
	}
		
 }

 
function validate_required(field)
{
	with (field)
	{
		if (value==null||value=="")
			{return false}
		else 
			{return true}
	}
}


