//-------------------------------------------------------//
// Author:Rodolfo Machon, Guillermo Machon
// Company:WebSoft, SA de CV 
// Nombre del archivo: inspecciones_mensuales_r.js
// Created: 2018-05-08
// Updates: 2018-05-08
// Copyright - All Rights Reserved
//-------------------------------------------------------//
//-------------------------------------------------------//
var xmlHttp;
var xmlHttpStream;
var openwindow;
//-------------------------------------------------------//
window.onload = function(){
	resizeTo(700,200);
	getAsesores();
};
//-------------------------------------------------------//
// LEVEL 1
function getAsesores(){
    var URL     = "../pl/asesores.get.pl?appid=RTM_LaHerradura&lan=es";
    xmlHttp	= GetXmlHttpObject(stateChangedGetAsesores);
    xmlHttp.open("GET",URL,true) ;
    xmlHttp.send(null);
}
function stateChangedGetAsesores(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        xmlHttpStream = xmlHttp.responseText;
		//alert(xmlHttpStream);
		var Asesores   = xmlHttpStream.split('~');
		var selec 	  = document.getElementById("i8_asesor_id"); 
		for(var i=0;i<Asesores.length-1;i++){
			var elementos  		= Asesores[i].split('|');
			var newOption 		= document.createElement("option");
			newOption.value		= elementos[0];			
			if (typeof newOption.textContent === 'undefined'){
				newOption.innerText = elementos[1];
			}else{
				newOption.textContent = elementos[1];
			}
			selec.appendChild(newOption);
		}	
    }
}
function Generar(){
	var periodo = document.form.i8_periodo.value;
	var asesor= document.form.i8_asesor_id.value;
	if(periodo===""){alert("Favor Ingresar el Mes");return;}	
	if (!openwindow || openwindow.closed){
		win = "window.open('../pl/inspecciones_mensuales_rept.pl?lan=es&appid=RTM_LaHerradura&i8_periodo="+periodo+"&i8_asesor_id="+asesor+"','GenerarInspecionesMensuales','left=100,top=20,width=675,height=550,scrollbars=yes,toolbar=no,menubar=yes,resizable=yes')";
		openwindow=eval(win);
	}else{openwindow.focus()}
}
//-------------------------------------------------------//
// 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;
}
function ShowCalendar(form,datetype,separator){
        var openwindow;
	if (!openwindow || openwindow.closed){
		win ="window.open('/RTM_v30/libraries/html/clnd.html?pbf="+form+"&datetype="+datetype+"&separator="+separator+"','Calendar','left=200,top=200,width=250,height=250,scrollbars=no,toolbar=no,menu=no')";
		openwindow=eval(win);
	}else{openwindow.focus()}
}
