// JavaScript Document
var nav4 = window.Event ? true : false;
var modulos=''
var URL = unescape(location.href)	
var xstart = URL.lastIndexOf("/") + 1
var xend = URL.length
var hereName = URL.substring(xstart,xend)
var url2=unescape(hereName)	
var xend2 = url2.lastIndexOf("?")
if (xend2>-1)
	{
	var final=hereName.substring(0,xend2)
	var nom_pagina=final.replace(/.php/,"")
	}
else
	{
	var nom_pagina=hereName.replace(/.php/,"")
	}

function mensajes()
{

var query = window.location.search.substring(1);
if (query=="we345hidq"){alert("Los datos ingresados son incorrectos.")}
if (query=="endsessions"){alert("Por favor, Identifíquese.")}
if (query=="enviook"){alert("Los datos de acceso fueron enviados a su email.")}
//if (query=="msjok"){alert("Su mensaje fue enviado con éxito."+"\n"+"En breve nos comunicaremos con usted."+"\n"+"Gracias!!!")}
//if (query=="bolsaok"){alert("Sus datos fueron enviados con éxito."+"\n"+"En breve nos comunicaremos con usted."+"\n"+"Gracias!!!")}
//alert("aaa");
}
function mensaje_import(procesadas,insertadas,noencontradas,dianoencontrados)
{
	
if (dianoencontrados!='')
	{leyen="Notese que los espacion en balnco estan representados por N"}
	else
	{leyen=""}
if(procesadas!="")
	{
		alert("El proceso concluyó con éxito."+"\n"+"-Cantidad de registros en el archivo: "+procesadas+"\n"+"-Cantidad de registros importados: "+insertadas+"\n"+"-Paradas no encontradas: "+noencontradas+"\n"+"-Combinación de días no encontrados:"+dianoencontrados+"\n"+leyen)
	}
}
function tamano()
{
	if(document.form1.lst_tipos.value=="I")
	{
	document.getElementById('tam').style.display=""
	}
	else
	{
	document.getElementById('tam').style.display="none"
	}
	if(document.form1.lst_tipos.value=="A")
		{
		document.getElementById('descrimedia').style.display="none"
		document.getElementById('linkmedia').style.display="none"
		}
	else
		{
		document.getElementById('descrimedia').style.display=""
		document.getElementById('linkmedia').style.display=""
		}
}
function valida_import(id)
{
if (document.form1.txt_file.value=="")
	{
	alert("Debe seleccionar el archivo a importar.")
	}
else
	{
	var archivo=document.form1.txt_file.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".csv")))
		{
			alert("El archivo debe ser tipo .csv")
		}
	else
		{
			document.form1.action="import.php?id="+id;
			document.form1.submit();
		}
	}
}
function valida_grlbanners()
{
	if(document.form1.lst_estilo.value==1)
	{
		if(document.form1.txt_guardado.value==""){document.form1.txt_guardado.value=document.form1.txt_imagen.value}
		if ((document.form1.txt_guardado.value=="")|(document.form1.txt_link.value==""))
			{
			alert("Todos los datos son obligatorios.")
			}
		else
			{
			var archivo=document.form1.txt_imagen.value
			extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
			if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif"))  )
				{
				alert("La archivo debe ser una imágen  .jpg o .gif");
				}
			else	
				{
				if (document.form1.txt_id.value!="")
					{
					accion="updt"
					id=document.form1.txt_id.value
					busca_duplicado(accion,'banners',document.form1.txt_imagen.value,id)
					}
				else
					{
					accion="add"
					id=document.form1.txt_id.value
					busca_duplicado(accion,'banners',document.form1.txt_imagen.value,id)
					}
				}
			}
		}
	else
		{
			if (document.form1.txt_id.value!="")
					{
					accion="updt"
					id=document.form1.txt_id.value
					busca_duplicado(accion,'banners',document.form1.txt_imagen.value,id)
					}
				else
					{
					accion="add"
					id=document.form1.txt_id.value
					busca_duplicado(accion,'banners',document.form1.txt_imagen.value,id)
					}
		}
}
function valida_documentos()
{
if(document.form1.txt_guardado.value==""){document.form1.txt_guardado.value=document.form1.txt_archivo.value}
if ((document.form1.txt_guardado.value=="")|(document.form1.txt_nombre.value==""))
	{
	alert("Debe especificar un título para el documento y un archivo.")
	}
else
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'documentos',document.form1.txt_nombre.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'documentos',document.form1.txt_nombre.value,id)
		}
	}
}
function valida_periodos()
{
if(document.form1.txt_guardado.value==""){document.form1.txt_guardado.value=document.form1.txt_foto.value}
if ((document.form1.txt_guardado.value=="")|(document.form1.txt_descripcion.value==""))
	{
	alert("Todos los datos son obligatorios.")
	}
else
	{
	var archivo=document.form1.txt_foto.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & (extension != ".zip"))
		{
			alert("La archivo debe ser un archivo comprimido .zip");
		}
		else	
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'periodos',document.form1.txt_descripcion.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'periodos',document.form1.txt_descripcion.value,id)
			}
		}
	}		
}
function updt_grlbanners(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_guardado.value=arr[1]

if(arr[5]==1)
		{
		var selObj = document.getElementById('lst_estilo');
		selObj.options[0].selected =1
		}
	else
		{
		var selObj = document.getElementById('lst_estilo');
		selObj.options[1].selected =2
		}
if(arr[5]==1)
{
	document.getElementById('ban1').style.display="block"
 	document.getElementById('ban3').style.display="block"
			document.getElementById('ban4').style.display="none"

	document.form1.txt_link.value=arr[2]
	var can = (document.getElementById('lst_pagina').length)
	opt=''
	if (can>0)
		{
		for (var g=0; g < can;g++)
			 {
			 var tex=document.form1.lst_pagina[g].text;
			   if (arr[3]==tex)
				{
					opt=g}
			 }
		}
	
	if (opt)
		{
		var selObj = document.getElementById('lst_pagina');
		selObj.options[opt].selected =opt
		}
	if(arr[4]==1)
		{
		var selObj = document.getElementById('lst_tipo');
		selObj.options[0].selected =1
		}
	else
		{
		var selObj = document.getElementById('lst_tipo');
		selObj.options[1].selected =2
		}
	
	}
else
	{
		
	document.getElementById('ban1').style.display="none"
	document.getElementById('ban3').style.display="none"
	document.getElementById('ban4').style.display="block"
	document.form1.txt_link.value=arr[2]
	var can = (document.getElementById('lst_pagina').length)
	opt=''
	if (can>0)
		{
		for (var g=0; g < can;g++)
			 {
			 var tex=document.form1.lst_pagina[g].text;
			   if (arr[3]==tex)
				{
					opt=g}
			 }
		}
	
	if (opt)
		{
		var selObj = document.getElementById('lst_pagina');
		selObj.options[opt].selected =opt
		}
	var oEditor = FCKeditorAPI.GetInstance('txt_descripcion');
		oEditor.SetHTML (arr[6], true);
	if(arr[4]==1)
		{
		var selObj = document.getElementById('lst_tipo');
		selObj.options[0].selected =1
		}
	else
		{
		var selObj = document.getElementById('lst_tipo');
		selObj.options[1].selected =2
		}
		
	}

}
function updt_periodos(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
document.form1.txt_guardado.value=arr[2]
}
function valida_galeria_items()
{
if(document.form1.txt_guardado.value==""){document.form1.txt_guardado.value=document.form1.txt_imagen.value}
if ((document.form1.txt_titulo.value=="")|(document.form1.txt_guardado.value==""))
	{
	alert("Todos los datos son obligatorios.")
	}
else
	{
	var archivo=document.form1.txt_guardado.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".jpg") & (extension != ".gif")))
		{
			alert("La extensión del archivo debe ser tipo jpg o gif.");
			document.form1.txt_guardado.value=""
		}
	else
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'galeria_items',document.form1.txt_titulo.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'galeria_items',document.form1.txt_titulo.value,id)
			}
		}
	}
}
function updt_galeria_items(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_titulo.value=arr[1]
document.form1.txt_guardado.value=arr[2]
}
function updt_moviles(foco,valores)
{

mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
var can = (document.getElementById('lst_tipo').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipo[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipo');
	selObj.options[opt].selected =opt
	}
var oEditor = FCKeditorAPI.GetInstance('txt_caracteristicas');
oEditor.SetHTML (arr[3], true);
}
function updt_personal(foco,valores,modulos)
{
document.getElementById('reset').style.display="block";	
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
a=modulos.split("@")
cant=a.length
for (var g=0; g < cant-1;g++)
	 {	
		var new_option = new Option(a[g], a[g], false, false);
		document.getElementById('lst_incgrupos').options[g] = new_option;	
	 }
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
document.form1.txt_apellidos.value=arr[2]
document.form1.txt_dni.value=arr[3]
document.form1.txt_email.value=arr[4]
document.form1.txt_puesto.value=arr[6]
var can = (document.getElementById('lst_tipo').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipo[g].text;
		  if (arr[7]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipo');
	selObj.options[opt].selected =opt
	}
}
function updt_notificaciones(foco,valores,modulos)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
mod1=modulos.split("|")
a=mod1[0].split("@")
cant=a.length
for (var g=0; g < cant-1;g++)
	 {	
		var new_option = new Option(a[g], a[g], false, false);
		document.getElementById('lst_inccompanias').options[g] = new_option;	
	 }
a=mod1[1].split("@")
cant=a.length
for (var g=0; g < cant-1;g++)
	 {	
		var new_option = new Option(a[g], a[g], false, false);
		document.getElementById('lst_incgrupos').options[g] = new_option;	
	 }
a=mod1[2].split("@")
cant=a.length
for (var g=0; g < cant-1;g++)
	 {	
		var new_option = new Option(a[g], a[g], false, false);
		document.getElementById('lst_incpersonal').options[g] = new_option;	
	 }
document.form1.txt_id.value=arr[0]
document.form1.txt_asunto.value=arr[1]
var can = (document.getElementById('lst_documento').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_documento[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_documento');
	selObj.options[opt].selected =opt
	}
var oEditor = FCKeditorAPI.GetInstance('txt_mensaje');
oEditor.SetHTML (arr[3], true);
if(arr[5]>0)
		{
			document.getElementById('opciones').style.display="block";
			if(arr[5]==1)
				{
				document.getElementById('adjunto1').checked=true
				document.getElementById('adjunto2').checked=false
				}
			else
				{
				document.getElementById('adjunto1').checked=false
				document.getElementById('adjunto2').checked=true
				}				
		}
	else
		{
			document.getElementById('opciones').style.display="none";
		}
}
function conadjunto()
{
	val=document.getElementById('lst_documento').value
	if(val>0)
		{
			document.getElementById('opciones').style.display="block";
		}
	else
		{
			document.getElementById('opciones').style.display="none";
		}
}
function updt_grupos(foco,valores)
{

mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
var can = (document.getElementById('lst_tipo').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipo[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipo');
	selObj.options[opt].selected =opt
	}
var oEditor = FCKeditorAPI.GetInstance('txt_incluye');
oEditor.SetHTML (arr[3], true);
}
function updt_tarifas(foco,valores)
{

mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
document.form1.txt_importe.value=arr[2]
document.form1.txt_desde.value=arr[3]
document.form1.txt_hasta.value=arr[4]
}
function updt_lineas(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
var can = (document.getElementById('lst_tipo').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipo[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipo');
	selObj.options[opt].selected =opt
	}
document.form1.txt_numero.value=arr[4]
var can = (document.getElementById('lst_compania').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_compania[g].text;
		  if (arr[5]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_compania');
	selObj.options[opt].selected =opt
	}

document.form1.txt_incidencia.value=arr[6].replace(/<br>/g,"\r");

}
function updt_itinerarios(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
var can = (document.getElementById('lst_linea').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_linea[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_linea');
	selObj.options[opt].selected =opt
	}
document.form1.txt_contacto.value=arr[3]
detalle=arr[4]
var oEditor = FCKeditorAPI.GetInstance('txt_notas');
oEditor.SetHTML (detalle, true);
}

function add_incidencias(foco){
	mue_form(foco);
	document.getElementById("lst_paradadesde").options.length = 0;
	document.getElementById("lst_paradadesde").options[0]=new Option("Seleccione...", 0, false, false);
	document.getElementById("lst_paradahasta").options.length = 0;
	document.getElementById("lst_paradahasta").options[0]=new Option("Seleccione...", 0, false, false);	
}

function updt_incidencias(foco,valores){
	mue_form(foco);
	valores=valores.replace(/ª/g,"'");
	valores=valores.replace(/ç/g,'"');
	arr=valores.split("|");

	document.form1.txt_id.value=arr[0];
	//Itinerario
	var can = (document.getElementById('lst_itinerario').length);
	opt='';
	if (can>0){
		for (var g=0; g < can;g++) {
			 var tex=document.form1.lst_itinerario[g].value;
			  if(arr[1]==tex){
			  	opt=g;
			  }
			 }
	}
	if (opt){
		var selObj = document.getElementById('lst_itinerario');
		selObj.options[opt].selected =opt;
	}
	
	var iParadaDesde=arr[2];
	
	var urlLocal = "includes/duplicado.php?modulo=busca_paradas_itinerario&id="+arr[1];
	var sep = (-1 < urlLocal.indexOf("?")) ? "&" : "?";   
  urlLocal = urlLocal + sep + "__=" + encodeURIComponent((new Date()).getTime());
  var cont=0;
  
  try {
		http.open("GET", urlLocal,false);		
    http.send(null);
		var a=http.responseText.split("#");
		var cant=a.length;
		for (var g=0; g < cant-1;g++) {
			var ide=a[g].split("|")[1];
			var nombre=a[g].split("|")[0];
			var new_option = new Option(nombre, ide, false, (ide==arr[2]));
			document.getElementById("lst_paradadesde").options[document.getElementById("lst_paradadesde").options.length] = new_option;	
			if(cont==1){
				var new_option = new Option(nombre, ide, false, (ide==arr[3]));
				document.getElementById("lst_paradahasta").options[document.getElementById("lst_paradahasta").options.length] = new_option;
			}
			if((iParadaDesde==ide)&&(cont==0)){
				cont=1;
			}			
		}
		
	} catch(err) {
		
	}
	
	
	
	document.form1.txt_incidencia.value=arr[4];



}



function updt_documentos(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
document.form1.txt_guardado.value=arr[3]
detalle=arr[4]
var oEditor = FCKeditorAPI.GetInstance('txt_comentarios');
oEditor.SetHTML (detalle, true);
}
function updt_perdocumentos(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.getElementById('deta').innerHTML=arr[0]
}
function updt_itinerario_detalles(foco,valores)
{
/*var objeto=eval(document.getElementById("lst_terminal"));
while (objeto.length=0)
	{
	 for (var g=0; g < objeto.length;g++) {
	 document.getElementById("lst_terminal").options[g] = null;}
	 }
*/
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
tipo=arr[1]
if(arr[1]==1)
	{
	var selObj = document.getElementById('lst_tipo');
	selObj.options[0].selected = 1
	}
if(arr[1]==2)
	{
	var selObj = document.getElementById('lst_tipo');
	selObj.options[1].selected = 2
	}
if(arr[1]==3)
	{
	var selObj = document.getElementById('lst_tipo');
	selObj.options[2].selected = 3
	}
var can = (document.getElementById('lst_dia').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_dia[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_dia');
	selObj.options[opt].selected =opt
	}
var new_optionl = new Option(arr[3],arr[6], false, false);
document.getElementById("lst_terminal").options[0] = new_optionl;
document.form1.txt_plataforma.value=arr[4]
/*a=arr[5].split("-")
cant=a.length+1
for (var g=0; g < cant-1;g++)
	 {	
		var new_option = new Option(a[g], a[g], false, false);
		document.getElementById('lst_inchorarios').options[g] = new_option;	
	 }*/
parte=arr[5].split(":")
var can = (document.getElementById('lst_hora').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_hora[g].text;
		   if (parte[0]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_hora');
	selObj.options[opt].selected =opt
	}
var can = (document.getElementById('lst_minutos').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_minutos[g].text;
		   if (parte[1]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_minutos');
	selObj.options[opt].selected =opt
	}
if(arr[7]==1)
	{document.getElementById('chk_vf').checked=true;}
else
	{document.getElementById('chk_vf').checked=false;}
if(arr[8]==1)
	{document.getElementById('chk_sl').checked=true;}
else
	{document.getElementById('chk_sl').checked=false;}
}

function updt_companias(foco,valores,modulos)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
a=modulos.split("@")
cant=a.length
for (var g=0; g < cant-1;g++)
	 {	
		var new_option = new Option(a[g], a[g], false, false);
		document.getElementById('lst_incgrupos').options[g] = new_option;	
	 }
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
var can = (document.getElementById('lst_provincia').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_provincia[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_provincia');
	selObj.options[opt].selected =opt
	}
	
var new_option = new Option(arr[3], arr[13], false, false);
document.getElementById('lst_localidad').options[0] = new_option;
//var selObj = document.getElementById(lst);

document.form1.txt_domicilio.value=arr[4]
document.form1.txt_telefono.value=arr[5]
document.form1.txt_email.value=arr[6]
detalle=arr[7]
var oEditor = FCKeditorAPI.GetInstance('txt_descripcion');
oEditor.SetHTML (detalle, true);
document.form1.txt_cp.value=arr[8]
document.form1.txt_cif.value=arr[9]
document.form1.txt_fax.value=arr[10]
document.form1.txt_mapa.value=arr[11]
document.form1.txt_actividad.value=arr[12]
}

function updt_oficinas(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
var can = (document.getElementById('lst_provincia').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_provincia[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_provincia');
	selObj.options[opt].selected =opt
	}
var can = (document.getElementById('lst_localidad').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_localidad[g].text;
		  if (arr[3]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_localidad');
	selObj.options[opt].selected =opt
	}
document.form1.txt_domicilio.value=arr[4]
document.form1.txt_telefono.value=arr[5]
document.form1.txt_email.value=arr[6]
document.form1.txt_mapa.value=arr[7]
if(arr[8]==1)
	{var selObj = document.getElementById('lst_tipo');
	selObj.options[0].selected =1}
else
	{var selObj = document.getElementById('lst_tipo');
	selObj.options[1].selected =2}
}
function updt_paradas(foco,valores)
{
	mue_form(foco)
	valores=valores.replace(/ª/g,"'")
	valores=valores.replace(/ç/g,'"')
	arr=valores.split("|")
	document.form1.txt_id.value=arr[0]
	document.form1.txt_nombre.value=arr[1]
	var can = (document.getElementById('lst_provincia').length)
	opt=''
	if (can>0)
		{
		for (var g=0; g < can;g++)
			 {
			 var tex=document.form1.lst_provincia[g].text;
			  if (arr[2]==tex)
			 	{opt=g}
			 }
		}
	if (opt)
		{
		var selObj = document.getElementById('lst_provincia');
		selObj.options[opt].selected =opt
		}
	document.form1.txt_mapa.value=arr[3];
	var new_option = new Option(arr[5], arr[4], false, false);
	document.getElementById('lst_localidad').options[0] = new_option;
	document.form1.txt_incidencia.value=arr[6];
	
}


function updt_internacionales(foco,valores)
{
mue_form(foco)
valores=valores.replace(/ª/g,"'")
valores=valores.replace(/ç/g,'"')
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
var oEditor = FCKeditorAPI.GetInstance('txt_descripcion');
oEditor.SetHTML (arr[1], true);
var can = (document.getElementById('lst_pais').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_pais[g].text;
		  if (arr[2]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_pais');
	selObj.options[opt].selected =opt
	}
}
function valida_moviles()
{

if ((document.form1.lst_tipo.value==0)|(document.form1.txt_nombre.value==""))
	{
	alert("Debe ingresar el tipo de móvil y el nombre.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	var archivo=document.form1.txt_foto.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif"))  )
		{
			alert("La imágen del móvil debe ser un archivo .jpg o .gif")
		}
	else
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'moviles',document.form1.txt_nombre.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'moviles',document.form1.txt_nombre.value,id)
			}
		}
	}
}
function valida_grupos()
{

if ((document.form1.lst_tipo.value==0)|(document.form1.txt_nombre.value==""))
	{
	alert("Debe ingresar la clase de vehículo y el nombre del grupo.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'grupos',document.form1.txt_nombre.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'grupos',document.form1.txt_nombre.value,id)
		}
	}
}
function valida_tarifas()
{

if ((document.form1.txt_importe.value=="")|(document.form1.txt_nombre.value=="")|(document.form1.txt_desde.value=="")|(document.form1.txt_hasta.value==""))
	{
	alert("Debe indicar el nombre de la tarifa, los días desde/hasta y el importe.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tarifas',document.form1.txt_nombre.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tarifas',document.form1.txt_nombre.value,id)
		}
	}
}
function valida_lineas()
{
if ((document.form1.lst_compania.value==0)|(document.form1.lst_tipo.value==0)|(document.form1.txt_nombre.value=="")|(document.form1.txt_numero.value==""))
	{
	alert("Todos los datos son obligatorios.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'lineas',document.form1.txt_nombre.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'lineas',document.form1.txt_nombre.value,id)
		}
	}
}
function valida_itinerarios()
{
if ((document.form1.lst_linea.value==0)|(document.form1.txt_nombre.value==""))
	{
	alert("Debe especificar el nombre del itinerario y la linea.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'itinerarios',document.form1.txt_nombre.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'itinerarios',document.form1.txt_nombre.value,id)
		}
	}
}
function valida_itinerario_detalles()
{
if ((document.form1.lst_terminal.value==0))
	{
	alert("Debe especificar el nombre de la terminal y una lista cronológica de los horarios.")
	document.form1.lst_terminal.focus();
	}
else	
	{
	/*var can = (document.getElementById('lst_inchorarios').length)
		if (can>0)
			{
			for (var g=0; g < can;g++)
				{
				if (modulos!='')
					{sep="-"}
				else
					{sep=""}
				modulos=modulos+sep+document.form1.lst_inchorarios[g].text
				}
			}*/
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'itinerario_detalles',document.form1.lst_tipo.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'itinerario_detalles',document.form1.lst_tipo.value,id)
		}
	}
}
function valida_companias()
{
if ((document.form1.lst_provincia.value==0)|(document.form1.lst_localidad.value==0)|(document.form1.txt_nombre.value=="")|(document.form1.txt_email.value==""))
	{
	alert("Debe especificar el nombre de la compañia, la provincia la población  y el email de contacto.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	q=document.form1.txt_email.value;
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
	if(b.test(q)==false)
		{
		alert ("La dirección de email es incorrecta")
		}	
	else
		{
		var n=document.form1.txt_cif.value
		if (n!="")
		{
			if (CompruebaDatos(n)) 
			{
				if (ValidaCIF(n))
					{
					err2=0
					}
				else
					{
					err2=1
					}
			}
			else
			{
			err2=1
			}
		}
		else
		{
		err2=0
		}	
		if(err2==0)
		{
		var can = (document.getElementById('lst_incgrupos').length)
		if (can>0)
			{
			for (var g=0; g < can;g++)
				{
				if (modulos!='')
					{sep="@"}
				else
					{sep=""}
				modulos=modulos+sep+document.form1.lst_incgrupos[g].text
				}
			}
			
		if(document.form1.txt_tarifas.value!=""){
			
			extension = (document.form1.txt_tarifas.value.substring(document.form1.txt_tarifas.value.lastIndexOf("."))).toLowerCase();
			if((extension!=".jpg")&&(extension!=".gif")){
				alert("Archivo de tarifas no válido. Debe ser un archivo .jpg o .gif");
				return false;
			}
		}
					
		if(document.form1.txt_infolegal.value!=""){
			
			extension = (document.form1.txt_infolegal.value.substring(document.form1.txt_infolegal.value.lastIndexOf("."))).toLowerCase();
			if(extension!=".pdf"){
				alert("Archivo de información legal para accionistas no válido. Debe ser un archivo .pdf");
				return false;
			}
		}	
			
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'companias',document.form1.txt_nombre.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'companias',document.form1.txt_nombre.value,id)
			}
		}
		}
	}
}
function valida_personal()
{
document.getElementById('reset').style.display="none";	
var err2=0
if ((document.form1.txt_nombre.value=="")|(document.form1.txt_apellidos.value=="")|(document.form1.txt_dni.value==""))
	{
	alert("Debe especificar el nombre, apellidos y DNI del empleado.")
	document.form1.txt_nombre.focus();
	err2=1
	}
else	
	{
	if(document.form1.txt_email.value!="")
		{
		q=document.form1.txt_email.value;
		var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
		if(b.test(q)==false)
			{
			alert ("La dirección de email es incorrecta")
			err2=1
			}
		else
			{
			err2=0
			}
		}
	var dni=document.getElementById('txt_dni').value
	var primera=dni.substring(0,1)
	var expr1=/\D/
	if(expr1.test(primera))
		{
		var expr=/^\D\d{8}\D$/
		}
	else
		{
		var expr=/^\d{8}\D$/
		}
	if ((dni!="")& (expr.test(dni)==false))
		{
		alert("El DNI / NIE ingresado es incorrecto")
		err2=1
		}
	else
		{
		err2=0
		}
	}
	if(err2==0)
		{
		var can = (document.getElementById('lst_incgrupos').length)
		if (can>0)
			{
			for (var g=0; g < can;g++)
				{
				if (modulos!='')
					{sep="@"}
				else
					{sep=""}
				modulos=modulos+sep+document.form1.lst_incgrupos[g].text
				}
			}
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'personal',document.form1.txt_dni.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'personal',document.form1.txt_dni.value,id)
			}
		}
	
}
function valida_perfil(id)
{
if ((document.form1.txt_email.value==""))
	{
	alert("Debe especificar una dirección de email.")
	}
else	
	{
	var archivo=document.form1.txt_imagen.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif"))  )
		{
		alert("La archivo debe ser una imágen  .jpg o .gif");
		}
	else	
		{
		if(document.form1.txt_email.value!="")
			{
			q=document.form1.txt_email.value;
			var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
			if(b.test(q)==false)
				{
				alert ("La dirección de email es incorrecta")
				}
			else
				{
				accion="updt"
				busca_duplicado(accion,'empleados',document.form1.txt_email.value,id)
				}
			}
		}
	}	
}
function valida_notificaciones(x)
{
document.getElementById('txt_tipo').value=x;
companias=document.getElementById('lst_inccompanias').length
grupos=document.getElementById('lst_incgrupos').length
personal=document.getElementById('lst_incpersonal').length
if ((document.form1.txt_asunto.value=="")|((companias==0)&(grupos==0)&(personal==0)))
	{
	alert("Debe especificar asunto y almenos un grupos de envío.")
	document.form1.txt_asunto.focus();
	}
else	
	{
	//companias
	var can = (document.getElementById('lst_inccompanias').length)
	if (can>0)
		{
		for (var g=0; g < can;g++)
			{
			if (modulos!='')
				{sep="@"}
			else
				{sep=""}
			modulos=modulos+sep+document.form1.lst_inccompanias[g].text
			}
		}
	//grupos
	modulos=modulos+'|';
	var can = (document.getElementById('lst_incgrupos').length)
	if (can>0)
		{
		for (var g=0; g < can;g++)
			{
			if (modulos!='')
				{sep="@"}
			else
				{sep=""}
			modulos=modulos+sep+document.form1.lst_incgrupos[g].text
			}
		}
	//personal
	modulos=modulos+'|';
	var can = (document.getElementById('lst_incpersonal').length)
	if (can>0)
		{
		for (var g=0; g < can;g++)
			{
			if (modulos!='')
				{sep="@"}
			else
				{sep=""}
			modulos=modulos+sep+document.form1.lst_incpersonal[g].text
			}
		}
	if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'notificaciones',document.form1.txt_asunto.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'notificaciones',document.form1.txt_asunto.value,id)
			}
	}
}
function valida_oficinas()
{
if ((document.form1.lst_provincia.value==0)|(document.form1.lst_localidad.value==0)|(document.form1.txt_nombre.value=="")|(document.form1.txt_email.value==""))
	{
	alert("Debe especificar el nombre de la oficina, la provincia, la población y el email de contacto.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	q=document.form1.txt_email.value;
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
	if(b.test(q)==false)
		{
		alert ("La dirección de email es incorrecta")
		}	
	else
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'oficinas',document.form1.txt_nombre.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'oficinas',document.form1.txt_nombre.value,id)
			}
		}
	}
}
function valida_comgrupo()
{
if (document.form1.txt_descripcion.value=="")
	{
	alert("Debe especificar el nombre del grupo.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'companias_grupos',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'companias_grupos',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_paradas()
{
/*var lst='lst_pais'
var indice1 = document.form1[lst].selectedIndex; 
var texto1=document.form1[lst][indice1].text;*/
//if (((document.form1.lst_localidad.value==0)&(texto1=='España'))|(document.form1.txt_nombre.value==""))
if ((document.form1.lst_localidad.value==0)|(document.form1.txt_nombre.value==""))
	{
	alert("Debe especificar el nombre de la parada y la población a la que pertenece.")
	document.form1.txt_nombre.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'paradas',document.form1.txt_nombre.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'paradas',document.form1.txt_nombre.value,id)
		}
	}
}
function valida_internacionales()
{
if ((document.form1.lst_pais.value==0))
	{
	alert("Debe especificar el país.")
	document.form1.lst_pais.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'internacionales',document.form1.lst_pais.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'internacionales',document.form1.lst_pais.value,id)
		}
	}
}
function valida_usuarios()
{
if ((document.form1.txt_nombre.value=="")|(document.form1.txt_email.value=="")|(document.form1.txt_clave1.value=="")|(document.form1.txt_clave2.value==""))
	{
	alert("Todos los datos son obligatorios.")
	}
else
	{
	if (document.form1.txt_clave1.value != document.form1.txt_clave2.value)
		{
		alert("Las claves no coinciden.")
		document.form1.txt_clave1.focus()
		}
	else
		{
			cant=document.form1.txt_clave1.value.length
			if (cant<6)
				{
				alert("Las claves deben poseer 6 caracteres.")
				}
				else
				{
				q=document.form1.txt_email.value;
				var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
				if(b.test(q)==false)
					{
					alert ("La dirección de email es incorrecta")
					}
				else
					{
					if (document.form1.txt_id.value!="")
						{
						accion="updt"
						id=document.form1.txt_id.value
						busca_duplicado(accion,'usuarios',document.form1.txt_email.value,id)
						}
					else
						{
						accion="add"
						id=document.form1.txt_id.value
						busca_duplicado(accion,'usuarios',document.form1.txt_email.value,id)
						}
					}
				}
		}
	}
}
////////////cif
function CompruebaDatos(n) 
{
  var resul = false;
  var temp = document.form1.txt_cif.value.toUpperCase(); // pasar a mayúsculas

  if (!/^[A-Za-z0-9]{9}$/.test(temp))  // Son 9 dígitos? 

     alert ("Longitud incorrecta, un CIF consta de 9 dígitos");

  else if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) // Es una letra de las admitidas ?

     alert("Error en Nro de CIF. El primer dígito es incorrecto, debe ser una letra de las siguientes: A,B,C,D,E,F,G,H,K,L,M,N,P,Q,S ");

  else 

     resul = true;

  return resul;
}
function ValidaCIF(n) 
{

  var v1 = new Array(0,2,4,6,8,1,3,5,7,9); 
  var temp = 0; 
  var temp1;

  
  for( i = 2; i <= 6; i += 2 ) 
    {
      temp = temp + v1[ parseInt(n.substr(i-1,1)) ];
      temp = temp + parseInt(n.substr(i,1));
    };

  temp = temp + v1[ parseInt(n.substr(7,1)) ];

  temp = (10 - ( temp % 10));

  if( temp == 10 )
    alert( "Error en Nro de CIF. El dígito de control es: J ó 0" );
  else
    if(n.substring(8,9)!=temp)
		//alert( "El dígito de control es: "+temp ); 
		alert("Error en Nro de CIF. El dígito de control debe ser: "+temp)
	else
		return true;
  
  //return true;
}


