var cntStatVoteYes; 
var cntStatVoteNo;
var cntBorderControl;
var cntStatResult;
var cntUniqueID;

var AjaxDealObject = {      
     handleSuccess:function(a){            
         this.processResult(a);            
     },   
   
     handleFailure:function(a){            
         document.getElementById(cntStatResult).innerHTML= o.status + " " + o.statusText;   
     },   
   
     processResult:function(a){      
		
         var rootDeal = a.responseXML.documentElement;                   
         //alert(a.responseXML);
         if (rootDeal.getElementsByTagName('error')[0].firstChild!=null){         
			document.getElementById(cntStatResult).style.color='#f00000';
			document.getElementById(cntStatResult).innerHTML=rootDeal.getElementsByTagName('error')[0].firstChild.nodeValue;						
        }else{        			
			var oYes = rootDeal.getElementsByTagName('yes')[0].firstChild.nodeValue;   
			var oNo = rootDeal.getElementsByTagName('no')[0].firstChild.nodeValue;   						
			document.getElementById(cntStatVoteYes).innerHTML=oYes;					
			document.getElementById(cntStatVoteNo).innerHTML=oNo;		
		showstrength (oYes,oNo);						
			document.getElementById(cntStatResult).innerHTML='Thank you!';								
			/*document.getElementById(cntBorderControl).style.border='2px solid #ffffff';*/
			document.getElementById(cntStatResult).style.color='#ffffff';
			/*var borderAnim = new YAHOO.util.ColorAnim(cntBorderControl, {borderColor: { to: '#AACC00' } });           
			borderAnim.animate();			*/
			var fontAnim = new YAHOO.util.ColorAnim(cntStatResult, { backgroundColor: { to: '#AACC00' } });           
			fontAnim.animate();			
			rootDeal=null;
			//alert(rootDeal);
		}  			   
     }   
     ,   
   
     startRequest:function(){    
        // var transaction = YAHOO.util.Connect.asyncRequest('GET', 'http://www.couponrepublic.com/util_rate.aspx', callback);
     }
           
 };   
   
 var callbackDeal =   
 {   
     success:AjaxDealObject.handleSuccess,   
     failure:AjaxDealObject.handleFailure,   
     scope: AjaxDealObject   
 };   
   
 //AjaxObject.startRequest();  
 
 function vote_deal(DealID, Vote, StatVoteYes, StatVoteNo, BorderControl, StatResult, UniqueID ){
	if (document.getElementById(StatResult).innerHTML!='Thank you!'){
	
	cntUniqueID=UniqueID;
	//alert('!');
	cntStatVoteYes=StatVoteYes; 
	//alert(cntStatVoteYes);
	cntStatVoteNo=StatVoteNo;
	//alert(cntStatVoteNo);
	cntStatResult=StatResult;
	cntBorderControl=BorderControl;
	//alert(cntStatResult);
	//alert(Vote);
	document.getElementById(cntStatResult).innerHTML='<img src=images/ajax-l.gif>';	
	var transaction = YAHOO.util.Connect.asyncRequest('GET', 'util_vote.aspx?pid=' + DealID + '&isyes=' + Vote , callbackDeal); 
	
	}
	
 
 }
 
 
 
function showstrength(Yes, No){

	if (Yes>0){
		var NoPercent;
		var TotalPercent;
		TotalPercent=0;
		if (No>0){
            var intNo =parseInt(No)
            var intYes =parseInt(Yes)
            var NoPercent  = (intNo / (intYes + intNo))* 100.00;            
            TotalPercent = Math.round(100.00 - NoPercent);
            
		}else{		
			TotalPercent = 100;
		}
					
			switch(true){
				case TotalPercent < 1:
					document.getElementById(cntUniqueID + '_div0').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div20').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div40').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div60').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div80').style.background='#ffffff';
					break;
				case TotalPercent > 0 && TotalPercent < 20 :
					document.getElementById(cntUniqueID + '_div0').style.background='#FF3333';
					document.getElementById(cntUniqueID + '_div20').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div40').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div60').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div80').style.background='#ffffff';
					break;
				case TotalPercent> 19 && TotalPercent < 40 :
					document.getElementById(cntUniqueID + '_div0').style.background='#FF9999';
					document.getElementById(cntUniqueID + '_div20').style.background='#FF9999';
					document.getElementById(cntUniqueID + '_div40').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div60').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div80').style.background='#ffffff';
					break;
				case TotalPercent > 39 && TotalPercent < 60 :
					document.getElementById(cntUniqueID + '_div0').style.background='#FFFF99';
					document.getElementById(cntUniqueID + '_div20').style.background='#FFFF99';
					document.getElementById(cntUniqueID + '_div40').style.background='#FFFF99';
					document.getElementById(cntUniqueID + '_div60').style.background='#ffffff';
					document.getElementById(cntUniqueID + '_div80').style.background='#ffffff';
					break;
				case TotalPercent > 59 && TotalPercent < 80 :
					document.getElementById(cntUniqueID + '_div0').style.background='#CCFF99';
					document.getElementById(cntUniqueID + '_div20').style.background='#CCFF99';
					document.getElementById(cntUniqueID + '_div40').style.background='#CCFF99';
					document.getElementById(cntUniqueID + '_div60').style.background='#CCFF99';
					document.getElementById(cntUniqueID + '_div80').style.background='#ffffff';
					break;
				case TotalPercent > 79 :
					document.getElementById(cntUniqueID + '_div0').style.background='#AACC00';
					document.getElementById(cntUniqueID + '_div20').style.background='#AACC00';
					document.getElementById(cntUniqueID + '_div40').style.background='#AACC00';
					document.getElementById(cntUniqueID + '_div60').style.background='#AACC00';
					document.getElementById(cntUniqueID + '_div80').style.background='#AACC00';
				
				}
				
				document.getElementById(cntUniqueID + '_lblStrength').innerHTML='Strength ' + TotalPercent  + '%';
	}else{ //Do nothing
	
	}
			 
}

