// JavaScript Document
$(document).ready( function(){						   
	
	/*$("#imagess a").click( function(){
		var title = $(this).attr("title");
		$("#imgp").hide();
		$("#imgp").attr("src", title).fadeIn('slow'); 
	});	*/ 	
	
	/*$("#imagess a").click(function(){
		var title = "http://localhost/technonavi/aplication/utilities/img.php?imagen="+ $(this).attr("title")+ "&w=220&h=200";
		//alert(title);
		var len = title.length;
		var text = title.substr(0,39);
		//var newtitle = text + title.substr(39,len);
		var newtitlee = "aplication/webroot/imgs/catalogo/"+$(this).attr("title") ;
		//alert(newtitle);
		$("#imgp").hide();
		$("#imgp").attr("src",newtitlee).fadeIn('slow'); 
		$("#imgp").attr("alt",newtitlee); 
		
		//alert(newtitle);
		$("#grande").attr("href",newtitlee); 
	
	});	*/
	
	
	$("#imagess a").click(function(){
		var title = "utilities/img.php?imagen="+ $(this).attr("title")+"&w=194&h=200";
		//alert(title);
		var len = title.length;
		var text = title.substr(0,33);
		
		
		
		var newtitle = "imgs/catalogo/"+ $(this).attr("title");
		$("#imgp").hide();
		$("#imgp").attr("src",title).fadeIn('slow'); 
		$("#imgp").attr("alt",title); 
		$("#grande").attr("href",newtitle); 
	
	});	
	
	
	$("#find").click( function(){
		var keyword = $("#buscar").val()					   	
		buscar('index.php',keyword)							
	})	
		
});
 
function valida_detalle(id, opcion){
	var f1 = eval("document.detalle");
	var total=0;
	
	f1.action="cesta.php?prod="+id+"&car="+opcion;
	f1.submit();
}

function validar(){
	if(document.frm.nombre.value==""){
		alert("CUIDADO: Por favor introduzca su nombre");
		document.frm.nombre.focus();
		return false;
	}else if(document.frm.apellidos.value==""){
		alert("CUIDADO:Por favor introduzca su apellido");
		document.frm.apellidos.focus();
		return false;
	}else if(document.frm.empresa.value==""){
		alert("CUIDADO: Por favor escriba el nombre de su empresa");
		document.frm.empresa.focus();
		return false;
	}else if(document.frm.email.value==""){
		alert("CUIDADO: Por favor escriba su e-mail");
		document.frm.email.focus();
		return false;
	}else if(document.frm.mensaje.value==""){
		alert("CUIDADO: Por favor escriba el mensaje");
		document.frm.mensaje.focus();
		return false;
	}else{
		document.frm.submit();
		//return true;	
	}
}



function validar_acceso(url){
	if(document.f1.email.value==""){
		alert("ERROR: ingrese su email ");
		document.f1.email.focus();
		return false;
	}else if(checkemail(document.f1.email.value)== false){
		document.f1.email.value="";
		document.f1.email.focus();
		return false;
	}else if(document.f1.password.value==""){
		alert("ERROR: ingrese password ");
		document.f1.password.focus();
		return false;
	}else{
		document.f1.action = url + "?cuenta=acceso";
		document.f1.submit();
	}	
}

function valida_diselo(){
	if(document.f1.nombre.value==""){
		alert("ERROR: ingrese su nombre ");
		document.f1.nombre.focus()
		return false;
	}else if(document.f1.email.value==""){
		alert("ERROR: ingrese su email ");
		document.f1.email.focus()
		return false;
	}else if(document.f1.nombre_amigo.value==""){
		alert("ERROR: ingrese el nombre de su amigo ");
		document.f1.nombre_amigo.focus()
		return false;
	}else if(document.f1.email_amigo.value==""){
		alert("ERROR: ingrese el email de su amigo ");
		document.f1.email_amigo.focus()
		return false;
	}else if(document.f1.titulo.value==""){
		alert("ERROR: ingrese el titulo de mensaje ");
		document.f1.titulo.focus()
		return false;
	}else if(document.f1.mansaje.value==""){
		alert("ERROR: ingrese el mensaje ");
		document.f1.mansaje.focus()
		return false;
	}else {
		document.f1.action="recomienda.php";
		document.f1.submit();
	}	
}


function validpsw(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46 || tecla==13) return true; //Tecla de retroceso (para poder borrar) 
    // dejar la línea de patron que se necesite y borrar el resto 
    //patron =/[A-Za-z]/; // Solo acepta letras 
    //patron = /\d/; // Solo acepta números
    patron = /\w/; // Acepta números y letras 
    //patron = /\D/; // No acepta números 
    // patron = /[\d.-]/; numeros el punto y el signo -
    te = String.fromCharCode(tecla); 
    verifica= patron.test(te);
	if(verifica==false){
		alert("El caracter que esta tratando de ingresar no se permite");		
		return false;
	}else{
		return true
	}	
	// uso  onKeyPress="return validpsw(event)"
}