//////////////
function valida_productores()
{
if ((document.form1.txt_nombrecomercial.value=="")|(document.form1.txt_empresa.value=="")|(document.form1.txt_cif.value=="")|(document.form1.txt_actividad.value=="")|(document.form1.txt_domicilio.value=="")|(document.form1.txt_cp.value=="")|(document.form1.lst_provincia.value==0)|(document.form1.lst_poblacion.value==0)|(document.form1.txt_telefono.value=="")|(document.form1.txt_email.value=="")|(document.form1.txt_apenom.value=="")|(document.form1.txt_contelefono.value=="")|(document.form1.txt_conemail.value=="")|(document.form1.lst_tipoentidad.value==0)|(document.form1.lst_tipoventa.value==0))
	{
	alert("Existen datos obligatorios."+"\n"+"Todos los datos obligatorios se expresan con el simbolo *"+"\n"+"Controle la info. suministrada." )
	}
else
	{
	q=document.form1.txt_email.value;
	if (q!="")
		{
		var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
		if(b.test(q)==false)
			{
			alert ("La dirección de email del productor es  incorrecta")
			err=1
			}
		else
			{
			err=0
			}
		}
	else
		{
		err=0
		}
	q=document.form1.txt_conemail.value;
	if (q!="")
		{
		var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
		if(b.test(q)==false)
			{
			alert ("La dirección de email del contacto es  incorrecta")
			err1=1
			}
		else
			{
			err1=0
			}
		}
	else
		{
		err1=0
		}
	var n=document.form1.txt_cif.value
	if (n!="")
		{
		if (CompruebaDatos(n)) 
			{
			if (ValidaCIF(n))
				{
				err2=0
				}
			else
				{
				err2=1
				}
			}
		else
			{
			err2=1
			}
		}
	else
		{
		err2=0
		}
	
	if ((err==0)&(err1==0)&(err2==0))
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'productores',document.form1.txt_nombrecomercial.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'productores',document.form1.txt_nombrecomercial.value,id)
			}
		}
	}
}
function valida_reglamento()
{
var eli = confirm("¿Acepta el reglamento de uso interno?");
if (eli== true)
{
	window.open('comandos.php?accion=reglamento&pag=reglamento.php', '_parent')
}
}
function enviar_notificacion(id)
{
var eli = confirm("¿Desea enviar la notificacion?");
if (eli== true)
{
	window.open('comandos.php?accion=enviar_notificacion&pag=notificaciones.php&id='+id, '_parent')
}
}
function notifica(id)
{
var eli = confirm("¿Desea notificar a todo el personal sobre la nómina procesada?");
if (eli== true)
{
	window.open('comandos.php?accion=notificar&pag=periodos.php&id='+id, '_parent')
}
}
function valida_declaracion()
{
var eli = confirm("Una vez aceptada la declaración no se podrán volver a modificar los datos de la misma"+"\n"+"¿Desea aceptar la declaración?");
if (eli== true)
{
if ((document.form1.txt_entidad.value=="")|(document.form1.txt_cif.value=="")|(document.form1.txt_fecha1.value=="")|(document.form1.txt_fecha2.value=="")|(document.form1.txt_fecha3.value=="")|(document.form1.txt_fecha4.value=="")|(document.form1.txt_nombre.value=="")|(document.form1.txt_dni.value==""))
	{
	alert("Todos los datos son obligatorios" )
	}
else
	{
	
	var n=document.form1.txt_cif.value
	if (n!="")
		{
		if (CompruebaDatos(n)) 
			{
			if (ValidaCIF(n))
				{
				err2=0
				}
			else
				{
				err2=1
				}
			}
		else
			{
			err2=1
			}
		}
	else
		{
		err2=0
		}
	
	if (err2==0)
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'declaracion',document.form1.txt_entidad.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'declaracion',document.form1.txt_entidad.value,id)
			}
		}
	}
}
}
function valida_solicitud()
{
q=document.form1.txt_email.value;
if (q!="")
	{
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
	if(b.test(q)==false)
		{
		alert ("La dirección de email del contacto de prodducción es  incorrecta")
		err=1
		}
	else
		{
		err=0
		}
	}
	else
		{
		err=0
		}
q=document.form1.txt_conemailp.value;
if (q!="")
	{
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
	if(b.test(q)==false)
		{
		alert ("La dirección de email del contacto de atencion al cliente es  incorrecta")
		err1=1
		}
	else
		{
		err1=0
		}
	}
else
	{
	err1=0
	}
q=document.form1.txt_conemaila.value;
if (q!="")
	{
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
	if(b.test(q)==false)
		{
		alert ("La dirección de email del contacto de Administración es  incorrecta")
		err2=1
		}
	else
		{
		err2=0
		}
	}
else
	{
	err2=0
	}
q=document.form1.txt_conemailaa.value;
if (q!="")
	{
	var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
	if(b.test(q)==false)
		{
		alert ("La dirección de email del contacto es  incorrecta")
		err3=1
		}
	else
		{
		err3=0
		}
	}
else
	{
	err3=0
	}
if ((err==0)&(err1==0)&(err2==0)&(err3==0))
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'solicitud',document.form1.txt_experiencia.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'solicitud',document.form1.txt_experiencia.value,id)
		}
		
	}
}
function valida_categoriaproductos()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción de la categoría.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'categoria_productos',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'categoria_productos',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_medioscobro()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción del medio de cobro.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'medios_cobro',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'medios_cobro',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_tipomovil()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción del tipo de móvil.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_movil',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_movil',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_paises()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar el nombre del país.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	var archivo=document.form1.txt_imagen.value
	extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
	if ((extension != "") & ((extension != ".jpg")) & ((extension != ".gif"))  )
		{
		alert("La archivo debe ser una imágen  .jpg o .gif");
		}
	else	
		{
		if (document.form1.txt_id.value!="")
			{
			accion="updt"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'paises',document.form1.txt_descripcion.value,id)
			}
		else
			{
			accion="add"
			id=document.form1.txt_id.value
			busca_duplicado(accion,'paises',document.form1.txt_descripcion.value,id)
			}
		}
	}
}
function valida_parametros()
{

if ((document.form1.txt_valor.value==""))
	{
	alert("Debe ingresar un valor para el parámetro.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'parametros',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'parametros',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_dia()
{

if ((document.form1.txt_descripcion.value=="")|(document.form1.txt_combinacion.value=="")|(document.form1.txt_abreviatura.value==""))
	{
	alert("Debe ingresar la descripción del día, la combinación y la abreviatura correspondiente.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'dias',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'dias',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_tipolinea()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción del tipo de móvil.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_linea',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_linea',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_estado(id)
{
	
opt="radiobutton"
for (i=0;i<document.form1.radiobutton.length;i++)
	{ 
        if (document.form1[opt][i].checked) 
          break; 
    } 
valor=document.form1[opt][i].value
if (valor==3)
{
	pag="productores.php"
}
else
	{
	pag="mi_solicitud.php?id="+id;		
	}
window.open('comandos.php?accion=estado_solicitud&id='+id+'&pag='+pag+'&valor='+valor+'&texto='+document.form1.txt_coment.value , '_parent')
}
function valida_productor_categorias()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción de la categoría.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'productor_categorias',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'productor_categorias',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_productor_sectores()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción del sector.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'productor_sectores',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'productor_sectores',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_tipoentidades()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción del tipo de venta.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_entidades',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_entidades',document.form1.txt_descripcion.value,id)
		}
	}
}

function valida_sectorproductos()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción del sector.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'sector_productos',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'sector_productos',document.form1.txt_descripcion.value,id)
		}
	}
}
function valida_tipoproductos()
{

if ((document.form1.txt_descripcion.value==""))
	{
	alert("Debe ingresar la descripción del tipo de producto.")
	document.form1.txt_descripcion.focus();
	}
else	
	{
	if (document.form1.txt_id.value!="")
		{
		accion="updt"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_productos',document.form1.txt_descripcion.value,id)
		}
	else
		{
		accion="add"
		id=document.form1.txt_id.value
		busca_duplicado(accion,'tipo_productos',document.form1.txt_descripcion.value,id)
		}
	}
}

