
//GENERICAS
// retorna un objeto con los valores pasados por GET
getQuery=function(){
	var i,eq,qs=location.search.substring(1), nv=qs.split('&'), o=[];
	for(i=0;i<nv.length;i++){
    	eq=nv[i].indexOf('=');
    	o[nv[i].substring(0,eq).toLowerCase()]=unescape(nv[i].substring(eq+1));
	}return(o);
}

//Cookies
//Deja  uan cookie :: sName es un string, oValue es un objeto,nVida en Horas
function setCookie(sName,sValue,nVida){
  var i,a=[],ex="",e="";
  if(nVida!=null) {
    ex=new Date((new Date()).getTime() + nVida * 3600000);
    ex="; expires=" + ex.toGMTString();
  }
  document.cookie=sName+"="+escape(sValue)+ex;
}

//devuelve el valor de esa cookie
function getCookie(sName){
	try{
		var d=document,c=unescape(d.cookie),bgin=sName+"=";
		return c.split(bgin)[1].split(";")[0];
	}catch(e){return false;}
}

function getCombo(oCombo){return(oCombo.options[oCombo.options.selectedIndex].value)}

//CADENAS------------------------------------------------------------------------------------------------------------------------
function l_trim(s){	while(s.indexOf(" ")==0)s=s.substring(1);return(s);}//anula los espacios por la izq
function r_trim(s){while(s.length && s.lastIndexOf(" ")==s.length-1)s=s.substring(0,s.length-1);return(s);}//anula los espacios por la izq
function trim(s){if(!s) return ""; return(l_trim(r_trim(s)));}//anula los espacios en dcha e izq
function contain(s,c){return(s.indexOf(c)!=-1);}
function capitalice(s){	return(s.charAt(0).toUpperCase() + s.substring(1).toLowerCase())}
function isEmail(s){var e=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/; return(e.test(s))}
function isUrl(s){e=new RegExp(/\b(http:\/\/)?(\w+\.)+[a-z]{2,3}/); return(e.test(s))}
function isNumber(s){e=new RegExp(/\d+/); return(e.test(s))}
function isTelephone(s){e=new RegExp(/\b(\+\d{1,3})?\d{9}\b/);return(e.test(s))}
function isZip(s){return new RegExp(/\d{5}/).test(s)}
function isInArray(a,o){for(var i in a)if(a[i]==o)return true;return false;}
function isLeapYear(y){return(y%4==0 && y%100==0);}

//valido mes y dia(sin bisiestos)
function isMonth(mm,dd){
	var largos=[1,3,5,7,8,10,12];
	if(mm.length>2 || dd.length>2 || (!isInArray(largos,mm) && dd>30) || (mm==2 && dd>29))	return false;
	return true;
}

//valido Año, mes y dia (incluidos bisiestos)
function isDate(aaaa,mm,dd){
	if(aaaa.length>4 || !isMonth(mm,dd) || (mm==2 && !isLeapYear(aaaa) && dd>28))return false;
	return true;
}

//BOOLEANAS------------------------------------------------------------------------------------------------------------------------
//En Safari peta ...
//function is_string(s){return s.constructor.toString().match(/String/)};
function is_string(s){return hasValue(s.toLowerCase)};
function is_checkbox(oCampo){return(oCampo.type=='checkbox')}
function is_radio(oCampo){return(oCampo.type=='radio')}
function is_combo(oCampo){return(oCampo.type=='select-one')}
function is_list(oCampo){return(oCampo.type=='select-multiple')}
function is_txt(oCampo){var t=oCampo.type; return(t=="text" || t=="textarea" || t=="password")}
function is_txtarea(oCampo){return(oCampo.type=='textarea')}
function is_hidden(oCampo){return(oCampo.type=='hidden')}
function ok_combo(oCombo){return hasValue(getCombo(oCombo))}
function ok_list(oList){return(oList.options.selectedIndex!=-0)}
function ok_txt(oText){return hasValue(oText.value)}
function ok_hidden(oHidden){return(oHidden.value!='');}
function hasValue(v){return((v!="")&&(v!=null)&&(v!=false)&&(v!="undefined"));}//Una variable tiene valor??


