//-------------------------------------------------------//
// Author:Rodolfo Machon
// Company:WebSoft, SA de CV 
// Nombre del archivo: recibos.tiangue.control.js
// Created: 2017-06-23
// Updates: 2017-06-23
// Copyright - All Rights Reserved
//-------------------------------------------------------//
//-------------------------------------------------------//
var xmlHttp10;
var xmlHttpStream10;
var xmlHttp11;
var xmlHttpStream11;
var OpenWindows  = new Object();
var appid = "RTM_v30";
//-------------------------------------------------------//
window.onload = function(){
		window.resizeTo(760,750);
		getFechaHoy();		
		getUserCajaDepartamento();
};
//-------------------------------------------------------//
//LEVEL 1
function getFechaHoy(){
    var URL     = "/cgi-bin/RTM_v30/pl/get_fecha_hoy.pl?appid="+appid;
    xmlHttp10	= GetXmlHttpObject(stateChangedGetFechaHoy);
    xmlHttp10.open("GET",URL,true) ;
    xmlHttp10.send(null);	
}
function stateChangedGetFechaHoy(){
    if (xmlHttp10.readyState==4 || xmlHttp10.readyState=="complete"){ 
        xmlHttpStream10=xmlHttp10.responseText;
        if (xmlHttpStream10!=="0" && xmlHttpStream10!==""){
           document.getElementById('dt_emision').value		= xmlHttpStream10;
           document.getElementById('dt_vencimiento').value	= xmlHttpStream10;
        }
    } 
}
function getUserCajaDepartamento(){
    var URL     = "/cgi-bin/RTM_v30/pl/user.caja.departamento.get.pl?appid=RTM_v30&lan=es";
    xmlHttp11	= GetXmlHttpObject(getUserCajaDepartamentoSC);
    xmlHttp11.open("GET",URL,true) ;
    xmlHttp11.send(null);
}
function getUserCajaDepartamentoSC(){
    if (xmlHttp11.readyState==4 || xmlHttp11.readyState=="complete"){ 
        xmlHttpStream11=xmlHttp11.responseText;
		if (xmlHttpStream11!=="false" && xmlHttpStream11!==""){
			var datos=xmlHttpStream11.split("|");
			document.getElementById('i8_user_id').value				= datos[0];
			document.getElementById('i8_emisor_id').value			= datos[0];
			document.getElementById('v32_lname').value				= datos[1];			
			document.getElementById('v32_fname').value				= datos[2];
			document.getElementById('i2_tipo_departamento_id').value= datos[3];
			document.getElementById('v64_tipo_departamento').value	= datos[4];
			document.getElementById('i2_cajero_id').value			= datos[5];
		}
    }
}
function saveRecibo(tid,cid,fie){
	var rid	    = document.getElementById('c16_recibo_id').value;        
	var contrib	= document.getElementById('v128_contribuyente').value;
	var dt_emi	= document.getElementById('dt_emision').value;
	var cajero  = document.getElementById('i2_cajero_id').value;
	var cantidad= document.getElementById('i4_cantidad').value;
	var depto	= document.getElementById('i2_tipo_departamento_id').value;
	var emid	= document.getElementById('i8_emisor_id').value;
	var concepto= document.getElementById(cid).innerHTML;
	if(rid == ""){alert("Favor Ingrese El Nombre del Recibo");return;}
	if(contrib == ""){alert("Favor Ingrese El Nombre del Contribuyente");return;}
    var URL     = "/cgi-bin/RTM_v30/pl/recibo.tiangue.save.pl";
	var str		= "appid="+appid+"&c16_recibo_id="+rid+"&c16_tarifa_id="+tid+"&v128_contribuyente="+contrib+"&dt_emision="+dt_emi+"&i2_cajero_id="+cajero+"&i8_emisor_id="+emid+"&i4_cantidad="+cantidad+"&i2_tipo_departamento_id="+depto+"&txt_concepto="+concepto+"&fiestas="+fie;
    xmlHttp12	= GetXmlHttpObject(saveReciboSC);
    xmlHttp12.open("PUT",URL,true) ;
	xmlHttp12.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp12.send(str);	
}
function saveReciboSC(){
    if (xmlHttp12.readyState==4 || xmlHttp12.readyState=="complete"){ 
        xmlHttpStream12=xmlHttp12.responseText;
        //alert(xmlHttpStream12);
        if (xmlHttpStream12!=="0" && xmlHttpStream12!==""){
			openRecibo(xmlHttpStream12);
        }
    } 
}
//-------------------------------------------------------//
//LEVEL 2
function openRecibo(mid){
    var winame = "Recibo";
    if (!OpenWindows[winame] || OpenWindows[winame].closed){
		win ="window.open('/cgi-bin/"+appid+"/bin/mdfx.pl?lan=es&appid="+appid+"&clase=recibos&id="+mid+"','"+"MAN_"+winame+"','left=400,top=0,width=100,height=100,resizable=yes,scrollbars=yes')";
		OpenWindows[winame]=eval(win);
    }else{OpenWindows[winame].focus()}
}
//-------------------------------------------------------//
// AUXILIAR
function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : evt.keyCode
    return !(charCode > 31 && (charCode < 48 || charCode > 57));
}
function showDiv(id) {
    var x = document.getElementById(id);
    if (x.style.display === 'none') {
        x.style.display = 'block';
    } else {
        x.style.display = 'none';
    }
}
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;
}