function valida_incidencias() {
	
	if (document.form1.lst_itinerario.value==0){
		alert("Debe seleccionar el itinerario");
		document.form1.lst_itinerario.focus();
		return false;
	}
	
	if (document.form1.lst_paradadesde.value==0){
		alert("Debe seleccionar la parada desde / en");
		document.form1.lst_paradadesde.focus();
		return false;
	}
	
	if (document.form1.txt_incidencia.value==""){
		alert("Debe introducir el texto de la incidencia")
		document.form1.txt_incidencia.focus();
		return false;
	}
		
	var URL = unescape(location.href);
	var xstart = URL.lastIndexOf("/") + 1;
	var xend = URL.length;
	var pagina = URL.substring(xstart,xend);
	pag=pagina.replace(/updt=1/, "updt=0");
	pag=pagina.replace(/add=1/, "add=0");
	accion1=pag.lastIndexOf("add");
	accion2=pag.lastIndexOf("updt");
	if (accion1>-1){accion="add";}
	if (accion2>-1){accion="updt";}
	pag=pag.replace(/&/gi,"|");
	
	nav=pag.lastIndexOf("totalRows_"+nom_pagina+"=")
	caracteres=nom_pagina.length
	if ((nav>-1) && (document.form1.txt_id.value=="")){
		numero=pag.substring(nav+11+caracteres,nav+10+caracteres+3)
		final=parseInt(numero)+1
		va="totalRows_"+nom_pagina+"="+numero
		pag=pag.replace(va,"totalRows_"+nom_pagina+"="+final)
	}
		
	if (document.form1.txt_id.value!=""){
		accion="updt_"+nom_pagina+"&id="+document.form1.txt_id.value
	}else{
		accion="add_"+nom_pagina
	}
		
	document.form1.action="comandos.php?accion="+accion+"&pag="+pag;
	document.form1.submit();
	
}