/*
//Dado un objeto, retorna si pertenece a esa clase
function instanceOf(object, constructorFunction) {
  while (object != null){
  	if (object == constructorFunction.prototype) return true;
    object = object.__proto__;
  } return false;
}
*/




//Devuelve un nuevo array con todos los elementos que encuentra cuyo  fieldName == fieldValue// OJO -> solo para objetos
Array.prototype.getElementsByField = function(fieldName,fieldValue){
	var i,o,arrTemp=new Array();
	for(i=0;o=this[i];i++) if(o[fieldName] && o[fieldName] == fieldValue) arrTemp.push(this[i]);
	return arrTemp;
}

//Devuelve un nuevo array con todos los elementos que encuentra cuyo  fieldName entre min y max // OJO -> solo para objetos
Array.prototype.getElementsInRange = function(fieldName,min,max){
	var i,arrTemp=new Array();
	for(i=0;i<this.length;i++) if(this[i][fieldName]>=min && this[i][fieldName]<=max) arrTemp.push(this[i]);
	return arrTemp;
}

//Devuelve un nuevo array con todos los elementos que encuentra cuyo  fieldName > min // OJO -> solo para objetos
Array.prototype.getElementsGT = function(fieldName,min){
	var i,arrTemp=new Array();
	for(i=0;i<this.length;i++) if(this[i][fieldName]>=min) arrTemp.push(this[i]);
	return arrTemp;
}

//Devuelve un nuevo array con todos los elementos que encuentra cuyo  fieldName < max // OJO -> solo para objetos
Array.prototype.getElementsLT = function(fieldName,max){
	var i,arrTemp=new Array();
	for(i=0;i<this.length;i++) if(this[i][fieldName]<=max) arrTemp.push(this[i]);
	return arrTemp;
}


//dado un objeto, si encuentro uno igual, me lo cargo
Array.prototype.deleteInnerElement = function(obj){
	for(var i=0;i<this.length;i++) if(this[i] == obj) return this.splice(i,1);
	return false;
}

//dado un objeto, si encuentro uno igual dentro de mi, retorno su posicion
//Ojo -> para cotejarlo hay que mirar igualdad estricta === o !==
Array.prototype.contains = function(obj){
	for(var i=0;i<this.length;i++)if(this[i] == obj) return i;
	return false;
}






//FORMULARIOS ----------------------------------------------------------------------------------------
//Marca un campo con una clase css
function highLightField(oCampo,sClase){
	var prevClass=oCampo.className; //guardo el estilo original del campo del formulario
	oCampo.className=sClase;
	oCampo.onblur=function(){this.className=prevClass;}
}

//marca un campo, le da foco ,alerta un mensaje y retorna falso
function setFormError(oCampo,sMnsj,sClase){
	if(sClase)highLightField(oCampo,sClase);
	alert(sMnsj);
	if(oCampo.focus)oCampo.focus();
	return false;
}

//Da trim() al valor de un campo
function trimTextField(o){try{o.value=trim(o.value)}catch(e){return false}}

//Dado un formulario, da trim() al valor de todos los campos de un formulario
function megaTrimForm(f){
	var i,t,a=f.getElementsByTagName("input");
	for(i in a){t=a[i].type; if(is_txt(a[i])) trimTextField(a[i]);}
}


//deuelve el codigo de las opciones de un combo con los dias del mes 
getComboDay = function(total,selected){
	var i,std="",s="",total=(total||31);
	for(i=1;i<=total;i++){
		std=(selected && selected==i)? 'selected' : '';
		s+=('<option '+std+' value="'+i+'">'+i+'</option>');
	}
	return s;
}

//deuelve el codigo de las opciones de un combo con los meses del año 
getComboMonth = function(selected){
	if(!hasValue(meses))meses=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
	var i,std="",s="",total=meses.length;
	for(i=1;i<=total;i++){
		std=(selected && selected==i)? 'selected' : '';
		s+=('<option '+std+' value="'+i+'">'+meses[i-1]+'</option>');
	}
	return s;
}

