var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function creaAjax(){
	var objetoAjax=false;
	try {
		/*Para navegadores distintos a internet explorer*/
		objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            /*Para explorer*/
            objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
            }
        catch (E) {
            objetoAjax = false;
        }
    }

    if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
        objetoAjax = new XMLHttpRequest();
    }
    return objetoAjax;
}

function generarMotivo(estado){
	var motivos = '<div class = "row"><span class="label1">Motivo del Estado:</span><span class="formw"><select name="motivoEstado">';
	if(estado == "En Vano"){
		motivos +='<option value="falla">Falla de F�brica</option>';
		motivos +='<option value="piezas">No llegan piezas</option>';
		motivos +='<option value="anterior">T�cnico anterior deja problemas</option>';
		motivos +='<option value="volver">Cliente solicita volver en otra ocasi�n</option>';
	}else if(estado == "Pendiente"){
		motivos +='<option value="piezas">Piezas no llegaron en las cajas</option>';
		motivos +='<option value="partes">Partes del mueble no llegaron</option>';
		motivos +='<option value="falla">Mueble con Da�os o Fallas</option>';
	}
	motivos+='</select></span></div>';
	if(estado == "En Vano" || estado == "Pendiente"){
		var divmotivo = document.getElementById("motivodiv");
		divmotivo.innerHTML = motivos;
	}
}

function validarComentario(){
	var valido = true;
	var coment = document.getElementById("comentario");
	var comentV = document.getElementById("comentario_v");
	comentV.style.visibility="hidden";
	if(vacio(coment.value)){
		comentV.innerHTML = "Obligatorio";
		comentV.style.visibility="visible";
		valido = false;
	}
	var razon = document.getElementById("razon");
	var razon_v=document.getElementById("razon_v");
	razon_v.style.visibility="hidden";
	if(razon.value=="nada"){
		razon_v.style.visibility="visible",
		razon_v.innerHTML="Obligatorio";
		valido = false;
	}
	return valido;
}

function validarCambioLog(){
	var correctos =0;
	var valido=0;
	var coment = document.getElementById("logComent");
	var comentV = document.getElementById("logComent_v");
	
	if(coment){
		comentV.style.visibility="hidden";
		correctos=2;
		if(!vacio(coment.value)){
			
			var visible = document.getElementsByName("logV");
			var visibleV = document.getElementById("logV_v");
			
 
			var seleccionado = false;
			for(var i=0; i<visible.length; i++) {	
			  if(visible[i].checked) {
				seleccionado = true;
				break;
			  }
			}
			visibleV.style.visibility="hidden";
			if(!seleccionado){
				visibleV.innerHTML = "Obligatorio";
				visibleV.style.visibility="visible";
			}else{
				valido++;
			}
			valido++;
		}else{
			comentV.style.visibility="visible";
			comentV.innerHTML = "Obligatorio";
		}
	}
	if(valido==correctos)
		return true;
	else
		return false;
}

function mailACoordinadoras(checked, retail, tienda){	
	var mailFrom = document.getElementById("mailFrom");
	var mailTo = document.getElementById("mailTo");
	var divFoto1 = document.getElementById("divFoto1");
	var divFoto2 = document.getElementById("divFoto2");
	var divFoto3 = document.getElementById("divFoto3");
	var divFoto4 = document.getElementById("divFoto4");
	var checkboxEmail = document.getElementById("checkboxEmail");
        var checkbox1 = '';
	if(checked==1){
		checkbox1 = 'Descartar e-mail:<input type = "checkbox" name = "borrarMail" value ="1" onClick="xajax_formEmail2(0,\''+retail+'\',\''+tienda+'\')" />';
		var div1 ='<span class="label1">De:</span><span class = "formw"><input type="text" name="fromMail" id="fromMail" size="25" value="vgomez@dmjservicios.cl" /><div class="verificador" id="fromMail_v"></div></span>';
		var div2 ='<span class="label1">Para:</span>';
		
		div2+='<span class="formw"><input type="text" name="toMail" id="toMail" size="25" value="grojas@dmjservicios.cl, verofuenzalida@dmjservicios.cl, mgaete@dmjservicios.cl" /><div class="verificador" id="toMail_v"></div></span>';
		
		var fot1 = '<span class="label1" >Foto 1:</span><span class="formw"><input name="foto1" id="foto1" type="file" size = "35" /></span>';
		var fot2 = '<span class="label1" >Foto 2:</span><span class="formw"><input name="foto2" id="foto2" type="file" size = "35" /></span>';
		var fot3 = '<span class="label1" >Foto 3:</span><span class="formw"><input name="foto3" id="foto3" type="file" size = "35" /></span>';
		var fot4 = '<span class="label1" >Foto 4:</span><span class="formw"><input name="foto4" id="foto4" type="file" size = "35" /></span>';
		
		
		mailFrom.innerHTML = div1;
		mailTo.innerHTML = div2;
		divFoto1.innerHTML = fot1;
		divFoto2.innerHTML = fot2;
		divFoto3.innerHTML = fot3;
		divFoto4.innerHTML = fot4;
		checkboxEmail.innerHTML = checkbox1;
		var eviar = document.getElementById("enviarMail");
		enviar.checked = true;
		
	}else{
		checkbox1 = 'Enviar e-mail:<input type = "checkbox" name = "enviarMail" value ="1" onClick="xajax_formEmail2(1,\''+retail+'\',\''+tienda+'\')"/>';
		mailFrom.innerHTML = "";
		mailTo.innerHTML = "";
		divFoto1.innerHTML = "";
		divFoto2.innerHTML = "";
		divFoto3.innerHTML = "";
		divFoto4.innerHTML = "";
		checkboxEmail.innerHTML = "";
		
	}
	
	
}

function mailACoordinadoras2(checked, retail, tienda){
	var mailFrom = document.getElementById("mailFrom");
	var mailTo = document.getElementById("mailTo");
	var checkboxEmail = document.getElementById("checkboxEmail");
	var checkbox1 ='';
	if(checked==1){
		checkbox1 = 'Descartar e-mail:<input type = "checkbox" name = "borrarMail" value ="1" onClick="xajax_formEmail(0,\''+retail+'\',\''+tienda+'\')" />';
		var div1 ='<span class="label1">De:</span><span class = "formw"><input type="text" name="fromMail" id="fromMail" value="vgomez@dmjservicios.cl" size="25" /><div class="verificador" id="fromMail_v"></div></span>';
		var div2 ='<span class="label1">Para:</span>';
		div2+='<span class="formw"><input type="text" name="toMail" id="toMail" size="25"  value="grojas@dmjservicios.cl, verofuenzalida@dmjservicios.cl, mgaete@dmjservicios.cl" /><div class="verificador" id="toMail_v"></div></span>';
		mailFrom.innerHTML = div1;
		mailTo.innerHTML = div2;
		checkboxEmail = checkbox1;
		var enviar = document.getElementById("enviarMail");
		enviar.checked = true;
		
	}else{
		checkbox1 = 'Enviar e-mail:<input type = "checkbox" name = "enviarMail" value ="1" onClick="xajax_formEmail(1,\''+retail+'\',\''+tienda+'\')"/>';
		mailFrom.innerHTML = "";
		mailTo.innerHTML = "";
		checkboxEmail.innerHTML = checkbox1;
		
	}
	
}

function marcarEliminar(){
	var elim = document.getElementById("presEliminar");
	elim.value="1";
}

function revisarSelectIntercambio(filaPregunta, filaIntercambio, numFilas, id){
	var elemento = document.getElementById(id);
	var resp = document.getElementById("respuesta");
	var num = document.getElementById("numFilas");
	var fila = document.getElementById("fila");
	resp.innerHTML = "";
	if(elemento.checked){
		if(numFilas!=""){ 
			if(numFilas==2){ //Ya no se pueden seleccionar m�s
				elemento.checked = false;
				resp.innerHTML = "No se pueden seleccionar m�s de dos";
				
			}else if(numFilas==1){
				if(filaPregunta==filaIntercambio){ //Puede seleccionarse
					
					num.value=2;
					
				}else{
					elemento.checked = false;
					resp.innerHTML = "No puede selelccionarse una solicitud en distinto bloque horario";
					
				}
			}
		
		}else{ //Es el primero que se selecciona
			fila.value = filaPregunta;
			num.value= 1;
			
		}
	}else{
		if(numFilas!="" && numFilas==2){
			num.value=1;
			
		}else if(numFilas!="" && numFilas==1){
			num.value = "";
			fila.value = "";
			
		}
	}

}

function validarIntercambioFinal(){
	var filas = document.getElementById("numFilas");
	var resp = document.getElementById("respuesta");
	if(filas.value && filas.value==2){
		resp.innerHTML = "";
		return true;
	}else{
		resp.innerHTML = "Debes seleccionar dos solicitudes";
		return false;
	}
}

function validarComent(){
	var resp = document.getElementById("autorComentario");
	var respv = document.getElementById("autorComentario_v");
	respv.style.visibility="hidden";
	if(!vacio(resp.value)){
		return true;
	}else{
		respv.innerHTML="Obligatorio";
		respv.style.visibility="visible";
		return false;
	}
}

function validarEnvioMail2(){
	var ret1 = validarEnvioMail();
	var ret2 = true;
	var coment = document.getElementById("comentario");
	if(coment){
		if(!vacio(coment.value)){
			
			var visible = document.getElementsByName("visible");
			var visibleV = document.getElementById("visible_v");
			
 
			var seleccionado = false;
			for(var i=0; i<visible.length; i++) {	
			  if(visible[i].checked) {
				seleccionado = true;
				break;
			  }
			}
			visibleV.style.visibility="hidden";
			if(!seleccionado){
				visibleV.innerHTML = "Obligatorio";
				visibleV.style.visibility="visible";
				ret2=false;
			}else{
				ret2=true;
			}
		}
	}
	if(ret1 && ret2)
		return true;
	else
		return false;
}

function validarEnvioMail(){
	var toMail = document.getElementById("toMail");
	
	if(toMail){
		var correctos = 2;
		var validos = 0;
		
		var fromMail = document.getElementById("fromMail");
		var toMailV = document.getElementById("toMail_v");
		var fromMailV = document.getElementById("fromMail_v");
		fromMailV.style.visibility="hidden";
		toMailV.style.visibility="hidden";
		if(vacio(fromMail.value)){
			fromMailV.innerHTML = "Obligatorio";
			fromMailV.style.visibility = "visible";
		}else if(mailValido(fromMail.value)){
			validos++;
		}else{
			fromMailV.innerHTML = "Direcci�n de correo incorrecta";
			fromMailV.style.visibility = "visible";
		}
		
		if(vacio(toMail.value)){
			toMailV.innerHTML = "Obligatorio";
			toMailV.style.visibility = "visible";
		}else{
			var comienzo = 0;
			var mailsBuenos = true;
			while(toMail.value.indexOf(",",comienzo)!=-1){
				fin = toMail.value.indexOf(",",comienzo);
				if(!mailValido(toMail.value.substring(comienzo,fin))){
					mailsBuenos = false;
					break;
				}else{
					comienzo = fin+2;
				}
			}
			if(!mailsBuenos){
				toMailV.innerHTML = "Direcci�n de correo incorrecta";
				toMailV.style.visibility = "visible";
			}else{
				if(mailValido(toMail.value.substring(comienzo,toMail.value.length))){
					validos++;
				}else{
					toMailV.innerHTML = "Direcci�n de correo incorrecta";
					toMailV.style.visibility = "visible";
				}
			}
		}

		return (correctos == validos);
	}else
		return true;
		
	
}

function desChequear(id){
	
	var check = document.getElementById(id);
	check.checked = false;
}

function validarNuevoReclamo(){
	var cliente = document.getElementById("reclamoCliente");
	var cliente_v = document.getElementById("reclamoCliente_v");
	cliente_v.style.visibility="hidden";
	if(vacio(cliente.value)){
		cliente_v.innerHTML="Obligatorio";
		cliente_v.style.visibility="visible";
		return false;
	}else{
		return true;
	}
	
}