function paradasdesde_incidencia(){
	var elem=document.getElementById("lst_itinerario");
	
	document.getElementById("lst_paradadesde").options.length = 0;
	document.getElementById("lst_paradadesde").options[0]=new Option("Seleccione...", 0, false, false);
	document.getElementById("lst_paradahasta").options.length = 0;
	document.getElementById("lst_paradahasta").options[0]=new Option("Seleccione...", 0, false, false);
	
	if(elem.options[elem.selectedIndex].value!="0"){
		
		var urlLocal = "includes/duplicado.php?modulo=busca_paradas_itinerario&id="+elem.options[elem.selectedIndex].value;
		var sep = (-1 < urlLocal.indexOf("?")) ? "&" : "?";   
    urlLocal = urlLocal + sep + "__=" + encodeURIComponent((new Date()).getTime());
    
    try {
			http.open("GET", urlLocal,false);		
	    http.send(null);
			var a=http.responseText.split("#");
			var cant=a.length;
			for (var g=0; g < cant-1;g++) {
				var ide=a[g].split("|")[1];
				var nombre=a[g].split("|")[0];
				var new_option = new Option(nombre, ide, false, false);
				document.getElementById("lst_paradadesde").options[document.getElementById("lst_paradadesde").options.length] = new_option;	
			}
			
		} catch(err) {
			
		}
		
	}
	
}

function paradashasta_incidencia(){
	var elem=document.getElementById("lst_itinerario");
	
	var sParadaDesde=document.getElementById("lst_paradadesde").options[document.getElementById("lst_paradadesde").selectedIndex].text;
	
	document.getElementById("lst_paradahasta").options.length = 0;
	document.getElementById("lst_paradahasta").options[0]=new Option("Seleccione...", 0, false, false);
	
	if(elem.options[elem.selectedIndex].value!="0"){
		
		var urlLocal = "includes/duplicado.php?modulo=busca_paradas_itinerario&id="+elem.options[elem.selectedIndex].value;
		var sep = (-1 < urlLocal.indexOf("?")) ? "&" : "?";   
    urlLocal = urlLocal + sep + "__=" + encodeURIComponent((new Date()).getTime());
    var cont=0;
    
    try {
			http.open("GET", urlLocal,false);		
	    http.send(null);
			var a=http.responseText.split("#");
			var cant=a.length;
			for (var g=0; g < cant-1;g++) {
				var ide=a[g].split("|")[1];
				var nombre=a[g].split("|")[0];				
				if(cont==1){
					var new_option = new Option(nombre, ide, false, false);
					document.getElementById("lst_paradahasta").options[document.getElementById("lst_paradahasta").options.length] = new_option;
				}
				if((sParadaDesde==nombre)&&(cont==0)){
					cont=1;
				}			
			}
			
		} catch(err) {
			
		}
		
	}
	
}

function activafechas()
{
	if (document.form1.lst_estado.value=='A')
		{
		document.getElementById('f1').style.display=""
		document.getElementById('f2').style.display=""
		}
	else
		{
		document.getElementById('f1').style.display="none"
		document.getElementById('f2').style.display="none"	
		}
}
function ocu_form()
{
document.getElementById('alta_modi').style.display="none"
document.getElementById('marco').style.display="none"
}
function ocu_form2()
{
document.getElementById('alta_modi').style.display="none"
document.getElementById('marco').style.display="none"
document.getElementById('s1').src="img/solapa11.jpg";
document.getElementById('s2').src="img/solapa2.jpg";
document.getElementById('s3').src="img/solapa3.jpg";
document.getElementById('s4').src="img/solapa4.jpg";
document.getElementById('s5').src="img/solapa5.jpg";
document.getElementById('s6').src="img/solapa6.jpg";
document.getElementById('tb1').style.display=""
document.getElementById('tb2').style.display="none"
document.getElementById('tb3').style.display="none"
document.getElementById('tb4').style.display="none"
document.getElementById('tb5').style.display="none"
document.getElementById('tb6').style.display="none"
document.getElementById('barcode').src='img/fdo_bar.gif'
}