//deuelve el codigo de las opciones de un combo con los meses del año 
getComboYear = function(minYear,maxYear,selected){
	var i,std="",s="";
	if(minYear>maxYear){i=minYear; minYear=maxYear; maxYear=i;}
	for(i=minYear;i<=maxYear;i++){
		std=(selected && selected==i)? 'selected' : '';
		s+=('<option '+std+' value="'+i+'">'+i+'</option>');
	}
	return s;
}

//devuelve el codigo de flash. values es un objeto con las variables para pasar a flash
getFlash=function(movie,width,height,values){
	var i,s='',code='';
	if(values){for(i in values)s+=('&'+i+'='+values[i]);movie+='?'+s.substring(1);}	
	code+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"  width="'+ width +'" height="'+ height +'">';
	code+='<param name="movie" value="'+ movie +'">';
	code+='<param name="quality" value="high">';
	code+='<param name="allowScriptAccess" value="always">';
	code+='<embed src="'+ movie +'" width="'+ width +'" height="'+ height +'" quality="high" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" scale="exactfit" ></embed></object>';
	return(code);
}


function openPop(theUrl,theName,theWidth,theHeight,scrollbars){
	scrollbars=(scrollbars)? 'Yes' : 'No';
	var centerX=screen.availWidth/2-theWidth/2 , centerY=screen.availHeight/2-theHeight/2;
	var theFeatures='menubar=no,status=no,location=no,resizable=no,left='+centerX+',top='+centerY+',scrollbars='+ scrollbars +',width='+theWidth+',height='+theHeight;
	var popWin=window.open(theUrl,theName,theFeatures);popWin.focus();
}




////////   AJAX  ////////////////////////////
function getAjax() {
	var ajax;
	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			ajax = false;
		}
	}
	
	if (!ajax && typeof XMLHttpRequest!='undefined'){
		ajax = new XMLHttpRequest();
	}
	
	/*
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4){
			if(ajax.status==200) ajax.onLoad(true); //disparo OK
			else ajax.onLoad(false); //disparo Error
		}
	}
	*/
	return ajax;
}

/*
//Carga un XML en una estructura sencilla de objetos Asyncronous
loadTable = function(oTable,tableFile,finalTask){
	var ajax = getAjax();
	
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4){
			if(ajax.status!=200)  return alert("Error cargando XML:"  + ajax.status);
			
			var i,x=this.responseXML,nMain=x.lastChild;
			for(i=0;i<nMain.childNodes.length;i++){
				var o = {};
				var nSec=nMain.childNodes[i],attList=nSec.attributes;
				if(attList){
					for(var e=0;e<attList.length;e++){
						var oAtt  = attList[e];
						o[oAtt.name] = oAtt.value;
					}
					if(nSec.firstChild.nodeValue) o.texto = nSec.firstChild.nodeValue;
					oTable.push(o);
				}
			}
			if(finalTask) finalTask.execute();
			
		}
	}	
	
	ajax.open("GET",tableFile,true);
	ajax.send(null);
}
*/


//Carga un XML en una estructura sencilla de objetos y rellena combo...
loadTableIntoCombo = function(tableFile,oCombo){
	var ajax = getAjax();
	
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4){
			if(ajax.status!=200)  return alert("Error cargando XML:"  + ajax.status);	
			var i,x=ajax.responseXML,nMain=x.lastChild;
			for(i=0;i<nMain.childNodes.length;i++){
				var s="",nSec=nMain.childNodes[i],attList=nSec.attributes;
				if(attList){
					for(var o={},e=0;oAtt=attList[e];e++) o[oAtt.name] = oAtt.value;
					oCombo.options[oCombo.options.length] = new Option(o.label,o.id,false,false);
				}
			}
			oCombo.disabled = false;
		}
	}
	ajax.open("GET",tableFile,true);
	ajax.send(null);
}



//Carga una tasbla Syncronous
getTable = function(tableFile){
	var ajax = getAjax();
	ajax.open("GET",tableFile,false);
	ajax.send(null);
	var i,x=ajax.responseXML,nMain=x.lastChild,oTable=[];
	for(i=0;i<nMain.childNodes.length;i++){
		var nSec=nMain.childNodes[i],attList=nSec.attributes,o={};
		if(attList){
			for(var e=0;e<attList.length;e++){
				var oAtt  = attList[e];
				o[oAtt.name] = oAtt.value;
			}
			if(nSec.firstChild && nSec.firstChild.nodeValue) o.texto = nSec.firstChild.nodeValue;
			oTable.push(o);
		}
	}
	return oTable;
}


