function busqueda(criteria){
	window.location = "busqueda.php?c="+criteria;
}

function checkEnter(e){ //e is event object passed from function invocation
//var characterCode literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//document.forms[0].submit() //submit the form
window.location = "busqueda.php?c="+document.getElementById('busqueda').value;
return false
}
else{
return true
}

}

function verificar(){
	nombre=document.getElementById('nombre').value;
	apellido=document.getElementById('apellido').value;
	email=document.getElementById('correo').value;
	mensaje=document.getElementById('mensaje').value;
	if(nombre!="" && apellido!="" && email!="" && mensaje!=""){
			
			var s = email;
			var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
			if (s.length == 0 ) {
				flag=0;
				return true;
			}
			if (filter.test(s)){
				flag=0;
				return true;
			}else{
				alert("Su correo no es valido");
				document.getElementById('email').focus();
				flag=1;
				return false;
			}
	
			
		
	}else{
		alert("Todos los campos son obligatorios.");
		return false;
	}
}

function calcular(){
	
	material=document.getElementById('material_select').value;
	//split para material que viene concatenado con su nombre
	material_array=material.split('||');
		
	cantidad=document.getElementById('cantidad_select').value;
	//split para cantidad que viene concatenado con su nombre
	cantidad_array=cantidad.split('||');
	
	if(document.getElementById('radio1').checked){
		costo_design=document.getElementById('radio1').value;
	}
	if(document.getElementById('radio2').checked){
		costo_design=document.getElementById('radio2').value;
	}
	
	costo=material_array[0]*cantidad_array[0];
	
	//alert(costo+"  antes");
	//costo=formatNumber(costo,'');
	//alert(costo+"  despues");
	//costo=parseFloat(costo);
	//alert(costo+"  despues de parse float");
	//costo_design=parseFloat(costo_design);
	
	if(costo_design=="0.00" || costo_design==0){
		costo=(costo);
	}else{	
		costo=(costo)+(eval(costo_design));
	}	
	
	costo=formatNumber(costo,'');
	document.getElementById('costo_div').innerHTML="<b>Costo: $"+costo+"</b>";
	document.getElementById('cantidad_value').value=cantidad_array[0];
	document.getElementById('cantidad_name').value=cantidad_array[1];
	document.getElementById('material_value').value=material_array[0];
	document.getElementById('material_name').value=material_array[1];
	document.getElementById('arte_precio').value=costo_design;
}

function formatNumber(num,prefix)
{
num = Math.round(parseFloat(num)*Math.pow(10,2))/Math.pow(10,2)
prefix = prefix || '';
num += '';
var splitStr = num.split('.');
var splitLeft = splitStr[0];
var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '.00';
splitRight = splitRight + '00';
splitRight = splitRight.substr(0,3);
var regx = /(\d+)(\d{3})/;
while (regx.test(splitLeft)) {
splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
}
return prefix + ' ' + splitLeft + splitRight;
}

function esPermitido(e){
	var charCode
	
	if (navigator.appName == "Netscape"){
		charCode = e.which;
	}else{
		charCode = e.keyCode;
	}	
	
	if ((charCode < 48 || charCode > 57)&&(charCode!=13 && charCode!=8  && charCode!=9 && charCode!=0)){
		alert("Por favor solo numeros!");
		return false
	}else{		
		return true;
	}
}

function actualizar(array){
	array_split = array.split('-');
	var pares="";
	for (var i=0;i<array_split.length;i++){
		if(pares==""){
			pares=array_split[i]+"-"+document.getElementById('cant_'+array_split[i]).value;
		}else{
			pares=pares+"|"+array_split[i]+"-"+document.getElementById('cant_'+array_split[i]).value;
		}
	}
	//alert(pares);
	window.location = "actualiza_carrito.php?pares="+pares;
}

function send_form(){
	document.form1.submit();
}
function send_form1(){
	document.form_login.submit();
}

function add_envio(){
	if(document.getElementById('radio1').checked){
		costo_envio=document.getElementById('radio1').value;
		document.getElementById('div_direccion').style.display="none";
	}
	if(document.getElementById('radio2').checked){
		costo_envio=document.getElementById('radio2').value;
		document.getElementById('div_direccion').style.display="inline";
	}
	
	var url ="ajax_carrito.php";
	var parametros = "envio="+costo_envio;
	var metodo = "POST";
	var update = "ajax_totales";
	var loader = "true";
	var img = "cargando";
	ajaxFunction(url,parametros,metodo,update,loader,img);

}

function tipo_pago(){
	if(document.getElementById('div_pago').style.display=="inline"){
		document.getElementById('div_pago').style.display="none";
	}else{	
		document.getElementById('div_pago').style.display="inline";
	}	
}

function send_carrito(){
	document.form_carrito.submit();
}


function verify_fields(){
	email=document.getElementById('emails').value;
	r_email=document.getElementById('r_email').value;
	contrasena=document.getElementById('contrasena').value;
	r_contrasena=document.getElementById('r_contrasena').value;
	nombre=document.getElementById('nombre').value;
	apellido=document.getElementById('apellido').value;
	compania=document.getElementById('compania').value;
	telefono1=document.getElementById('telefono1').value;
	telefono2=document.getElementById('telefono2').value;
	
	if(!(nombre=="" || apellido=="" || telefono1=="" || email=="" || r_email=="" || contrasena=="" || r_contrasena=="")){
		
		flag1=0;
		
//para validar q el correo sea valido		
			var s = email;
			var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
			if (s.length == 0 ) {
				flag=0;
				//return true;
				flag1=1;
			}
			if (filter.test(s)){
				flag=0;
				//return true;
				flag1=1;
			}else{
				alert("Su correo no es valido");
				document.getElementById('email').focus();
				flag=1;
				flag1=0;
				return false;
			}	
//hasta aqui para validar que el correo sea valido

			if(email!=r_email){
				alert("Los email no coinciden.");
				return false;
			}
			
			
			if(contrasena!=r_contrasena){
				alert("Las contrase&ntilde;as deben coincidir.");
				return false;
			}
			
			if(flag1==1){
				return true;
			}else{
				return false;
			}
			
			
	}else{
		alert("Los campos con * son obligatorios.");
		return false;
	}
			
}

function hide_div(){
	document.getElementById('div_busqueda').innerHTML='<input type="text" id="busqueda" name="busqueda" value="" onkeypress="checkEnter(event)" style="font-size:11px;width:153px;border:0;">';
}

function direccionar(option){
	if(option==1){
		window.location = "productos.php";
	}else if(option==2){
		window.location = "user_acces.php?show=1";
	}
}

function cerrar_session(){
	window.location = "logout.php";
}