function mue_form(foco)
{
document.getElementById('alta_modi').style.display="block"
document.getElementById(foco).focus()
document.getElementById('marco').style.display="none"
var foto=document.getElementById('tdimg')
if (foto){document.getElementById('tdimg').innerHTML=""}
/*if (nom_pagina=='novedades')
	{
	tinyMCE.getInstanceById('txt_copete').setHTML("")
	tinyMCE.getInstanceById('txt_detalle').setHTML("")
	document.form1.txt_titulo.value=""
	document.form1.txt_fecha.value=""
	}
else*/
	//{
	document.forms[0].reset()	
	//}
	if (nom_pagina=="media"){document.getElementById('tam').style.display="none"}
}
function mue_form2()
{
document.getElementById('alta_modi').style.display="block"
document.getElementById('marco').style.display="none"
var foto=document.getElementById('tdimg')
if (foto){document.getElementById('tdimg').innerHTML=""}
/*if (nom_pagina=='novedades')
	{
	tinyMCE.getInstanceById('txt_copete').setHTML("")
	tinyMCE.getInstanceById('txt_detalle').setHTML("")
	document.form1.txt_titulo.value=""
	document.form1.txt_fecha.value=""
	}
else*/
	//{
	document.forms[0].reset()	
	//}
	if (nom_pagina=="media"){document.getElementById('tam').style.display="none"}
}
function updt_categoriaproductos(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_sectorproductos(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_tipoproductos(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_paises(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_comgrupo(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_parametros(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
document.form1.txt_valor.value=arr[2]
}
function updt_productor_categorias(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_productor_sectores(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_medioscobro(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_tipomovil(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_tipomovil(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
document.form1.txt_guardado.value=arr[2]
}
function updt_dias(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
document.form1.txt_combinacion.value=arr[2]
document.form1.txt_abreviatura.value=arr[3]
}
function updt_tipolinea(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_tipoentidades(foco,valores)
{
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_descripcion.value=arr[1]
}
function updt_usuarios(foco,valores,modulos)
{
a=modulos.split("|")
cant=a.length
for (var g=0; g < cant-1;g++)
	 {	
		var new_option = new Option(a[g], a[g], false, false);
		document.getElementById('lst_incmodulos').options[g] = new_option;	
	 }
valores=valores.replace(/ª/,"'")
mue_form(foco)
arr=valores.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombre.value=arr[1]
document.form1.txt_email.value=arr[2]
document.form1.txt_clave1.value=arr[3]
document.form1.txt_clave2.value=arr[3]
if (arr[4]=='A'){tipo='Administrador'}
if (arr[4]=='U'){tipo='Usuario'}
}
function updt_productores(foco,valores)
{
valor=valores.replace(/ª/g,"'")
valo=valor.replace(/º/g,'"')
mue_form2()
arr=valo.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombrecomercial.value=arr[1]
document.form1.txt_cif.value=arr[2]
document.form1.txt_actividad.value=arr[3]
document.form1.txt_domicilio.value=arr[4]
document.form1.txt_cp.value=arr[5]
var new_option = new Option(arr[6], arr[25], false, false);
document.getElementById('lst_poblacion').options[0] = new_option;
var can = (document.getElementById('lst_provincia').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_provincia[g].text;
		   if (arr[7]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_provincia');
	selObj.options[opt].selected =opt
	}
document.form1.txt_telefono.value=arr[8]
document.form1.txt_fax.value=arr[9]
document.form1.txt_email.value=arr[10]
document.form1.txt_wep.value=arr[11]
var can = (document.getElementById('lst_tipoentidad').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipoentidad[g].text;
		   if (arr[12]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipoentidad');
	selObj.options[opt].selected =opt
	}
document.form1.txt_actividadprincipal.value=arr[13]
var can = (document.getElementById('lst_tipoventa').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipoventa[g].text;
		   if (arr[14]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipoventa');
	selObj.options[opt].selected =opt
	}
str=arr[15]
document.form1.txt_descripcion.value=str.replace(/<br>/g,"\r")
str=arr[16]
document.form1.txt_observaciones.value=str.replace(/<br>/g,"\r")
document.form1.txt_apenom.value=arr[17]
document.form1.txt_cargo.value=arr[18]
document.form1.txt_funcion.value=arr[19]
document.form1.txt_contelefono.value=arr[20]
document.form1.txt_movil.value=arr[21]
document.form1.txt_confax.value=arr[22]
document.form1.txt_conemail.value=arr[23]
document.form1.txt_empresa.value=arr[24]
document.form1.txt_referencia.value=arr[28]
var can = (document.getElementById('lst_sector').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_sector[g].text;
		   if (arr[26]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_sector');
	selObj.options[opt].selected =opt
	}
var can = (document.getElementById('lst_categoria').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_categoria[g].text;
		   if (arr[27]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_categoria');
	selObj.options[opt].selected =opt
	}
if((arr[29]==0))
	{
	document.form1.txt_referencia.disabled=true
	document.getElementById('lst_categoria').disabled=true
	document.getElementById('lst_sector').disabled=true
	document.getElementById('msj').innerHTML="<span  style=color:#FF0000>El productor aún  no acepto la DECLARACION DE INTENCIONES</span>"
	}
else
	{
	document.form1.txt_referencia.disabled=false
	document.getElementById('lst_categoria').disabled=false
	document.getElementById('lst_sector').disabled=false
	document.getElementById('msj').innerHTML="<span  style=color:#00CC33>El productor acepto la DECLARACION DE INTENCIONES</span>"
	}
	
}
function updt_productores2(foco,valores)
{
valor=valores.replace(/ª/g,"'")
valo=valor.replace(/º/g,'"')
arr=valo.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_nombrecomercial.value=arr[1]
document.form1.txt_cif.value=arr[2]
document.form1.txt_actividad.value=arr[3]
document.form1.txt_domicilio.value=arr[4]
document.form1.txt_cp.value=arr[5]
var new_option = new Option(arr[6], arr[25], false, false);
document.getElementById('lst_poblacion').options[0] = new_option;
var can = (document.getElementById('lst_provincia').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_provincia[g].text;
		   if (arr[7]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_provincia');
	selObj.options[opt].selected =opt
	}
document.form1.txt_telefono.value=arr[8]
document.form1.txt_fax.value=arr[9]
document.form1.txt_email.value=arr[10]
document.form1.txt_wep.value=arr[11]
var can = (document.getElementById('lst_tipoentidad').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipoentidad[g].text;
		   if (arr[12]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipoentidad');
	selObj.options[opt].selected =opt
	}
document.form1.txt_actividadprincipal.value=arr[13]
var can = (document.getElementById('lst_tipoventa').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_tipoventa[g].text;
		   if (arr[14]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_tipoventa');
	selObj.options[opt].selected =opt
	}
str=arr[15]
document.form1.txt_descripcion.value=str.replace(/<br>/g,"\r")
str=arr[16]
document.form1.txt_observaciones.value=str.replace(/<br>/g,"\r")
document.form1.txt_apenom.value=arr[17]
document.form1.txt_cargo.value=arr[18]
document.form1.txt_funcion.value=arr[19]
document.form1.txt_contelefono.value=arr[20]
document.form1.txt_movil.value=arr[21]
document.form1.txt_confax.value=arr[22]
document.form1.txt_conemail.value=arr[23]
document.form1.txt_empresa.value=arr[24]
cant=document.form1.length
	for (var g=0; g < cant;g++)
		{
			if ((document.form1.elements[g].value!="Editar")&(document.form1.elements[g].value!="Guardar y confirmar")&(document.form1.elements[g].value!="Cancelar")&(document.form1.elements[g].value!="Confirmar Datos!"))
			{
				document.form1.elements[g].disabled=true
			}
		}
	
}
function updt_declaracion(foco,valores)
{
valor=valores.replace(/ª/g,"'")
valo=valor.replace(/º/g,'"')
arr=valo.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_entidad.value=arr[1]
document.form1.txt_cif.value=arr[2]
document.form1.txt_fecha1.value=arr[3]
document.form1.txt_fecha2.value=arr[4]
document.form1.txt_fecha3.value=arr[5]
document.form1.txt_fecha4.value=arr[6]
document.form1.txt_nombre.value=arr[7]
document.form1.txt_dni.value=arr[8]
if(arr[9]==1)
{
document.getElementById('save').style.display="none"
cant=document.form1.length
	for (var g=0; g < cant;g++)
		{
			if ((document.form1.elements[g].value!="Editar")&(document.form1.elements[g].value!="Guardar")&(document.form1.elements[g].value!="Cancelar"))
			{
				document.form1.elements[g].disabled=true
			}
		}
}
	
}
function updt_solicitud(foco,valores)
{
valor=valores.replace(/ª/g,"'")
valo=valor.replace(/º/g,'"')
arr=valo.split("|")
document.form1.txt_id.value=arr[0]
document.form1.txt_experiencia.value=arr[1]
document.form1.txt_empleados.value=arr[2]
document.form1.txt_facturacion.value=arr[3]
document.form1.txt_produccion.value=arr[4]
document.form1.txt_domicilio.value=arr[5]
document.form1.txt_cp.value=arr[6]
var can = (document.getElementById('lst_provincia').length)
opt=''
if (can>0)
	{
	for (var g=0; g < can;g++)
		 {
		 var tex=document.form1.lst_provincia[g].text;
		   if (arr[7]==tex)
		 	{opt=g}
		 }
	}
if (opt)
	{
	var selObj = document.getElementById('lst_provincia');
	selObj.options[opt].selected =opt
	}
var new_option = new Option(arr[8], arr[9], false, false);
document.getElementById('lst_poblacion').options[0] = new_option;

document.form1.txt_telefono.value=arr[10]
document.form1.txt_fax.value=arr[11]
document.form1.txt_email.value=arr[12]
document.form1.txt_wep.value=arr[13]
document.form1.txt_condiciones1.value=arr[14]
document.form1.txt_garantias.value=arr[15]
document.form1.txt_condiciones2.value=arr[16]
document.form1.txt_transporte.value=arr[17]
publico=arr[18].split("#")
cant=publico.length
for (var g=1; g < 8;g++)
	{
	com="chk_publico"+g
	valor=document.getElementById(com).value
	for (var v=0; v < cant;v++)		
		{
		if(publico[v]==valor)
			{
				document.getElementById(com).checked=true
			}
		}
	}
sexo=arr[19].split("#")
cant=sexo.length
for (var g=1; g < 3;g++)
	{
	com="chk_sex"+g
	valor=document.getElementById(com).value
	for (var v=0; v < cant;v++)		
		{
		if(sexo[v]==valor)
			{
				document.getElementById(com).checked=true
			}
		}
	}
edad=arr[20].split("#")
cant=edad.length
for (var g=1; g < 7;g++)
	{
	com="chk_edad"+g
	valor=document.getElementById(com).value
	for (var v=0; v < cant;v++)		
		{
		if(edad[v]==valor)
			{
				document.getElementById(com).checked=true
			}
		}
	}
ocupacion=arr[21].split("#")
cant=ocupacion.length
for (var g=1; g < 8;g++)
	{
	com="chk_ocupacion"+g
	valor=document.getElementById(com).value
	for (var v=0; v < cant;v++)		
		{
		if(ocupacion[v]==valor)
			{
				document.getElementById(com).checked=true
			}
		}
	}
compra=arr[22].split("#")
cant=compra.length
for (var g=1; g < 11;g++)
	{
	com="chk_compra"+g
	valor=document.getElementById(com).value
	for (var v=0; v < cant;v++)		
		{
		if(compra[v]==valor)
			{
				document.getElementById(com).checked=true
			}
		}
	}
cobro=arr[23].split("#")
cant=compra.length
for (var g=1; g < 5;g++)
	{
	com="chk_cobro"+g
	valor=document.getElementById(com).value
	for (var v=0; v < cant;v++)		
		{
		if(cobro[v]==valor)
			{
				document.getElementById(com).checked=true
			}
		}
	}
document.form1.txt_estadisticas.value=arr[24]
document.form1.txt_certificados.value=arr[25]
document.form1.txt_otrasobs.value=arr[26]
//
document.form1.txt_apenomp.value=arr[27]
document.form1.txt_cargop.value=arr[28]
document.form1.txt_funcionp.value=arr[29]
document.form1.txt_contelefonop.value=arr[30]
document.form1.txt_movilp.value=arr[31]
document.form1.txt_confaxp.value=arr[32]
document.form1.txt_conemailp.value=arr[33]
//
document.form1.txt_apenoma.value=arr[34]
document.form1.txt_cargoa.value=arr[35]
document.form1.txt_funciona.value=arr[36]
document.form1.txt_contelefonoa.value=arr[37]
document.form1.txt_movila.value=arr[38]
document.form1.txt_confaxa.value=arr[39]
document.form1.txt_conemaila.value=arr[40]
//
document.form1.txt_apenomaa.value=arr[41]
document.form1.txt_cargoaa.value=arr[42]
document.form1.txt_funcionaa.value=arr[43]
document.form1.txt_contelefonoaa.value=arr[44]
document.form1.txt_movilaa.value=arr[45]
document.form1.txt_confaxaa.value=arr[46]
document.form1.txt_conemailaa.value=arr[47]
cant=document.form1.length
	for (var g=0; g < cant;g++)
		{
			if ((document.form1.elements[g].value!="Editar")&(document.form1.elements[g].value!="Guardar")&(document.form1.elements[g].value!="Cancelar")&(document.form1.elements[g].name!="txt_coment")&(document.form1.elements[g].name!="radiobutton")&(document.form1.elements[g].name!="guardar")&(document.form1.elements[g].value!="Confirmar Datos!"))
			{
				document.form1.elements[g].disabled=true
			}
		}

}
function asignaclase()
{
if (nom_pagina=='articulos') {document.getElementById('articulos').className = 'current'}
if (nom_pagina=='usuarios') {document.getElementById('usuarios').className = 'current'}
if (nom_pagina=='clientes') {document.getElementById('clientes').className = 'current'}
if (nom_pagina=='proveedores') {document.getElementById('proveedores').className = 'current'}
}
function validausu()
{
	var browserName=navigator.appName;
if ((document.form_usuario.usuario.value=="" )|(document.form_usuario.clave.value==""))
	{
	alert("Debes ingresar el Usuario y la Contraseña.")
	document.form_usuario.usuario.focus()
	}
else
	{
	
	document.form_usuario.submit()
/*	parent.TopUp.close();
	 if (browserName=="Microsoft Internet Explorer")
 {
window.location="admin/per_documentos.php"
 }*/
	
	
	 
	}
	//parent.TopUp.close()
}

function intro(event) 
{
	var x=event.keyCode
	if (x==13)  
	{
	validausu();
	return true;
	}
}

function intro_forms() 
{
	var x=event.keyCode
	if (x==13)  
	{
	if (nom_pagina=="clientes"){valida_clientes()}
	return true;
	}
}
function intro_busca(pagina) 
{
	var x=event.keyCode
	if (x==13)  
	{
	buscar(pagina);
	return true;
	}
}
function intro_busca2(pagina) 
{
	var x=event.keyCode
	if (x==13)  
	{
	buscar2(pagina);
	return true;
	}
}
function eliminar(cod,tabla,campo,archivo)
{
	
var eli = confirm("¿Deseas eliminar el Registro?");
if (eli== true)
{

 if (tabla=='companias'){
	
	 var urlLocal = "includes/duplicado.php?comando=eliminar&modulo=compania&id="+cod;
	var sep = (-1 < urlLocal.indexOf("?")) ? "&" : "?";   
    urlLocal = urlLocal + sep + "__=" + encodeURIComponent((new Date()).getTime());

	http.open("GET",urlLocal,false);
    http.send(null);
	
   respuesta=http.responseText;

	
	if (respuesta=="true"){
		alert("Debe eliminar antes la información asociada");
		return;
	}
 }

var URL = unescape(location.href)	
var xstart = URL.lastIndexOf("/") + 1
var xend = URL.length
var pagina = URL.substring(xstart,xend)
pag=pagina.replace(/&/gi,"|")
sql="delete from "+tabla+" where "+campo+"="+cod
nav=pag.lastIndexOf("totalRows_"+nom_pagina+"=")
caracteres=nom_pagina.length
if (nav>-1)
	{
	numero=pag.substring(nav+11+caracteres,nav+10+caracteres+3)
	final=parseInt(numero)-1
	va="totalRows_"+nom_pagina+"="+numero
	pag=pag.replace(va,"totalRows_"+nom_pagina+"="+final)
	}
window.open('comandos.php?accion=delete&sql='+sql+'&file='+archivo+'&pag='+pag+'&id='+cod , '_parent')
}
}
function buscar(pagina)
{
if(document.getElementById('txt_busca').value=="")
{
alert("Tienes que ingresar el dato a buscar.")
document.getElementById('txt_busca').focus()
}
else
{
window.open(pagina+'?valor='+document.getElementById('txt_busca').value , '_parent')
}
}
function buscar2(pagina)
{
if(document.getElementById('txt_busca').value=="")
{
alert("Tienes que ingresar el dato a buscar.")
document.getElementById('txt_busca').focus()
}
else
{
window.open(pagina+'?valor='+document.getElementById('txt_busca').value+"&tipo="+document.getElementById('lst_busca').value , '_parent')
}
}
function oculta_submen()
{
document.getElementById('marco').style.display="none"
}
function muestra_submen()
{
document.getElementById('marco').style.display=""
}
function orden(op,campo)
{
obj = document.getElementById(op);
var top=obj.offsetTop 
var left=obj.offsetParent.offsetLeft 
var query = window.location.search.substring(1);
var esta=document.getElementById('alta_modi').style.display
tt=document.getElementById('tbl').offsetTop
ll=document.getElementById('tbl').offsetLeft
var navegador = navigator.appName 
if (navegador == "Microsoft Internet Explorer") 
{
document.getElementById('marco').style.left=left+360+ll+'px'
document.getElementById('marco').style.top=tt+190+'px'
}
else 
{
document.getElementById('marco').style.left=left+ll+'px'
document.getElementById('marco').style.top=tt+30+'px'
}
	

muestra_submen()
col="<div><div id=item><ul><li><a href=javascript:ira('asc','"+campo+"') onclick=oculta_submen()>Ascending Order</a></li></ul></div><div id=item2><ul><li><a href=javascript:ira('desc','"+campo+"')  onclick=oculta_submen()>Descending Order</a></li></ul></div>"
document.getElementById('interior').innerHTML=col
}

function embebed_on(op,tipo,cuenta,img,tipoo)
{
document.getElementById('foto').value=img;	
if(cuenta>0)
{
xs=50;
ob="par_"+cuenta;
}
else
{
xs=10;
ob=op;
}
var obj = document.getElementById(ob);
var top=obj.offsetParent.offsetTop;
var left=obj.offsetParent.offsetLeft; 
var tt=document.getElementById('tbl').offsetTop;
var ll=document.getElementById('tbl').offsetLeft;
var navegador = navigator.appName;

if(tipoo==1)
	{
	document.getElementById('marco').style.width="190px";
	resta=100;	
	ttop=200;
	elemento='txti_'+op;
	valor=document.getElementById(elemento).value
	document.getElementById('ampliar').style.display="block"
	}
if(tipoo==2)
	{
	document.getElementById('marco').style.width="300px";
	resta=0;
	ttop=50;
	elemento='txtm_'+op;
	valor=document.getElementById(elemento).value	
	document.getElementById('ampliar').style.display="none"
	}
if(tipoo==3)
	{
	document.getElementById('marco').style.width="190px";
	resta=100;	
	ttop=200;
	elemento='txtii_'+op;
	valor=document.getElementById(elemento).value
	document.getElementById('ampliar').style.display="block"
	}
if(tipoo==4)
	{
	document.getElementById('marco').style.width="300px";
	resta=0;
	ttop=50;
	elemento='txtmm_'+op;
	valor=document.getElementById(elemento).value	
	document.getElementById('ampliar').style.display="none"
	}
if(tipo==1)
{
	if (navegador == "Microsoft Internet Explorer") 
	{
	document.getElementById('marco').style.left=left+-60+ll+'px'
	document.getElementById('marco').style.top=xs+tt+180+top+'px'
	}
	else 
	{
	document.getElementById('marco').style.left=left+ll+'px'
	document.getElementById('marco').style.top=xs+tt+30+top+'px'
	}
}
else
{
	//if (navegador == "Microsoft Internet Explorer") 
	//{
	//document.getElementById('marco').style.left=left+160+ll+resta+'px'
	//document.getElementById('marco').style.top=xs+tt+50+top+ttop+'px'
	//}
	//else 
	//{
	document.getElementById('marco').style.left=left+ll+-310+resta+'px'
	document.getElementById('marco').style.top=xs+tt+top+-80+'px'
	//}
}
document.getElementById('marco').style.display=""
document.getElementById('interior').innerHTML=valor
}
function embebed_off()
{
	document.getElementById('marco').style.display="none"
}
function ira(orden,campo)
{
var URL = unescape(location.href)	
var xstart = URL.lastIndexOf("/") + 1
var xend = URL.length
var pagina = URL.substring(xstart,xend)
var query1=pagina.lastIndexOf("?")	
if (query1<0)
	{pag=pagina+"?ord="+orden+"&campo="+campo}
else
	{
	var inicio=pagina.lastIndexOf("?ord=")	
	if (inicio>0)
		{
			if (orden=='asc') {pag=pagina.replace(/ord=desc/, "ord=asc")}
	    	if (orden=='desc') {pag=pagina.replace(/ord=asc/, "ord=desc")}
		}
	else
		{
		var inicio=pagina.lastIndexOf("&ord=")	
			if (inicio>0)
			{
				if (orden=='asc') {pag=pagina.replace(/ord=desc/, "ord=asc")}
	    		if (orden=='desc') {pag=pagina.replace(/ord=asc/, "ord=desc")}
			}
			else
			{		
			pag=pagina+"&ord="+orden+"&campo="+campo
			}
		}
	}
var inicio=pag.lastIndexOf("campo=")	
if (inicio>0){pag=pag.substring(0,inicio-1)+"&campo="+campo}
window.open(pag, '_parent')
}
function control_errores(x,valores)
{
if (x>0){document.getElementById('alta_modi').style.display=""}	
if (x==1)
	{
	val=valores.split("|")
	document.form1.txt_nombre.value=val[1]
	document.form1.txt_id.value=val[0]
	alert("La imágen no debe superar los "+val[2]+".")
	}
if (x==2)
	{
	alert("El email fué enviado con éxito.")
	}
if (x==3)
	{
	val=valores.split("|")
	document.form1.txt_nombre.value=val[1]
	document.form1.txt_id.value=val[0]
	alert("El archivo no debe superar los "+val[2]+".")
	}
}
function duplicado_cmd() { 
	if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
			 var a=http.responseText
			 if (a<1)
			 {
				var URL = unescape(location.href)	
				var xstart = URL.lastIndexOf("/") + 1
				var xend = URL.length
				var pagina = URL.substring(xstart,xend)
				pag=pagina.replace(/updt=1/, "updt=0")
				pag=pagina.replace(/add=1/, "add=0")
				accion1=pag.lastIndexOf("add")
				accion2=pag.lastIndexOf("updt")
				if (accion1>-1){accion="add"}
				if (accion2>-1){accion="updt"}
				pag=pag.replace(/&/gi,"|")
				//alert("comandos.php?accion="+accion+"_clientes&pag="+pag)
				nav=pag.lastIndexOf("totalRows_"+nom_pagina+"=")
				caracteres=nom_pagina.length
				if ((nav>-1) && (document.form1.txt_id.value==""))
					{
						numero=pag.substring(nav+11+caracteres,nav+10+caracteres+3)
						final=parseInt(numero)+1
						va="totalRows_"+nom_pagina+"="+numero
						pag=pag.replace(va,"totalRows_"+nom_pagina+"="+final)
					}
					
					if (document.form1.txt_id.value!="")
						{
						accion="updt_"+nom_pagina+"&id="+document.form1.txt_id.value
						}
						else
						{
						accion="add_"+nom_pagina
						}
					if(pagina=='per_perfil.php')
						{
						pag='per_perfil.php';
						accion='editar_perfil';
						}
						
					document.form1.action="comandos.php?accion="+accion+"&pag="+pag+"&modulos="+modulos
					document.form1.submit();
			 }
			 else
			 {
				alert("Ya existe un registro similar.") 
			 }
			 enProceso = false;
			}
			
       }
    }
}
function busca_duplicado(comando,modulo,valor,id)
{
if (!enProceso && http) 
	{
   	   var url = "includes/duplicado.php?comando="+comando+"&modulo="+modulo+"&valor="+valor+"&id="+id
	   http.open("GET", url, true);
	   http.onreadystatechange = duplicado_cmd;
       enProceso = true;
       http.send(null);
    }
}
function buscaprovincia() {
	var valor = document.getElementById("lst_pais").value;
    if (!enProceso && http) {
       var url = "includes/duplicado.php?pais="+valor+"&modulo=buscaprovincia";
	   var mm=1;
	   http.open("GET", url, true);
	   http.onreadystatechange = handleHttpResponse_provincia;
       enProceso = true;
       http.send(null);	  
    }
}
function handleHttpResponse_provincia() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
		    var qbusco = http.responseText.split("?");
			var busca='lst_provincia'
			var objeto=eval(document.getElementById("lst_provincia"));
			while (objeto.length=0)
			{
			 for (var g=0; g < objeto.length;g++) {
			 document.getElementById("lst_provincia").options[g] = null;}
			 }
			var new_optionl = new Option('Seleccione...', 0, false, false);
			document.getElementById("lst_provincia").options[0] = new_optionl;
			var final;
			var resulta = http.responseText.split("#"); 
			      for (var i=0; i < resulta.length; i++) {
				   	if (final==null) { 
				    final = (resulta[i] + "<p>");
							}
					else
					{final = final + (resulta[i] + "<p>");}
					//busco separador
					var m;
					var patron=/,/i;
					var lugar
					var codigo
					m=resulta[i];
					lugar=m.search(patron);
					codigo=m.substr(lugar+1,10);
					var new_option = new Option(resulta[i].substr(0,lugar), codigo, false, false);
					//alert (codigo);
					if (lugar>0){		  	        
					document.getElementById(busca).options[i+1] = new_option;
					}
					}
					//divLista.innerHTML = final;
			 enProceso = false;
				
          }
       }
    }
}

function buscapoblacion() {
	var valor = document.getElementById("lst_provincia").value;
    if (!enProceso && http) {
       var url = "includes/duplicado.php?provincia="+valor+"&modulo=buscapoblacion";
	   var mm=1;
	   http.open("GET", url, true);
	   http.onreadystatechange = handleHttpResponse_poblacion;
       enProceso = true;
       http.send(null);	  
    }
}
function handleHttpResponse_poblacion() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
		    var qbusco = http.responseText.split("?");
			var busca='lst_localidad'
			var objeto=eval(document.getElementById("lst_localidad"));
			while (objeto.length=0)
			{
			 for (var g=0; g < objeto.length;g++) {
			 document.getElementById("lst_poblacion").options[g] = null;}
			 }
			var new_optionl = new Option('Seleccione...', 0, false, false);
			document.getElementById("lst_localidad").options[0] = new_optionl;
			var final;
			var resulta = http.responseText.split("#"); 
			      for (var i=0; i < resulta.length; i++) {
				   	if (final==null) { 
				    final = (resulta[i] + "<p>");
							}
					else
					{final = final + (resulta[i] + "<p>");}
					//busco separador
					var m;
					var patron=/,/i;
					var lugar
					var codigo
					m=resulta[i];
					lugar=m.search(patron);
					codigo=m.substr(lugar+1,10);
					var new_option = new Option(resulta[i].substr(0,lugar), codigo, false, false);
					//alert (codigo);
					if (lugar>0){		  	        
					document.getElementById(busca).options[i+1] = new_option;
					}
					}
					//divLista.innerHTML = final;
			 enProceso = false;
				
          }
       }
    }
}
function buscagrupos() {
	var objeto=eval(document.getElementById("lst_incgrupos"));
	while (objeto.length=0)
		{
		for (var g=0; g < objeto.length;g++) {
		document.getElementById("lst_incgrupos").options[g] = null;}
		}
	var valor = document.getElementById("lst_tipo").value;
    if (!enProceso && http) {
       var url = "includes/duplicado.php?grupo="+valor+"&modulo=buscagrupos";
	   var mm=1;
	   http.open("GET", url, true);
	   http.onreadystatechange = handleHttpResponse_grupos;
       enProceso = true;
       http.send(null);	  
    }
}
function handleHttpResponse_grupos() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
		    var qbusco = http.responseText.split("?");
			var busca='lst_grupos'
			var objeto=eval(document.getElementById("lst_grupos"));
			while (objeto.length=0)
			{
			 for (var g=0; g < objeto.length;g++) {
			 document.getElementById("lst_grupos").options[g] = null;}
			 }
			var new_optionl = new Option('Seleccione...', 0, false, false);
			document.getElementById("lst_grupos").options[0] = new_optionl;
			var final;
			var resulta = http.responseText.split("#"); 
			      for (var i=0; i < resulta.length; i++) {
				   	if (final==null) { 
				    final = (resulta[i] + "<p>");
							}
					else
					{final = final + (resulta[i] + "<p>");}
					//busco separador
					var m;
					var patron=/,/i;
					var lugar
					var codigo
					m=resulta[i];
					lugar=m.search(patron);
					codigo=m.substr(lugar+1,10);
					var new_option = new Option(resulta[i].substr(0,lugar), codigo, false, false);
					//alert (codigo);
					if (lugar>0){		  	        
					document.getElementById(busca).options[i+1] = new_option;
					}
					}
					//divLista.innerHTML = final;
			 enProceso = false;
				
          }
       }
    }
}
function buscaterminal() {
	var valor = document.getElementById("lst_localidad").value;
    if (!enProceso && http) {
       var url = "includes/duplicado.php?localidad="+valor+"&modulo=buscaterminal";
	   var mm=1;
	   http.open("GET", url, true);
	   http.onreadystatechange = handleHttpResponse_terminal;
       enProceso = true;
       http.send(null);	  
    }
}
function handleHttpResponse_terminal() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) {
		    var qbusco = http.responseText.split("?");
			var busca='lst_terminal'
			var objeto=eval(document.getElementById("lst_terminal"));
			while (objeto.length=0)
			{
			 for (var g=0; g < objeto.length;g++) {
			 document.getElementById("lst_terminal").options[g] = null;}
			 }
			var new_optionl = new Option('Seleccione...', 0, false, false);
			document.getElementById("lst_terminal").options[0] = new_optionl;
			var final;
			var resulta = http.responseText.split("#"); 
			      for (var i=0; i < resulta.length; i++) {
				   	if (final==null) { 
				    final = (resulta[i] + "<p>");
							}
					else
					{final = final + (resulta[i] + "<p>");}
					//busco separador
					var m;
					var patron=/,/i;
					var lugar
					var codigo
					m=resulta[i];
					lugar=m.search(patron);
					codigo=m.substr(lugar+1,10);
					var new_option = new Option(resulta[i].substr(0,lugar), codigo, false, false);
					//alert (codigo);
					if (lugar>0){		  	        
					document.getElementById(busca).options[i+1] = new_option;
					}
					}					
				//divLista.innerHTML = final;
			 enProceso = false;
				
          }
       }
    }
}