/*
//funcion encarga de crear el objeto AJAX
function getAjax() {
	var ajax;
	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			ajax = false;
		}
	}
	
	if (!ajax && typeof XMLHttpRequest!='undefined'){
		ajax = new XMLHttpRequest();
	}
	
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4){
			if(ajax.status==200) ajax.onLoad(true); //disparo OK
			else ajax.onLoad(false); //disparo Error
		}
	}
	return ajax;
}


//Carga un XML en una estructura sencilla de objetos Asyncronous
loadTable = function(oTable,tableFile,finalTask){
	var ajax = getAjax();
	ajax.onLoad = function(ok){
		if(!ok) return alert("Error cargando XML:"  + this.status);
		var i,x=this.responseXML,nMain=x.firstChild;
		//oTable = [];
		for(i=0;i<nMain.childNodes.length;i++){
			var o = {};
			var nSec=nMain.childNodes[i],attList=nSec.attributes;
			if(attList){
				for(var e=0;e<attList.length;e++){
					var oAtt  = attList[e];
					o[oAtt.name] = oAtt.value;
				}
				if(nSec.firstChild.nodeValue) o.texto = nSec.firstChild.nodeValue;
				oTable.push(o);
			}
		}
		if(finalTask) finalTask.execute();
	}
	ajax.open("GET",tableFile,true);
	ajax.send(null);
}

//Carga un XML en una estructura sencilla de objetos y rellena combo...
loadTableIntoCombo = function(oTable,tableFile,oCombo){
	var ajax = getAjax();
	ajax.onLoad = function(ok){
		if(!ok) return alert("Error cargando XML:"  + this.status);
		var i,x=this.responseXML,nMain=x.firstChild;
		for(i=0;i<nMain.childNodes.length;i++){
			var nSec=nMain.childNodes[i],attList=nSec.attributes;
			if(attList){
				for(var o={},e=0;oAtt=attList[e];e++){
					o[oAtt.name] = oAtt.value;
				}
				oCombo.innerHTML += ('<option value="'+o.id+'">'+o.label+'</option>');
			}
		}
		oCombo.disabled = false;
	}
	ajax.open("GET",tableFile,true);
	ajax.send(null);
}
*/

///Clase Task --> representa una tarea.
Task=function(){
	var arr=[],i;
	for(i=0;i<arguments.length;i++) arr.push(arguments[i]); //En javascript, arguments NO ES array. Corrijo
	
	this.taskObj=arr.shift();	
	this.taskFunction=arr.shift();
	this.taskArguments=arr;	
	this.execute=function(){this.taskObj[this.taskFunction].apply(this.taskObj,this.taskArguments)}
}


//Listado de tareas a realizar
TaskList=function(){
	this.tasks=[];
	this.push=function(newTask){this.tasks.push(newTask)};
	this.execute=function(){for(var i=0;i<this.tasks.length;i++)this.tasks[i].execute()};
}

//Ejecuta una tarea transcurrido un tiempo...
//Si "repeat", la tarea se vuelve a repetir hasta que algo externo dispare su metodo stopWait
TimerTask=function(time,task,repeat){
	this.isRunning=true;
	this.time=time;
	this.task=task;
	this.finish=function(){
		if(!this.isRunning)return this.stopWait();		
		this.task.execute();
		this.onRepeat(); //Aparte de ejecutar la tarea, disparo un callback cada vez que salta.
		if(!repeat)this.stopWait();
	}
	this.stopWait=function(){		
		clearInterval(this.waitCounter);
		delete this.waitCounter;
		this.isRunning=false;
	}
	this.init=function(){
		var killTask = new Task(this,"finish");
		this.waitCounter = setTimeout(function(){killTask.execute()},this.time*1000);
	}
}







