//var uri_imagenes = "http://www.relojesoutlet.es";
var imagesReloj = [
{id:1, img:"/css/img/breil_gran.png"},
{id:2, img:"/css/img/dg_gran.png"},
{id:3, img:"/css/img/radiant_gran.png"}
]
var timeOutID = null; //Identificador de timeout
var timeOutCargando = null; //Identificador de timeout
function limpiarTimeOuts(){
  	window.clearTimeout(timeOutCargando);	
		timeOutCargando = null;
}

var myWait = new YAHOO.tecnopyme.util.wait("Cargando Reloj");
var uri_imagenes = "";
var curTop = null;
var panel = new YAHOO.widget.Panel("datos_relojID",
	{ fixedcenter: true, constraintoviewport: false, underlay:"none", close:false, visible:false, draggable:false, modal:true
		}
	);

function atp_setCurrentYPos(pos) {
try{
 if (document.body && document.body.scrollTop)
   document.body.scrollTop = pos;
 if (document.documentElement && document.documentElement.scrollTop)
   document.documentElement.scrollTop = pos;
 if (window.pageYOffset)
   window.pageYOffset = pos;
}	catch(e){;}	
            
}
	
function info(id, his, fromCesta){	
	  
  	var params = "id=" + id;
  	endTimeOut(timeOutCargando);
		timeOutCargando = beginTimeOut(tiempoTimeOut);
		
  	myWait.show();
  	fromCesta = fromCesta || false;
	  if (fromCesta)
				params += "&from=cesta";
		else
				params += "&from=info";
		params += "&timeout=" + timeOutCargando;  	
		if (his){
			var request = '/articulos/json_info.php?his=y&' + params;
			aObj = new JSONscriptRequestHistory(request);
			// Build the script tag
			aObj.buildScriptTag();
		}else{
			
			var request = '/articulos/json_info.php?his=n&' + params;
		  aObj = new JSONscriptRequest(request);
			// Build the script tag
			aObj.buildScriptTag();
			// Execute (add) the script tag
			aObj.addScriptTag();
		}
		

}
function ocultar(){
panel.hide();

//YAHOO.util.Dom.setStyle("datos_relojID_c", "visibility", "hidden");
//.setProperty("visible", false);
}
function processRequestInfo(jData){
var texto = "";

	if (jData != null) {
		if ((jData.timeout != timeOutCargando) && (timeOutCargando != null))
			return;
	}else{
	  	endTimeOut(timeOutCargando);
		return;
	}
	endTimeOut(timeOutCargando);
	timeOutCargando = null;
	myWait.hide();
	//width:"1016px", height:"380px",
	wp = (YAHOO.util.Dom.getViewportWidth() < 1016 ? YAHOO.util.Dom.getViewportWidth(): 1016);
	if (wp == 1016)
		overflow ="hidden";
	else
		overflow ="scroll";
	wd = wp -20; 
	panel.cfg.setProperty("width", wp + "px");
	texto += "<div style='width:" + wd + "px; height:490px; border:0; background-color:white; overflow:" + overflow + ";";
	var img;
	for (var i = 0; i < imagesReloj.length; i++){
		if (imagesReloj[i]["id"] == jData.data.ID_FABRICANTE)
			img = imagesReloj[i]["img"];
	}

	texto += "background-image:url(" + img + ");";
	texto += "background-repeat:no-repeat; ";
	texto += "background-position:bottom right;";
	texto += "'>\n";
	texto += "<table cellpadding=0 cellspacing=0 width='100%' style='margin:0; padding:0; border:0'><tr style='border:0'>\n";
	
	texto += "<td rowspan='2' style='width:326px; height:490px; border:0; background-repeat:no-repeat; background-image:url(" + uri_imagenes + "/images/490_" + jData.data.FOTO + ")'>&nbsp;\n";
		//texto += "<img src='" + uri_imagenes + "/images/490_" + jData.data.FOTO + "'>\n";
	texto += "</td>";
	texto += "<td style='border:0;vertical-align:top; text-align:left;'>\n";
		texto += "<div style='padding:20px;'>\n";
		texto += "<div class='med'>" + jData.data.NOMBRE_ID_FABRICANTE + "</div>\n";
		texto += "<div class='med'>" + jData.data.NOMBRE_ID_MARCA;
		if (jData.data.MODELO != "")
			texto += " - " + jData.data.MODELO;
		texto += "</div>\n";
		texto += "<div class='peq' style='padding-bottom:10px;'>" + jData.data.REFERENCIA + "</div>\n";
		
		//NOMBRE_ID_DESTINATARIO
		var t = "";
		t += jData.data.NOMBRE_ID_DESTINATARIO + ", ";
		t += jData.data.NOMBRE_ID_TIPO_RELOJ + ", ";
		if (jData.data.NOMBRE_ID_COLOR_ESFERA != "")
			t += "esfera de color " + jData.data.NOMBRE_ID_COLOR_ESFERA + ", ";
		
		t += jData.data.NOMBRE_ID_METROS + ", ";
		
		if (jData.data.NOMBRE_ID_TIPO_CAJA != ""){
			t += "caja de " + jData.data.NOMBRE_ID_TIPO_CAJA;
			if (jData.data.NOMBRE_ID_COLOR_CAJA != "")
			 	t+= " de color " + jData.data.NOMBRE_ID_COLOR_CAJA;
			t += ", ";
		}
		
		if (jData.data.NOMBRE_ID_TIPO_CRISTAL != "")
			t += "cristal " + jData.data.NOMBRE_ID_TIPO_CRISTAL + ", ";
			
		t += "maquinaria " + jData.data.NOMBRE_ID_MAQUINARIA + ", ";
		
		t += "correa de " + jData.data.NOMBRE_ID_CORREA;
		if (jData.data.NOMBRE_ID_COLOR_CORREA != "")
		 t += " de color " + jData.data.NOMBRE_ID_COLOR_CORREA;
		
		texto += "<div class='peq' style=''><p>" + t + "</p></div>\n";
		if (jData.data.OBSERVACIONES != "")
			texto += "<div class='peq' style=' margin-top:20px;'>" + jData.data.OBSERVACIONES + "</div>\n";
		texto += "</div>\n";
	texto += "</td>\n";
	texto += "<td rowspan='2' style='border:0; width:300px; vertical-align:top; '>\n";
		texto += "<div style='text-align:right; margin-right:80px;'>\n";
		//alert(YAHOO.util.Dom.getDocumentScrollTop());
		curTop = YAHOO.util.Dom.getDocumentScrollTop();
		texto += "<div style='margin-top:20px; margin-bottom:80px;'><a href='#' onclick='ocultar(); return false;'><img style='border:0' src='/css/img/cerrar.png' style='cursor:pointer;'></a></div>\n";
		if (jData.from != "cesta"){
			if (jData.data.UNIDADES > 0)
				texto += "<div style='margin-bottom:20px;'><a href='/compra/carro.php?ACCION=MODIFY&ID=" + jData.data.ID + "&cant=1'><img style='border:0' src='/css/img/addcesta.png' style='cursor:pointer;'></a></div>\n";
		}
		texto += "<div style='margin-bottom:20px;'><a style='margin-bottom:20px;' href='#' onclick=\"javascript:showMailWindow('" + jData.data.REFERENCIA + "'); return false;\"><img style='border:0' src='/css/img/attcliente.png' style='cursor:pointer;'></a></div>";
		texto += "<div style='margin-bottom:20px;'><a style='margin-bottom:20px;' href='/articulos/imprimir.php?id=" + jData.data.ID + "'><img style='border:0' src='/css/img/imprimir.png' style='cursor:pointer;'></a></div>\n";
		texto += "</div>\n";
	texto += "</td>\n";
	texto += "</tr>\n";
	texto += "<tr>\n";
	texto += "<td style='*border-bottom:0; border-left:0; border-right:0; border-top:1px solid white; vertical-align:bottom; text-align:left;'>\n";
		texto += "<div style='padding:20px;'>\n";
		texto += "<div style=''>\n";
			texto += "<div class='med'>Precio Recomendado</div>\n";
			texto += "<div class='med'>" +  Math.round(jData.data.PVPR) + " &euro;</div>\n";
		
			texto += "<div class='gran' style='margin-top:20px;'>Precio Outlet</div>\n";
			var pvpr = parseFloat(jData.data.PVPR);
			var dto_ptje = parseFloat(jData.data.DTO_PTJE);
			var outlet = pvpr - (pvpr * dto_ptje / 100) ;
			texto += "<div class='gran'>" +  Math.round(outlet) + " &euro; <span class='peq'> (IVA incluido)</span></div>\n";
			if (jData.data.UNIDADES == 0){
				texto += "<div class='gran' style='color:red;'>Agotado</div>\n";
			}
		texto += "</div>\n";
	
		texto += "</div>\n";
	texto += "</td>\n";
	
	texto += "</tr>\n";
	texto += "</table>\n";
	texto += "</div>\n";

	panel.setBody(texto);
	panel.render(document.body);
	panel.show();
}