function solonumeros(evt)
{
// Backspace = 8, Enter = 13, ‘0' = 48, ‘9' = 57, ‘.’ = 46
if (window.event)
	{var key = window.event.keyCode;}
else
	{var key = nav4 ? evt.which : evt.keyCode;}
return (key <= 13 || (key >= 48 && key <= 57) || key == 46 || key == 44);
}
function formateo(control)
{
var val=document.getElementById(control).value
//var val=document.form2.importe.value 
var val=val.replace(".","") 
var val=val.replace(".","") 
var val=val.replace(".","") 
var cant=val.length 
var esta=val.search(",") 
if (esta<0){ 
if (cant==0) document.getElementById(control).value='' 
if (cant==4) document.getElementById(control).value=val.substr(0,1) + "." + val.substr(1,15) 
if (cant==5) document.getElementById(control).value=val.substr(0,2) + "." + val.substr(2,15) 
if (cant==6) document.getElementById(control).value=val.substr(0,3) + "." + val.substr(3,15) 
if (cant==7) document.getElementById(control).value=val.substr(0,1) + "." + val.substr(1,3) + "." + val.substr(4,15) 
if (cant==8) document.getElementById(control).value=val.substr(0,2) + "." + val.substr(2,3) + "." + val.substr(5,15) 
}
}
function change(img,x)
{
if(x==0)
{a=""}
else
{a="s"}
if (img=='s1')
	{
	document.getElementById('s1').src="img/solapa11.jpg";
	document.getElementById('s2').src="img/solapa"+a+"2.jpg";
	document.getElementById('s3').src="img/solapa"+a+"3.jpg";
	document.getElementById('s4').src="img/solapa"+a+"4.jpg";
	document.getElementById('s5').src="img/solapa"+a+"5.jpg";
	document.getElementById('tb1').style.display=""
	document.getElementById('tb2').style.display="none"
	document.getElementById('tb3').style.display="none"
	document.getElementById('tb4').style.display="none"
	document.getElementById('tb5').style.display="none"
	}
if (img=='s2')
	{
	document.getElementById('s1').src="img/solapa1.jpg";
	document.getElementById('s2').src="img/solapa"+a+"22.jpg";
	document.getElementById('s3').src="img/solapa"+a+"3.jpg";
	document.getElementById('s4').src="img/solapa"+a+"4.jpg";
	document.getElementById('s5').src="img/solapa"+a+"5.jpg";
	document.getElementById('tb1').style.display="none"
	document.getElementById('tb2').style.display=""
	document.getElementById('tb3').style.display="none"
	document.getElementById('tb4').style.display="none"
	document.getElementById('tb5').style.display="none"
	}
if (img=='s3')
	{
	document.getElementById('s1').src="img/solapa1.jpg";
	document.getElementById('s2').src="img/solapa"+a+"2.jpg";
	document.getElementById('s3').src="img/solapa"+a+"33.jpg";
	document.getElementById('s4').src="img/solapa"+a+"4.jpg";
	document.getElementById('s5').src="img/solapa"+a+"5.jpg";
	document.getElementById('tb1').style.display="none"
	document.getElementById('tb2').style.display="none"
	document.getElementById('tb3').style.display=""
	document.getElementById('tb4').style.display="none"
	document.getElementById('tb5').style.display="none"
	}
if (img=='s4')
	{
	document.getElementById('s1').src="img/solapa1.jpg";
	document.getElementById('s2').src="img/solapa"+a+"2.jpg";
	document.getElementById('s3').src="img/solapa"+a+"3.jpg";
	document.getElementById('s4').src="img/solapa"+a+"44.jpg";
	document.getElementById('s5').src="img/solapa"+a+"5.jpg";
	document.getElementById('tb1').style.display="none"
	document.getElementById('tb2').style.display="none"
	document.getElementById('tb3').style.display="none"
	document.getElementById('tb4').style.display=""
	document.getElementById('tb5').style.display="none"
	}
if (img=='s5')
	{
	document.getElementById('s1').src="img/solapa1.jpg";
	document.getElementById('s2').src="img/solapa"+a+"2.jpg";
	document.getElementById('s3').src="img/solapa"+a+"3.jpg";
	document.getElementById('s4').src="img/solapa"+a+"4.jpg";
	document.getElementById('s5').src="img/solapa"+a+"55.jpg";
	document.getElementById('tb1').style.display="none"
	document.getElementById('tb2').style.display="none"
	document.getElementById('tb3').style.display="none"
	document.getElementById('tb4').style.display="none"
	document.getElementById('tb5').style.display=""
	}
if (img=='s6')
	{
	document.getElementById('s1').src="img/solapa1.jpg";
	document.getElementById('s2').src="img/solapa"+a+"2.jpg";
	document.getElementById('s3').src="img/solapa"+a+"3.jpg";
	document.getElementById('s4').src="img/solapa"+a+"4.jpg";
	document.getElementById('s5').src="img/solapa"+a+"5.jpg";
	document.getElementById('tb1').style.display="none"
	document.getElementById('tb2').style.display="none"
	document.getElementById('tb3').style.display="none"
	document.getElementById('tb4').style.display="none"
	document.getElementById('tb5').style.display="none"
	}
}
function save_cancel(x,o)
{
	if (x==1)
	{
	document.getElementById('save').style.display=""
	document.getElementById('cancel').style.display=""
	document.getElementById('edit').style.display="none"
	document.getElementById('aceptar').style.display="none"
	cant=document.form1.length
	for (var g=0; g < cant;g++)
		{
			if ((document.form1.elements[g].value!="Editar")&(document.form1.elements[g].value!="Guardar")&(document.form1.elements[g].value!="Cancelar"))
			{
				document.form1.elements[g].disabled=false
			}
		}
	}
	else
	{
	document.getElementById('save').style.display="none"
	document.getElementById('cancel').style.display="none"
	document.getElementById('edit').style.display=""
	document.getElementById('aceptar').style.display=""
	cant=document.form1.length
	for (var g=0; g < cant;g++)
		{
			if ((document.form1.elements[g].value!="Editar")&(document.form1.elements[g].value!="Guardar")&(document.form1.elements[g].value!="Cancelar")&(document.form1.elements[g].value!="Confirmar Datos!"))
			{
				document.form1.elements[g].disabled=true
			}
		}
	}
}
function addd(lst,lstinc)
{
var m=document.form1.lst_hora.value
var mm=document.form1.lst_minutos.value
if ((m==0)&(mm!='sin parada')){
	alert("debes seleccionar la hora.");
	var selObj = document.getElementById(lst);
	selObj.options[0].selected = 1
}
else{

	var can = (document.getElementById(lstinc).length)
	var indice1 = document.form1[lst].selectedIndex; 
	var texto1=document.form1[lst][indice1].text;
	var indice2 = document.form1.lst_hora.selectedIndex; 
	var texto2=document.form1.lst_hora[indice2].text;
	if(texto1=='sin parada')
		{texto='sin parada'}
	else
		{texto=texto2+":"+texto1}
	var error =0
		if (can>0)
			{
			/*for (var g=0; g < can;g++)
				 {
				var tex=document.form1[lstinc][g].text;
				var valor=document.form1[lstinc][g].value;
				if ((texto==tex))
					{
					error=1
					break;
					}
				else
					{
					error=0
					}
				}	*/
			error=0
			}
		else
			{
			error=0
			}
		
	
		if (error==0)
			{		
			var valor = document.form1[lst].value;
			var new_option = new Option(texto, valor, false, false);
			document.getElementById(lstinc).options[can] = new_option;
			var selObj = document.getElementById(lst);
			selObj.options[0].selected = 1
			}
		else
			{
			if((m<100000))
				{
				alert("El horario que desea agrgar ya existe.");
				}
			
			}
	}
}
function quit(lst,lstinc)
{
var indi =  document.form1[lstinc].selectedIndex; 
if (indi==-1){
alert("There is no item selected!.")}
else
{
document.getElementById(lstinc).options[indi] = null;
var selObj = document.getElementById(lst);
selObj.options[0].selected = 1
var selObj = document.getElementById('lst_hora');
selObj.options[24].selected = 1
}
}
function ampliar_foto()
{
var foto=document.getElementById('foto').value
if (foto)
{
	window.open('ampliar_foto.php?foto='+foto,'window','width=450,height=400,scrollbars=yes,top=10,left=340')	
}
}
function itinerario(id,ide)
{
window.open('view_itinerario.php?id='+id+'&ide='+ide,'window','width=920,height=600,scrollbars=yes,top=10,left=340')
}
function valida_dias()
{
	inicial=document.form1.txt_fecha.value
	final=document.form1.txt_fecha2.value
	var curDate=new Date();
	a=inicial.split("/")
	startDate=a[2]+"-"+a[1]+"-"+a[0]
	b=final.split("/")
	endDate=b[2]+"-"+b[1]+"-"+b[0]
	f11=a[1]+"-"+a[0]+"-"+a[2]
	f22=b[1]+"-"+b[0]+"-"+b[2]
	f1=new Date(f11); 
	f2=new Date(f22);
	if(f2<f1)
		{
		alert("La fecha inicial debe ser menor que la fecha final")
		}
	else	
		{
		curDate.DateDiff({interval:"d",date1:startDate,date2:endDate})
		dias=curDate.difference
		if(dias<1)
			{
				alert("Debe selecionar al menos un día.")
			}
			else
			{
				document.form1.action="presu21.php?dias="+dias;
				document.form1.submit();
			}
		}
	
	
	//if((document.form1.txt_dias.value==0))
	//{
//		alert("Debes indicar la cantidad de días.")
//	}
//	else
//	{
		
	//}
}