function validacaracter(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46 || tecla==13 || tecla==32) return true; //Tecla de retroceso (para poder borrar) 
    // dejar la línea de patron que se necesite y borrar el resto 
    //patron =/[A-Za-z]/; // Solo acepta letras 
    //patron = /\d/; // Solo acepta números
    patron = /\w/; // Acepta números y letras 
    //patron = /\D/; // No acepta números 
    // patron = /[\d.-]/; numeros el punto y el signo -
    te = String.fromCharCode(tecla); 
    return patron.test(te);	
	// uso  onKeyPress="return validacaracter(event)"
}

function actualiza_producto(){
	document.cesta.action="cesta.php?car=update";
	document.cesta.submit();	
}

function validnum(e) { 
	tecla = (document.all) ? e.keyCode : e.which; 
	//alert(tecla)
    if (tecla==8 || tecla==46) return true; //Tecla de retroceso (para poder borrar) 
    // dejar la línea de patron que se necesite y borrar el resto 
    //patron =/[A-Za-z]/; // Solo acepta letras 
    patron = /\d/; // Solo acepta números
    //patron = /\w/; // Acepta números y letras 
    //patron = /\D/; // No acepta números 
    //patron = /[\d.-]/; numeros el punto y el signo -
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
	// uso  onKeyPress="return validnum(event)"
}

function buscar(url,texto){
	document.f2.action=url+'?q='+ texto;
	document.f2.submit(); 
}

	var testresults
	function checkemail_(value){
		var str = value
		var filter=/^.+@.+\..{2,3}$/

		if (filter.test(str))
			testresults=true
		else{
			alert("Por favor ingrese un e-mail valido...");
			testresults=false
		}
		return (testresults)
	}	
	
	function clave(value){
		var str = value
		var filter=/^.+@.+\..{2,3}$/
			if (filter.test(str))
		testresults=true
			else{
			alert(" Do not accept specials caracters ")
			testresults=false
		}
		return (testresults)
	}

function validar_mis_datos(url){
		document.cuenta.action = "cuenta.php?cuenta="+ url;
		document.cuenta.submit();
}

function validar_mi_contrasenia(url){
		document.cuenta.action = "cuenta.php?cuenta="+ url;
		document.cuenta.submit();
}

//ingreso de clientes
function validar_clientes_olda(opcion){
	//alert(opcion);
	if(document.frm_reg.nombre.value==""){
		alert(" ERROR: Por favor ingrese el nombre ");
		document.frm_reg.nombre.focus();
		return false
	}else if(document.frm_reg.apellidos.value==""){
		alert(" ERROR: Por favor ingrese el apellido ");
		document.frm_reg.apellidos.focus();
		return false	
	}else if(document.frm_reg.dni.value==""){
		alert(" ERROR: Por favor ingrese el dni ");
		document.frm_reg.dni.focus();
		return false	
	}else if(document.frm_reg.email.value==""){
		alert(" ERROR: Por favor ingrese el email ");
		document.frm_reg.email.focus();
		return false	
	}else if(checkemail(document.frm_reg.email.value)== false){
		document.frm_reg.email.value="";
		document.frm_reg.email.focus();
		return false;
	}else if(document.frm_reg.password.value==""){
		alert(" ERROR: Por favor ingrese el Password ");
		document.frm_reg.password.focus();
		return false	
	}else if(document.frm_reg.password_confirma.value==""){
		alert(" ERROR: Por favor ingrese la Conf. de password ");
		document.frm_reg.password_confirma.focus();
		return false	
	}else if(document.frm_reg.password.value!=document.frm_reg.password_confirma.value){
		alert(" ERROR: Por favor ingrese la Conf. de password correcta");
		document.frm_reg.password_confirma.focus();
		return false	
	}else if(document.frm_reg.empresa.value==""){
		alert(" ERROR: Por favor ingrese la Empresa ");
		document.frm_reg.empresa.focus();
		return false	
	}else if(document.frm_reg.direccion.value==""){
		alert(" ERROR: Por favor ingrese la Direccion ");
		document.frm_reg.direccion.focus();
		return false	
	}/*else if(document.frm_reg.suburbio.value==""){
		alert(" ERROR: Por favor suburbio ");
		document.frm_reg.suburbio.focus();
		return false	
	}*/else if(document.frm_reg.cp.value==""){
		alert(" ERROR: Por favor ingrese el codigo postal ");
		document.frm_reg.cp.focus();
		return false	
	}else if(document.frm_reg.poblacion.value==""){
		alert(" ERROR: Por favor ingrese la poblacion ");
		document.frm_reg.poblacion.focus();
		return false	
	}else if(document.frm_reg.provincia.value==""){
		alert(" ERROR: Por favor ingrese la provincia ");
		document.frm_reg.provincia.focus();
		return false	
	}else if(document.frm_reg.pais.value==""){
		alert(" ERROR: Por favor seleccione el pais ");
		document.frm_reg.pais.focus();
		return false	
	}else if(document.frm_reg.telefono.value==""){
		alert(" ERROR: Por favor ingrese el telefono ");
		document.frm_reg.telefono.focus();
		return false	
	}else{
		document.frm_reg.action='cuenta.php?cuenta='+opcion;
		document.frm_reg.submit();
	}
	
}

