var pagDiv = 0;

var doShowDiv = function(direccionPag, idioma_lowercase, max_pag, idModuloDiv){ 
	var idioma_uppercase = idioma_lowercase.toUpperCase();
	if(idioma_uppercase != "ES" && idioma_uppercase != "EN" && idioma_uppercase != "FR") {
		idioma_uppercase = "EN";
	}
	var continuePag = true;
	if (direccionPag=='next' && $(this).attr("fexnumpags")==(pagDiv+1)) continuePag = false;
	if (direccionPag=='back' && pagDiv==0) continuePag = false;

	if (jQuery("#contenidos:first").size()>0 && continuePag){
		if (direccionPag=='next') pagDiv+=1;
		else if (direccionPag=='back') pagDiv-=1;
		t = new Date();
		var tempus = t.getTime();
		var scriptUrl='/doLoadDiv.php?rutaSeccion='+ auxUrlDiv +'&pag='+pagDiv+'&id_modulo='+idModuloDiv+'&randomaux='+tempus;
		jQuery("#contenidos:first").empty().html('<img src="/img/loading_'+idioma_uppercase+'.gif" border="0">').load(scriptUrl);
	}

	// Cursor
	if(pagDiv == 0) {
		document.getElementById('carroussel_back_arrow').style.cursor = "default";
	}
	else {
		document.getElementById('carroussel_back_arrow').style.cursor = "pointer";
	}

	if(pagDiv == (max_pag-1)) {
		document.getElementById('carroussel_next_arrow').style.cursor = "default";
	}
	else {
		document.getElementById('carroussel_next_arrow').style.cursor = "pointer";
	}
}


function colorea(lista,indice){
	eval('document.addCart.lista'+lista+'.selectedIndex='+indice+'');
}
function muestraAreaTexto(parametro){
	cadena='document.addCart.lista'+parametro+'.value';
	valor=eval(cadena);
	cadena2='document.addCart.texto'+valor+'.value';
	valor=eval(cadena2);
	if (valor>0) {
		document.getElementById('areaPoster').innerHTML='<img src="/imgs/clear.gif" width="10" height="8" nowrap><b>Texto personalizado:</b><BR><img src="/imgs/clear.gif" width="10" height="8" nowrap><INPUT TYPE="text" MAXLENGTH="18" NAME="textoPoster" VALUE="" style="width:140px">';
	}else document.getElementById('areaPoster').innerHTML='<img src="/imgs/clear.gif" width="10" height="8" nowrap>';
}
function actualizaPrecio(parametro){
	cadena='document.addCart.lista'+parametro+'.value';
	valor=eval(cadena);
	cadena2='document.addCart.texto'+valor+'.value';
	valor=eval(cadena2);
	valorAux=valor;
	//precio=document.addCart.precio_base.value;
	precio=document.addCart.precio.value;
	residuo=eval('residuo'+parametro);
	//alert(' --->'+residuo);
	valor=Math.round(valor*100)+Math.round(precio*100)-Math.round(residuo*100);
	//document.addCart.precio.value=valor;
	document.addCart.precio.value=valor/100;
	eval('residuo'+parametro+'='+valorAux);
	totales();
}
function totales(){
	var preaux=0;
	var valor = document.addCart.precio.value;
	valor = valor.replace(",", "");
	auxPrecio=Math.round(valor*document.addCart.cantidad.value*100);
	preaux=auxPrecio/100;
	preaux = MoneyFormat(preaux);
	document.getElementById('span_total').innerHTML=preaux;
	//document.addCart.total.value=auxPrecio/100;
}
function checkNum() {
	var num=document.addCart.cantidad.value;
	var cad=num.toString();
	var comprueba="OK";
	var signoDecimal="false";
	var i=0; 
	  while (i<cad.length){
		if (!isNum(cad.charAt(i)))
		  { comprueba="KO"; }
		i++;
	  }
	if (num<1) comprueba="KOK";
	if (comprueba=="KO") alert ('Introduzca una cifra numérica en el campo cantidad.');
	if (comprueba=="KOK") alert ('Introduzca un valor positivo en el campo cantidad.');
	if (comprueba=="OK") document.addCart.submit();
}
function isNum(i){
	if (i == 0 || i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9){
		return true;
	}else { return false; }                                                        
}                                                                             
function abreWin(laURL,nombre,otros, ancho, alto, centrado) { //v3.0
  if(window.screen)if(centrado)if(centrado=="true"){
    var izda = (screen.width-ancho)/2;
    var arriba = (screen.height-alto)/2;
    otros+=(otros!='')?',':'';
    otros+=',left='+izda+',top='+arriba;
  }
  //window.open(laURL,nombre,otros+((otros!='')?',':'')+'width='+ancho+',height='+alto);
  window.open(laURL,"","width="+ancho+",height="+alto);

}
function sumaLote(cantLote){
	cantCaja=parseInt(document.addCart.cantidad.value)+parseInt(cantLote);
	document.addCart.cantidad.value=cantCaja;
	totales();
}
function restaLote(cantLote){
	var cantCaja=document.addCart.cantidad.value;
	if (cantCaja>cantLote) document.addCart.cantidad.value=cantCaja-cantLote;
	totales();
}
function MoneyFormat(amount) {
	var val = parseFloat(amount);
	if (isNaN(val)) { return "0.00"; }
	if (val <= 0) { return "0.00"; }
	val += "";
	// Next two lines remove anything beyond 2 decimal places
	if (val.indexOf('.') == -1) { return val+".00"; }
	else { val = val.substring(0,val.indexOf('.')+3); }
	val = (val == Math.floor(val)) ? val + '.00' : ((val*10 ==
	Math.floor(val*10)) ? val + '0' : val);
	return val;
} 

