// JavaScript Document
var objCald3n15=new Array();
function getBack_objd3n15(obj){
	if(obj.objAjax.readyState==4){
		//obj.divestrellas.style.
	}
}
function calificacion(divv, stars, srcImg){
	try{
			this.error=new Array();
			this.urrl=null;
			this.divs=new Array();
			this.conceptos=new Array();
			this.prcnt=true;
			this.serial=Math.floor((Math.random()+0.2)*10000);
			this.shwcncpts=false;
			this.automatico=true;
			this.metodo="GET";
			objCald3n15.push(this);
			this.estrellas=isNaN(parseInt(stars))?0:parseInt(stars);
			this.ig=new Image();
			this.ig.src=(this.srcImg);
			if (divv){
				this.divcontenedor=divv;
				temp='';
				this.divestrellas=document.createElement('div');
				for(var i=0; i<this.estrellas; i++){
					d='<div id="_st_'+this.serial+'_'+i+'" onMouseMove="javascript:objCald3n15['+(objCald3n15.length-1)+'].calificar(parseInt(this.getAttribute(\'pos\')))" onclick="javascript:objCald3n15['+(objCald3n15.length-1)+'].setCalificacion(parseInt(this.getAttribute(\'pos\')))" style="float:left" pos="'+i+'">';
					d+='<img src="'+srcImg+'" alt="imagen" /></div>';
					/*if (navigator.appName.toUpperCase()=='MICROSOFT INTERNET EXPLORER'){
						d.attachEvent('onclick', function(){d.style.backgroundColor = '#cc0000'});
					}else{
						d.addEventListener('click',function () {this.style.backgroundColor = '#cc0000'},false);
					}*/
					temp+=d;
					
				}
				this.divestrellas.innerHTML=temp;
				temp='';
				this.spn=document.createElement('div');
				this.spn.style.fontSize="7px";
				this.spn2=document.createElement('div');
				this.spn2.style.fontSize="10px";
				this.mensaje=document.createElement('div');
				this.mensaje.style.display='none';
				this.divcontenedor.appendChild(this.divestrellas);
				this.divcontenedor.appendChild(this.spn);
				this.divcontenedor.appendChild(this.spn2);
				this.divcontenedor.appendChild(this.mensaje);
				this.divs=this.divestrellas.getElementsByTagName('div');
				
			}else{
				this.error.push('no contenedor');
			}
		}catch(e){
			this.error.push(e);
			alert(e);
		}
		//setTimeout('objCald3n15.setearAnchosyAltos()',200);
	
}

calificacion.prototype.Errores=function(){
	if(this.error.length>0){return true;}else{ return false;}
}

calificacion.prototype.setMetodo=function(metodo){
	if (this.Errores())return false;
	if(metodo){
		this.metodoEnvio=metodo.toUpperCase();
	}
}

calificacion.prototype.setValor=function(valor){
	if (this.Errores())return false;
	if(!isNaN(parseInt(valor))){
		if(valor>0){
			if(this.divs[valor-1]){
				this.calificar(valor-1);
			}
		}
	}
}

calificacion.prototype.doajax=function doajax(){
			var xmlhttp=false;
			/* for IE...*/
			try{
				xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			}catch(e){
				try{
					xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
				}catch(E){
					xmlhttp = false;
				}
			}
			/* for Mozilla...*/
			if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
				xmlhttp = new XMLHttpRequest();
			}
			return xmlhttp;
		}
		
calificacion.prototype.setearAnchosyAltos=function(){
	if (this.Errores())return false;
	this.divcontenedor.width=this.divs.length*this.ig.width;
}
calificacion.prototype.setConceptos=function(conceptos_){
	if (this.Errores())return false;
	this.conceptos=conceptos_;
}
calificacion.prototype.setURL=function(url){
	if (this.Errores())return false;
	this.urrl=url;
}
calificacion.prototype.mostrarPorcentaje=function(boleano){
	if (this.Errores())return false;
	if (boleano){
		this.spn.style.display='block';
	}else{
		this.spn.style.display='none';
	}
}
calificacion.prototype.mostrarConceptos=function(boleano){
	if (this.Errores())return false;
	if (boleano){
		this.spn2.style.display='block';
	}else{
		this.spn2.style.display='none';
	}
}
calificacion.prototype.calificar=function(num){
	if (this.Errores())return false;
	var p=this.divs.length-1;
	for(var s=0; s<this.divs.length;s++){
		if(num<s){
			this.divs[s].style.opacity=0.2;
			this.divs[s].style.filter='alpha(opacity=20)';
			
		}else{
			this.divs[s].style.opacity=1;
			this.divs[s].style.filter='alpha(opacity=100)';
		}
		//this.divs[s].getElementsByTagName('img')[0].style.display
		
	}
	
		this.spn.innerHTML=parseFloat((((num+1)/(this.divs.length))*100)).toFixed(2)+"%";
	
	
		if (this.conceptos.length){
			this.spn2.innerHTML=this.conceptos[num];
		}
}


calificacion.prototype.sincronizarCalificacion=function(){
	if (this.Errores())return false;
	this.objAjax=this.doajax();
	if(this.objAjax){
		var oj=this;
		this.objAjax.onreadystatechange=function(){
			getBack_objd3n15(oj);
		}
		this.objAjax.open("GET", this.urrl+"cal="+this.valor, true );
		//this.objAjax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		this.divestrellas.style.display='none';
		this.mensaje.style.display='block';
		this.mensaje.innerHMTL='calificando..'
		this.objAjax.send(null);
		
	} 
}
calificacion.prototype.setCalificacion=function(num){
	if (this.Errores())return false;
	this.valor=num;
	if(this.automatico){
		if (this.urrl!=null){
			switch (this.metodoEnvio){
				case 'GET':
					window.location=this.urrl+"&cal="+num;
					break;
				case 'AJAX':
					this.sincronizarCalificacion();
					break;
				default:
					window.location=this.urrl+"&cal="+num;
					break;
			}
		}
	}
}

