function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 

function ocultarHijos(esto){
	esto.className = "ocultarHijos";
}
function tratarMenu(esto, accion){
		 esto.className = "showChilds";
}
function tratarMenuS(esto, accion){
		 esto.className = "showChildsS";
}
function tratarMenuT(esto, accion){
		 esto.className = "showChildsT";
}


function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}


function respuestaCalcularImporte(){
	
 if (oHTTP.readyState == 4) { 
     if (oHTTP.status == 200) { 
        if (oHTTP.responseText.indexOf('invalid') == -1) {

						
						var respuesta= oHTTP.responseText;
						
						//Importes pedidos
						document.getElementById("incrementoContra").innerHTML = parseFloat(respuesta.split(',')[1]).toFixed(2) + ' €';
						document.getElementById("totalTPV").innerHTML = parseFloat(respuesta.split(',')[2]).toFixed(2) + ' €';
						document.getElementById("totalContra").innerHTML = parseFloat(respuesta.split(',')[3]).toFixed(2) + ' €';
						
						//Importes portes
						document.getElementById("portesTPV").innerHTML = parseFloat(respuesta.split(',')[5]).toFixed(2) + ' €';
						document.getElementById("portesContra").innerHTML = parseFloat(respuesta.split(',')[5]).toFixed(2) + ' €';

						bEnProceso = false;
					}
				}
			}

}

function respuestaCalcularImporteOLD(){

//document.getElementById("texto_importe").innerHTML = oHTTP.responseText;
var array= eval(oHTTP.responseText);
//document.getElementById("incrementoTPV").innerHTML = parseFloat(array[0]).toFixed(2) + " €";
document.getElementById("incrementoContra").innerHTML = parseFloat(array[1]).toFixed(2) + " €";
document.getElementById("totalTPV").innerHTML = parseFloat(array[2]).toFixed(2) + " €";
document.getElementById("totalContra").innerHTML = parseFloat(array[3]).toFixed(2) + " €";
//document.getElementById("totalTransferencia").innerHTML = parseFloat(array[4]).toFixed(2) + " €";

//document.getElementById("portesTransferencia").innerHTML = parseFloat(array[5]).toFixed(2) + " €";
document.getElementById("portesTPV").innerHTML = parseFloat(array[5]).toFixed(2) + " €";
document.getElementById("portesContra").innerHTML = parseFloat(array[5]).toFixed(2) + " €";

}

function respuestaCalcularImporteSin(importe){

//Importes pedidos
document.getElementById("incrementoContra").innerHTML = parseFloat(importe*0.04) + " €";
document.getElementById("totalTPV").innerHTML = parseFloat(importe) + " €";
document.getElementById("totalContra").innerHTML = parseFloat(importe*1.04) + " €";

//Importes portes
document.getElementById("portesTPV").innerHTML = parseFloat(0) + " €";
document.getElementById("portesContra").innerHTML = parseFloat(0) + " €";

}

function respuestaCalcularImporteSinOLD(importe){

//document.getElementById("texto_importe").innerHTML = oHTTP.responseText;
var array= eval(oHTTP.responseText);
//document.getElementById("incrementoTPV").innerHTML = parseFloat(array[0]).toFixed(2) + " €";
document.getElementById("incrementoContra").innerHTML = parseFloat(importe*0.04) + " €";
document.getElementById("totalTPV").innerHTML = parseFloat(importe) + " €";
document.getElementById("totalContra").innerHTML = parseFloat(importe*1.04) + " €";
//document.getElementById("totalTransferencia").innerHTML = parseFloat(array[4]).toFixed(2) + " €";

//document.getElementById("portesTransferencia").innerHTML = parseFloat(array[5]).toFixed(2) + " €";
document.getElementById("portesTPV").innerHTML = parseFloat(0) + " €";
document.getElementById("portesContra").innerHTML = parseFloat(0) + " €";

}

