	function openit(sURL)
	{newwindow=open(sURL,"popupnav","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=yes,status=no,width=640 ,height=480, left=10, top=10");}

var cliente= '';

function enviar() {
	var valido = false;
	
	// Comprobamos 'nombre'
	for (var i=0;i!=document.getElementById('formu').nombre.value.length;i++) 
	{
		if(document.getElementById('formu').nombre.value.charAt(i)!=' ') 
			{ valido = true; }
	}
	if (valido == false) 
	{
		mensaje("Nombre");
		document.getElementById('formu').nombre.value='';
		document.getElementById('formu').nombre.focus();
		return valido;
	}
	valido=false;
	
	// Comprobamos 'apellidos'
	for (var i=0;i!=document.getElementById('formu').apellidos.value.length;i++) 
	{					
		if(document.getElementById('formu').apellidos.value.charAt(i)!=' ') 
			{ valido = true; }
	}
	if (valido == false) 
	{
		mensaje("Apellidos");
		document.getElementById('formu').apellidos.value='';
		document.getElementById('formu').apellidos.focus();
		return valido;
	}
	valido=false;

	// Comprobamos 'DNi/NIf'
		for (var i=0;i!=document.getElementById('formu').dni.value.length;i++) 
		{
			if(document.getElementById('formu').dni.value.charAt(i)!=' ') 
				{ valido = true; }
		}	
		var aux= document.getElementById('formu').dni.value;
		if (! (isNaN(aux.substring(0,7))) ) 	
			{ valido = true; } else {valido = false}
		if (document.getElementById('formu').dni.value.length >=7) 
			{ valido = true; } else {valido = false}
		if (valido == false) 
			{
				mensaje("DNI/NIF");
				document.getElementById('formu').dni.value='';
				document.getElementById('formu').dni.focus();
				return valido;
			}
	
	valido == false;
	// Comprobamos 'email'
	if (document.getElementById('formu').email.value != '') 
		{ valido = true; } else {valido = false}
	for (var i=0;i!=document.getElementById('formu').email.value.length;i++) 
	{
		if(document.getElementById('formu').email.value.charAt(i)!=' ') 
			{ valido = true; }
	}
	if ( (document.getElementById('formu').email.value.indexOf('@') == -1) || (document.getElementById('formu').email.value.indexOf('.') == -1) )
		{valido = false} else {valido = true}
	if (valido == false) 
	{
		mensaje("E-mail");
		document.getElementById('formu').email.value='';
		document.getElementById('formu').email.focus();
		return valido;
	}
	
	if (cliente=='')
	{ 
		mensaje("Cliente");
		return valido;
	}
	
	if (valido == true) 
	{
		if( (cliente=='1') && (document.getElementById('formu').codoficina[document.getElementById('formu').codoficina.selectedIndex].value!= -1) ) 
		{ 
			document.getElementById('formu').oficina.value= document.getElementById('formu').codoficina[document.getElementById('formu').codoficina.selectedIndex].text ;
		}else { document.getElementById('formu').codoficina.value="-1"; }
		
		document.getElementById('formu').submit();
		return valido;
	}
	
	
		
}	
function valor1(array, pos){
	var aux= array.split('#');
	return(aux[pos]);
}
	
function rellena(){
	document.getElementById('indiqueoficina').style.display = "block";
	document.getElementById('oficinas').options.length=oficinas.length;
	var hay = 0;
	for (i=1;i<oficinas.length;i++){
		if (valor1(oficinas[i],1) !=''){
			for(var j=0;j<3;j++)
			{
			var cadena1= valor1(oficinas[i],0);
				if (cadena1.length<2)
					cadena1='00'+cadena1
				else if (cadena1.length<3)
						cadena1='0'+cadena1
					else
						{
							j=3
						}
			}
			document.getElementById('oficinas').options[i-hay].value= cadena1;
			var cadena= valor1(oficinas[i],1);
			document.getElementById('oficinas').options[i-hay].text=cadena1 + '     ' +cadena;
		}else { hay ++}
	}document.getElementById('oficinas').options.length= document.getElementById('oficinas').options.length - hay;
	
}
function almacena(resp){
	cliente = resp;
	if (resp == '0')
		{document.getElementById("formu").codoficina[0].selected="true" }
}
function iniciar() {
	rellena();
	var idprod='';
	var arrayparam=location.search.replace(/^./,"").split(/&/);
	idprod=arrayparam[0].substring((arrayparam[0].indexOf("=")+1),arrayparam[0].length);
	document.getElementById('formu').idproducto.value=idprod;
	document.getElementById('formu').nombre.focus();
}
function cambia(id){
		if(id!=-1){
			document.getElementById('formu').codoficina.value=id;
			document.getElementById('formu').oficina.text=document.getElementById('oficinas').options[id].text;
		}
		else {document.getElementById('formu').codoficina.value="";document.getElementById('formu').codoficina.text="";}
	}
function mensaje(param){
		alert("Por favor, verifique que los datos introducidos en el campo \ "+ param +" \ son correctos");
	}