function validarNuevoFormMail(){
	var correctos = 2;
	var validos = 0;
	
	var fromMail = document.getElementById("nuevoMailDe");
	var toMail = document.getElementById("nuevoMailPara");
	var fromMailV = document.getElementById("nuevoMailDe_v");
	var toMailV = document.getElementById("nuevoMailPara_v");
	fromMailV.style.visibility="hidden";
	toMailV.style.visibility="hidden";
	if(vacio(fromMail.value)){
		fromMailV.innerHTML = "Obligatorio";
		fromMailV.style.visibility = "visible";
	}else if(mailValido(fromMail.value)){
		validos++;
	}else{
		fromMailV.innerHTML = "Direcci�n de correo incorrecta";
		fromMailV.style.visibility = "visible";
	}
	
	if(vacio(toMail.value)){
		toMailV.innerHTML = "Obligatorio";
		toMailV.style.visibility = "visible";
	}else{
		var comienzo = 0;
		var mailsBuenos = true;
		while(toMail.value.indexOf(",",comienzo)!=-1){
			fin = toMail.value.indexOf(",",comienzo);
			if(!mailValido(toMail.value.substring(comienzo,fin))){
				mailsBuenos = false;
				break;
			}else{
				comienzo = fin+2;
			}
		}
		if(!mailsBuenos){
			toMailV.innerHTML = "Direcci�n de correo incorrecta";
			toMailV.style.visibility = "visible";
		}else{
			if(mailValido(toMail.value.substring(comienzo,toMail.value.length))){
				validos++;
			}else{
				toMailV.innerHTML = "Direcci�n de correo incorrecta";
				toMailV.style.visibility = "visible";
			}
		}
	}
	
	
	return (correctos == validos);
}

function autoFormSubmit(){
	document.getElementById("upload_form").submit();

}

function generarInsertados(){
	var insert = document.getElementById("insertados");
	insert.style.visibility = "visible";
}

function validarParis(){
	
	var tipoCliente = document.getElementById("tipoCliente");
	var nboleta = document.getElementById("nboleta");
	var nboletaV = document.getElementById("nboleta_v");
	nboletaV.style.visibility="hidden";
	if(tipoCliente.value=="nada"){
		return false;
	}else {
		if(vacio(nboleta.value)){
			nboletaV.innerHTML = "Obligatorio";
			nboletaV.style.visibility="visible";
			return false;
		}else if(isInteger(nboleta.value)){
			return true;
		}else{
			nboletaV.innerHTML = "Debe ser un numero";
			nboletaV.style.visibility="visible";
			return false;
		}
	}
}

function validarNuevaSolicitud(conRut){
	
	var elim = document.getElementById("presEliminar");
	if(elim){
		if(elim.value==1){
			if(!confirm("�Seguro desea Eliminar?"))
				return false;
		}
	}
	var retail = document.getElementById("retailer");
	if(retail && retail.value=="Servicios_Particulares"){
		return validarServiciosParticulares();
	}else{
		var retorno1 = validarIngresoSolicitud(conRut,1);
		var retorno2=false;
		
		
		var tipoSol = document.getElementById("tipoSol");
		
		if(tipoSol.value=="armado" || tipoSol.value=="despacho"){
                    var r1;
                    var r2;
			if(retail.value=="Lider" || retail.value=="Arteknia" || retail.value=="MundoLider" || retail.value=="ABCDIN" || retail.value=="CIC" || retail.value=="EASY" || retail.value=="Sodimac" || retail.value=="Falabella" || retail.value == "Falabella-Internet" || retail.value=="Paris" || retail.value=="DSur" || retail.value=="Hites" || retail.value=="Favatex"){
				r1 = validarMuebles2("nada");
				r2=true;
				if(retail.value=="Paris" ){
					r2 = validarParis();
				}
				if(r1 && r2)
					retorno2 = true;
				else retorno2 = false;
			}else if(retail.value=="nada"){
				retorno2=false;
			}else if(retail.value == "Paris"){
				r1 = validarMuebles3("nada");
				r2 = validarParis();
				if(r1 && r2)
					retorno2 = true;
				else retorno2 = false;
			}else{
				retorno2 = validarMuebles3("nada");
			}
		}else if(tipoSol.value=="plasma"){
			retorno2 = validarTelevisores();
		}else if(tipoSol.value=="parrilla"){
			retorno2 = validarParrillas();
		}else {
			retorno2 = validarCantidad();
		}
		
		
		var retorno3 = validarNuevaAgendada();
		var retorno4 = false;
		var cTraslado = document.getElementById("cTraslado");
		var cTrasladoV = document.getElementById("cTraslado_v");
		cTrasladoV.style.visibility = "hidden";
		if(vacio(cTraslado.value)){
			var comuna = document.getElementById("comuna");
			if(comuna){
				if(comuna.value=="San Felipe" || comuna.value=="Los Andes" || comuna.value=="Paine" || comuna.value=="Colina" || 
					comuna.value=="Do�ihue" || comuna.value=="Rengo" || comuna.value=="Graneros" || comuna.value=="Villa Alemana" ||
					comuna.value=="Cabildo" || comuna.value=="Nogales" || comuna.value=="Algarrobo" || comuna.value=="Casablanca" || 
					comuna.value=="San Fernando" || comuna.value=="Machal�" || comuna.value=="Requ�noa" || comuna.value=="Coinco" || 
					comuna.value=="Peumo" || comuna.value=="Pichilemu" || comuna.value=="Mostazal" || comuna.value=="Quinta de Tilcoco" || 
					comuna.value=="Codegua" || comuna.value=="Quillota" || comuna.value=="Olmu�" || comuna.value=="Calera" || 
					comuna.value=="El Quisco" || comuna.value=="Puchuncav�" || comuna.value=="La Cruz"){
					
					cTrasladoV.innerHTML = "Obligatorio";
					cTrasladoV.style.visibility = "visible";
					retorno4 = false;
				}else{
					retorno4 = true;
				}
			}else
				retorno4=true;
		}else{
			if(isInteger(cTraslado.value)){
				retorno4 = true;
			}else{
				cTrasladoV.innerHTML = "Debe ser un numero";
				cTrasladoV.style.visibility="visible";
			}
		}
		if(retorno1 & retorno2 & retorno3 & retorno4)
			return true;
		else
			return false;
	}
}

function validarModificarSolicitud(conRut){
	var retail = document.getElementById("retailer");
	var elim = document.getElementById("presEliminar");
	if(elim){
		if(elim.value==1){
			if(!confirm("�Seguro desea Eliminar?"))
				return false;
		}
	}
	if(retail && retail.value=="Servicios_Particulares"){
		return validarServiciosParticulares();
	}else{
		var retorno1 = validarIngresoSolicitud(conRut,1);
		var retorno2=false;
		
		
		var tipoSol = document.getElementById("tipoSol");
		
		
		if(tipoSol.value=="armado"){
                    var r1, r2;
			if(retail.value=="Lider" || retail.value=="MundoLider" || retail.value=="ABCDIN" || retail.value=="CIC" || retail.value=="EASY" || retail.value=="Sodimac" || retail.value=="Falabella" || retail.value == "Falabella-Internet" || retail.value=="Paris" || retail.value=="DSur" || retail.value=="Hites" || retail.value=="Favatex"){
                            r1 = validarMuebles2("nada");
				r2 = true;
				if(retail.value=="Paris" ){
					r2 = validarParis();
				}
				if(r1 && r2)
					retorno2 = true;
				else retorno2 = false;
			}else if(retail.value=="nada"){
				retorno2=false;
			}else if(retail.value == "Paris"){
				r1 = validarMuebles3("nada");
				r2 = validarParis();
				if(r1 && r2)
					retorno2 = true;
				else retorno2 = false;
			}else{
				retorno2 = validarMuebles3("nada");
			}
		}else if(tipoSol.value=="plasma"){
			retorno2 = validarTelevisores();
		}else if(tipoSol.value=="parrilla"){
			retorno2 = validarParrillas();
		}else{
			retorno2 = validarCantidad();
                }
		
		
		var retorno3 = validarNuevaAgendada();
		var retorno4 = false;
		var cTraslado = document.getElementById("cTraslado");
		var cTrasladoV = document.getElementById("cTraslado_v");
		cTrasladoV.style.visibility = "hidden";
		if(vacio(cTraslado.value)){
			if(comuna){
				if(comuna.value=="San Felipe" || comuna.value=="Los Andes" || comuna.value=="Paine" || comuna.value=="Colina" || 
					comuna.value=="Do�ihue" || comuna.value=="Rengo" || comuna.value=="Graneros" || comuna.value=="Villa Alemana" ||
					comuna.value=="Cabildo" || comuna.value=="Nogales" || comuna.value=="Algarrobo" || comuna.value=="Casablanca" || 
					comuna.value=="San Fernando" || comuna.value=="Machal�" || comuna.value=="Requ�noa" || comuna.value=="Coinco" || 
					comuna.value=="Peumo" || comuna.value=="Pichilemu" || comuna.value=="Mostazal" || comuna.value=="Quinta de Tilcoco" || 
					comuna.value=="Codegua" || comuna.value=="Quillota" || comuna.value=="Olmu�" || comuna.value=="Calera" || 
					comuna.value=="El Quisco" || comuna.value=="Puchuncav�" || comuna.value=="La Cruz"){
					
					cTrasladoV.innerHTML = "Obligatorio";
					cTrasladoV.style.visibility = "visible";
					retorno4 = false;
				}
			}else
				retorno4=true;
			
		}else{
			if(isInteger(cTraslado.value)){
				retorno4 = true;
			}else{
				cTrasladoV.innerHTML = "Debe ser un numero";
				cTrasladoV.style.visibility="visible";
			}
		}
		var retorno5 = validarEnvioMail();
		var retorno6 = validarEnvioAntecedente();
		
		if(retorno1 & retorno2 & retorno3 & retorno4 & retorno5 &retorno6)
			return true;
		else
			return false;
	}	
}

function validarEnvioAntecedente(){
	var retorno = true;
	var razon = document.getElementById("razonFelicit");
	var razon_v = document.getElementById("razonFelicit_v");
	var tecnico = document.getElementById("tecnAntecedente");
	var ejecutivo = document.getElementById("ejecutivoAntecedente");
	var comentario = document.getElementById("comentario");
	var comentario_v = document.getElementById("comentario_v");
	var validarRazon = false;
	var contadorSelect = 0;
	razon_v.style.visibility="hidden";
	comentario_v.style.visibility="hidden"
	if(tecnico && tecnico.value!="nada"){
		validarRazon=true;
		contadorSelect++;
	}
	if(ejecutivo && ejecutivo.value!="nada"){
		validarRazon = true;
		contadorSelect++;
	}
	if(contadorSelect>1){
		razon_v.innerHTML="S�lo puede elegir un t�cnico o un ejecutivo";
		razon_v.style.visibility="visible";
		retorno = false;
	}else if(validarRazon){
		if(razon.value=="nada"){
			razon_v.style.visibility="visible";
			razon_v.innerHTML="Obligatorio";
			retorno = false;
		}
		if(vacio(comentario.value)){
			comentario_v.style.visibility="visible"
			comentario_v.innerHTML="Obligatorio";
			retorno = false;
		}
	}
	return retorno;
}

function validarServicioTecnico(){
	var correctos = 1;
	var valido = 0;
	var elim = document.getElementById("presEliminar");
	if(elim){
		if(elim.value==1){
			if(!confirm("�Seguro desea Eliminar?"))
				return false;
		}
	}
	var descServicio = document.getElementById("descServicio");
	var descServicioV = document.getElementById("descServicio_v");
	descServicioV.style.visibility="hidden";
	if(descServicio.text==""){
		descServicioV.innerHTML = "Obligatorio";
		descServicioV.style.visibility="visible";
	}else{
		valido++;
	}
	
	var retorno = validarIngresoSolicitud(false,1);
	var retorno2 = validarEnvioAntecedente();
	if(valido == correctos && retorno && retorno2) return true;
	else return false;
}

function validarServicioTecnico2(){
	var correctos = 1;
	var valido = 0;
	
	var descServicio = document.getElementById("descServicio");
	var descServicioV = document.getElementById("descServicio_v");
	descServicioV.style.visibility="hidden";
	if(descServicio.text==""){
		descServicioV.innerHTML = "Obligatorio";
		descServicioV.style.visibility="visible";
	}else{
		valido++;
	}
	var cant = document.getElementById("cantidad");
	
	var retorno = false;
	if(cant) retorno = validarNuevaSolicitud(true);
	else retorno = validarIngresoSolicitud(true,1);
	if(valido == correctos) return retorno;
	else return false;
}