function agrf2(dbl,event)
{
var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if(Key==13 | dbl==1){
	var m=document.getElementById('lst_busca2').value
	var indice1 = document.getElementById('lst_busca2').selectedIndex; 
	var texto1=document.getElementById('lst_busca2')[indice1].text;
	if (m>0)
		{
		document.getElementById('tr_busca2').style.display="none"
		document.getElementById('txt_localidad2').focus()
		document.getElementById('txt_localidad2').value=texto1
		document.getElementById('loc_id2').value=m
		}
	
}
if (Key==27){
	document.getElementById('tr_busca2').style.display="none"
	document.form1.txt_localidad2.value=""
	document.getElementById('loc_id2').value=""
	document.form1.txt_localidad2.focus()
}
}
function tipo_banner()
{
	if(document.getElementById('lst_estilo').value==2)
		{
			document.getElementById('ban1').style.display="none"
			document.getElementById('ban3').style.display="none"
			document.getElementById('ban4').style.display="block"
		}
	else
		{
			document.getElementById('ban1').style.display="block"
			document.getElementById('ban3').style.display="block"
			document.getElementById('ban4').style.display="none"
		}
}
function adddd(lst,lstinc)
{
var m=document.form1[lst].value
if (m==0){
	alert("Debe seleccionar un item.");}
else{

	var can = (document.getElementById(lstinc).length)
	if(lst=='txt_link')
		{
		texto='L.'+document.form1.txt_link2.value+'---'+document.form1.txt_link.value
		}
	else
		{
		var indice1 = document.form1[lst].selectedIndex; 
		var texto=document.form1[lst][indice1].text;
		}
	var error =0
		if (can>0)
			{
			for (var g=0; g < can;g++)
				 {
				var tex=document.form1[lstinc][g].text;
				var valor=document.form1[lstinc][g].value;
				if ((texto==tex))
					{
					error=1
					break;
					}
				else
					{
					error=0
					}
				}	
			
			}
		else
			{
			error=0
			}
		
	
		if (error==0)
			{		
			var valor = document.form1[lst].value;
			var new_option = new Option(texto, valor, false, false);
			document.getElementById(lstinc).options[can] = new_option;
			if(lst!='txt_link')
				{
				var selObj = document.getElementById(lst);
				selObj.options[0].selected = 1
				}
			}
		else
			{
			if((m<100000)|(lst=='txt_link'))
				{
				alert("El item que desea agregar ya existe.");
				}
			if(lst!='txt_link')
				{
				var selObj = document.getElementById(lst);
				selObj.options[0].selected = 1
				}
			}
	}
}
function quit2(lst,lstinc)
{
var indi =  document.form1[lstinc].selectedIndex; 
if (indi==-1){
alert("no hay ningún item seleccionado.")}
else
{
document.getElementById(lstinc).options[indi] = null;
//var selObj = document.getElementById(lst);
//selObj.options[0].selected = 1
}
}


