//-------------------------------------------------------//
// Author:Rodolfo Machon
// Company:WebSoft, SA de CV 
// Nombre del archivo: cambiar_contrasena.js
// Created: 2016-09-01
// Updates: 2016-09-01
// Copyright - All Rights Reserved
//-------------------------------------------------------//
//-------------------------------------------------------//
var xmlHttp1;
var xmlHttpStream1;
var xmlHttp2;
var xmlHttpStream2;
var openwindow;
//-------------------------------------------------------//
window.onload = function(){
    lan     = document.form.lan.value;
    appid   = document.form.appid.value;
    
	window.resizeTo(400,300);   
    capturar_departamento();
}
//-------------------------------------------------------//
function capturar_departamento(){
    var URL     = "/cgi-bin/"+appid+"/pl/get_user.pl?appid="+appid+"&lan="+lan;
    xmlHttp1	= GetXmlHttpObject(stateChangedCapturar);
    xmlHttp1.open("GET",URL,true) ;
    xmlHttp1.send(null);
}
function stateChangedCapturar(){
    if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete"){ 
        xmlHttpStream1=xmlHttp1.responseText;
        if (xmlHttpStream1!="false" && xmlHttpStream1!=""){
            var datos=xmlHttpStream1.split("|");
            document.form.v64_elabora.value=datos[0];
            document.form.i8_user_id.value=datos[1];
        }
    }
}
function actualizarPwd(){
    var userId  = document.form.i8_user_id.value;
    var pwd     = document.form.contrasena.value;
    var pwdN    = document.form.contrasenaNueva.value;
    var pwdNc   = document.form.contrasenaConfirmar.value;

    if(pwdN==pwdNc){
           var URL = "/cgi-bin/"+appid+"/pl/cambio_pwd.pl?appid="+appid+"&i8_user_id="+userId+"&contrasena="+pwd+"&contrasenaNueva="+pwdN+"&contrasenaConfirmar="+pwdNc;
          xmlHttp2	= GetXmlHttpObject(stateChangedActualizarPwd);
          xmlHttp2.open("GET",URL,true) ;
          xmlHttp2.send(null);
    }else{
        alert("Error al actualizar su password. Verifique la informacion ingresada.");
        document.form.all.cambiar.style.visibility='visible';
    }
}
function stateChangedActualizarPwd(){
    var userId=document.form.i8_user_id.value;
    var clase="users";
   
    if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete"){ 
        xmlHttpStream2=xmlHttp2.responseText;
        //alert(xmlHttpStream2);
        if (xmlHttpStream2=="true"){
            win="window.open('/cgi-bin/"+appid+"/pl/pwd.pl?id="+userId+"&clase="+clase+"&appid="+appid+"&lan="+lan+"','pwd','left=5,top=5,width=250,height=250,scrollbars=yes,toolbar=no,menu=no')";
            eval(win);
            close();
        }else{
            alert("Error al actualizar su password. Verifique la informacion solicitada.")
            document.form.all.cambiar.style.visibility='visible';
        }
    }
}  
//-------------------------------------------------------//
// Auxiliar
function GetXmlHttpObject(handler){
	var objXmlHttp=null;	
	if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		objXmlHttp = new XMLHttpRequest();
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 		
	}
	if(window.ActiveXObject){// code for IE6, IE5
		objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		objXmlHttp.onreadystatechange=handler 		
	}
	if(objXmlHttp==null){alert("Your Browser Does Not Suppport AJAX")}
	return objXmlHttp;
}