function validarServiciosParticulares(){
	var correctos = 5;
	var valido = 0;
	elementosSP_nulos = new Array("fechaSP", "precio");
	elementosSP_nada = new Array("tecnico1", "tecnico2", "tecnico3", "tecnico4", "region", "horaArmado");
        var a, b;
	for(j=0; j<elementosSP_nada.length; j++){
		a = document.getElementById(elementosSP_nada[j]+"_v");
		a.style.visibility="hidden";
	}
	for(i=0; i<elementosSP_nulos.length; i++){
		a = document.getElementById(elementosSP_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	var contadorTecns = 0;
	for(k=0; k< elementosSP_nada.length; k++){
		a = document.getElementById(elementosSP_nada[k]);
		b = document.getElementById(elementosSP_nada[k]+"_v");
		if(a.value=="nada"){
			if(elementosSP_nada[k]=="tecnico1" || elementosSP_nada[k]=="tecnico2" || elementosSP_nada[k]=="tecnico3" || elementosSP_nada[k]=="tecnico4"){
				contadorTecns++;
			}else{
				b.innerHTML="Obligatorio";
				b.style.visibility="visible";
			}
		}
		else if(elementosSP_nada[k]=="region" || elementosSP_nada[k]=="horaArmado"){
			valido++;
		}
		
	}
	if(contadorTecns!=4){
		valido++;
	}else{
		var tecnV = document.getElementById("tecnico1_v");
		tecnV.innerHTML = "Debe ingresar al menos un t�cnico";
		tecnV.style.visibility="visible";
	}
	for(m=0; m< elementosSP_nulos.length; m++){
		a = document.getElementById(elementosSP_nulos[m]);
		b = document.getElementById(elementosSP_nulos[m]+"_v");
		if(vacio(a.value)){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			if(elementosSP_nulos[m]=="precio"){
				if(isInteger(a.value)){
					valido++;
				}else{
					b.innerHTML = "Debe ser un n�mero";
					b.style.visibility="visible";
				}
			}else if(elementosSP_nulos[m]=="fechaSP"){
				if(validarFecha("fechaSP","Nada")){
					valido++;
				}
			}else{
				valido++;
			}
		}
		
	}
	if(valido==correctos)
		return true;
	else return false;
}

function validarIngresoSolicitud(conRut, origen){
	var correctos = 4;
	var valido = 0;
	var elementos_nada = new Array("retailer", "region","tienda", "tipoCliente");
	
	var retail = document.getElementById("retailer");
	
	
	if(origen==0){
		correctos++;
		var ejecutivo = document.getElementById("ejecutivo");
		var ejecutivo_v = document.getElementById("ejecutivo_v");
		ejecutivo_v.style.visibility="hidden";
		if(vacio(ejecutivo.value)){
			ejecutivo_v.innerHTML = "Obligatorio";
			ejecutivo_v.style.visibility="visible";
		}else{
			valido++;
		}
	}
	
	var a,b;
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}

	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada" || vacio(a.value)){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
		}
		
	}
	
	var coment = document.getElementById("comentario");
        var seleccionado;
	if(coment){
		if(!vacio(coment.value)){
			correctos++;
			var visible = document.getElementsByName("visible");
			var visibleV = document.getElementById("visible_v");
			
 
			seleccionado = false;
			for(var i=0; i<visible.length; i++) {	
			  if(visible[i].checked) {
				seleccionado = true;
				break;
			  }
			}
			visibleV.style.visibility="hidden";
			if(!seleccionado){
				visibleV.innerHTML = "Obligatorio";
				visibleV.style.visibility="visible";
			}else{
				valido++;
			}
		}
	}
	var tipoSol = document.getElementById("tipoSol");
	if(tipoSol){
		if(tipoSol.value=="armado" || tipoSol.value=="despacho"){ 
			var muebleDomicilio = document.getElementsByName("muebleDomicilio");
			if(muebleDomicilio && muebleDomicilio.length!=0){
				correctos++;
				var muebleDomicilioV = document.getElementById("muebleDomicilio_v");

				seleccionado = false;
				for(i=0; i<muebleDomicilio.length; i++) {	
				  if(muebleDomicilio[i].checked) {
					seleccionado = true;
					break;
				  }
				}
				muebleDomicilioV.style.visibility="hidden";
				if(!seleccionado){
					muebleDomicilioV.innerHTML = "Obligatorio";
					muebleDomicilioV.style.visibility="visible";
				}else{
					valido++;
				}
				
			}
			var muebleLugar = document.getElementsByName("muebleLugar");
			if(muebleLugar && muebleLugar.length!=0){
				correctos++;
				var muebleLugarV = document.getElementById("muebleLugar_v");

				seleccionado = false;
				for(i=0; i<muebleLugar.length; i++) {	
				  if(muebleLugar[i].checked) {
					seleccionado = true;
					break;
				  }
				}
				muebleLugarV.style.visibility="hidden";
				if(!seleccionado){
					muebleLugarV.innerHTML = "Obligatorio";
					muebleLugarV.style.visibility="visible";
				}else{
					valido++;
				}
				
			}
		}else if(tipoSol.value!="plasma" && tipoSol.value!="parrilla" && tipoSol.value!="puertas" && tipoSol.value!="persianas"){
			if(retail && retail.value=="Sodimac"){
				correctos = correctos+3;
				var ordenI = document.getElementById("ordenInstalacion");
				var ordenIV = document.getElementById("ordenInstalacion_v");
				var oin = document.getElementById("oin");
				var oinV = document.getElementById("oin_v");
				var proyecto = document.getElementById("proyecto");
				var proyectoV = document.getElementById("proyecto_v");
				ordenIV.style.visibility="hidden";
				oinV.style.visibility="hidden";
				proyectoV.style.visibility="hidden";
				if(vacio(ordenI.value)){
					ordenIV.style.visibility="visible";
					ordenIV.innerHTML = "Obligatorio";
				}else{
					if(isInteger(ordenI.value) && ordenI.value.length >=6){
						valido++;
					}else{
						ordenIV.innerHTML = "Debe ser un n�mero de m�nimo 6 d�gitos";
						ordenIV.style.visibility="visible";
					}
				}
				if(vacio(oin.value)){
					oinV.style.visibility="visible";
					oinV.innerHTML = "Obligatorio";
				}else{
					if(isInteger(oin.value) && oin.value.length >= 5){
						valido++;
					}else{
						oinV.innerHTML = "Debe ser un n�mero de m�nimo 5 d�gitos";
						oinV.style.visibility="visible";
					}
				}
				if(vacio(proyecto.value)){
					proyectoV.style.visibility="visible";
					proyectoV.innerHTML = "Obligatorio";
				}else{
					if(isInteger(proyecto.value) && proyecto.value.length >= 6){
						valido++;
					}else{
						proyectoV.innerHTML = "Debe ser un n�mero de m�nimo 6 digitos";
						proyectoV.style.visibility="visible";
					}
				}
			}
		}
	}
	if(retail.value=="ABCDIN"){
		correctos++;
		var ot = document.getElementById("ot");
		var otV = document.getElementById("ot_v");
		otV.style.visibility="hidden";
		if(vacio(ot.value)){
			otV.innerHTML="Obligatorio";
			otV.style.visibility="visible";
		}else{
			valido++;
		}
	}
	
	if(retail.value=="Arteknia"){
		correctos=correctos+2;
		var nbol = document.getElementById("nboleta");
		var nbolv = document.getElementById("nboleta_v");
		nbolv.style.visibility = "hidden";
		if(vacio(nbol.value)){
			nbolv.innerHTML="Obligatorio";
			nbolv.style.visibility="visible";
		}else{
			valido++;
		}
		
		var reservas = document.getElementById("reservas");
		var reservasV = document.getElementById("reservas_v");
		reservasV.style.visibility="hidden";
		if(vacio(reservas.value)){
			reservasV.innerHTML="Obligatorio";
			reservasV.style.visibility="visible";
		}else{
			valido++;
		}
	}

	if(retail.value=="CIC"){
		correctos++;
		var ret2 = document.getElementById("retailer2");
		var ret2V = document.getElementById("retailer2_v");
		ret2V.style.visibility="hidden";
		if(ret2.value=="nada"){
			ret2V.innerHTML="Obligatorio";
			ret2V.style.visibility="visible";
		}else{
			valido++;
		}
	}
	
	if(valido==correctos){
		var retorno1 = true;
		if(retail.value=="Paris" ){
			retorno1 = validarParis();
		}
		var retorno2 = false;
		var tipoCliente = document.getElementById("tipoCliente");
		var tipoClienteV = document.getElementById("tipoCliente_v");
		if(tipoCliente.value=="particular"){
			retorno2 = validarFormArmado2(conRut);
		}else if(tipoCliente.value=="tienda"){
			retorno2 = validarFormTienda();
		}else
			retorno2 = false;
		if(retorno1 && retorno2)	return true;
		else return false;
	}
	else
		return false;
	
}

function validarFormTienda(){
	
	var valido=0;
	var correctos = 3;
	var elementos_nulos = new Array("nombreResponsable", "fonoResponsable");
	var elementos_nada = new Array("cargo");
	var a,b;
	for(i=0; i< elementos_nulos.length; i++){
		a = document.getElementById(elementos_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	
	for(j=0; j< elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}

	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
		}
	}
	
	for(m=0; m< elementos_nulos.length; m++){
		a = document.getElementById(elementos_nulos[m]);
		b = document.getElementById(elementos_nulos[m]+"_v");
		if(vacio(a.value)){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
			
		}
	}
	
	var retail = document.getElementById("retailer");
	if(retail.value != "ABCDIN"){
		correctos++;
		var mail = document.getElementById("mailResponsable");
		var mail_v = document.getElementById("mailResponsable_v");
		mail_v.style.visibility="hidden";
		if(vacio(mail.value)){
			mail_v.innerHTML = "Obligatorio";
			mail_v.style.visibility="visible";
		}else{
			if(mailValido(mail.value)){
				valido++;
			}
			else{
				mail_v.innerHTML="Mail no valido";
				mail_v.style.visibility="visible";
			}
		}
		
	}
	if(valido==correctos)
		return true;
	else 
		return false;
}

function validarFormArmado2(conRut){
	
	var valido=0;
	var correctos = 4;
	var elementos_nulos = new Array("nombre", "direccion");
	
	if(conRut){
		var rut = document.getElementById("rut");
		var rutV = document.getElementById("rut_v");
		rutV.style.visibility="hidden";
		if(!vacio(rut.value)){
			correctos++;
			if(checkRutField(rut.value, rutV)){
				valido++;
			}
		}
	}
	
	var elementos_nada = new Array("regionC", "comuna");
	var alguno=false;
        var a, b;
	for(i=0; i<elementos_nulos.length; i++){
		a = document.getElementById(elementos_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}

	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
		}
		
	}
	var mail = document.getElementById("mail");
	var mailV = document.getElementById("mail_v");
	mailV.style.visibility="hidden"
	if(!vacio(mail.value)){
		correctos++;
		if(mailValido(mail.value)){
			valido++;
		}
		else{
			mailV.innerHTML="Mail no valido";
			mailV.style.visibility="visible";
		}
	}
	var cel = document.getElementById("cel");
	var celV = document.getElementById("cel_v");
	celV.style.visibility="hidden";
	if(!vacio(cel.value)){
		correctos++;
		largo = cel.value.length;
		if(isInteger(cel.value) &(largo==8)){
			valido++;
			alguno=true;
		}
		else{
			celV.innerHTML="Numero invalido";
			celV.style.visibility="visible";
		}
	}
	var codigo= document.getElementById("codigo");
	var codigoV= document.getElementById("codigo_v");
	codigoV.style.visibility="hidden";
	var fono= document.getElementById("telefono");
	var fonoV= document.getElementById("telefono_v");
	fonoV.style.visibility="hidden";
	var r =0;
	var largo=0;
	if(!vacio(codigo.value)){
		correctos=correctos+2;
		largo = codigo.value.length;
		if(largo<3 & isInteger(codigo.value)){
			valido++;
			r++;
		}
		else{
			codigoV.innerHTML="Codigo invalido";
			codigoV.style.visibility="visible";
		}
		if(!vacio(fono.value)){
			largo = fono.value.length;
			if((largo==6 || largo==7) & isInteger(fono.value)){
				valido++;
				r++;
			}
			else{
				fonoV.innerHTML="Telefono invalido";
				fonoV.style.visibility="visible";
			}
		}
		else{
			fonoV.innerHTML = "Obligario";
			fonoV.style.visibility="visible";
		}
	} else if(!vacio(fono.value)){
		correctos = correctos+2;
		largo = fono.value.length;
		if((largo==6 || largo==7) & isInteger(fono.value)){
			valido++;
			r++;
		}
		else{
			fonoV.innerHTML="Telefono invalido";
			fonoV.style.visibility="visible";
		}
		if(!vacio(codigo.value)){
			largo = codigo.value.length;
			if(largo<3 & isInteger(codigo.value)){
				valido++;
				r++;
			}
			else{
				codigoV.innerHTML="Codigo invalido";
				codigoV.style.visibility="visible";
			}
		}
		else{
			codigoV.innerHTML="Obligatorio";
			codigoV.style.visibility="visible";
		}
	}
	if(r==2){
		alguno=true;
	}
	if(!alguno){
		celV.innerHTML = "Ingrese telefono de contacto";
		celV.style.visibility="visible";
	}
	
	for(m=0; m< elementos_nulos.length; m++){
		a = document.getElementById(elementos_nulos[m]);
		b = document.getElementById(elementos_nulos[m]+"_v");
		if(vacio(a.value)){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			
			valido++;
			
		}
	}
	
	if(valido==correctos && alguno==true)
		return true;
	else 
		return false;
	

}