function calcularImporte(){
if (document.getElementById("provinciaEnvio_requerido_texto")!=null){
	provincia = document.getElementById("provinciaEnvio_requerido_texto").value
	importeProductos = document.getElementById("importeProductos").value
	recepcion = document.getElementById("recepcion").value

//window.open("http://junfuer.ringo.com/recursos/aplicaciones/tienda/calcularPortes.asp?provincia="+provincia+"&importeProductos="+importeProductos)
	//if (parseFloat(importeProductos) < 120){
		 if (!bEnProceso && oHTTP) {
		
				var sUrl = "./recursos/aplicaciones/tienda/calcularPortes.asp?provincia="+provincia+"&importeProductos="+importeProductos+"&recepcion="+recepcion;
				
				oHTTP.open("GET", sUrl, true);
				oHTTP.onreadystatechange = respuestaCalcularImporte;
				bEnProceso = true;
				oHTTP.send(null);
		}
		
	//}
	//else
	//{
		//respuestaCalcularImporteSin(importeProductos);
	//}
}
}
function cambiarRecepcion(){
if (document.getElementById("provinciaEnvio_requerido_texto")!=null){
	provincia = document.getElementById("provinciaEnvio_requerido_texto").value

	if ((provincia!="Ceuta") && (provincia!="Islas Baleares") && (provincia!="Las Palmas") && (provincia!="Melilla") &&(provincia!="Tenerife")){
	
	
		oRecepcion = document.getElementById("bloqueRecepcion");
		oContenido = document.getElementById("selectRecepcion");
		if(document.getElementById("recepcion").type =="hidden"){
			oRecepcion.removeChild(oContenido);
			
			var oSpan = document.createElement("span");
			oSpan.setAttribute("id","selectRecepcion");
					
			var oSelect= document.createElement("select");
			oSelect.setAttribute("name","recepcion");
			oSelect.setAttribute("id","recepcion");
			oSelect.onchange=function(){calcularImporte();return false;};
			
			var oOpcion = document.createElement("option");
			oOpcion.setAttribute("value","Domicilio");
			oOpcion.innerHTML = "Domicilio";
			oSelect.appendChild(oOpcion);
			var oOpcion = document.createElement("option");
			oOpcion.setAttribute("value","Oficina");
			oOpcion.innerHTML = "Oficina";
			oSelect.appendChild(oOpcion);
							
			//Añadimos el *select*
			oSpan.appendChild(oSelect);
			oRecepcion.appendChild(oSpan);	
		}
	}else {
		oRecepcion = document.getElementById("bloqueRecepcion");
		oContenido = document.getElementById("selectRecepcion");
		if (document.getElementById("recepcion").type!="hidden"){
		oRecepcion.removeChild(oContenido);
			
			var oSpan = document.createElement("span");
			oSpan.setAttribute("id","selectRecepcion");
			
			var oHidden = document.createElement("input");
			oHidden.setAttribute("type","hidden");
			oHidden.setAttribute("name","recepcion");
			oHidden.setAttribute("id","recepcion");
			oHidden.setAttribute("value","Domicilio");
			oSpan.innerHTML = "Domicilio";
			oSpan.appendChild(oHidden);
			oRecepcion.appendChild(oSpan);
			
/**			var oTexto = document.createElement("p");
			oTexto.innerHTML = "Domicilio";
			oSpan.appendChild(oTexto);*/
			oRecepcion.appendChild(oSpan);
		}
	}
}
}



