var sesionGeneral = new Array()

var _canal = ''
var email = ''
var pass  = '' 

onload = function(){
	var numPaso = el('hidPasoActual').value
	
	

	switch(numPaso){
		case '1':	
			break
	    case '2':
	        break
	}
}

function login(){
    /*var bValido = true
    bValido = bValido & cumpleRegExp(el('txtEmail'),REGEXP_NOVACIO)
    bValido = bValido & cumpleRegExp(el('txtPassword'),REGEXP_NOVACIO)
    if(!bValido)return */

    email = el('txtEmail').value
    pass = el('txtPassword').value   

	//alert(email)
   httpReq = new XMLHTTPWrapper();		
   httpReq.callURL('CallSP.aspx?cmd=AG_Valida_LoginMenu&varchar@email=' + email + '&varchar@pass=' + pass + '&varchar@menu=01&d='+ new Date(),onLogin)    
}

function onLogin(txtResponse,params){
       if(txtResponse){
	    var oXMLResp =  new XMLDoc(txtResponse)
	    if(oXMLResp.selectSingleNode('xml/result/fila')){
			var cod= oXMLResp.selectSingleNode('xml/result/fila/@codigo').text
			var msg= oXMLResp.selectSingleNode('xml/result/fila/@descripcion').text
			if(cod==0){
				var oXML = new XMLDoc()
//				var oNewElem = ChangeTagName(oXMLResp,'xml/result[1]/fila','params')
				//var oNewElem = new XMLDoc(oXMLResp.xml().replace('<fila','<params'))
				
				var oNewElem = xmlTagName(txtResponse,2,1,'params')
				 
				//oXML.documentElement.appendChild(oNewElem)
				oXML.documentElement.appendChild(oNewElem.documentElement)
				el('hidSessionName').value = 'sesionLogin'
				el('hidValores').value = oXML.xml().trim()
				el('hidOp').value = 'guardarsesion;gotopaso(2)'
				__doPostBack('btnPostBack')
			}else{
				alert(msg)
			}
	    }else{
	        alert('El usuario y/o contraseña son incorrectos')
	    }
    }else{
        alert('No se pudo conectar con el servidor, inténtelo mas tarde')
    }
}

function openChangePass(){
	var oXML= new XMLDoc()
	var xt =  new XSLTranformer(oXML.xml().trim(),'config/UserManager/xslt/FormPass.xsl') 
	setTextBox('Cambio de Contraseña',xt.transform())
	showBox()
}

var iPuntosPass = 0