showDetail = function(){

	//Cargo tablas
	d=document;
	d.bbdd={};
	d.bbdd.collection = getTable("collection/bbdd/watches.xml");
	d.bbdd.brands = getTable("collection/bbdd/brands.xml");
	d.bbdd.types = getTable("collection/bbdd/types.xml");	
	d.bbdd.features = getTable("collection/bbdd/features.xml");
	d.bbdd.materials = getTable("collection/bbdd/materials.xml");
	

	//Analizo query y depuro resultado
	var result=d.bbdd.collection,oQuery = getQuery();
	if(hasValue(oQuery.id)) result = result.getElementsByField("id",oQuery.id)[0];
	if(!result){
		alert("No se han encontrado el producto solicitado");
		return history.back();
	}
	
	
	//pinto resultados
	var productCode='',nl='<br />';
	var oBrand = d.bbdd.brands.getElementsByField("id",result.brand)[0]
	var oType =  d.bbdd.types.getElementsByField("id",result.type)[0];
	var oMaterial = d.bbdd.materials.getElementsByField("id",result.material)[0];


	//Parseo features (puede tener varias)
	if(result.feature){
		var i,featureIndex,arrTemp=result.feature.split(","),arrFeatures=[];
		for(i=0;featureIndex=arrTemp[i];i++) arrFeatures.push(d.bbdd.features.getElementsByField("id",featureIndex)[0].label);
	}


	
							productCode +=(nl + '<img src="'+oBrand.img1+'" />'+ nl+ nl);	
							productCode +=('     <strong>Marca: </strong>'+oBrand.label+'<br />' + nl);
	if(result.label) 		productCode +=('     <strong>Modelo: </strong>'+result.label+'<br />' + nl);
	if(result.ref) 			productCode +=('     <strong>Referencia: </strong>'+result.ref+'<br />' + nl);
	if(result.pvp) 			productCode +=('     <strong>Pvp: </strong>'+result.pvp+' &euro;<br />' + nl);
	//if(result.thick) 		productCode +=('     <strong>Grosor: </strong>'+result.thick+'<br />' + nl);
	if(oType.label) 		productCode +=('     <strong>Movimiento: </strong>'+oType.label+'<br />' + nl);
	if(result.cal) 			productCode +=('     <strong>Calibre: </strong>'+result.cal+'<br />' + nl);
	if(result.diam) 		productCode +=('     <strong>Diametro: </strong>'+result.diam+'<br />' + nl);
	if(result.feature) 		productCode +=('     <strong>Complicaciones: </strong>'+arrFeatures.toString()+'<br />' + nl);
	if(oMaterial.label) 	productCode +=('     <strong>Material: </strong>'+oMaterial.label+'<br />' + nl);
	if(result.texto)		productCode +=('     <strong>Especificaciones: </strong>'+result.texto+'<br />' + nl);
	
	d.getElementById("descriptionCell").innerHTML = productCode;
	
	//CUantas imagenes?
	var arrImages = [];
	if(result.img1) arrImages.push(result.img1);
	if(result.img2) arrImages.push(result.img2);
	if(result.img3) arrImages.push(result.img3);

	//Monto cadena de la tabla de iconitos
	var iconStr = '';
	iconStr += '<table border="0" cellspacing="2" cellpadding="0">';
    for(i=0;sImage=arrImages[i];i++) iconStr += ('<tr><td align="center" class="tabla_blanca_contenido"><a href="javascript:showBig(\''+sImage+'\')"><img width="100" height="70" src="'+sImage+'" border="0" /></a></td></tr>');
    iconStr += '</table>';
	d.getElementById("iconsCell").innerHTML = 	iconStr;
	
	//Disparo la 1¼
	showBig(arrImages[0]);
	
	//tomo resultado en top y monto paginacion
	if(top.result.length>0){
		//Me localizo en el total
		var i,curr,tot=top.result.length;
		for(i=0;curr=top.result[i];i++){
			if(curr.id==result.id){
				currPos = i;
				var pre = (i!=0)? top.result[i-1] : 0;
				var pos = (i<tot-1)? top.result[i+1] : 0;
				break;
			}
		}
		
		
		//Monto enlace
		var leftCode = (pre)? ('<a class="texto_negro10normal" href="productDetail.html?id='+pre.id+'">&lt;</a> ') : ('&lt;') ;
		var midCode = ((currPos+1) + '|' + tot ); 
		var rightCode = (pos)? ('<a class="texto_negro10normal" href="productDetail.html?id='+pos.id+'">&gt;</a> ') : ('&gt;');
		var pagCode = '<span class="texto_negro10normal">' + leftCode + midCode + rightCode + '</span>';
		var pagCell = d.getElementById("paginationCell");
		pagCell.innerHTML = pagCode;
		
		
		//Monto email		
		var eCell = d.getElementById("emailCell");
		var pagCode = '<a class="texto_negro10normal" href="mailto:info@deutsche-uhren.com?Subject=Deseo informacion acerca del producto REF: '+curr.ref+'"  >solicitar informacion</a>';
		eCell.innerHTML = pagCode;
		
	}
}