function validarIngresoPiezas(conCliente,conRut){
	var elementos_nulos = new Array("encargadoPieza", "nomPieza", "cantidadPieza");
	var elementos_nulos2 = new Array("nomPieza", "cantidadPieza");
	var elementos_nada = new Array("retailer", "tienda", "region", "proveedor");
	var filas =  document.getElementById("filas2");
	var valido=0;
	var correctos = 7;
	var elim = document.getElementById("presEliminar");
	if(elim){
		if(elim.value==1){
			if(!confirm("�Seguro desea Eliminar?"))
				return false;
		}
	}
	var a, b;
	for(j=0; j<elementos_nulos.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
		
	for(l=0; l<elementos_nada.length; l++){
		a = document.getElementById(elementos_nada[l]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_nulos.length;p++){
		a = document.getElementById(elementos_nulos[p]);
		if(vacio(a.value)){
			b = document.getElementById(elementos_nulos[p]+"_v");
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}else{
			if(elementos_nulos[p] == "cantidadPieza"){
				if(isInteger(a.value)){
					valido++
				}else{
					b = document.getElementById(elementos_nulos[p]+"_v");
					b.innerHTML = "Debe ser un numero";
					b.style.visibility = "visible";
				}
			}else{
				valido++;
			}
		}
	}
	
	for(m=0; m<elementos_nada.length;m++){
		a = document.getElementById(elementos_nada[m]);
		if(a.value == "nada"){
			b = document.getElementById(elementos_nada[m]+"_v");
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}
		else{
			valido++;
		}
	}

	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*2;
		for(r=0;r<filas.value;r++){
			for(s=0; s<elementos_nulos2.length; s++){
				a = document.getElementById(elementos_nulos2[s]+""+(r+1));
				b = document.getElementById(elementos_nulos2[s]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(vacio(a.value)){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					if(elementos_nulos2[s] == "cantidadPieza"){
						if(isInteger(a.value)){
							valido++;
						}
						else{
							b.innerHTML="Debe ser un numero";
							b.style.visibility="visible";
						}
					}
					else{
						valido++;
					}
				}
				
			}
		}
	}
	
	if(valido == correctos){
		if(conCliente==1){
			var retorno1 = false;
			var retorno2 = false;
			var tipoCliente = document.getElementById("tipoCliente");
			var tipoClienteV = document.getElementById("tipoCliente_v");
			tipoClienteV.style.visibility="hidden";
			if(tipoCliente.value=="nada"){
				tipoClienteV.innerHTML = "Obligatorio";
				tipoClienteV.style.visibility="visible";
				retorno1 = false;
			}else if(tipoCliente.value=="particular"){
				if(conRut==1)
					retorno1 = validarFormArmado2(true);
				else
					retorno1 = validarFormArmado2(false);
			}else if(tipoCliente.value=="tienda"){
				retorno1 = validarFormTienda();
			}else
				retorno1 = false;
			var retail = document.getElementById("retailer");
			if(retail.value=="Lider" || retail.value=="MundoLider" || retail.value=="ABCDIN" || retail.value=="CIC" || retail.value=="Paris" || retail.value=="DSur" || retail.value=="EASY" || retail.value=="Hites" || retail.value=="Favatex"){
				retorno2 = validarMuebles2("nada");
			}else if(retail.value=="nada"){
				retorno2=false;
			}else{
				retorno2 = validarMuebles3("nada");
			}
			if(retorno1 && retorno2)
				return true;
			else
				return false;
		}else{
			return true;
		}
	}
	else{
		return false;
	}
}

function validarMueblesCualquiera(retail,pagina,tipo){
	if(tipo=="plasma"){
		retorno2 = validarTelevisores2(pagina);
	}else if(tipo == "puertas" || tipo =="persianas"){
            retorno2 = validarCantidad2(pagina);
        }else{
		if(retail=="Lider"  || retail=="Arteknia" || retail=="MundoLider" || retail =="ABCDIN" || retail == "CIC" || retail == "Falabella" || retail == "Falabella-Internet" || retail == "Sodimac" || retail == "Paris" || retail == "DSur" || retail == "EASY" || retail=="Hites" || retail=="Favatex"){
			retorno2 = validarMuebles2(pagina);
		}else if(retail=="nada"){
			retorno2=false;
		}else{
			retorno2 = validarMuebles3(pagina);
		}
	}
	return retorno2;
}

function validarCantidad(){
	var valido = 0;
	var cantV = document.getElementById("cantidad_v");
	cantV.style.visibility="hidden";
	var cant = document.getElementById("cantidad");
	if(vacio(cant.value)){
		cantV.innerHTML="Obligatorio";
		cantV.style.visibility="visible";
	}else if(isInteger(cant.value)){
		valido++;
	}else{
		cantV.innerHTML = "Debe ser un n�mero";
		cantV.style.visibility="visible";
	}
	if(valido==1)
		return true;
	else
		return false;
	

}

function validarMuebles2(pagina){
	
	var elementos_nulos = new Array("cantidad");
	var elementos_nada = new Array("familia", "mueble");
	var filas =  document.getElementById("filas");
	var valido=0;
	var correctos = 2;
	var dir = ""+pagina;
	
	var fam = document.getElementById("familia");
	var cantV = document.getElementById("cantidad_v");
	cantV.style.visibility="hidden";
	var cant = document.getElementById("cantidad");
	if(fam.value!="1"){
		correctos++;
		
		if(vacio(cant.value)){
			cantV.innerHTML="Obligatorio";
			cantV.style.visibility="visible";
		}else{
			valido++;
		}
	}

        var a, b;
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}

	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
			if(elementos_nada[k]=="mueble"){
				dir= dir+"&m="+a.value;
			}
		}
		
	}
	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*3;
		for(r=0;r<filas.value;r++){
			for(m=0; m<elementos_nada.length; m++){
				a = document.getElementById(elementos_nada[m]+""+(r+1));
				b = document.getElementById(elementos_nada[m]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(a.value=="nada"){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					if(elementos_nada[m]=="mueble"){
						dir= dir+";"+a.value;
					}
					valido++;
				}
			}
		}
		dir= dir+"&c="+cant.value;
		for(s=0;s<filas.value;s++){
			for(n=0; n<elementos_nulos.length; n++){
				a = document.getElementById(elementos_nulos[n]+""+(s+1));
				b = document.getElementById(elementos_nulos[n]+""+(s+1)+"_v");
				b.style.visibility="hidden";
				if(vacio(a.value)){
					b.innerHTML=" Obligatorio";
					b.style.visibility="visible";
				}
				else{
					dir= dir+";"+a.value;
					valido++;
				}
			}
		}
	}else{
		dir= dir+"&c="+cant.value;
	}
	
	if(valido == correctos){
		if(pagina!="nada")
			window.location.href = dir;
		return true;
	}
	else{
		return false;
	}
}