function testPassword(passwd){
    el('largoClave').innerHTML = passwd.length
    
    var description = new Array();
    description[0] = "<table width=160 cellpadding=4 cellspacing=0 ><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8 width=30 bgcolor=#ff0000></td><td height=4 width=120 bgcolor=tan></td></tr></table></td></tr><tr><td width=90><b>Muy Baja</b></td></tr></table>";
    description[1] = "<table width=160 cellpadding=4 cellspacing=0 ><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8 width=60 bgcolor=#990000></td><td height=4 width=90 bgcolor=tan></td></tr></table></td></tr><tr><td width=90><b>Baja</b></td></tr></table>";
    description[2] = "<table width=160 cellpadding=4 cellspacing=0 ><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8 width=90 bgcolor=#990099></td><td height=4 width=60 bgcolor=tan></td></tr></table></td></tr><tr><td width=90><b>Regular</b></td></tr></table>";
    description[3] = "<table width=160 cellpadding=4 cellspacing=0 ><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8 width=120 bgcolor=#000099></td><td height=4 width=30 bgcolor=tan></td></tr></table></td></tr><tr><td width=90><b>Alta</b></td></tr></table>";
    description[4] = "<table width=160 cellpadding=4 cellspacing=0 ><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8 width=150 bgcolor=#0000ff></td></tr></table></td></tr><tr><td width=90><b>Muy Alta</b></td></tr></table>";
    description[5] = "<table width=160 cellpadding=4 cellspacing=0 ><tr><td><table cellpadding=0 cellspacing=2><tr><td height=8 width=150 bgcolor=tan></td></tr></table></td></tr><tr><td width=90><b>Nula</b></td></tr></table>";

    var intScore =0;    
    //Minúscula
    if (passwd.match(/[a-z]/)){ 
        intScore = (intScore+2)
    } 
    //Mayúscula
    if (passwd.match(/[A-Z]/)){
        intScore = (intScore+2)
    } 
    //Número
    if (passwd.match(/\d+/)){
        intScore = (intScore+2)
    } 
    //Caracter especial
    if (passwd.match(/[.!,@#$%^&*?_~]/)){
        intScore = (intScore+2)
    }  
    //Largo 8
    if(passwd.length >=8){
        intScore = (intScore+2)
    }
     
	iPuntosPass = intScore

    if(intScore ==0){
        strVerdict = description[5];
    }else if(intScore <= 2){
        strVerdict = description[0];
    }else if (intScore <= 4){
        strVerdict = description[1];
    } else if (intScore <= 6){
        strVerdict = description[2];
    }else if (intScore <= 8){
        strVerdict = description[3];
    }else{
        strVerdict = description[4];
    }

    document.getElementById("fuerzaClave").innerHTML= (strVerdict);
    }
	
	function changePass(button){

	var oXML= new XMLDoc()
	var bInsertValido = true
	var els = document.getElementsByName('formpass')
	n = oXML.documentElement
	for(i=0;i<els.length;i++){
		o = els[i]
			if(o.onblur ){				
					o.onblur()				
			}
			if(o.getAttribute('valido')!=undefined){bInsertValido = bInsertValido && eval(o.getAttribute('valido'))}	
			if(bInsertValido){
		        switch(o.type){
					case "password":
					case "text":
		            case "textarea": //textbox
		            case "textbox": //textarea
						var s = new String(o.value)
		                n.setAttribute(o.id,s.replace(/\"/g,''))
		                break
		            case "select-one":
						n.setAttribute('txt_'+o.id,o.options[o.selectedIndex].text)
						n.setAttribute('cod_'+o.id,o.options[o.selectedIndex].value)	
		                break
		            case "radio":	                	
		                n.setAttribute(o.id,getSelectedRadio(o.name).value) 
		                break
		        }
		   }
		  
	}	
	
	if(!bInsertValido){
		alert('Debe ingresar toda la información antes de continuar.')
		return
	}
	
	if (el('newpass').value != el('newpass2').value ){
		alert('La nueva clave con la repetición de la clave no coinciden')
		el('newpass').focus();
		return
	}
	if ((iPuntosPass) < 6 ){
		alert('Debe ingresar una contraseña con seguridad REGULAR o superior')
		return
	}
	
	button.disabled=true
	var url = 'CallSP.aspx?cmd=GEN_USERMANAGER&varchar@xmlparams='+oXML.xml.trim() +'&int@idaction=5'
	showBox()
	httpReq = new XMLHTTPWrapper();
	//var divLoading = el('loadingBox')
	//divLoading.style.display = 'block'
	//divLoading.innerHTML = eval('LOADING_'+LANG)
	httpReq.callURL(url + '&d=' + new Date(),onchangePass,[null,button],true)
}

function compararPass(text){
	return (text==el('newpass').value)
}

function onchangePass(txtResponse,params){ 
//	alert(txtResponse)
	//alert('Contraseña modificada correctamente')
	hideBox();
	setTextBox('login','txtEmail');
	el('txtEmail').value = ''
	setTextBox('login','txtPassword');
	el('txtPassword').value = ''
}

function setTextBox(titulo,cuerpo){
        el('lbTitulo').innerHTML = titulo
        el('lbCuerpo').innerHTML = cuerpo
    }
 
