function hideURLbar(){ 
	window.scrollTo(0,1);
}			

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

//########### TIENDA ############//
function cesta_check(){
	if($("#tabla_cesta_status tbody tr#cesta_vacia").length == 2){
		$("#tabla_cesta_status thead").hide();
		$("#tabla_cesta_status tbody").prepend("<tr><td height=\"5\" style=\"background:#fff; border:none\"></td></tr>");
	}
}

function login(){
	if($("#email_login").attr("value") == ""){
		alert("El campo \"Correo electrónico\" está vacío");
	
	} else if($("#password_tienda").attr("value") == ""){		
		alert("El campo \"Contraseña\" está vacía");
		
	} else {
		$.ajax({
			url: "Content/Scripts/ajax_tienda.php?accion=login",
			type: "post",
			data: {email:$("#email_login").attr("value"),password:$("#password_tienda").attr("value")},
			success:function(dato){
				if(dato != "error"){
					var id_cliente = dato;
					$.cookie("sn_cliente_tienda_id",id_cliente);
					$("#id_cliente").attr("value",id_cliente);					
					
					$("#login_usuario_Wrapper").show();
					$("#login_form_Wrapper").hide();
					
					document.location = "index.php?seccion=tienda";
					//$("#cesta_menu_Wrapper").load("Content/Scripts/ajax_tienda.php?accion=ver_cesta_status&id_cliente="+id_cliente);
					//$("#bienvenida_cliente strong").load("Content/Scripts/ajax_tienda.php?accion=nombre_cliente&id_cliente="+id_cliente);
				} else {
					alert("El usuario o contraseña son incorrectos");
				}
			}	
		});
	}
}

//########### IMAGEN ###########//

function ajustar_zoom(){
	var ancho_original = $("#ancho_original").attr("value");
	var alto_original = $("#alto_original").attr("value");
	var ratio = alto_original/ancho_original;
	
	var ancho_total = $(window).width();
	var alto_total = $(window).height();
	
	if(ratio < 1){
		var ancho2 = ancho_total-280;
		var alto2 = ancho2*ratio;
	} else {
		var alto2 = alto_total-180;
		var ancho2  = alto2/ratio; 	
	}
	
	if(ancho2 < ancho_original || alto2 < alto_original){
		$(".imagen img").css({width:ancho2+"px", height:alto2+"px"});
		$("#ancho").attr("value",ancho2);
		$("#alto").attr("value",alto2);
		
		//$("#redes_imagen").css({top:(alto2)-65+"px"});
		
		$("#info div").each(function(){
			if($(this).width() > (ancho2-10)){
				$(this).css({width:(ancho2-10)+"px"});
			}
		});		
	}
	
	//var ancho = $("#zoom").width();
	var ancho = $("#ancho").attr("value");
	var alto = $("#alto").attr("value");
	
	var xpos = (ancho_total - ancho)/2;
	var ypos = (alto_total - alto)/2 - 50;
	$("#zoom").css({left:xpos+"px",top:ypos+"px"});	
	
}


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

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

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

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)){
	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;
 	}	
}



