

//------------------------------------------------------------------------------------
function iratras(){
	javascript:history.back();
}

function iradelante(){
	javascript:history.forward();
}

function ir_apagina(nom_pagina){
	window.location.href = nom_pagina;
}

//------------------------------------------------------------------------------------
/* 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,pagina){
	var accion=pagina;
//	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

//------------------------------------------------------------------------------------
function CambiarValor_2(id_form,id_var,valor){
	//document.forms[id_form].accion.value=valor;
	document.forms[id_form].elements[id_var].value=valor
 	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 toggle_2(elemento){
		if (document.getElementById(elemento).style.display=='none')
			{document.getElementById(elemento).style.display='block';}
		else
			{document.getElementById(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;}
		
}

//------------------------------------------------------------------------------------
// Revisar este codigo pues no funciona bien
function VerificarClaves(id_form,clave1,clave2,tamCadena){
		
		var c1=jsTrim_(document.forms[id_form].elements[clave1].value);
		var c2=jsTrim_(document.forms[id_form].elements[clave2].value);
		
		if (!EsEntero(tamCadena)){
			tamCadena=255;
		}
		
		//if (c1.length>=tamCadena && c2.length>=tamCadena){
			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 PasarEleCheckeados(id_formPadre,varPadre)
{	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;
		}
	}
	window.opener.document.forms[id_formPadre].elements[varPadre].value=txt;
}
//-----------------------------------------------------------------------------------
function PasarEleCheckeados_2(id_formPadre,varPadre,varAdicional)
{	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;
		}
	}
	window.opener.document.forms[id_formPadre].elements[varPadre].value=txt;
	if (varAdicional!=""){
		valor=document.forms[0].elements[varAdicional].value;
		window.opener.document.forms[id_formPadre].elements[varAdicional].value=valor;
	}
}

//-----------------------------------------------------------------------------------
function checkearTodos(){
	for (var i=0;i < document.forms[0].elements.length;i++)	{
		var elemento = document.forms[0].elements[i];
		if (elemento.type == "checkbox"){
			elemento.checked="true";
		}
	}
}

//-----------------------------------------------------------------------------------
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;
}

//------------------------------------------------------------------------------------
// Desactivar un elemento del formulario id_form
function desactivar_elemento(id_form,elemento){
	//alert (id_form+' '+elemento);
		document.forms[id_form].elements[elemento].disabled=true;
}
//------------------------------------------------------------------------------------
// Activar un elemento del formulario id_form
function activar_elemento(id_form,elemento){
		document.forms[id_form].elements[elemento].disable=false;
}
//------------------------------------------------------------------------------------
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;
}
/*
<form action method="POST" name="formulario" id="formulario" onsubmit="tu_funcion(); ">*/

//Para Checkear Fomulario


function VerificarForm_Productos(id_form) {
	//alert (document.formu.age.value+' '+document.formu.age.type);
	var flag=true;
	var errorMsg="";
		
	var anchoMin=document.forms[id_form].elements['val_anchomin'].value;
	var anchoMax=document.forms[id_form].elements['val_anchomax'].value;
	var anchoLim=document.forms[id_form].elements['val_ancholim'].value;
	var largoMin=document.forms[id_form].elements['val_largomin'].value;
	var largoMax=document.forms[id_form].elements['val_largomax'].value;
	var largoLim=document.forms[id_form].elements['val_largolim'].value;
	anchoMin=parseFloat(anchoMin);
	anchoMax=parseFloat(anchoMax);
	largoMin=parseFloat(largoMin);
	largoMax=parseFloat(largoMax);
	anchoLim=parseFloat(anchoLim);
	largoLim=parseFloat(largoLim);
	
	
	if (anchoMin>=anchoMax){
		errorMsg += "El Ancho minimo debe ser menor que el Ancho maximo.\n";
	}
	
	if (largoMin>=largoMax){
		
		errorMsg += "El Largo minimo debe ser menor que el Largo maximo.\n";
	}
	
	if ((anchoLim<anchoMin) || (anchoLim>anchoMax)){
		errorMsg += "Limite Dificultad Ancho no esta en el rango.\n";
	}
	
	if ((largoLim<largoMin) || (largoLim>largoMax)){
		errorMsg += "Limite Dificultad Largo no esta en el rango.\n";
	} 
	
	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 erronea: -\n";		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;

}




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