function checkLogin()
{
	with (window.document.loginForm) {
		if (txtUserName.value == '') {
			alert('Introduzca su e-mail');
			return;
		} else if (txtPassword.value == '') {
			alert('Introduzca su contraseņa');
			return;
		} else {
			login(txtUserName.value,txtPassword.value);
		}
	}
}


function login(txtUserName,txtPassword) {
	
	var posit = origen;	

    var xhr = getTransport_login();
    xhr.onreadystatechange = function() {
        updateChange_login(xhr);
    }

	xhr.open('post', 'datasource/login.php', true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send('swfaddress=login&txtUserName=' + txtUserName + '&txtPassword=' + txtPassword + '&posit=' + posit);
 
}

function logout() {

    var xhr = getTransport_login();
    xhr.onreadystatechange = function() {
        updateChange_login(xhr);
    }

	xhr.open('post', 'datasource/login.php', true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xhr.send('swfaddress=logout');
 
}
             
function getTransport_login() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
        	return new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
            return new ActiveXObject('Microsoft.XMLHTTP');
    	}
    }
}

function updateContent_login(html) {
                var content = document.getElementById('cont_log');
                content.innerHTML = html;
                
                while (html.match(/(<script[^>]+javascript[^>]+>\s*(\/\/*<!\[CDATA\[)?(<!--)?\s*)/i)) {
                    html = html.substr(html.indexOf(RegExp.$1) + RegExp.$1.length);
                    if (!html.match(/((\/\/ *\]\]>)?(-->)?\s*<\/script>)/)) break;
                    block = html.substr(0, html.indexOf(RegExp.$1));
                    html = html.substring(block.length + RegExp.$1.length);
                    eval(block);
                }
}
            
function updateChange_login(xhr) {	
    if (xhr.readyState != 4) {
		document.getElementById('cont_log').innerHTML='<div align="center"><img src="imagenes/ajax-loader.gif" width="220" height="19" /></div>';
	}else{
        if (xhr.status == 200) {
            updateContent_login(xhr.responseText);           
        } else {
            //alert('Error: ' + xhr.status + '!');
        }
    }
}