function validar_acceso_left_1(){
	if(document.frm_reg_1.email.value==""){
		alert("ERROR: ingrese su email ");
		document.frm_reg_1.email.focus();
		return false;
	}else if(checkemail(document.frm_reg_1.email.value)== false){
		document.frm_reg_1.email.value="";
		document.frm_reg_1.email.focus();
		return false;
	}else if(document.frm_reg_1.password.value==""){
		alert("ERROR: ingrese password ");
		document.frm_reg_1.password.focus();
		return false;
	}else{
		//document.frm_reg.action = url + "?cuenta=acceso";
		//document.frm_reg.submit();
	}	
}


function busca_old(){
	url='index.php';
	texto=document.getElementById("q").value;
	if(texto=="" || texto==" Search"){
		alert("Ingrese un criterio para la busqueda");	
		document.getElementById("q").focus();
		return false;
	}else{
		location.href=url+'?q='+ texto;
		//document.frm_search.submit();
	}
}

function img_inicio(){
	document.getElementById("ini").style.backgroundImage='url(aplication/webroot/imgs/img_inicio_blank.jpg)';	
}
function img_inicio_out(){
	document.getElementById("ini").style.backgroundImage='';	
}

function img_cuenta(){
	document.getElementById("cue").style.backgroundImage='url(aplication/webroot/imgs/img_cuenta_blank.jpg)';	
}
function img_cuenta_out(){
	document.getElementById("cue").style.backgroundImage='';	
}

/**/
function img_pedido(){
	document.getElementById("ped").style.backgroundImage='url(aplication/webroot/imgs/img_pedido_blank.jpg)';	
}
function img_pedido_out(){
	document.getElementById("ped").style.backgroundImage='';	
}
/**/

function img_servicio(){
	document.getElementById("sera").style.backgroundImage='url(aplication/webroot/imgs/img_servicios_blank.jpg)';	
}
function img_servicio_out(){
	document.getElementById("sera").style.backgroundImage='';	
}

/**/

function img_contactenos(){
	document.getElementById("cont").style.backgroundImage='url(aplication/webroot/imgs/img_contactenos_blank.jpg)';	
}
function img_contactenos_out(){
	document.getElementById("cont").style.backgroundImage='';	
}
function btn_menos(){
	valor = document.getElementById("cantidad").value;
	if(valor>1){
		valor = valor - 1;
		document.getElementById("cantidad").value = parseInt(valor)
	}
}
function btn_mas(){
	valor = document.getElementById("cantidad").value;
	valor = parseInt(valor) + 1;
	document.getElementById("cantidad").value = parseInt(valor)
}

function ver_sgte(x,y){
	archivo="page_novedades.php?x="+ x + "&y="+y;
	$("#prod_nov").hide();
	$("#prod_nov").load(archivo).fadeIn('slow');
}

function validar_envio_logo(valor){
	//alert(valor)
	document.getElementById("tipo_envio").value=valor;
	if(valor==2){
		document.getElementById("paquete").style.display='';
		document.getElementById("nombre_envio").value="Ud. a elegido PAQUETE AZUL";
	}else{
		document.getElementById("paquete").style.display='';
		document.getElementById("nombre_envio").value="Ud. a elegido ENVIO EXPRESS";
	}
}

/*function validar_pago_logo(valor){
	//alert(valor)
	document.getElementById("tipo_pago").value=valor;
	if(valor==1){
		document.getElementById("paquete").style.display='';
		document.getElementById("nombre_pago").value="Ud. a elegido PAYPAL";
	}else if(valor==2){
		document.getElementById("paquete").style.display='';
		document.getElementById("nombre_pago").value="Ud. a elegido Transferencia Bancaria";
	}else if(valor==3){
		document.getElementById("paquete").style.display='';
		document.getElementById("nombre_pago").value="Ud. a elegido CONTRA REEMBOLSO";
	}
}*/