function olvide(x)
{
	if(x==1)
		{
		document.getElementById('olv').style.display="block";
		document.getElementById('login').style.height="290px";	
		}
	else
		{
		document.getElementById('olv').style.display="none";
		document.getElementById('login').style.height="220px";		
		}		
}
/***ajax*///
function getHTTPObject()
{
 var xmlhttp = null;
 //Internet Explorer
 try
 {
  xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
 }
 catch (e)
 {
  try
  {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (e)
  {
   xmlhttp = null;
  }
 }
//Mozilla y Safari
 if ((xmlhttp == null) && (typeof XMLHttpRequest != 'undefined'))
 {
  try
  {
   xmlhttp = new XMLHttpRequest();
  }
  catch (e)
  {
   xmlhttp = null;
  }
 }
 return xmlhttp;
}
var enProceso = false; // lo usamos para ver si hay un proceso activo
var http =  getHTTPObject(); // Creamos el objeto XMLHttpRequest
function guardaoferta()
{
if((document.oferta.txt_plazo.value=="")|(document.oferta.txt_entrega.value=="")|(document.oferta.txt_cantidad.value=="")|(document.oferta.txt_precio.value=="")|(document.oferta.txt_dto.value==""))
	{
	alert("Todos los datos son obligatorios.");
	}
else
	{
	var x=confirm("¿Deseas guardar la oferta?");
	if(x)
		{
		document.oferta.action="prv_cmd.php?accion=guardaroferta&id="+document.oferta.txt_id.value;
		document.oferta.submit();
		}
	}
}
function updt_oferta(valores)
{
valores=valores.replace(/ª/g,"'");
valores=valores.replace(/ç/g,'"');
arr=valores.split("|");
document.oferta.txt_id.value=arr[0];
document.oferta.txt_plazo.value=arr[4];
document.oferta.txt_entrega.value=arr[5];
document.oferta.txt_cantidad.value=arr[6];
document.oferta.txt_precio.value=arr[2];
document.oferta.txt_dto.value=arr[3];
if(arr[0]>0)
	{
	document.getElementById('quitar').style.visibility="visible";
	}
else
	{
	document.getElementById('quitar').style.visibility="hidden";	
	}
if(arr[7]==0)
	{
	document.getElementById('txt_plazo').disabled=true;
	document.getElementById('txt_entrega').disabled=true;
	document.getElementById('txt_cantidad').disabled=true;
	document.getElementById('txt_precio').disabled=true;
	document.getElementById('txt_dto').disabled=true;
	document.getElementById('quitar').style.display="none";
	document.getElementById('guardar').style.display="none";
	}
}
function quitaroferta(id)
{
var x=confirm("¿Realmente deseas quitar la oferta?");
if(x)
	{
	window.open('prv_cmd.php?accion=quitaroferta&id='+id, '_parent');
	}
}

function valida_olvide(){
	if (document.form_usuario.txt_email.value=="")
		{
		alert("Debe indicar su email.")
		}
	else
		{
		q=document.form_usuario.txt_email.value;
		var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
		if(b.test(q)==false)
			{
			alert ("La dirección de email es incorrecta")
			}
		else
			{
				document.form_usuario.action="olvido.php"
				document.form_usuario.submit();
			}
		}
	}