//  Muestra la ampliacion
showBig = function(image){
	d.getElementById("bigCell").innerHTML = '<img width="217" height="153" src="'+image+'" onClick="openPopUp(this.src)"/>';
}

openPopUp = function(s){
	openPop(s,"detalle",326,230,false);

}


searchResult = function(){

	//Cargo tablas
	d=document;
	d.bbdd={};
	d.bbdd.collection = getTable("collection/bbdd/watches.xml");	
	d.bbdd.types = getTable("collection/bbdd/types.xml");	
	d.bbdd.brands = getTable("collection/bbdd/brands.xml");
	d.bbdd.features = getTable("collection/bbdd/features.xml");
	d.bbdd.materials = getTable("collection/bbdd/materials.xml");
	
	
	//Analizo query y depuro resultado
	var result = d.bbdd.collection,oQuery = getQuery();
	if(hasValue(oQuery.type)) result = result.getElementsByField("type",oQuery.type);
	if(hasValue(oQuery.brand)) result = result.getElementsByField("brand",oQuery.brand);
	if(hasValue(oQuery.material)) result = result.getElementsByField("material",oQuery.material);
	
	//A–ado diametro
	if(hasValue(oQuery.diam)){
		var dm = oQuery.diam;
		if(dm=="a") result = result.getElementsInRange("diam",38,40);
		if(dm=="b") result = result.getElementsInRange("diam",40,42);
		if(dm=="c") result = result.getElementsInRange("diam",40,44);
		if(dm=="d") result = result.getElementsGT("diam",44);
	}


	//A–ado precio
	if(hasValue(oQuery.pvp)){
		var pv = oQuery.pvp;
		if(pv=="a") result = result.getElementsLT("pvp",500);
		if(pv=="b") result = result.getElementsInRange("pvp",500,700);
		if(pv=="c") result = result.getElementsInRange("pvp",700,1000);
		if(pv=="d") result = result.getElementsInRange("pvp",1000,1500);
		if(pv=="e") result = result.getElementsInRange("pvp",1500,2000);
		if(pv=="f") result = result.getElementsGT("pvp",2000);
	}
	
	
	//Parseo features a mano (puede haber varios) y al final (quedan menos que filtrar)
	if(result.length>0 && hasValue(oQuery.feature)){
		var i,f=oQuery.feature.toString(),oF,arr=[];
		for(i=0;oF=result[i];i++){
			if(!oF.feature) continue;
			var arrFeatures = oF.feature.split(",");
			if(isInArray(arrFeatures,f)){
				arr.push(oF);
			}
		}
		result = arr;
	}


	//Ningun resultado
	if(result.length==0){
		alert("No se han encontrado resultados para esta solicitud");
		history.back();
	}
	
	//pinto resultados
	var i,resultCode='',nl=new String(String.fromCharCode(13)+String.fromCharCode(10));
	for(i=0;o=result[i];i++){
		resultCode +=('<table width="100%" border="0" class="texto_negro10normal">' + nl);
		resultCode +=(' <tr>' + nl);
		resultCode +=('   <td width="110" valign="top"><a href="productDetail.html?id='+o.id+'"><img src="'+o.img1+'" width="109" height="77" border="0" /></a></td>' + nl);
		resultCode +=('   <td>' + nl);
		resultCode +=('     <strong>Marca:</strong>'+d.bbdd.brands.getElementsByField("id",o.brand)[0].label+'<br />' + nl);
		resultCode +=('     <strong>Modelo:</strong>'+o.label+'<br />' + nl);
		//resultCode +=('     <strong>Referencia:</strong>'+o.ref+'<br />' + nl);
		//resultCode +=('     <strong>Calibre:</strong>'+o.cal+'<br />' + nl);
		//resultCode +=('     <strong>Diametro:</strong>'+o.diam+'<br />' + nl);
		//resultCode +=('     <strong>Grosor:</strong>'+o.thick+'<br />' + nl);
		resultCode +=('     <strong>Pvp:</strong>'+o.pvp+'<br />' + nl);
		resultCode +=('   </td>' + nl);
		resultCode +=(' </tr>' + nl);
		resultCode +=('</table>' + nl);		
	}
	var cell = document.getElementById("resultCell");
	cell.innerHTML = resultCode;
	
	
	//almaceno resultado en top
	top.result = result;
}



