
/* uso de esta fns
id_form=identiifcador del form, valor=pagina a la cual se hace referencia
<INPUT TYPE='submit' name='eliminar' value='Eliminar seleccionado' onClick=\"JavaScript:destino('TS','TiposSello_Eliminar.php');\">*/
//------------------------------------------------------------------------------------
function destino(id_form,valor){
	var accion=valor;
//	alert ("Pasando por JS");
//	window.document.frmTiposSello.action = accion;
 	window.document.forms[id_form].action = accion;
	document.forms[id_form].submit();
 	return true;
}
//------------------------------------------------------------------------------------
function destino_mismapagina(id_form,valor){
	var accion=valor;
//	alert ("Pasando por JS");
//	window.document.frmTiposSello.action = accion;
 	window.document.forms[id_form].action = accion;
	document.forms[id_form].submit();
 	return true;
}

function submit_fns(id_form){
//	var accion="'tabla_ped','../fns_clasesBase/CargaTablaPedidos_class.php?var=52";
//	alert ("Pasando por JS");
//	window.document.frmTiposSello.action = accion;
// 	window.document.forms[id_form].action = accion;
	alert (document.forms[id_form].name);
	document.forms[id_form].submit();
 	return true;
}


//------------------------------------------------------------------------------------
//cambiar el valor de una variable de un formulario
//en esta caso la variable se llama "accion"
///

function CambiarValor(id_form,valor){
//	alert ("Pasando por JS fredy" );
	document.forms[id_form].accion.value=valor;
//	alert (	document.forms[id_form].accion.value);
 	return true;
 
} //fin de funcion


//------------------------------------------------------------------------------------
//funcion para ocultar o mostrar un bloque que este dentro de un  <Div>bloque</Div>
function toggle(elemento){
	if (elemento.style.display=='none')
		{elemento.style.display='block';}
	else
		{elemento.style.display='none';}
}
//------------------------------------------------------------------------------------
function EsNumerico(valor){
		var number = parseFloat(valor);
		if (isNaN(number)==true)
			return false; 
			//alert("No es numérico");
		else
			return true;
			//alert("Es numérico");
}
//------------------------------------------------------------------------------------
function EsEntero(valor){ 
      //intento convertir a entero. 
     //si era un entero no le afecta, si no lo era lo intenta convertir 
     valor = parseInt(valor) 

      //Compruebo si es un valor numérico 
      if (isNaN(valor)) { 
            //entonces (no es numero) devuelvo el valor cadena vacia 
            return false;
      }else{ 
            //En caso contrario (Si era un número) devuelvo el valor 
            return true; 
      } 
}
//------------------------------------------------------------------------------------
	
function popUp(URL,target_,ancho,alto) {
	left_=(screen.width-ancho) / 2;
	top_=(screen.height-(alto*2)) / 2;
	param="toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0";
	window.open(URL,target_,param + ",width=" + ancho + ",height=" + alto + ",left =" + left_ + ",top =" + top_);
}
	

//------------------------------------------------------------------------------------
function Confirmacion(mensaje){
		if (msm=""){ mensaje="Desea realizar la acción?";}
		if (confirm (mensaje)){
			return true;
		}
		else { return false;}
		
}

//------------------------------------------------------------------------------------
function VerificarClavesIguales(id_form,clave1,clave2){
		
		var c1=jsTrim_(document.forms[id_form].elements[clave1].value);
		var c2=jsTrim_(document.forms[id_form].elements[clave2].value);
		if 	(c1==c2)
			{return true;}
		else { alert("Las claves no son iguales"); return false;}
}
//------------------------------------------------------------------------------------
function jsTrim_(JSvalue) { 
	//La típica función de quitar espacios en blanco de la mayoría de los lenguajes de programación
	var JStemp = JSvalue;
	var JSobj = /^(\s*)([\W\w]*)(\b\s*$)/;
	//Elimina los espacios de delante y detrás
	if (JSobj.test(JStemp)) 
		{ JStemp = JStemp.replace(JSobj, '$2'); }
		//Elimina los espacios duplicados
	var JSobj = / +/g;
	JStemp = JStemp.replace(JSobj, " ");
	if (JStemp == " ") 
		{ JStemp = ""; }
	return JStemp;
}


