function irARecomendar(elemID, id, origen, clibro, cnov, txnoved,opcion,tipo,idiom){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop += offsetTrail.offsetTop;
    offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined" && navigator.appName=="Microsoft Internet Explorer" ) {
    offsetLeft += parseInt(document.body.leftMargin);
    offsetTop += parseInt(document.body.topMargin);
    }
    window.scrollTo(offsetLeft,offsetTop);
    mostrarRecomendar(id,origen,clibro,cnov,txnoved,opcion,tipo,idiom);
}
function irAOpinar(elemID, id, origen, clibro, idTienda, nombre){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop += offsetTrail.offsetTop;
    offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined" && navigator.appName=="Microsoft Internet Explorer" ) {
    offsetLeft += parseInt(document.body.leftMargin);
    offsetTop += parseInt(document.body.topMargin);
    }
    window.scrollTo(offsetLeft,offsetTop);
    mostrarOpinarProducto(id,origen,clibro,idTienda,nombre);
}
function mostrarOpinarProducto(id,origen,clibro,idTienda,nombre){
    var div=id;
	var coment=document.getElementById(div);
	var posId=id.substring(id.length-1,id.length);
    var urlOrigen=location.pathname;
    if (urlOrigen==null) urlOrigen="";

	if (isNaN(posId)){
		posId="";
	}
	if (coment.innerHTML==""){
		var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
		var peticion = function (oXML) {
			coment.innerHTML=oXML.responseText;
            var capaComentar=document.getElementById('opinar');
            capaComentar.style.display='block';
			coment.style.display='block';
		}
		myConn.connect("/fichas/opinionProducto", "POST", "codigo="+clibro+"&nombre="+nombre+"&idtienda="+idTienda+"&autor=", peticion);
	}else{
         var capaComentar=document.getElementById('opinar');
		capaComentar.style.display='block';
		coment.style.display='block';
	}
}
function cerrarOpinarProducto(){
     document.getElementById('opinar').style.display='none';
}
function validarOpinionProducto() {
	myErrorText='';
    var tipo='';
    if (document.envio.nombre.value=="") {
        myErrorText+='nombre';
    }
	if (!isEmail(document.envio.email.value)) {
            if(myErrorText!='')
                myErrorText+=', ';
            myErrorText+='e-mail';
        }
	if (document.envio.starAction.value=="" || document.envio.starAction.value=="0") {
            if(myErrorText!='')
                myErrorText+=', ';
            myErrorText+='valoracion';
        }
	if (document.envio.critica.value=="") {
             if(myErrorText!='')
                myErrorText+=', ';
                myErrorText+='opinion';
        }
	if (myErrorText!='') {
            myErrorText='Compruebe los siguientes campos: '+myErrorText;
             document.envio.error_msn.value=myErrorText;
            document.envio.action=document.envio.url.value;
            var recIn=document.getElementById('capaError');
            if(document.getElementById('capaError').lastChild!=null){
                document.getElementById('capaError').removeChild(document.getElementById('capaError').lastChild);
            }
                var txError = document.createElement("p");
                var myTexto;
                var imErr;
                if (myErrorText!=null && myErrorText!=""){
                    imErr=document.createElement("img");
                    imErr.src="/i/error2.gif";
                    imErr.alt="Error datos";
                    myTexto = document.createTextNode(myErrorText);
                }
                if (imErr!=null && typeof(imErr)!='undefined' && imErr.nodeType==1) txError.appendChild(imErr);
                txError.appendChild(myTexto);
                txError.id="txError";
                txError.className="txReco";
                txError.style.fontFamily="Arial";
                txError.style.fontSize="12px"
                txError.style.color="red";
                txError.style.textDecoration="none";
                txError.style.textAlign="justify";
                txError.style.margin="4px 4px 0 4px";
                //recIn.insertBefore(txError,getFirstChild(recIn));
                recIn.appendChild(txError);

            //mostrarResultadoOpinarProducto();
            //document.envio.submit();
	} else {
                if (document.envio.tipogeneral.checked) tipo = document.envio.tipogeneral.value + "|";
		if (document.envio.tiponoticia.checked) tipo = tipo + document.envio.tiponoticia.value;
		document.envio.tipoboletin.value = tipo;


        mostrarResultadoOpinarProducto('capaResultado');

		//document.envio.submit();
	}
}

function mostrarResultadoOpinarProducto(id){
    document.getElementById('capaOpinion').style.display='none';
    document.getElementById('capaError').style.display='none';
    document.getElementById(id).style.display='block';
    var div=id;
	var coment=document.getElementById(div);
    var myConn = new XHConn();
    if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más actual.");
    var peticion = function (oXML) {
        coment.innerHTML=oXML.responseText;
    }
    myConn.connect("/fichas/opinionProductoGuardar", "POST", "tipoboletin="+document.envio.tipoboletin.value+"&codigo="+document.envio.codigo.value+"&critica="+document.envio.critica.value+"&nombre="+document.envio.nombre.value+"&email="+document.envio.email.value+"&valoracion="+document.envio.starAction.value+"&titulo="+document.envio.titulo.value+"&idtienda="+document.envio.idtienda.value, peticion);
}
function borrarTxt(){
    alert('borrando');
    document.getElementById('capaInfo').style.display='none';
    alert('borrado');
}