/*

function mueveAV(){
	enlace = document.getElementById("enlaceImagen");
	imagenes=document.getElementById("fichaProductos").getElementsByTagName("img");
	rutaImagen = imagenes[0].getAttribute("src");
	document.getElementById("posicion").value = parseInt(document.getElementById("posicion").value) +1;
	var posicion=parseInt(document.getElementById("posicion").value);
	enlace.setAttribute("href", rutaImagen.substring(rutaImagen.lastIndexOf("_")+1,0) + "0"+ posicion +rutaImagen.slice(-4));
	rutaImagen = rutaImagen.substring(rutaImagen.lastIndexOf("_")+1,0) + "0"+ posicion + "[2]" + rutaImagen.slice(-4);
	imagenes[0].setAttribute("src",rutaImagen);
	
	//imagen.setAttributte("src",)
	//posicion=parseInt(document.getElementById("posicion").value)+1;
	document.getElementById("boton_ret").style.visibility = "visible";
habilitarAV();
	}

function mueveRET(){

	enlace = document.getElementById("enlaceImagen");
	imagenes=document.getElementById("fichaProductos").getElementsByTagName("img");
	document.getElementById("posicion").value = parseInt(document.getElementById("posicion").value) -1;
	rutaImagen = imagenes[0].getAttribute("src");
	var posicion=parseInt(document.getElementById("posicion").value);
	enlace.setAttribute("href",rutaImagen.substring(rutaImagen.lastIndexOf("_")+1,0) + "0"+ posicion +rutaImagen.slice(-4));
	rutaImagen = rutaImagen.substring(rutaImagen.lastIndexOf("_")+1,0) + "0"+ posicion + "[2]" + rutaImagen.slice(-4);
	imagenes[0].setAttribute("src",rutaImagen);
	document.getElementById("boton_av").style.visibility = "visible";
	habilitarRET();
}


function habilitarAV(){

	if(document.getElementById("fichaProductos")!=null) {
		var ultima = parseInt(document.getElementById("numImagenes").value);
		
		var posicion=parseInt(document.getElementById("posicion").value);
		if (posicion >= ultima){
			document.getElementById("boton_av").style.visibility = "hidden";
		}else{
			document.getElementById("boton_av").style.visibility = "visible";
		}
	}
}

function habilitarRET(){
	if(document.getElementById("fichaProductos")!=null) {
		var posicion=parseInt(document.getElementById("posicion").value);
		if (posicion <=1){
			document.getElementById("boton_ret").style.visibility = "hidden";
		}else{
			document.getElementById("boton_ret").style.visibility = "visible";
		}
	}
}

function reiniciarFotos(){
	if(document.getElementById("fichaProductos")!=null) {
		document.getElementById("posicion").value = 1;
		habilitarRET();
		habilitarAV();
	}
}
*/

function reiniciarFotos(){
	if(document.getElementById("fichaProductos")!=null) {
		var numImagenes = document.getElementById("numImagenes").value;
		var lista = document.getElementById("botones_imagenes").getElementsByTagName("ul");
		if (numImagenes==0){
			var titulo = document.getElementById("botones_imagenes").getElementsByTagName("p")[0];
			titulo.innerHTML="No hay imagenes";
		}
		for (i=1;i<=numImagenes; i++){
			var enlace = document.createElement("a");
			enlace.setAttribute("href", "javascript:cambiarFoto("+i+");");
			//enlace.setAttribute("onclick", "cambiarFoto("+i+");return false;");
			enlace.innerHTML = i;
			var elemento = document.createElement("li");
			if (i == 1){
				elemento.className = "selected";
				//elemento.addClassName('selected');
			}
			elemento.appendChild(enlace);
			lista[0].appendChild(elemento);
		}
		document.getElementById("posicion").value=1;
	}
}