//------------------------------------------------------------------------------------
/*function valoresChecked(id_form,nombre){
	nom=document.form[id_form].+nombre;
	//cafe=document.formu.cafe;

  	respuesta=document.formu.respuesta;
  	txt="";

  	for (i=0;i<nom.length;++i){
 		if (nom[i].checked) {
			txt=txt + cafe[i].value + " ";
  		}
  	}
    respuesta.value="Tu quieres café con " + txt;
 
}*/

//-----------------------------------------------------------------------------------
function todos(id_formPadre,varPadre,chkbox)
{	var txt = "";
	var flag=true;
	for (var i=0;i < document.forms[0].elements.length;i++)	{
		var elemento = document.forms[0].elements[i];
		if (elemento.type == "checkbox"){
			if (elemento.checked==true)
				if (flag){
					txt+=elemento.value;
					flag=false;
				}
				else txt+=', '+elemento.value;
					
			//elemento.checked = "checked"; //chkbox.checked
		}
	}
	window.opener.document.forms[id_formPadre].elements[varPadre].value=txt;
	
	//return txt;
}


//------------------------------------------------------------------------------------
function TS_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_tiposello.value == ""){
		errorMsg += "\n\tNombre Tipo Sello \t- Entre Tipo de Sello";	
	}
	
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}

//------------------------------------------------------------------------------------
/////////////////////////////////////////////
function TM_CheckForm_addUpdate(id_form){ 

	//inicio de variables
	var errorMsg = "";

	//Check nombre
	if (document.forms[id_form].nom_tipomaterial.value == ""){
		errorMsg += "\n\tNombre Tipo Sello \t- Entre Tipo de Sello";	
	}
	if (document.forms[id_form].densidad.value == ""){
		errorMsg += "\n\tDensidad \t- Entre densidad";	
	}
	if (document.forms[id_form].abreviatura.value == ""){
		errorMsg += "\n\tAbreviatura \t- Entre abreviatura";	
	}
	
		
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}

//------------------------------------------------------------------------------------
////////////////////////////////
//para Colores
/////////////////////////////////
function COL_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_color.value == ""){
		errorMsg += "\n\tNombre de Color \t- Entre Color";	
	}
	
	if (document.forms[id_form].valor.value == ""){
		errorMsg += "\n\tValor \t- Entre Valor del Color";	
	}
	
	if (!EsNumerico(document.forms[id_form].valor.value)){
		errorMsg += "\n\tValor \t- Entre un Valor numérico";	
	}
	
	
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
//------------------------------------------------------------------------------------
//Formularios Categoria 
//funcion para verificar entrada de campos en formuarios Add y Update 
function CAT_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_categoria.value == ""){
		errorMsg += "\n\tNombre de Categoria \t- Entre Categoria";	
	}
	

	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
//------------------------------------------------------------------------------------
//Formularios Productos
//funcion para verificar entrada de campos en formuarios Add y Update 
function PRO_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_producto.value == ""){
		errorMsg += "\n\tNombre de Producto \t- Entre nombre del Producto";
	}
	
	if (document.forms[id_form].val_desctroquel.value == ""){
		errorMsg += "\n\tDescuento por troquel \t- Entre Descuento por troquel";
	}
	if (document.forms[id_form].val_softloop.value == ""){
		errorMsg += "\n\tSoft Loop \t- Entre Soft Loop";
	}
		
	if (document.forms[id_form].id_categoria.value==3 &&
	    document.forms[id_form].val_softloop.value==0){
	    	errorMsg += "\n\tSoft Loop debe ser diferente de 0";
	}
		
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
//------------------------------------------------------------------------------------
//Formularios Estados
//funcion para verificar entrada de campos en formuarios Add y Update 
function EST_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_estado.value == ""){
		errorMsg += "\n\tNombre de Estado \t- Entre nombre del Estado";
	}
	
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
//------------------------------------------------------------------------------------
//Formularios Ciudades
//funcion para verificar entrada de campos en formuarios Add y Update 
function CIU_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_ciudad.value == ""){
		errorMsg += "\n\tNombre de Ciudad \t- Entre nombre de la Ciudad";
	}
	
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}
//------------------------------------------------------------------------------------