if (document.images) {
  var boton1_off = new Image();
  boton1_off.src = "/i/ico_star2.gif";
  var boton1_on = new Image();
  boton1_on.src = "/i/ico_star.gif";
}

// Carga de imagen cuando el ratón pasa por encima
function entra(formName, boton) {
    var botonString = boton;
  if(document.getElementById(formName).starAction.value=='0'){
      if (document.images) {
        if (botonString.indexOf('boton1')!=-1) {
          document.images[boton].src = boton1_on.src;
        }
            if (botonString.indexOf('boton2')!=-1) {
                document.images['boton1'].src = boton1_on.src;
                document.images[boton].src = boton1_on.src;
        }
            if (botonString.indexOf('boton3')!=-1) {
                document.images['boton1'].src = boton1_on.src;
                document.images['boton2'].src = boton1_on.src;
                document.images[boton].src = boton1_on.src;
        }
            if (botonString.indexOf('boton4')!=-1) {
                document.images['boton1'].src = boton1_on.src;
                document.images['boton2'].src = boton1_on.src;
                document.images['boton3'].src = boton1_on.src;
                document.images[boton].src = boton1_on.src;
        }
            if (botonString.indexOf('boton5')!=-1) {
                document.images['boton1'].src = boton1_on.src;
                document.images['boton2'].src = boton1_on.src;
                document.images['boton3'].src = boton1_on.src;
                document.images['boton4'].src = boton1_on.src;
                document.images[boton].src = boton1_on.src;
        }
      }
   }
}

// Carga de imagen cuando el ratón abandona el área de la imagen
function sale(formName, boton) {
  var botonString = boton;
  if(document.getElementById(formName).starAction.value=='0'){
      if (document.images) {
        if (botonString.indexOf('boton1')!=-1) {
          document.images[boton].src = boton1_off.src;
        }
            if (botonString.indexOf('boton2')!=-1) {
                document.images['boton1'].src = boton1_off.src;
          document.images[boton].src = boton1_off.src;
        }
            if (botonString.indexOf('boton3')!=-1) {
                document.images['boton1'].src = boton1_off.src;
                document.images['boton2'].src = boton1_off.src;
          document.images[boton].src = boton1_off.src;
        }
            if (botonString.indexOf('boton4')!=-1) {
                document.images['boton1'].src = boton1_off.src;
                document.images['boton2'].src = boton1_off.src;
                document.images['boton3'].src = boton1_off.src;
          document.images[boton].src = boton1_off.src;
        }
            if (botonString.indexOf('boton5')!=-1) {
                document.images['boton1'].src = boton1_off.src;
                document.images['boton2'].src = boton1_off.src;
                document.images['boton3'].src = boton1_off.src;
                document.images['boton4'].src = boton1_off.src;
          document.images[boton].src = boton1_off.src;
        }
      }
    }
}

function fijarValorStar(formName, val){
    document.getElementById(formName).starAction.value=val;
    switch(val){
        case "1":
            document.images['boton1'].src = boton1_on.src;
            document.images['boton2'].src = boton1_off.src;
            document.images['boton3'].src = boton1_off.src;
            document.images['boton4'].src = boton1_off.src;
            document.images['boton5'].src = boton1_off.src;
        break;
        case "2":
            document.images['boton1'].src = boton1_on.src;
            document.images['boton2'].src = boton1_on.src;
            document.images['boton3'].src = boton1_off.src;
            document.images['boton4'].src = boton1_off.src;
            document.images['boton5'].src = boton1_off.src;
        break;
        case "3":
            document.images['boton1'].src = boton1_on.src;
            document.images['boton2'].src = boton1_on.src;
            document.images['boton3'].src = boton1_on.src;
            document.images['boton4'].src = boton1_off.src;
            document.images['boton5'].src = boton1_off.src;
        break;
        case "4":
            document.images['boton1'].src = boton1_on.src;
            document.images['boton2'].src = boton1_on.src;
            document.images['boton3'].src = boton1_on.src;
            document.images['boton4'].src = boton1_on.src;
            document.images['boton5'].src = boton1_off.src;
        break;
        case "5":
            document.images['boton1'].src = boton1_on.src;
            document.images['boton2'].src = boton1_on.src;
            document.images['boton3'].src = boton1_on.src;
            document.images['boton4'].src = boton1_on.src;
            document.images['boton5'].src = boton1_on.src;
        break;
    }
}