function validarCantidad2(pagina){
        var elementos_nulos = new Array("cantidad");
	var elementos_nada = new Array("mueble");
	var filas =  document.getElementById("filas");
	var valido=0;
	var correctos = 2;
	var dir = ""+pagina;

	var cantV = document.getElementById("cantidad_v");
	cantV.style.visibility="hidden";
	var cant = document.getElementById("cantidad");
        if(vacio(cant.value)){
                cantV.innerHTML="Obligatorio";
                cantV.style.visibility="visible";
        }else{
                valido++;
        }

	var a;
        var b;
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}

	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
			if(elementos_nada[k]=="mueble"){
				dir= dir+"&m="+a.value;
			}
		}

	}
	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*2;
		for(r=0;r<filas.value;r++){
			for(m=0; m<elementos_nada.length; m++){
				a = document.getElementById(elementos_nada[m]+""+(r+1));
				b = document.getElementById(elementos_nada[m]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(a.value=="nada"){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					if(elementos_nada[m]=="mueble"){
						dir= dir+";"+a.value;
					}
					valido++;
				}
			}
		}
		dir= dir+"&c="+cant.value;
		for(s=0;s<filas.value;s++){
			for(n=0; n<elementos_nulos.length; n++){
				a = document.getElementById(elementos_nulos[n]+""+(s+1));
				b = document.getElementById(elementos_nulos[n]+""+(s+1)+"_v");
				b.style.visibility="hidden";
				if(vacio(a.value)){
					b.innerHTML=" Obligatorio";
					b.style.visibility="visible";
				}
				else{
					dir= dir+";"+a.value;
					valido++;
				}
			}
		}
	}else{
		dir= dir+"&c="+cant.value;
	}

	if(valido == correctos){
		if(pagina!="nada")
			window.location.href = dir;
		return true;
	}
	else{
		return false;
	}
}
function validarMuebles3(pagina){
	
	var elementos_nulos = new Array("cantidad","inputMueble");
	var elementos_nada = new Array("tipo");
	var filas =  document.getElementById("filas");
	var valido=0;
	var correctos = 3;
	var dir = ""+pagina;
	
	var tipoV = document.getElementById("tipo_v");
	tipoV.style.visibility="hidden";
	var tipo = document.getElementById("tipo");
	if(tipo.value=="nada"){
		tipoV.innerHTML="Obligatorio";
		tipoV.style.visibility="visible";
	}else{
		valido++;
		dir=dir+"&t="+tipo.value;
	}
	var a,b;
	for(j=0; j<elementos_nulos.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
	
	
	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*3;
		for(r=0;r<filas.value;r++){
			for(m=0; m<elementos_nada.length; m++){
				a = document.getElementById(elementos_nada[m]+""+(r+1));
				b = document.getElementById(elementos_nada[m]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(a.value=="nada"){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					valido++;
					dir = dir+";"+a.value;
				}
			}
		}
	}
	var nom = document.getElementById("inputMueble");
	var nomV = document.getElementById("inputMueble_v");
	if(vacio(nom.value)){
		nomV.innerHTML = "Obligatorio";
		nomV.style.visibility = "visible";
	}else{
		dir = dir+"&m="+nom.value;
		valido++;
	}
	if(!vacio(filas.value)){
		for(s=0;s<filas.value;s++){
			for(n=0; n<elementos_nulos.length; n++){
				a = document.getElementById(elementos_nulos[n]+""+(s+1));
				b = document.getElementById(elementos_nulos[n]+""+(s+1)+"_v");
				b.style.visibility="hidden";
				if(elementos_nulos[n] == "inputMueble"){
					if(vacio(a.value)){
						b.innerHTML=" Obligatorio";
						b.style.visibility="visible";
					}
					else{
						valido++;
						dir = dir+";"+a.value;
					}
				}
			}
		}
	}
	var cant = document.getElementById("cantidad");
	var cantV = document.getElementById("cantidad_v");
	if(vacio(cant.value)){
		cantV.innerHTML = "Obligatorio";
		cantV.style.visibility = "visible";
	}else{
		dir = dir+"&c="+cant.value;
		valido++;
	}
	if(!vacio(filas.value)){
		for(x=0;x<filas.value;x++){
			for(y=0; y<elementos_nulos.length; y++){
				a = document.getElementById(elementos_nulos[y]+""+(x+1));
				b = document.getElementById(elementos_nulos[y]+""+(x+1)+"_v");
				b.style.visibility="hidden";
				if(elementos_nulos[y] == "cantidad"){
					if(vacio(a.value)){
						b.innerHTML=" Obligatorio";
						b.style.visibility="visible";
					}
					else{
						valido++;
						dir = dir+";"+a.value;
					}
				}
			}
		}
	}
	
	if(valido == correctos){
		if(pagina!="nada")
			window.location.href = dir;
		return true;
	}
	else{
		return false;
	}
}

function validarMuebles4(pagina){
	
	var elementos_nulos = new Array("cantidad","inputMueble");
	var elementos_nada = new Array("tipo");
	var filas =  document.getElementById("filas");
	var valido=0;
	var correctos = 4;
	var dir = ""+pagina;
	var precioV = document.getElementById("precio_v");
	precioV.style.visibility="hidden";
	
	var tipoV = document.getElementById("tipo_v");
	tipoV.style.visibility="hidden";
	var tipo = document.getElementById("tipo");
	if(tipo.value=="nada"){
		tipoV.innerHTML="Obligatorio";
		tipoV.style.visibility="visible";
	}else{
		valido++;
		dir=dir+"&t="+tipo.value;
	}

        var a,b;
	for(j=0; j<elementos_nulos.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
	
	
	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*4;
		for(r=0;r<filas.value;r++){
			for(m=0; m<elementos_nada.length; m++){
				a = document.getElementById(elementos_nada[m]+""+(r+1));
				b = document.getElementById(elementos_nada[m]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(a.value=="nada"){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					valido++;
					dir = dir+";"+a.value;
				}
			}
		}
	}
	var nom = document.getElementById("inputMueble");
	var nomV = document.getElementById("inputMueble_v");
	if(vacio(nom.value)){
		nomV.innerHTML = "Obligatorio";
		nomV.style.visibility = "visible";
	}else{
		dir = dir+"&m="+nom.value;
		valido++;
	}
	if(!vacio(filas.value)){
		for(s=0;s<filas.value;s++){
			for(n=0; n<elementos_nulos.length; n++){
				a = document.getElementById(elementos_nulos[n]+""+(s+1));
				b = document.getElementById(elementos_nulos[n]+""+(s+1)+"_v");
				b.style.visibility="hidden";
				if(elementos_nulos[n] == "inputMueble"){
					if(vacio(a.value)){
						b.innerHTML=" Obligatorio";
						b.style.visibility="visible";
					}
					else{
						valido++;
						dir = dir+";"+a.value;
					}
				}
			}
		}
	}
	var prec = document.getElementById("precio");
	if(vacio(prec.value) || prec.value == 0){
		precioV.innerHTML = "Obligatorio";
		precioV.style.visibility = "visible";
	}else{
		dir = dir+"&p="+prec.value;
		valido++;
	}
	if(!vacio(filas.value)){
		for(s=0;s<filas.value;s++){
			a = document.getElementById("precio"+(s+1));
			b = document.getElementById("precio"+(s+1)+"_v");
			b.style.visibility="hidden";
			if(vacio(a.value) || a.value==0){
				b.innerHTML=" Obligatorio";
				b.style.visibility="visible";
			}
			else{
				valido++;
				dir = dir+";"+a.value;
			}
		}
	}
		
	var cant = document.getElementById("cantidad");
	var cantV = document.getElementById("cantidad_v");
	if(vacio(cant.value)){
		cantV.innerHTML = "Obligatorio";
		cantV.style.visibility = "visible";
	}else{
		dir = dir+"&c="+cant.value;
		valido++;
	}
	if(!vacio(filas.value)){
		for(x=0;x<filas.value;x++){
			for(y=0; y<elementos_nulos.length; y++){
				a = document.getElementById(elementos_nulos[y]+""+(x+1));
				b = document.getElementById(elementos_nulos[y]+""+(x+1)+"_v");
				b.style.visibility="hidden";
				if(elementos_nulos[y] == "cantidad"){
					if(vacio(a.value)){
						b.innerHTML=" Obligatorio";
						b.style.visibility="visible";
					}
					else{
						valido++;
						dir = dir+";"+a.value;
					}
				}
			}
		}
	}
	
	if(valido == correctos){
		if(pagina!="nada")
			window.location.href = dir;
		return true;
	}
	else{
		return false;
	}
}

function validarParrillas(){
	var elementos_nulos = new Array("cantidad");
	var elementos_nada = new Array("parrilla");
	var filas =  document.getElementById("filas");
	var valido=0;
	var correctos = 2;
	var a, b;
	for(i=0; i<elementos_nada.length; i++){
		a = document.getElementById(elementos_nada[i]+"_v");
		a.style.visibility="hidden";
	}
	for(j=0; j<elementos_nulos.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_nulos.length;p++){
		a = document.getElementById(elementos_nulos[p]);
		b = document.getElementById(elementos_nulos[p]+"_v");
		if(vacio(a.value)){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		} else{
			if(isInteger(a.value)){
				valido++;
			}else{
				b.innerHTML="Debe ser un n�mero";
				b.style.visibility="visible";
			}
		
			
		}
	}
	
	for(q=0; q<elementos_nada.length;q++){
		a = document.getElementById(elementos_nada[q]);
		if(a.value=="nada"){
			b = document.getElementById(elementos_nada[q]+"_v");
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		} else{
			valido++;
		}
	}

	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*2;
		for(r=0;r<filas.value;r++){
			for(m=0; m<elementos_nada.length; m++){
				a = document.getElementById(elementos_nada[m]+""+(r+1));
				b = document.getElementById(elementos_nada[m]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(a.value=="nada"){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					valido++;
				}
			}
		}
		for(s=0;s<filas.value;s++){
			for(n=0; n<elementos_nulos.length; n++){
				a = document.getElementById(elementos_nulos[n]+""+(s+1));
				b = document.getElementById(elementos_nulos[n]+""+(s+1)+"_v");
				b.style.visibility="hidden";
				if(vacio(a.value)){
					b.innerHTML=" Obligatorio";
					b.style.visibility="visible";
				}
				else{
					if(isInteger(a.value)){
						valido++;
					}else{
						b.innerHTML="Debe ser un n�mero";
						b.style.visibility="visible";
					}
				}
			}
		}
	}
	
	if(valido == correctos){
		return true;
	}
	else{
		return false;
	}
}

function validarTelevisores2(pagina){
	var elementos_nulos = new Array("marcaTv","cantidad");
	var elementos_nada = new Array("soporteTv","tipoSoporteTv", "tamanioTv");
	var filas =  document.getElementById("filas");
	var valido=0;
	var correctos = 5;
	var dir = ""+pagina;
	var stringCant ="";
	var stringTamanio = "";
	var stringMarca = "";
	var stringSoporte = "";
	var stringTipoSoporte = "";
	var a,b;
	var cant = document.getElementById("cantidad");
	for(i=0; i<elementos_nada.length; i++){
		a = document.getElementById(elementos_nada[i]+"_v");
		a.style.visibility="hidden";
	}
	for(j=0; j<elementos_nulos.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_nulos.length;p++){
		a = document.getElementById(elementos_nulos[p]);
		b = document.getElementById(elementos_nulos[p]+"_v");
		if(vacio(a.value) || a.value=="--Marca--"){
			
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}
		else{
			if(elementos_nulos[p]=="cantidad"){
				if(isInteger(a.value)){
					
					if(elementos_nulos[p]=="cantidad"){
						stringCant = "&c="+a.value;
					}
					valido++;
				}else{
					b.innerHTML="Debe ser un n�mero";
					b.style.visibility="visible";
				}
			}else{
				if(elementos_nulos[p]=="marcaTv"){
					stringMarca = "&b="+a.value;
				}
				valido++;
			}
			
		}
	}
	
	for(q=0; q<elementos_nada.length;q++){
		a = document.getElementById(elementos_nada[q]);
		if(a.value=="nada"){
			b = document.getElementById(elementos_nada[q]+"_v");
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}
		else{
			valido++;
			if(elementos_nada[q]=="soporteTv"){
				stringSoporte = "&m="+a.value;
	
			}
			if(elementos_nada[q]=="tipoSoporteTv"){
				stringTipoSoporte = "&p="+a.value;
			}
			if(elementos_nada[q]=="tamanioTv"){
				stringTamanio = "&t="+a.value;
			}
		}
	}
	
	
	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*5;
		for(r=0;r<filas.value;r++){
			for(m=0; m<elementos_nada.length; m++){
				a = document.getElementById(elementos_nada[m]+""+(r+1));
				b = document.getElementById(elementos_nada[m]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(a.value=="nada"){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					valido++;
					if(elementos_nada[m]=="soporteTv"){
						stringSoporte += ";"+a.value;
			
					}
					if(elementos_nada[m]=="tipoSoporteTv"){
						stringTipoSoporte += ";"+a.value;
					}
					if(elementos_nada[m]=="tamanioTv"){
						stringTamanio += ";"+a.value;
					}
				}
			}
		}
		for(s=0;s<filas.value;s++){
			for(n=0; n<elementos_nulos.length; n++){
				a = document.getElementById(elementos_nulos[n]+""+(s+1));
				b = document.getElementById(elementos_nulos[n]+""+(s+1)+"_v");
				b.style.visibility="hidden";
				if(vacio(a.value) || a.value=="--Marca--"){
					b.innerHTML=" Obligatorio";
					b.style.visibility="visible";
				}
				else{
					if(elementos_nulos[n]=="cantidad"){
						if(isInteger(a.value)){
							
							if(elementos_nulos[n]=="cantidad"){
								stringCant += ";"+a.value;
							}
							valido++;
						}else{
							b.innerHTML="Debe ser un n�mero";
							b.style.visibility="visible";
						}
					}else{
						if(elementos_nulos[n]=="marcaTv"){
							stringMarca += ";"+a.value;
						}
						valido++;
					}
				}
			}
		}
	}
	
	dir+= stringCant+""+stringTamanio+""+stringMarca+""+stringSoporte+""+stringTipoSoporte;
	if(valido == correctos){
		if(pagina!="nada")
			window.location.href = dir;
		return true;
	}
	else{
		return false;
	}
}
function validarTelevisores(){
	var elementos_nulos = new Array("marcaTv","tamanioTv","cantidad");
	var elementos_nada = new Array("soporteTv","tipoSoporteTv");
	var filas =  document.getElementById("filas");
	var valido=0;
	var correctos = 5;
	var a,b;
	for(i=0; i<elementos_nada.length; i++){
		a = document.getElementById(elementos_nada[i]+"_v");
		a.style.visibility="hidden";
	}
	for(j=0; j<elementos_nulos.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_nulos.length;p++){
		a = document.getElementById(elementos_nulos[p]);
		b = document.getElementById(elementos_nulos[p]+"_v");
		if(vacio(a.value) || a.value=="--Marca--"){
			
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}
		else{
			if(elementos_nulos[p]=="tamanioTv" || elementos_nulos[p]=="cantidad"){
				if(isInteger(a.value)){
					valido++;
				}else{
					b.innerHTML="Debe ser un n�mero";
					b.style.visibility="visible";
				}
			}else{
				valido++;
			}
			
		}
	}
	
	for(q=0; q<elementos_nada.length;q++){
		a = document.getElementById(elementos_nada[q]);
		if(a.value=="nada"){
			b = document.getElementById(elementos_nada[q]+"_v");
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}
		else{
			valido++;
		}
	}

	if(!vacio(filas.value)){
		var total = filas.value;
		correctos = correctos+ total*5;
		for(r=0;r<filas.value;r++){
			for(m=0; m<elementos_nada.length; m++){
				a = document.getElementById(elementos_nada[m]+""+(r+1));
				b = document.getElementById(elementos_nada[m]+""+(r+1)+"_v");
				b.style.visibility="hidden"
				if(a.value=="nada"){
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
				else{
					valido++;
				}
			}
		}
		for(s=0;s<filas.value;s++){
			for(n=0; n<elementos_nulos.length; n++){
				a = document.getElementById(elementos_nulos[n]+""+(s+1));
				b = document.getElementById(elementos_nulos[n]+""+(s+1)+"_v");
				b.style.visibility="hidden";
				if(vacio(a.value) || a.value=="--Marca--"){
					b.innerHTML=" Obligatorio";
					b.style.visibility="visible";
				}
				else{
					if(elementos_nulos[n]=="cantidad"){
						if(isInteger(a.value)){
							valido++;
						}else{
							b.innerHTML="Debe ser un n�mero";
							b.style.visibility="visible";
						}
					}else{
						valido++;
					}
				}
			}
		}
	}
	
	if(valido == correctos){
		return true;
	}
	else{
		return false;
	}
}

function validarNuevaAgendada(){
	
	var valido =0;
	var correctos = 0;
	var fechaArmado = document.getElementById("fechaArmado");
	var fechaArmadoV = document.getElementById("fechaArmado_v");
	var horaCompromiso = document.getElementById("horaArmado");
	var horaCompromisoV = document.getElementById("horaArmado_v");
	
	if(fechaArmadoV)
		fechaArmadoV.style.visibility="hidden";
	if(horaCompromisoV)
		horaCompromisoV.style.visibility="hidden";
	
	var cTraslado = document.getElementById("cTraslado");
	var cTrasladoV = document.getElementById("cTraslado_v");
	cTrasladoV.style.visibility = "hidden";
	if(vacio(cTraslado.value)){
	}else{
		correctos++;
		if(isInteger(cTraslado.value)){
			valido++;
		}else{
			cTrasladoV.innerHTML = "Debe ser un numero";
			cTrasladoV.style.visibility="visible";
		}
	}
	if(fechaArmado){
		if(!vacio(fechaArmado.value)){
			correctos++;
			if(validarFecha("fechaArmado","Nada")){
				valido++;
			}
		}
	}
	var coment = document.getElementById("comentario");
	var visible = document.getElementsByName("visible");
	var visibleV = document.getElementById("visible_v");
        var seleccionado;
	if(coment){
		visibleV.style.visibility="hidden";
		
		
 
		
		if(!vacio(coment.value)){
			correctos++;
			seleccionado = false;
			for(var i=0; i<visible.length; i++) {	
			  if(visible[i].checked) {
				seleccionado = true;
				break;
			  }
			}
			if(!seleccionado){
				visibleV.innerHTML = "Obligatorio";
				visibleV.style.visibility="visible";
			}else{
				valido++;
			}
		}
	}
	var tipoSol = document.getElementById("tipoSol");
	if(tipoSol.value=="armado"){
		var muebleDomicilio = document.getElementsByName("muebleDomicilio");
		if(muebleDomicilio && muebleDomicilio.length!=0){
			correctos++;
			var muebleDomicilioV = document.getElementById("muebleDomicilio_v");

			seleccionado = false;
			for(i=0; i<muebleDomicilio.length; i++) {	
			  if(muebleDomicilio[i].checked) {
				seleccionado = true;
				break;
			  }
			}
			muebleDomicilioV.style.visibility="hidden";
			if(!seleccionado){
				muebleDomicilioV.innerHTML = "Obligatorio";
				muebleDomicilioV.style.visibility="visible";
			}else{
				valido++;
			}
			
		}
		var muebleLugar = document.getElementsByName("muebleLugar");
		if(muebleLugar && muebleLugar.length!=0){
			correctos++;
			var muebleLugarV = document.getElementById("muebleLugar_v");

			seleccionado = false;
			for(i=0; i<muebleLugar.length; i++) {	
			  if(muebleLugar[i].checked) {
				seleccionado = true;
				break;
			  }
			}
			muebleLugarV.style.visibility="hidden";
			if(!seleccionado){
				muebleLugarV.innerHTML = "Obligatorio";
				muebleLugarV.style.visibility="visible";
			}else{
				valido++;
			}
			
		}
	}	
	return (valido==correctos);
}

function validarLogin(){

	var valido=0;
	var usuario = document.getElementById("usuario");
	var vUsuario = document.getElementById("usuario_v");
	var password = document.getElementById("password");
	var vPassword = document.getElementById("password_v");
	
	vUsuario.style.visibility = "hidden";
	vPassword.style.visibility = "hidden";
	
	if(vacio(usuario.value)){
		vUsuario.innerHTML = "Debe ingresar nombre de usuario";
		vUsuario.style.visibility="visible";
		
	}
	else
		valido++;
	
	if(vacio(password.value)){
		vPassword.innerHTML = "Debe ingresar password";
		vPassword.style.visibility="visible";
	}
	else
		valido++;
	
	return (valido==2);
}

function validarBusqueda3(){
	var correctos = 0;
	var validos = 0;
	var numero = document.getElementById("numeroPieza");
	var numeroV = document.getElementById("numeroPieza_v");
		
	numeroV.style.visibility="hidden";
		
	if(numero.value!="--Num Solicitud--"){
		correctos++;
		if(isInteger(numero.value)){
			validos++;
		}else{
			numeroV.innerHTML="Num incorrecto";
			numeroV.style.visibility="visible";
		}
	}
	
	return (validos==correctos);
	
}

function validarBusqueda(){
	var correctos = 0;
	var validos = 0;
	var numero = document.getElementById("numero");
	var boleta = document.getElementById("boleta");
	var rutCliente= document.getElementById("rutCliente");
	var cliente = document.getElementById("cliente");
	var numeroV = document.getElementById("numero_v");
	var boletaV = document.getElementById("boleta_v");
	var rutClienteV= document.getElementById("rutCliente_v");
	var clienteV = document.getElementById("cliente_v");
	
	numeroV.style.visibility="hidden";
	boletaV.style.visibility="hidden";
	rutClienteV.style.visibility="hidden";
	clienteV.style.visibility="hidden";
	
	if(numero.value!="--Num Solicitud--"){
		correctos++;
		if(isInteger(numero.value)){
			validos++;
		}else{
			numeroV.innerHTML="Num incorrecto";
			numeroV.style.visibility="visible";
		}
	}
	
	if(boleta.value!="--Num Boleta--" && boleta.value!="--Num Solicitud Paris--"){
		correctos++;
		if(isInteger(boleta.value)){
			validos++;
		}else{
			boletaV.innerHTML="Num boleta incorrecto";
			boletaV.style.visibility="visible";
		}
	}
	
	if(rutCliente & rutCliente.value!="--Rut Cliente--"){
		correctos++;
		if(checkRutField(rutCliente.value, rutClienteV)){
			validos++;
		}
	}
	
	return (validos==correctos);
	
}

function validarBusquedaReclamos(){
	var correctos = 0;
	var validos = 0;
	var numero = document.getElementById("numero");
	var numeroV = document.getElementById("numero_v");
	var fecha = document.getElementById("fecha");
	var fechaV = document.getElementById("fecha_v");
	var fecha2 = document.getElementById("fecha2");
	var fecha2V = document.getElementById("fecha2_v");
	
	fechaV.style.visibility="hidden";
	fecha2V.style.visibility="hidden";
	numeroV.style.visibility="hidden";
	
	if(!vacio(fecha.value)){
		correctos++;
		if(validarFecha("fecha","Nada")){
			validos++;
		}
	}
	if(!vacio(fecha2.value)){
		correctos++;
		if(validarFecha("fecha2","Nada")){
			validos++;
		}
	}
	
	if(numero.value!="--Num Solicitud--"){
		correctos++;
		if(isInteger(numero.value)){
			validos++;
		}else{
			numeroV.innerHTML="Num incorrecto";
			numeroV.style.visibility="visible";
		}
	}
	
	
	return (validos==correctos);

}

function validarBusqueda2(){
	var correctos = 0;
	var validos = 0;
	var numero = document.getElementById("numero");
	var boleta = document.getElementById("bBoleta");
	var rutCliente= document.getElementById("rutCliente");
	var numeroV = document.getElementById("numero_v");
	var boletaV = document.getElementById("bBoleta_v");
	var rutClienteV= document.getElementById("rutCliente_v");
	var fecha = document.getElementById("fecha");
	var fechaV = document.getElementById("fecha_v");
	var fecha2 = document.getElementById("fecha2");
	var fecha2V = document.getElementById("fecha2_v");
	
	fechaV.style.visibility="hidden";
	fecha2V.style.visibility="hidden";
	numeroV.style.visibility="hidden";
	boletaV.style.visibility="hidden";
	rutClienteV.style.visibility="hidden";
	
	if(!vacio(fecha.value)){
		correctos++;
		if(validarFecha("fecha","Nada")){
			validos++;
		}
	}
	if(!vacio(fecha2.value)){
		correctos++;
		if(validarFecha("fecha2","Nada")){
			validos++;
		}
	}
	
	if(numero.value!="--Num Solicitud--"){
		correctos++;
		if(isInteger(numero.value)){
			validos++;
		}else{
			numeroV.innerHTML="Num incorrecto";
			numeroV.style.visibility="visible";
		}
	}
	
	if(boleta.value!="--Num Boleta--"){
		correctos++;
		if(isInteger(boleta.value)){
			validos++;
		}else{
			boletaV.innerHTML="Num boleta incorrecto";
			boletaV.style.visibility="visible";
		}
	}
	
	if(rutCliente & rutCliente.value!="--Rut Cliente--"){
		correctos++;
		if(checkRutField(rutCliente.value, rutClienteV)){
			validos++;
		}
	}
	
	return (validos==correctos);
	
}

function validarNuevoUsuario(){
	var usuario = document.getElementById("user");
	var usuarioV = document.getElementById("user_v");
	var pass = document.getElementById("pass1");
	var passV = document.getElementById("pass1_v");
	var pass2 = document.getElementById("pass2");
	var pass2V = document.getElementById("pass2_v");
	var nombre1 = document.getElementById("nombre1");
	var nombre2 = document.getElementById("nombre2");
	var nombre1V = document.getElementById("nombre1_v");
	var nombre2V = document.getElementById("nombre2_v");
	usuarioV.style.visibility="hidden";
	passV.style.visibility="hidden";
	pass2V.style.visibility="hidden";
	nombre1V.sytle.visibility="hidden";
	nombre2V.sytle.visibility="hidden";
	var validos =0;
	
	if(!vacio(nombre1.value)){
		validos++;
	}else{
		nombre1V.innerHTML="Obligatorio";
		nombre1V.style.visibility="visible";
	}
	
	if(!vacio(nombre2.value)){
		validos++;
	}else{
		nombre2V.innerHTML="Obligatorio";
		nombre2V.style.visibility="visible";
	}
	
	if(!vacio(usuario.value)){
		validos++;
	}
	else{
		usuarioV.innerHTML = "Debe ingresar un nombre de usuario";
		usuarioV.style.visibility="visible";
	}
	if(!vacio(pass.value)){
		if(pass.value.length>=6){
			validos++;
		}else{
			passV.innerHTML = "La contrase&ntilde;a debe tener m&iacute;nimo 6 caracteres";
			passV.style.visibility="visible";
		}
	}else{
		passV.innerHTML = "Debe ingresar una contrase&ntilde;a";
		passV.style.visibility="visible";
	}
	if(!vacio(pass2.value)){
		if(pass2.value == pass.value){
			validos++;
		}else{
			pass2V.innerHTML = "La contrase&ntilde;a no coincide con la anterior";
			pass2V.style.visibility="visible";
		}
	}else{
		pass2V.innerHTML = "Debe confirmar la contrase&ntilde;a";
		pass2V.style.visibility="visible";
	}
	
	return (validos==5);
}

function validarNuevoCliente(validarRut){

	var valido=0;
	var correctos = 7;
	var elementos_opcionales = new Array("direccionF", "codigoF", "fax", "mail", "web", "giro");
	var elementos_nulos = new Array("rSocial", "direccionC", "codigo", "fono");
	if(validarRut){
		elementos_nulos[4]="rut";
		correctos++;
	}
	var elementos_nada = new Array("region", "ciudad","comuna");
	var a,b;
	
	for(i=0; i<elementos_nulos.length; i++){
		a = document.getElementById(elementos_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_opcionales.length; p++){
		a = document.getElementById(elementos_opcionales[p]+"_v");
		a.style.visibility="hidden";
	}
	
	
	//Validar Codigof
	var codigo= document.getElementById("codigoF");
	var codigoV= document.getElementById("codigoF_v");
	var fono= document.getElementById("fax");
	var fonoV= document.getElementById("fax_v");
		
	var largo=0;
	if(!vacio(codigo.value)){
		correctos=correctos+2;
		largo = codigo.value.length;
		if(largo<3 & isInteger(codigo.value)){
			valido++;
		}
		else{
			codigoV.innerHTML="Codigo invalido";
			codigoV.style.visibility="visible";
		}
		if(!vacio(fono.value)){
			largo = fono.value.length;
			if((largo==6 || largo==7) & isInteger(fono.value)){
				valido++;
			}
			else{
				fonoV.innerHTML="Telefono invalido";
				fonoV.style.visibility="visible";
			}
		}
		else{
			fonoV.innerHTML = "Obligario";
			fonoV.style.visibility="visible";
		}
	} else if(!vacio(fono.value)){
		correctos = correctos+2;
		largo = fono.value.length;
		if((largo==6 || largo==7) & isInteger(fono.value)){
			valido++;
		}
		else{
			fonoV.innerHTML="Telefono invalido";
			fonoV.style.visibility="visible";
		}
		if(!vacio(codigo.value)){
			largo = codigo.value.length;
			if(largo<3 & isInteger(codigo.value)){
				valido++;
			}
			else{
				codigoV.innerHTML="Codigo invalido";
				codigoV.style.visibility="visible";
			}
		}
		else{
			codigoV.innerHTML="Obligatorio";
			codigoV.style.visibility="visible";
		}
	}
	
	var mail= document.getElementById("mail");
	var mailV= document.getElementById("mail_v");
	if(!vacio(mail.value)){
		correctos++;
		if(mailValido(mail.value)){
			valido++;
		}
		else{
			mailV.innerHTML="Mail invalido";
			mailV.style.visibility="visible";
		}
	}
	
	var sitio = document.getElementById("web");
	var sitioV = document.getElementById("web_v");
	if(!vacio(sitio.value)){
		correctos++;
		if(ValidaURL(sitio.value)){
			valido++;
		}
		else{
			sitioV.innerHTML="URL invalido";
			sitioV.style.visibility="visible";
		}
	}

	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
		}
		
	}
	
	for(m=0; m< elementos_nulos.length; m++){
		a = document.getElementById(elementos_nulos[m]);
		b = document.getElementById(elementos_nulos[m]+"_v");
		if(vacio(a.value)){
			b.innerHTML=" Obligatorio";
			b.style.visibility="visible";
		}
		else{
			if(elementos_nulos[m]=="rut"){
				if(checkRutField(a.value, b))
					valido++;
			}else if(elementos_nulos[m]=="fono"){
				largo = a.value.length;
				if(isInteger(a.value) & (largo==6 || largo==7)){
					valido++;
				}
				else{
					b.innerHTML="Telefono invalido";
					b.style.visibility="visible";
				}
				
			}else if(elementos_nulos[m] == "codigo"){
				if(a.value.length<=3 & isInteger(a.value)){
					valido++;
				}
				else{
					b.innerHTML="Codigo invalido";
					b.style.visibility="visible";
				}
			}
			else{
				valido++;
			}
		}
		
	}
	
	return (valido==correctos);

}

function validarRut(){
	var a = document.getElementById("bRut");
	var b = document.getElementById("bRut_v");
	if(!vacio(a.value)){
		if(checkRutField(a.value, b))
			return true;
		else
			return false;
	}
	else
		return true;
}

function validarNuevoRecurso(validarRut){

	var valido=0;
	var correctos = 8;
	var elementos_opcionales = new Array("nombre2", "codigo_t", "fono_t", "mail2", "mail", "direccion", "fono", "codigo", "apellido2");
	var elementos_nulos = new Array("nombre1", "cel", "apellido1", "fechaNac");
	if(validarRut){
		elementos_nulos[4]="rut";
		correctos++;
	}
	var elementos_nada = new Array("region", "ciudad","comuna","sexo");
	
	var a,b;
	for(i=0; i<elementos_nulos.length; i++){
		a = document.getElementById(elementos_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_opcionales.length; p++){
		a = document.getElementById(elementos_opcionales[p]+"_v");
		a.style.visibility="hidden";
	}
	
	
	
	var codigo= document.getElementById("codigo");
	var codigoV= document.getElementById("codigo_v");
	var fono= document.getElementById("fono");
	var fonoV= document.getElementById("fono_v");
		
	var largo=0;
	if(!vacio(codigo.value)){
		correctos=correctos+2;
		largo = codigo.value.length;
		if(largo<3 & isInteger(codigo.value)){
			valido++;
		}
		else{
			codigoV.innerHTML="Codigo invalido";
			codigoV.style.visibility="visible";
		}
		if(!vacio(fono.value)){
			largo = fono.value.length;
			if((largo==6 || largo==7) & isInteger(fono.value)){
				valido++;
			}
			else{
				fonoV.innerHTML="Telefono invalido";
				fonoV.style.visibility="visible";
			}
		}
		else{
			fonoV.innerHTML = "Obligario";
			fonoV.style.visibility="visible";
		}
	} else if(!vacio(fono.value)){
		correctos = correctos+2;
		largo = fono.value.length;
		if((largo==6 || largo==7) & isInteger(fono.value)){
			valido++;
		}
		else{
			fonoV.innerHTML="Telefono invalido";
			fonoV.style.visibility="visible";
		}
		if(!vacio(codigo.value)){
			largo = codigo.value.length;
			if(largo<3 & isInteger(codigo.value)){
				valido++;
			}
			else{
				codigoV.innerHTML="Codigo invalido";
				codigoV.style.visibility="visible";
			}
		}
		else{
			codigoV.innerHTML="Obligatorio";
			codigoV.style.visibility="visible";
		}
	}
	
	var codigoT= document.getElementById("codigo_t");
	var codigoTV= document.getElementById("codigo_t_v");
	var fonoT= document.getElementById("fono_t");
	var fonoTV= document.getElementById("fono_t_v");
		
	largo=0;
	if(!vacio(codigoT.value)){
		correctos=correctos+2;
		largo = codigoT.value.length;
		if(largo<3 & isInteger(codigoT.value)){
			valido++;
		}
		else{
			codigoTV.innerHTML="Codigo invalido";
			codigoTV.style.visibility="visible";
		}
		if(!vacio(fonoT.value)){
			largo = fonoT.value.length;
			if((largo==6 || largo==7) & isInteger(fonoT.value)){
				valido++;
			}
			else{
				fonoTV.innerHTML="Telefono invalido";
				fonoTV.style.visibility="visible";
			}
		}
		else{
			fonoTV.innerHTML = "Obligario";
			fonoTV.style.visibility="visible";
		}
	} else if(!vacio(fonoT.value)){
		correctos = correctos+2;
		largo = fonoT.value.length;
		if((largo==6 || largo==7) & isInteger(fonoT.value)){
			valido++;
		}
		else{
			fonoTV.innerHTML="Telefono invalido";
			fonoTV.style.visibility="visible";
		}
		if(!vacio(codigoT.value)){
			largo = codigoT.value.length;
			if(largo<3 & isInteger(codigoT.value)){
				valido++;
			}
			else{
				codigoTV.innerHTML="Codigo invalido";
				codigoTV.style.visibility="visible";
			}
		}
		else{
			codigoTV.innerHTML="Obligatorio";
			codigoTV.style.visibility="visible";
		}
	}
	
	var mail2= document.getElementById("mail2");
	var mail2V= document.getElementById("mail2_v");
	if(!vacio(mail2.value)){
		correctos++;
		if(mailValido(mail2.value)){
			valido++;
		}
		else{
			mail2V.innerHTML="Mail invalido";
			mail2V.style.visibility="visible";
		}
	}
	
	var mail1= document.getElementById("mail");
	var mail1V= document.getElementById("mail_v");
	if(!vacio(mail1.value)){
		correctos++;
		if(mailValido(mail1.value)){
			valido++;
		}
		else{
			mail1V.innerHTML="Mail invalido";
			mail1V.style.visibility="visible";
		}
	}

	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
		}
		
	}
	
	for(m=0; m< elementos_nulos.length; m++){
		a = document.getElementById(elementos_nulos[m]);
		b = document.getElementById(elementos_nulos[m]+"_v");
		if(vacio(a.value)){
			b.innerHTML=" Obligatorio";
			b.style.visibility="visible";
		}
		else{
			if(elementos_nulos[m]=="rut"){
				if(checkRutField(a.value, b))
					valido++;
				
			}else if(elementos_nulos[m]=="cel"){
				largo = a.value.length;
				if(isInteger(a.value) &(largo==8)){
					valido++;
				}
				else{
					b.innerHTML="Numero invalido";
					b.style.visibility="visible";
				}
			}else if(elementos_nulos[m]=="fechaNac"){
				if(validarFecha("fechaNac","Nada")){
					valido++;
					
				}else{
					b.innerHTML="Obligatorio";
					b.style.visibility="visible";
				}
			}
			else{
				valido++;
			}
		}
		
	}
	
	return (valido==correctos);

}


function validarNuevoEjecutivo(validarRut){

	var valido=true;
	var elementos_opcionales = new Array("nombre2", "mail2", "apellido2", "codigo", "fono");
	var elementos_nulos = new Array("nombre1", "cel", "apellido1", "fechaNac", "direccion", "mail" );
	
	if(validarRut){
		elementos_nulos[6]="rut";
	}
	var elementos_nada = new Array("nomUsuario", "region", "ciudad","comuna","sexo", "estado");
	
	var a,b;
	for(i=0; i<elementos_nulos.length; i++){
		a = document.getElementById(elementos_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_opcionales.length; p++){
		a = document.getElementById(elementos_opcionales[p]+"_v");
		b = document.getElementById(elementos_opcionales[p]);
		a.style.visibility="hidden";
		if(elementos_opcionales[p]=="codigo" && !vacio(b.value)){
			largo = b.value.length;
			if(!(largo<3 & isInteger(b.value))){
				valido=false;
				a.style.visibility="visible";
				a.innerHTML="Codigo invalido";
			}
			
		}else if(elementos_opcionales[p]=="fono" && !vacio(b.value)){
			largo = b.value.length;
			if(!((largo==6 || largo==7) & isInteger(b.value))){
				valido=false;
				a.style.visibility="visible";
				a.innerHTML="Telefono invalido";
			}
		}
	}
	
	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
			valido=false;
		}
	}
	
	for(m=0; m< elementos_nulos.length; m++){
		 a = document.getElementById(elementos_nulos[m]);
		b = document.getElementById(elementos_nulos[m]+"_v");
		if(vacio(a.value)){
			b.innerHTML=" Obligatorio";
			b.style.visibility="visible";
			valido=false;
		}
		else{
			if(elementos_nulos[m]=="rut"){
				if(!checkRutField(a.value, b))
					valido=false;
				
			}else if(elementos_nulos[m]=="cel"){
				largo = a.value.length;
				if(isInteger(a.value) &(largo==8)){
					
				}
				else{
					b.innerHTML="Numero invalido";
					b.style.visibility="visible";
					valido = false;
				}
			}else if(elementos_nulos[m]=="fechaNac"){
				if(!validarFecha("fechaNac","Nada")){
					b.style.visibility="visible";
					b.innerHTML="Fecha invalida";
					valido = false;
				}
		
			}else if(elementos_nulos[m]=="mail"){
				if(!mailValido(a.value)){
					valido=false;
					b.style.visibility="visible";
					b.innerHTML="E-mail invalido";
				}
			}
			
		}
		
	}
	
	var mail2= document.getElementById("mail2");
	var mail2V= document.getElementById("mail2_v");
	if(!vacio(mail2.value)){
		
		if(!mailValido(mail2.value)){
			valido=false;
			mail2V.innerHTML="Mail invalido";
			mail2V.style.visibility="visible";
		}
	}
	
	
	return valido;

}

