// JavaScript Document

/* Author: Fernando Loor */


function limpiarDiv()
        {
            var div;
            div = document.getElementById('bdy');
            while(div.hasChildNodes())
            {
                div.removeChild(div.lastChild);
            }
        }
		

    var http_request = false;

    function makeRequest(url,pos,lgn) {
		       
		http_request = false;		
		limpiarDiv();
		
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Ver nota sobre esta linea al final
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Falla :( No es posible crear una instancia XMLHTTP');
            return false;
        }
		
				
        http_request.onreadystatechange = function(){
				if (http_request.readyState == 4) {	
         		   if (http_request.status == 200) {
                		var xmldoc = http_request.responseXML;
						var idN = xmldoc.getElementsByTagName('id').item(pos);
						var ttl = xmldoc.getElementsByTagName('titulo').item(pos);
						var root_node = xmldoc.getElementsByTagName('cuerpo').item(pos);
						var img_node = xmldoc.getElementsByTagName('url').item(pos);
						var valor=document.getElementById('bdy');
						ttlTexto = document.createTextNode(ttl.firstChild.data);
						nodoTexto = document.createTextNode(root_node.firstChild.data+"...");
						nodoImg = document.createTextNode(img_node.firstChild.data);
						esp = document.createTextNode(' ');
						var to=document.createElement('h3');
						var lnk=document.createElement('a');
						var p1=document.createElement('p');
						var imag=document.createElement('img');
						var operacion = lgn-pos;
						lnk.setAttribute('href','site/webpages/noticias.php?spot='+idN.firstChild.data);
						imag.setAttribute('src','site/backend/'+nodoImg.data);
						to.appendChild(ttlTexto);
						p1.appendChild(nodoTexto);
						valor.appendChild(to);
						valor.appendChild(imag);
						valor.appendChild(p1);
						valor.appendChild(esp);						
						lnk.appendChild(document.createTextNode('Leer mas'));
						valor.appendChild(lnk);						            			
           			} else {
                		alert('Hubo problemas con la peticion');
            		}
				}
        };
        http_request.open('GET', url, true);
		http_request.send(null);
    }
	
	function check(){
		
		var a=document.getElementById('form2');
		
		if( (a.usuario.value=="") && (a.password.value=="") ){
			alert('El siguiente error(es) ha ocurrido:\n-Campo Usuario esta vacio\n -Campo Password esta vacio');
		}
		
		else if(a.usuario.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Usuario esta vacio');
		}else if(a.password.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Password esta vacio');
		}
		
		a.setAttribute('action','loginUsr.php');
	}
	
	
	
	function checkC(){
		var a=document.getElementById('contacto');
		if(a.nombre.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Nombre esta vacio');
		}
		
		if(a.email.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Email esta vacio');
		}
	}
	
	function validar(){
		
		var a=document.getElementById('grabar');
		if(a.usuario.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Usuario esta vacio');
			
		}
		
		if(a.password.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Password esta vacio');
			
		}
		
		if(a.repass.value != a.password.value){
			alert('El siguiente error(es) ha ocurrido:\n-Contrase&ntilde;as no coinciden');
				
		}
		
		if(a.email.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Email esta vacio');
			
		}
		
		a.setAttribute('action','grabar.php');
		
	}
	
	
	function validarEd(){
		
		var a=document.getElementById('edicion');
		
		
		if(a.password.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Password necesita valor');
		}
		
		if(a.email.value=="") {
			alert('El siguiente error(es) ha ocurrido:\n-Campo Email necesita valor');
		}
		
		a.setAttribute('action','edicion.php');
	}
	
	
	
	