function ajuste_resize(){
	var ancho = $(window).width();
	if(ancho > 1000){
		$("body, html").css({overflowX:"hidden"});
	} else {
		$("body, html").css({overflowX:"auto"});
	}
}

function number_format(number, decimals, dec_point, thousands_sep) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');
    // *    returns 13: '100 050.00'
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

function txt2cesta(ctxt){
	
	ctxt = ctxt.substring(0,ctxt.length-6);
	
	var items = ctxt.split("[item]");
	var num = items.length;
	
	var i = 0;
	var salida = "";
	if(items[0] != ""){
		for(i=0;i<num;i++){
			
			var item = items[i].split("##");
			
			var id_item = item[0];
			var nombre = item[1];
			var autor = item[2];
			var precio = parseFloat(item[3],2);
			var cantidad = parseInt(item[4]);
			var precio_total = number_format(precio*cantidad,2,",",".");
		
			salida = salida + "<tr id=\""+id_item+"\">";
			salida = salida + "<td align=\"center\">";
			salida = salida + "<div class=\"info_producto\">";
			salida = salida + id_item+"##"+nombre+"##"+autor+"##"+precio+"##"+cantidad+"[item]";
			salida = salida + "</div>";
			salida = salida + "<a class=\"b_quitar_cesta\" href=\"#\"><img src=\"Content/Images/b_menos.jpg\" alt=\"Quitar\" title=\"Quitar\"/></a>";
			salida = salida + "</td>";
			salida = salida + "<td><strong>"+nombre+"</strong><br/>"+autor+"</td>";
			salida = salida + "<td align=\"right\" style=\"background:#fefefe\">"+cantidad+"</td>";
			salida = salida + "<td align=\"right\">"+precio_total+" €</td>";
			salida = salida + "</tr>";			
		}
	}
	return salida;
}




function cesta2txt(){
	var salida = "";
	$("#tabla_cesta tbody tr").each(function(){
		var item = $(this).find(".info_producto").html();
		salida = salida + item;		
	});
	return salida;
}



function replaceAll(find, replace, str) {
  return str.replace(new RegExp(find, 'g'), replace);
}

function marcar_dia(fecha){
	$("td#"+fecha)
	.removeClass()
	.addClass("dia_activo")
	.attr("alt","Ver agenda de este día")
	.attr("title","Ver agenda de este día");
}

function marcar_dias(){
	$(".fechas_marcas").each(function(){
		var fecha = $(this).attr("value");
		alert(fecha);
		marcar_dia(fecha);
	});
}

function desmarcar_dias(){
	$(".marca").hide();
}


function trim(str){
	return str.replace(/^\s*|\s*$/g,"");
}

function stopRKey(evt) {
	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}

function explorer(){
	if ('\v'=='v'){
		return true;		
	} else {
		return false;	
	}
}
			
function safari(){
   var is_safari = navigator.userAgent.toLowerCase().indexOf('safari/') > -1;  
   if (is_safari ) return true;  	
}

function iPhoneCheck() {
	var agent = navigator.userAgent.toLowerCase();
	var iphone = (agent.indexOf('iphone')!=-1);
	if (iphone) {
		return true;
	} else {
		return false;
	}
}     
function iniciar() {

	var imagenes = new Array();
	
	for(i=0; i<cargar.length; i++){
		imagenes[i]=document.createElement("img");
		imagenes[i].src=cargar[i];
	}
	
}

function escala_img(im,porcentaje,centrar){
	
	var ancho = im.width();
	var alto = im.height();
	var ancho2 = (ancho*porcentaje)/100;
	var alto2 = (alto*porcentaje)/100;
	im.css({width:ancho2+"px",height:alto2+"px"});
	if(centrar){
		var l = (ancho2)/2;
		$("#foto_Intro").css({marginLeft:"-"+l+"px"});	
	}
}

function escala_alto(im,alt_max){
	var alt = im.height();
	var anch = im.width();
	var ratio = anch/alt;
	var alto = alt_max;
	var ancho = alt_max*ratio;
	var l = anch/4;
	im.css({width:ancho+"px",height:alto+"px",marginLeft:"-"+l+"px"});
	
}
function ancho_ratio(ancho,alto,alt_max){
	var ratio = alto/ancho;
	var a = alt_max/ratio;
	return a;
}


//###################################//

function encripta2(){

	usu = document.getElementById('login').value;
	hash = hex_md5(document.getElementById('password').value);	
	url = document.getElementById('url').value;
	document.location = "valida.php?u="+usu+"&p="+hash+"&url="+url;

}

function encripta(myfield,e){
	
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13 || keycode == 32)	{
		usu = document.getElementById('login').value;
		hash = hex_md5(document.getElementById('password').value);	
		url = document.getElementById('url').value;
		document.location = "valida.php?u="+usu+"&p="+hash+"&url="+url;
	}
}

function hoy(dia,mes,anio){
	var ahora = new Date();
	var d = ahora.getDate();
	var m = ahora.getMonth() + 1;
	
	if(d < 10){
		d = "0"+d;	
	}
	
	if(m < 10){
		m = "0"+m;	
	}
	
	$("#"+dia).attr("value",d);
	$("#"+mes).attr("value",m);
	$("#"+anio).attr("value",ahora.getFullYear());
	
}

function ayer(dia,mes,anio){
	var d = $("#dia_ayer").attr("value");
	var m = $("#mes_ayer").attr("value");
	var a = $("#anio_ayer").attr("value");
	
	$("#"+dia).attr("value",d);
	$("#"+mes).attr("value",m);
	$("#"+anio).attr("value",a);
	
}

function esBisiesto(anio) {
	var BISIESTO;
	if(parseInt(anio)%4==0){
		if(parseInt(anio)%100==0){
			if(parseInt(anio)%400==0){
				BISIESTO=true;
			} else {
				BISIESTO=false;
			}
		} else {
			BISIESTO=true;
		}
	} else BISIESTO=false;
	return BISIESTO;
} 

function validar_fecha(dia,mes,anio){

if (esEntero(anio) && esEntero(mes) && esEntero(dia) && anio > 0 && mes > 0 && dia > 0){
	if(dia < 1 || dia > 31){
		return false;	
	} else if(mes < 1 || mes > 12){
		return false;	
	} else if(anio < 1000){ 
		return false;
	} else {
		if(mes == 02){
			if(dia > 29){
				return false;
			} else if(!esBisiesto(anio) && dia == 29){
				return false;
			} else {
				return true;	
			}
		} else {
			return true;	
		} 
	}
}else return false; 
}

function esEntero(valor){
	if(!isNaN(valor)){

		for(var i = 0; i<valor.length;i++){
			if(valor.charCodeAt(i)<48 || valor.charCodeAt(i)>57)
			return false;
		}
    }else{
		return false;
    }
    return true;
}       

function validar_duracion(m,s) {
	if(m < 0){
		return false;
 	} else if(s < 0 || s > 60){
 		return false;
 	} else {
 		return true;
 	}	
}

function validar_hora(h,m) {
	if(h < 0 || h > 23){
		return false;
 	} else if(m < 0 || m > 59){
 		return false;
 	} else {
 		return true;
 	}	
}