showChoosen = function(){
	
	//Cargo tablas
	d=document;
	d.bbdd={};
	d.bbdd.collection = getTable("relojes/collection/bbdd/watches.xml");
	d.bbdd.brands = getTable("relojes/collection/bbdd/brands.xml");
	d.bbdd.types = getTable("relojes/collection/bbdd/types.xml");	
	d.bbdd.features = getTable("relojes/collection/bbdd/features.xml");
	d.bbdd.materials = getTable("relojes/collection/bbdd/materials.xml");

	//Analizo query y depuro resultado
	var result=d.bbdd.collection.getElementsByField("home","true")[0];
	if(!result){
		alert("No se han encontrado el producto");
		return history.back();
	}
	
	//pinto resultados
	var productCode='',nl='<br />';
	var oBrand = d.bbdd.brands.getElementsByField("id",result.brand)[0]
	var oType =  d.bbdd.types.getElementsByField("id",result.type)[0];
	var oMaterial = d.bbdd.materials.getElementsByField("id",result.material)[0];
	
	//Parseo features (puede tener varias)
	var i,featureIndex,arrTemp=result.feature.split(","),arrFeatures=[];
	for(i=0;featureIndex=arrTemp[i];i++) arrFeatures.push(d.bbdd.features.getElementsByField("id",featureIndex)[0].label);
	
	//productCode +=(nl + '<img src="relojes/'+oBrand.img1+'" />'+ nl+ nl);	
	productCode +=('<span class="texto_rojo9bold">&iexcl;&iexcl;Novedad!!</span><br /><br />');

	productCode +=('     <strong>Marca: </strong>'+oBrand.label+'<br />' + nl);
	productCode +=('     <strong>Modelo: </strong>'+result.label+'<br />' + nl);
	productCode +=('     <strong>Referencia: </strong>'+result.ref+'<br />' + nl);
	productCode +=('     <strong>Pvp: </strong>'+result.pvp+' &euro;<br />' + nl);
	//productCode +=('     <strong>Calibre: </strong>'+result.cal+'<br />' + nl);
	//productCode +=('     <strong>Diametro: </strong>'+result.diam+'<br />' + nl);
	//productCode +=('     <strong>Grosor: </strong>'+result.thick+'<br />' + nl);
	productCode +=('     <strong>Tipo: </strong>'+oType.label+'<br />' + nl);
	productCode +=('     <strong>Funciones: </strong>'+arrFeatures.toString()+'<br />' + nl);
	productCode +=('     <strong>Material: </strong>'+oMaterial.label+'<br />' + nl);
	productCode +=('     <strong>Especificaciones: </strong>'+result.texto+'<br />' + nl);
	
	d.getElementById("descriptionCell").innerHTML = productCode;
	
	//CUantas imagenes?
	var arrImages = [];
	if(result.img1) arrImages.push(result.img1);
	if(result.img2) arrImages.push(result.img2);
	if(result.img3) arrImages.push(result.img3);
	
	

	//Disparo la 1¼
	showBig(arrImages[0]);
}