function validar_pago_logo(valor){
	document.getElementById("tipo_pago").value=valor;
	if(valor==1){
		document.getElementById("paquete").style.display='block';
		document.getElementById("nombre_pago").value="Ud. a elegido SAFETYPAY";
		document.getElementById("moneda").style.display='block';
	}else if(valor==2){
		document.getElementById("paquete").style.display='block';
		document.getElementById("nombre_pago").value="Ud. a elegido TRANS. BANCARIA";
		document.getElementById("moneda").style.display='none';
	}
}

function validar_sendcontrasenia(opcion){
	if(document.cuenta.email.value==""){
		alert(" ERROR: Por favor ingrese su email ");
		document.cuenta.email.focus();
		return false
	}else if(checkemail(document.cuenta.email.value)== false){
		document.cuenta.email.value="";
		document.cuenta.email.focus();
		return false;
	}else{
		document.cuenta.action='cuenta.php?cuenta='+opcion;
		document.cuenta.submit();
	}
}

function validar_send_mailings(opcion){
	if(document.frmemail.email.value==""){
		alert(" ERROR: Por favor ingrese su email ");
		document.frmemail.email.focus();
		return false
	}else if(checkemail(document.frmemail.email.value)== false){
		document.frmemail.email.value="";
		document.frmemail.email.focus();
		return false;
	}else{
		document.frmemail.action='cuenta.php?cuenta='+opcion;
		document.frmemail.submit();
	}
}


function regresar_rp(){
	location.href='cuenta.php?cuenta=recuperar_contrasenia';	
}

function calcular(valor){
	subtotal=0;
	var cod=document.cesta.elements["id[]"];
	tot=document.getElementById("totpro").value;
	for(var g=0;g<tot;g++){
		cantidad = document.getElementById('canti'+g).value;
		if(cantidad>0){
			flag = document.getElementById('canti'+g).value*document.getElementById('txtprecio'+g).value;
			document.getElementById('txttot'+g).value = flag.toFixed(2);
			subtotal = subtotal + parseInt(document.getElementById('txttot'+g).value);
			//actualiza_cesta("update" , cod , cantidad);
			document.cesta.action = 'cesta.php?car=update';
			document.cesta.submit();
		}else if(cantidad==0 || cantidad==""){
			alert("Debe ingresar una cantidad valida");	
			subtotal = subtotal + parseInt(document.getElementById('txttot'+g).value);
			document.getElementById('canti'+g).value = document.getElementById('cantih'+g).value;
			document.getElementById("subtot").value=subtotal.toFixed(2);
			return false;
		}
	}
	document.getElementById("subtot").value=subtotal.toFixed(2);
}


function actualiza_cesta(opcion , id , cantidad){
	//alert("das");
	archivo="update_cesta.php?car="+opcion+'&id='+id+'&cantidad='+cantidad;
	$("#capa_cesta").load(archivo);
}

function validar_ocasion(opcion){
	if(document.cuenta.ocasion.value == ""){
		alert("Inngrese Nombre de Ocasión");
		document.cuenta.ocasion.focus();
		return false
	}else{
		document.cuenta.action='cuenta.php?cuenta='+opcion;
		document.cuenta.submit();
	}	
}

function eliminar_ocasion(id){
	if(!confirm("Esta Seguro que desea Eliminar el Registro")){
		return false;	
	}else{
		location.replace('cuenta.php?cuenta=deleteocasion&id='+id);			
	}	
}

function validar_acceso_top(){
	if(document.ftop.q.value==""){
		alert("Ingrese un criterio para la busqueda");
		document.ftop.q.focus();
		return false;
	}else{
		document.ftop.action='index.php?q='+document.ftop.q.value;
		document.ftop.submit();
	}	
}

function validar_e(val){
	//alert(val);
	document.envio.tipo_envio.value=val;
}

function ver_mapa(){
	//$("#mapa_empresa").fadeIn('slow');	
	//$("#reporte_egreso").
	window.open('mapa.php','Hydrosuministros','width=780,height=360,scrollbars=0');
}

function ver_todo_d(valor){
	$('#capad'+valor).show('slow');	
	//alert(document.getElementById('capad'+valor).value);
}

function ocultar_todo_d(valor){
	$('#capad'+valor).hide('slow');	
	//alert(document.getElementById('capad'+valor).value);
}

function ver_respuesta(){
	$('#oculto').show('slow');	
}

function ver_banco(valor){
	document.checkout_confirmation.slcBankID.value=valor;
}

function apedido(){
	document.cesta.action='pedido.php';
	document.cesta.submit();
}

function ver_exoneracion(valor){
	//alert(valor);
	if(valor!='Perú'){
		$('#exo').show('slow');
	}else{
		$('#exo').hide('slow');
	}
	
	if(valor=='Perú' || valor=='México' || valor=='Austria'){
		$('#her').show('slow');
		$('#her1').show('slow');
	}else{
		$('#her').hide('slow');
		$('#her1').hide('slow');
	}
	
}