function validarNuevoContacto(validarRut){

	var valido=0;
	var correctos = 9;
	var elementos_opcionales = new Array("nombre2", "apellido2", "mail", "mail2", "depto", "cargo");
	var elementos_nulos = new Array("nombre1", "apellido1","direccion", "codigo", "fono", "cel");
	if(validarRut){
		elementos_nulos[6]="rut";
		correctos++;
	}
	var elementos_nada = new Array("region", "ciudad","comuna");
	
	var a,b;
	for(i=0; i<elementos_nulos.length; i++){
		a = document.getElementById(elementos_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nulos[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(p=0; p<elementos_opcionales.length; p++){
		a = document.getElementById(elementos_opcionales[p]+"_v");
		a.style.visibility="hidden";
	}
	
	
	var mail= document.getElementById("mail");
	var mailV= document.getElementById("mail_v");
	if(!vacio(mail.value)){
		correctos++;
		if(mailValido(mail.value)){
			valido++;
		}
		else{
			mailV.innerHTML="Mail invalido";
			mailV.style.visibility="visible";
		}
	}
	
	var mail2= document.getElementById("mail2");
	var mail2V= document.getElementById("mail2_v");
	if(!vacio(mail2.value)){
		correctos++;
		if(mailValido(mail2.value)){
			valido++;
		}
		else{
			mail2V.innerHTML="Mail invalido";
			mail2V.style.visibility="visible";
		}
	}
	
	for(k=0; k< elementos_nada.length; k++){
		a = document.getElementById(elementos_nada[k]);
		b = document.getElementById(elementos_nada[k]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible";
		}
		else{
			valido++;
		}
		
	}
	
	for(m=0; m< elementos_nulos.length; m++){
		a = document.getElementById(elementos_nulos[m]);
		b = document.getElementById(elementos_nulos[m]+"_v");
		if(vacio(a.value)){
			b.innerHTML=" Obligatorio";
			b.style.visibility="visible";
		}
		else{
			if(elementos_nulos[m]=="rut"){
				if(checkRutField(a.value, b))
					valido++;
			}else if(elementos_nulos[m]=="fono"){
				var largo = a.value.length;
				if(isInteger(a.value) & (largo==6 || largo==7)){
					valido++;
				}
				else{
					b.innerHTML="Telefono invalido";
					b.style.visibility="visible";
				}
				
			}else if(elementos_nulos[m] == "codigo"){
				if(a.value.length<=3 & isInteger(a.value)){
					valido++;
				}
				else{
					b.innerHTML="Codigo invalido";
					b.style.visibility="visible";
				}
			}else if(elementos_nulos[m]=="cel"){
				if(a.value.length==8 & isInteger(a.value)){
					valido++;
				}
				else{
					b.innerHTML="Numero invalido";
					b.style.visibility="visible";
				}
			}
			else{
				valido++;
			}
		}
		
	}
	
	return (valido==correctos);

}

function validarNuevoMueble(){
	var valido = 0;
	var correctos = 4;
	var elementos_nulos = new Array("nombre");
	var elementos_nada = new Array("familia", "tipo", "retailer");
	var a,b;
	for(i=0; i<elementos_nulos.length; i++){
		a = document.getElementById(elementos_nulos[i]+"_v");
		a.style.visibility="hidden";
	}
	
	for(j=0; j<elementos_nada.length; j++){
		a = document.getElementById(elementos_nada[j]+"_v");
		a.style.visibility="hidden";
	}
	
	for(k=0; k<elementos_nulos.length; k++){
		a = document.getElementById(elementos_nulos[k]);
		b = document.getElementById(elementos_nulos[k]+"_v");
		if(vacio(a.value)){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}else{
			valido++;
		}
	}
	
	for(l=0; l<elementos_nada.length; l++){
		a = document.getElementById(elementos_nada[l]);
		b = document.getElementById(elementos_nada[l]+"_v");
		if(a.value=="nada"){
			b.innerHTML="Obligatorio";
			b.style.visibility="visible"
		}else{
			valido++;
		}
	}
	var retail = document.getElementById("retailer");
	if (retail.value=="Falabella" || retail.value=="Sodimac" || retail.value=="Falabella-Internet"){
		correctos++;
		var precio = document.getElementById("precio");
		var precioV = document.getElementById("precio_v");
		precioV.style.visibility="hidden";
		if(precio.value=="nada"){
			precioV.innerHTML = "Obligatorio";
			precioV.style.visibility="visible";
		}else{
			valido++;
		}
	}
	if(valido == correctos)
		return true;
	else return false;
	
}

function validarBusquedaMuebles(){
	var codigo = document.getElementById("bCodigo");
	var codigoV = document.getElementById("bCodigo_v");
	var id = document.getElementById("bId");
	var idV = document.getElementById("bId_v");
	codigoV.style.visibility="hidden";
	idV.style.visibility="hidden";
	var correctos = 0;
	var valido = 0;
	if(!vacio(codigo.value)){
		correctos++;
		if(isInteger(codigo.value)){
			valido++;
		}else{
			codigoV.innerHTML = "<br/>El c�digo debe ser un n�mero";
			codigoV.style.visibility="visible";
		}
	}
	if(!vacio(id.value)){
		correctos++;
		if(isInteger(id.value)){
			valido++;
		}else{
			idV.innerHTML = "<br/>El Id del mueble debe ser un n�mero";
			idV.style.visibility="visible";
		}
	}
	if(valido == correctos) return true;
	else return false;
}

function validarReporte(){
	var valido=0;
	var correctos=2;
	var fechaInicio = document.getElementById("fechaInicio");
	var fechaTermino = document.getElementById("fechaTermino");
	var fechaInicio_v = document.getElementById("fechaInicio_v");
	var fechaTermino_v = document.getElementById("fechaTermino_v");
	fechaInicio_v.style.visibility="hidden";
	fechaTermino_v.style.visibility="hidden";
	if(!vacio(fechaInicio.value)){
		if(validarFecha("fechaInicio","Nada")){
			valido++;
		}
		
	}else{
		fechaInicio_v.innerHTML ="Obligatorio";
		fechaInicio_v.style.visibility="visible";
	}
	
	if(!vacio(fechaTermino.value)){
		if(validarFecha("fechaTermino","Nada")){
			valido++;
		}
		
	}else{
		fechaTermino_v.innerHTML ="Obligatorio";
		fechaTermino_v.style.visibility="visible";
	}
	return (valido==correctos);
}

function validarFormContacto(){
	var valido = true;
	var nombre = document.getElementById("nombre");
	var nombre_v = document.getElementById("nombre_v");
	var mail = document.getElementById("email");
	var mailV = document.getElementById("email_v");
	var telefono = document.getElementById("telefono");
	var telefonoV = document.getElementById("telefono_v");
	var telymail = document.getElementById("telymail");
	var comentario= document.getElementById("comentario");
	var comentarioV = document.getElementById("comentario_v");
	nombre_v.style.visibility="hidden";
	mailV.style.visibility="hidden";
	telefonoV.style.visibility="hidden";
	comentarioV.style.visibility="hidden";
	telymail.style.visibility="hidden";
	if(vacio(nombre.value)){
		valido = false;
		nombre_v.innerHTML = "Obligatorio";
		nombre_v.style.visibility="visible";
	}
	
	if(vacio(telefono.value) && vacio(mail.value)){
		valido = false;
		telymail.innerHTML = "Debe ingresar tel&eacute;fono o email";
		telymail.style.visibility="visible";
	}else{
		if(!vacio(telefono.value) && !isInteger(telefono.value)){
			valido=false;
			telefonoV.innerHTML = "N&uacute;mero inv&aacute;lido";
			telefonoV.style.visibility="visible";
		}
		if(!vacio(mail.value) && !mailValido(mail.value)){
			valido=false;
			mailV.innerHTML = "Direcci&oacute;n incorrecta";
			mailV.style.visibility="visible";
		}
	}
	if(vacio(comentario.value)){
		comentarioV.style.visibility="visible";
		comentarioV.innerHTML="Obligatorio";
		valido = false;
	}
	return valido;
}

function vacio(q) {   
	for ( i = 0; i < q.length; i++ ) {   
		if ( q.charAt(i) != " " ) {   
			return false;   
		}   
	}   
	return true;   
}

function goLites(BTN1){
	var boton1 = document.getElementById(BTN1);
	boton1.style.color = "#FFFFFF";
	boton1.style.borderTopColor = "#666666";
	boton1.style.borderBottomColor = "#666666";
	boton1.style.backgroundColor = "#000000";
	boton1.style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#ff000000',EndColorStr='#ffCCCCCC')";
	
}

function goDims(BTN1){
	var boton1 = document.getElementById(BTN1);
	boton1.style.color = "#FFFFFF";
	boton1.style.borderTopColor = "#AAAAAA";
	boton1.style.borderBottomColor = "#AAAAAA";
	boton1.style.backgroundColor = "#33CC00";
	boton1.style.filter=":progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#ff33FF33',EndColorStr='#ff336600')";
	
}

function goLite(BTN){
	var boton = document.getElementById(BTN);
	boton.style.color = "#000000";
	boton.style.borderTopColor = "#666666";
	boton.style.borderBottomColor = "#666666";
}

function goDim(BTN){
	var boton = document.getElementById(BTN);
	boton.style.color = "#FFFFFF";
	boton.style.borderTopColor = "#AAAAAA";
	boton.style.borderBottomColor = "#AAAAAA";
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function ValidaURL(url) {
	var re=/^(http:|https:|ftp:)\/\/\w+(\.\w+)*(\-\w+)?\.\w{2,3}(\:\d{2,6})?(\/{1,2}(\:|\-|\w|\.|\?|\/|\=|\&|\%|\@|\\|\,)*)?$/;
	return re.test(url);
}

function mailValido(direccion){
	var s = direccion
	var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	
	if (filter.test(s))
		return true;
	else
		return false;
}

function checkCDV( dvr, verific ){
	dv = dvr + "";
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')  {
		verific.innerHTML = "Rut no valido";
		verific.style.visibility = "visible";
		return false;
	}
	return true;
}

function checkDV( crut,verific ){
  
	largo = crut.length;
	if ( largo < 2 )
	{
		verific.innerHTML="Debe ingresar el rut completo.";
		verific.style.visibility="visible";
		return false;
	}

	if ( largo > 2 )
		rut = crut.substring(0, largo - 1);
	else
		rut = crut.charAt(0);
	dv = crut.charAt(largo-1);
	checkCDV( dv, verific );

	if ( rut == null || dv == null )
		return 0;

	var dvr = '0';

	suma = 0;
	mul  = 2;

	for (i= rut.length -1 ; i >= 0; i--)
	{
		suma = suma + rut.charAt(i) * mul;
		if (mul == 7)
			mul = 2;
		else
			mul++;
	}


	res = suma % 11;
	if (res==1)
		dvr = 'k';
	else if (res==0)
		dvr = '0';
	else
	{
		dvi = 11-res;
		dvr = dvi + "";
	}

	if ( dvr != dv.toLowerCase() )
	{
		verific.innerHTML="Rut incorrecto";
		verific.style.visibility="visible";
		return false;
	}

	return true;

}

function checkRutField(texto, verific){

  var tmpstr = "";
  for ( i=0; i < texto.length ; i++ )   {
	if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' && texto.charAt(i) != 'k') tmpstr = tmpstr + texto.charAt(i);
	if ( texto.charAt(i) == "k")
	  tmpstr = tmpstr + "K";
  }
  texto = tmpstr;
  largo = texto.length;

  if ( largo < 2 )
  {
	verific.innerHTML="Debe ingresar el rut completo.";
	verific.style.visibility="visible";
	return false;
  }


  for (i=0; i < largo ; i++ )
  {
	if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
	{
	  verific.innerHTML="Ingrese un rut valido";
	  verific.style.visibility="visible";
	  return false;
	}
  }

  if ( checkDV(texto, verific) )
	return true;
  return false;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
   } 
   return this;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function masGrande(dtStr,n){
	var ahora = new Date();
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if(ahora.getFullYear() -year > n) return true;
	else if(ahora.getFullYear() -year== n){
		if(ahora.getMonth() +1-month>0) return true;
		else if(ahora.getMonth() +1-month==0) {
			if(ahora.getDate()-day>=0) return true;		

		}
	
	}
	return false;


}

function masQue(id,n){
	var miEdad = document.getElementById(id);
	if(masGrande(miEdad.value,n)){
		return true;		
	
	}
	else {
		
		return false;
	}
	return true;

}

function isDate(fecha){
	var da = document.getElementById(fecha);
	var val = fecha+"_v";
	var verific = document.getElementById(val);
	var dtStr = da.value;
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strDay=dtStr.substring(pos2+1);
	var strYear=dtStr.substring(0,pos1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		verific.innerHTML="Formato: aaaa-mm-dd";
		
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		verific.innerHTML="Mes invalido";
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		verific.innerHTML="Dia invalido";
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		verific.innerHTML ="A�o entre "+minYear+" y "+maxYear;
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		verific.innerHTML="Fecha invalida";
		return false;
	}
	return true;
}

function validarFecha(fecha,vacia){

	var valor = document.getElementById(fecha);
	var ver = fecha+"_v";
	var verific = document.getElementById(ver);
	verific.style.visibility="hidden";
	
	if(vacio(valor.value)){
		if(vacia == true){
			return true;
			}
		verific.style.visibility="visible";
		verific.innerHTML = "Debes ingresar una fecha";
		return false;
	}
	
	else if(!isDate(fecha)){
		verific.style.visibility = "visible";
		return false;
	}
	return true;
	
}











