//-------------------------------------------------------//
// Author:Rodolfo Machon
// Company:WebSoft, SA de CV 
// Nombre del archivo: inmueble_abonos_asws.js
// Created: 2015-11-01
// Updates: 2015-11-01
//-------------------------------------------------------//
//-------------------------------------------------------//
var weekdays 	= new Array("Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado");
var months 		= new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
var today 		= new Date();
var weekday 	= today.getDay();
var monthday 	= today.getDate();
var month 		= today.getMonth();
var year 		= today.getFullYear();
var weekday		= weekdays[weekday];
var month 		= months[month];
var dateString	= (String(weekday))+" "+(String(monthday))+" de "+(String(month))+" de "+(String(year));
var Prop		= document.form.propietarios.value;
var isIE 		= document.all?true:false;
var isNS 		= document.layers?true:false;
var exp_id		= document.form.i8_expediente_id.value;	
var appid		= document.data.appid.value;
var lan			= document.data.lan.value;
var AbrirWindow	= new Object();
var xmlHttp11;
var xmlHttpStream11;
//-------------------------------------------------------//
window.onload = function(){
	var w = document.form.width.value;
	var h = document.form.height.value;
	document.form.fecha_emision.value 		= dateString;
	document.form.dt_vencimiento.value 		= GetFechaHoy();

	window.resizeTo(w,h);
	GetPageParams();	
	CapturarUsuario();
	GetUserFunctions();
	GetUserViews();	
}
//-------------------------------------------------------//
if (window.ActiveXObject){
	var Propietarios = new ActiveXObject("Microsoft.XMLDOM");
	Propietarios.async=false;
	Propietarios.loadXML(Prop);
}else if (document.implementation && document.implementation.createDocument){
	var Propietarias = document.implementation.createDocument("","",null);
	Propietarios= document.implementation.createDocument("","",null);
	Propietarios.loadXML(Prop);
}else{
	alert('Your browser cannot handle this script');
}
function onlyDigits(e,decReq) {
	var key = (isIE) ? window.event.keyCode : e.which;
	var obj = (isIE) ? event.srcElement : e.target;
	var isNum = (key > 47 && key < 58) ? true:false;
	var dotOK = (key==46 && decReq=='decOK' && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;
	window.event.keyCode = (!isNum && !dotOK && isIE) ? 0:key;
	e.which = (!isNum && !dotOK && isNS) ? 0:key;
	return (isNum || dotOK);
}
function CapturarUsuario(){
    var URL     = "../pl/capturar_usuario.pl?appid="+appid+"&lan="+lan+"&id="+exp_id;
    xmlHttp11	= GetXmlHttpObject(stateChangedCapturarUsuario);
    xmlHttp11.open("GET",URL,true) ;
    xmlHttp11.send(null);
}
function stateChangedCapturarUsuario(){
    if (xmlHttp11.readyState==4 || xmlHttp11.readyState=="complete"){ 
        xmlHttpStream11=xmlHttp11.responseText;
		//alert(xmlHttpStream11);
        if (xmlHttpStream11!="false" && xmlHttpStream11!=""){
			var respuesta	= xmlHttpStream11;
			var respuestas	= respuesta.split("|");
			var usuario		= respuestas[0];
			var fin  		= respuestas[1];
			var ultima_modificacion  = respuestas[2];
			document.form.v128_usuario.value = usuario;
			document.form.dt_ultima_modificacion.value = ultima_modificacion;
        }
    } 
}
function GetUserFunctions(){
	var cid		= "bsws";
	var clase	= "inmueble"
	var oid		= "3005"
    var URL     = "../pl/get_user_option_functions.pl?appid="+appid+"&lan="+lan+"&clase="+clase+"&cid="+cid+"&oid="+oid;
    xmlHttp12	= GetXmlHttpObject(stateChangedGetUserFunctions);
    xmlHttp12.open("GET",URL,true) ;
    xmlHttp12.send(null);
}
function stateChangedGetUserFunctions(){
    if (xmlHttp12.readyState==4 || xmlHttp12.readyState=="complete"){ 
        xmlHttpStream12=xmlHttp12.responseText;
        if (xmlHttpStream12!="false" && xmlHttpStream12!=""){
			var ol 		= document.getElementById("functions_ol");
			var funs_a	= xmlHttpStream12.split("~~");
			for(var i=0;i<funs_a.length-1;i++ ) {
				var li		= document.createElement("li");
				var mems_a	= funs_a[i].split("[]");
				li.innerHTML= "<a href='#' id='"+mems_a[0]+"' onClick='"+mems_a[1]+"'>"+mems_a[2]+"</a>";
				ol.appendChild(li);
			}			
        }
    }
}
function GetUserViews(){
	var cid		= "bsws";
	var clase	= "inmueble"
	var oid		= "3005"
    var URL     = "../pl/get_user_option_views.pl?appid="+appid+"&lan="+lan+"&clase="+clase+"&cid="+cid+"&oid="+oid;
    xmlHttp13	= GetXmlHttpObject(stateChangedGetUserViews);
    xmlHttp13.open("GET",URL,true) ;
    xmlHttp13.send(null);
}
function stateChangedGetUserViews(){
    if (xmlHttp13.readyState==4 || xmlHttp13.readyState=="complete"){ 
        xmlHttpStream13=xmlHttp13.responseText;
        if (xmlHttpStream13!="false" && xmlHttpStream13!=""){
			var ol 		= document.getElementById("views_ol");
			var vis_a	= xmlHttpStream13.split("~~");
			for(var i=0;i<vis_a.length-1;i++ ) {
				var li		= document.createElement("li");
				var mems_a	= vis_a[i].split("[]");
				li.innerHTML= "<a href='#' id='"+mems_a[0]+"' onClick=OpenView('"+mems_a[0]+"','"+mems_a[1]+"','"+mems_a[2]+"','"+mems_a[3]+"','"+mems_a[4]+"','','"+mems_a[6]+"','"+mems_a[7]+"','"+mems_a[8]+"','"+mems_a[9]+"','"+mems_a[10]+"','"+mems_a[11]+"')>"+mems_a[1]+"</a>";
				ol.appendChild(li);
			}			
        }
    }
}
//-------------------------------------------------------//
function ActivarOpciones() {
	if (document.all.opciones_div.style.display=='inline') {
		document.all.opciones_div.style.display	= 'none';
    }else{
		document.all.opciones_div.style.display	= 'inline';		
	}
}
function removeAbonos(){
	var DescarPers 	= "";
	var Rows   	= GridData.split("~~");
	var ok = confirm("Esta Segur@ que Desea Eliminar los Movimientos?");
	if(ok!==true){return;}
	if(Rows<1){alert(document.form.empty_grid.value);return;}
	for(var k=1;k<Rows.length;k++ ) {
		if(eval("document.form.chk_"+k+".checked")){
			var RowsValues	= Rows[k-1].split("&&");
			var PER = eval("document.form.PER_"+k+".value");
			var FEC = eval("document.form.FEC_"+k+".value");
			var REC = eval("document.form.REC_"+k+".value");			
			var TIP = eval("document.form.TIP_"+k+".value");			
			DescarPers += PER+"|"+FEC+"|"+REC+"|"+TIP+"~~";
		}
	}
	document.descargar.Descargas.value = DescarPers;
	if(document.descargar.Descargas.value!=""){
		//alert(document.descargar.Descargas.value)
		document.descargar.submit();
	}else{ alert("No Hay Periodos Marcados a Eliminar")}
}
function removeExpedienteAbonosCompensaciones(){
	var id = document.form.id.value;
    winame="deleteExpedienteAbonosCompensaciones";
    if (!AbrirWindow[winame] || AbrirWindow[winame].closed){
        win ="window.open('../pl/expediente.abonos.compensaciones.remove.pl?appid="+appid+"&lan="+lan+"&clase=inmueble&id="+id+"','"+winame+"','left=0,top=0,width=100,height=100,resizable=yes,scrollbars=yes')";
        AbrirWindow[winame]=eval(win);
    }
    else{AbrirWindow[winame].focus()}
}
function moveExpedienteAbonos(){
	var MoverPers 	= "";
	var Rows   	= GridData.split("~~");
	var ok = confirm("Esta Segur@ que Desea Mover los Abonos?");
	if(ok!=true){return;}
	if(Rows<1){alert(document.form.empty_grid.value);return}
	for(var k=1;k<Rows.length;k++ ) {
		if(eval("document.form.chk_"+k+".checked")){
			var RowsValues	= Rows[k-1].split("&&");
			var PER = eval("document.form.PER_"+k+".value");
			var FEC = eval("document.form.FEC_"+k+".value");
			var REC = eval("document.form.REC_"+k+".value");			
			var TIP = eval("document.form.TIP_"+k+".value");			
			MoverPers += PER+"|"+FEC+"|"+REC+"|"+TIP+"~~";
		}
	}
	document.mover.abonos.value = MoverPers;
	if(document.mover.abonos.value!=""){
		alert(document.mover.abonos.value)
		//document.mover.submit();
	}else{ alert("No Hay Periodos Marcados a Mover")}
}
function modifyAbonos() {
	var id 	  = document.form.id.value;
	var clase = "inmueble_abonos"; 
    winame = "modifyAbonos";
    if (!AbrirWindow[winame] || AbrirWindow[winame].closed){
        win ="window.open('../bin/gdfl.pl?appid="+appid+"&lan="+lan+"&clase="+clase+"&id="+id+"','"+winame+"','left=0,top=0,width=100,height=100,resizable=yes,scrollbars=yes')";
        AbrirWindow[winame]=eval(win);
    }
    else{AbrirWindow[winame].focus()}
}
//-------------------------------------------------------//
function moveExpedienteAbono(per){
    var tables;	
	var id 	  		= document.form.id.value;
	var gen_id		= document.form.c3_tipo_generador_id.value;
	if (!tables || tables.closed){
		tables = window.open("../pl/abono.move.pl?lan="+lan+"&appid="+appid+"&id="+id+"&i8_periodo="+per+"&c3_tipo_generador_id="+gen_id,"Abonos","top=50,left=50 width=600,height=180,resizable=no,status=no,scrollbars=no");
	}else{tables.focus()}
}