////////////////////////////////
//para Clientes
/////////////////////////////////
function CLI_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_cliente.value == ""){
		errorMsg += "\n\t error \t- Entre Cliente";	
	}
	if (document.forms[id_form].razonsocial.value == ""){
		errorMsg += "\n\t error \t- Entre Razon Social";	
	}
	
	if (document.forms[id_form].direccion.value == ""){
		errorMsg += "\n\t error \t- Entre Direccion";	
	}
	
	if (document.forms[id_form].telefono1.value != ""){
		if (!EsEntero(document.forms[id_form].telefono1.value)){
			errorMsg += "\n\tTelefono 1\t- Entre solo numeros";	
		}
	}
	
	if (document.forms[id_form].telefono2.value != ""){
		if (!EsEntero(document.forms[id_form].telefono2.value)){
			errorMsg += "\n\tTelefono 2 \t- Entre solo numeros";	
		}
	}
	
	if (document.forms[id_form].fax1.value != ""){
		if (!EsEntero(document.forms[id_form].fax1.value)){
			errorMsg += "\n\tFax 1\t- Entre solo numeros";	
		}
	}
		
	if (document.forms[id_form].fax2.value != ""){
		if (!EsEntero(document.forms[id_form].fax2.value)){
			errorMsg += "\n\tFax 2\t- Entre solo numeros";	
		}
	}
	
	if (document.forms[id_form].zip_code.value != ""){
		if (!EsEntero(document.forms[id_form].zip_code.value)){
			errorMsg += "\n\tZIP Code\t- Entre solo numeros";	
		}
	}
	
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}	
////////////////////////////////
//para Contactos
/////////////////////////////////
function CONT_CheckForm_addUpdate(id_form) { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre

	if (document.forms[id_form].nom_contacto.value == ""){
		errorMsg += "\n\tNombre de Contacto \t- Entre Contacto";	
	}
	
	if ((document.forms[id_form].email.value == "") || 
		(document.forms[id_form].email.value.length > 0 && 
		(document.forms[id_form].email.value.indexOf("@",0) == - 1 ||
		 document.forms[id_form].email.value.indexOf(".",0) == - 1))) 
	{ 
		errorMsg += "\n\tEmail \t- Entre su e-mail (direccón de correo electrónico)";
	}
	
	if (document.forms[id_form].tel.value == ""){
		errorMsg += "\n\tTelefono \t- Entre telefono";	
	}
	
	if (document.forms[id_form].movil.value == ""){
		errorMsg += "\n\tmovil \t- Entre movil";	
	}
	
	if (!EsEntero(document.forms[id_form].tel.value)){
		errorMsg += "\n\tTelefono \t- Entre un Valor numérico";	
	}
	
	if (!EsEntero(document.forms[id_form].movil.value)){
		errorMsg += "\n\tMovil \t- Entre un Valor numérico";	
	}
	
	
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido agregada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}


/*
<form action method="POST" name="formulario" id="formulario" onsubmit="tu_funcion(); ">*/

//Para Checkear Fomulario


function CheckForm_modelo () { 

	//inicio de variables
	var errorMsg = "";

	//Check nombre
	if (document.frmEntrada.nom_tiposello.value == ""){
		errorMsg += "\n\tNombre Tipo Sello \t- Entre Tipo de Sello";	
	}
	
	//Check apellido
	if (document.frmEntrada.apellido.value == ""){
		errorMsg += "\n\tApellido(s) \t- Entre su apellido(s)";
	}
	
	if (document.frmEntrada.empresa.value == ""){
		errorMsg += "\n\tEmpresa \t- Entre el nombre de su empresa";
	}
	if (document.frmEntrada.telefono.value == ""){
		errorMsg += "\n\tTeléfono \t- Entre un número telefónico";
	}
	//Check e-mail valido
	if ((document.frmEntrada.email.value == "") || (document.frmEntrada.email.value.length > 0 && (document.frmEntrada.email.value.indexOf("@",0) == - 1 || document.frmEntrada.email.value.indexOf(".",0) == - 1))) { 
		errorMsg += "\n\tE-mail \t- Entre su e-mail (direccón de correo electrónico)";
	}
	
	if (document.frmEntrada.body.value == ""){
		errorMsg += "\n\tComentarios \t- Entre un comentario";
	}
	//Desplegar problemas encontrados
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Su información no ha sido enviada porque existen problemas con el formulario.\n";
		msg += "Por favor corrija el problema y reenvie el formulario.\n";
		msg += "______________________________________________________________\n\n";
		msg += "La siguiente información es necesaria: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	
	return true;
}