function cambiarFoto(numFoto){
	var posicion = document.getElementById("posicion").value;
	var cambiar = false;
	if(document.getElementById("tipo").value!="imagen"){
		cambiar=true;
		document.getElementById("tipo").value="imagen";
	}

	var	enlace=document.getElementById("enlaceImagen");	
	var	imagenes=document.getElementById("fichaProductos").getElementsByTagName("img");
	if ((posicion!= numFoto)||cambiar){
		var enlace = document.getElementById("enlaceImagen");
		var rutaImagen = "/archivos/imagen/productos/";
		if (numFoto<10) {
			enlace.setAttribute("href", rutaImagen + document.getElementById("referencia").value + "_0"+ numFoto +".jpg");
			fichero = document.getElementById("referencia").value + "_0"+ numFoto + "[2].jpg";
	}else{
		enlace.setAttribute("href",  rutaImagen +document.getElementById("referencia").value + "_"+ numFoto +".jpg");
		fichero = document.getElementById("referencia").value + "_"+ numFoto + "[2].jpg";
	}	
			imagenes[0].setAttribute("src",rutaImagen + fichero);
	}

		var lista = document.getElementById("botones_imagenes").getElementsByTagName("ul")[0].getElementsByTagName("li");
		lista[numFoto-1].className = "selected";
		document.getElementById("posicion").value = numFoto;

	if (cambiar){
		var video = document.getElementById("bloque_video");
		video.className = "video_oculto";
		enlace.className = "";
		var listaVideos = document.getElementById("botones_videos").getElementsByTagName("ul")[0].getElementsByTagName("li");
		if (listaVideos != null){
			listaVideos[posicion-1].className="";
		var pelicula = document.getElementById("pelicula");
		pelicula.Stop();
		pelicula.Rewind();
		}

	}else{
		lista[posicion-1].className = "";
	}

	

}

function reiniciarVideos(){
	if(document.getElementById("fichaProductos")!=null) {
		var numVideos = document.getElementById("numVideos").value;
		var lista = document.getElementById("botones_videos").getElementsByTagName("ul");
		if (numVideos==0){
			var titulo = document.getElementById("botones_videos").getElementsByTagName("p")[0];
			titulo.innerHTML="No hay videos";
		}

		for (i=1;i<=numVideos; i++){
			var enlace = document.createElement("a");
			enlace.setAttribute("href", "javascript:cambiarVideo("+i+");");
			//enlace.setAttribute("onclick", "cambiarFoto("+i+");return false;");
			enlace.innerHTML = i;
			var elemento = document.createElement("li");
			elemento.appendChild(enlace);
			lista[0].appendChild(elemento);
		}
		document.getElementById("posicion").value=1;
	}
}




function cambiarVideo(numVideo){
	
	var posicion = document.getElementById("posicion").value;
	var cambiar = false;
	if(document.getElementById("tipo").value!="video"){
		cambiar=true;
		document.getElementById("tipo").value="video";
	}
	
	var	video=document.getElementById("bloque_video");	
	//obtengo video
	if ((posicion!= numVideo)||cambiar){
		//var enlace = document.getElementById("enlaceImagen");
		var rutaVideo = "/archivos/flash/productos/";
		if (numVideo<10) {
			//enlace.setAttribute("href", rutaImagen + document.getElementById("referencia").value + "_0"+ numFoto +".jpg");
			fichero = document.getElementById("referencia").value + "_0"+ numVideo + ".swf";
		}else{
			//enlace.setAttribute("href",  rutaImagen +document.getElementById("referencia").value + "_"+ numFoto +".jpg");
			fichero = document.getElementById("referencia").value + "_"+ numVideo + ".swf";
			
		}	
	//imagenes[0].setAttribute("src",rutaImagen + fichero);
	}
	
	var lista = document.getElementById("botones_videos").getElementsByTagName("ul")[0].getElementsByTagName("li");
	document.getElementById("posicion").value = numVideo;
	lista[numVideo-1].className = "selected";
	
	if (cambiar){
		var imagen = document.getElementById("enlaceImagen");
		//imagen.setAttribute("class", "video_oculto");
		imagen.className= "video_oculto";
		//video.setAttribute("class","video_visible");
		video.className = "video_visible";
		var listaImagenes = document.getElementById("botones_imagenes").getElementsByTagName("ul")[0].getElementsByTagName("li");
		if (listaImagenes != null){
			listaImagenes[posicion-1].className ="";
		}
	}else{
		lista[posicion-1].className="";
	}	
	var pelicula = document.getElementById("pelicula");
		pelicula.Play();
		

}


