
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// INFOSOFT SA DE CV
// Fecha: 2005-01-17
// Updates: 2005-08-18;2006-01-30;02-02-2007;2014-03-09
// Author: Rodolfo Machon
// Nombre del archivo: comm.js
// Description:
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var openwindow	= new Array(50);
var openImg = new Image();
openImg.src = "../img/open.gif";
var closedImg = new Image();
closedImg.src = "../img/closed.gif";
function GetBack(component,clase,getback,opener_form,left,top,id_field,field_focus,winame,properties){
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var id_value= "";
	var bn		= "";
	var componente	= component.split("__");
	if(componente.length>1){
		bn = componente[1]
		component=componente[0]+"."+componente[1];
	}else{
		bn = "bin";
		component=component+".pl";
	}
	if(id_field!=""){
		if(componente=="LIST"){
			id_field	 = parent.list.document.linkl.id_field.value;
			var id_value = eval("parent.form.document.linkf."+id_field+".value");
			if(id_value==""){
				alert('Please Choose ID Firts');
				return;
			}
		}else{
			id_value = eval("parent.form.document.form."+id_field+".value");
			if(id_value==""){
				alert('Please Choose ID Firts');
				return;
			}
		}
	}
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../"+bn+"/"+component+"?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id_value+"&getback="+getback+"&opener_form="+opener_form+"&field_focus="+field_focus+"','"+componente[0]+clase+"','left="+left+",top="+top+",width=100,height=100,"+properties+"')";
		openwindow[winame]=eval(win);
	}else{openwindow[winame].focus()}
}
function OpenWindow(winame,comm,fields,values,properties){
	var commands	= comm.split(",");
	var lan			= parent.list.document.linkl.lan.value;
	var appid		= parent.list.document.linkl.appid.value;
	var component	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;
	var id			= eval("parent.form.document.linkf."+id_field+".value");

	if(values!=""){id=id+"|"+values}

	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../bin/"+commands[0]+".pl?lan="+lan+"&appid="+appid+"&clase="+commands[1]+"&id="+id+"&fields="+fields+"&values="+values+"','"+commands[0]+commands[1]+"','left="+commands[2]+",top="+commands[3]+",width=100,height=100,"+properties+"')";
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}
}
function OpenWindowNABS(winame,comm,fields,values,properties){
	var commands	= comm.split(",");
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var component	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;
	var id		= eval("parent.form.document.linkf."+id_field+".value");
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../pl/"+comm+"?lan="+lan+"&appid="+appid+"&clase="+commands[1]+"&id="+id+"&fields="+fields+"&values="+values+"','','left=100,top=100,width=800,height=700,,scrollbars=yes,toolbar=no,menu=no,statusbar=no')";
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}
}
function OpenFrameNABS(winame,comm,fields,values){
	var commands	= comm.split(",");
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;
	var id		= eval("parent.form.document.linkf."+id_field+".value");
	parent.report.location.href = "../pl/nuc_repts.pl?lan="+lan+"&appid="+appid+"&id="+id+"";
}
function ConstructTable(){
	var j			= 20;
	var grid_header		= parent.list.document.linkl.gh.value.split(",");	
	var grid_links		= parent.list.document.linkl.gl.value.split("~~");
	var T  			= parent.list.document.getElementById('t');
	var NewRow		= T.insertRow(0);
	var NewCell		= NewRow.insertCell(0);
	NewCell.innerHTML	= "";
	for (var i=0;i<grid_links.length-1;i++){
		record		= grid_links[i].split("|");
		NewRow		= T.insertRow(i+1);
		NewCell		= NewRow.insertCell(0);
		href		= "<a href=javascript:"+record[3]+"('"+j+"','"+record[1]+"','"+record[4]+"','"+record[5]+"')>"+record[2]+"</a>";
		NewCell.innerHTML	= href;
		j++;
	}
}
function OpenFrame(winame,comm,fields,values){
	var commands	= comm.split(",");
	var lan			= parent.list.document.linkl.lan.value;
	var appid		= parent.list.document.linkl.appid.value;
	var component	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;
	var id			= eval("parent.form.document.linkf."+id_field+".value");
	var frame		= "parent.report.location.href='"+commands[0]+".pl?lan="+lan+"&appid="+appid+"&clase="+commands[1]+"&id="+id+"&fields="+fields+"&values="+values+"'";
	//alert(frame);
	eval(frame);
}
function OpenFramePL(winame,comm,fields,values){
	var commands	= comm.split(",");
	var lan			= parent.list.document.linkl.lan.value;
	var appid		= parent.list.document.linkl.appid.value;
	var component	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;
	var id			= eval("parent.form.document.linkf."+id_field+".value");
	var frame		= "parent.report.location.href='../"+commands[2]+"/"+commands[0]+".pl?lan="+lan+"&appid="+appid+"&clase="+commands[1]+"&id="+id+"&fields="+fields+"&values="+values+"'";
	eval(frame);
}
function GetOptions(){
	var clase	= parent.list.document.linkl.clase.value;
	var id_field	= parent.list.document.linkl.id_field.value;
	var id		= eval("parent.form.document.linkf."+id_field+".value");
	if(id!=""){
		var frame	= "parent.list.location.href='comml.pl?clase="+clase+"&id="+id+"&id_field="+id_field+"'";
		//alert(frame);
		eval(frame);
	}	
}
function CloseAll(){
     if (users && users.open && !users.closed) users.close();
     if (desktop_layouts && desktop_layouts.open && !desktop_layouts.closed) desktop_layouts.close();     
     if (profiles && profiles.open && !profiles.closed) profiles.close();
     if (permissions && permissions.open && !permissions.closed) permissions.close();
}
function SystemPrintPreview(OLECMDID){ 
	 //var OLECMDID = 10; 
	 /* OLECMDID values: 
	 * 6 - print 
	 * 7 - print preview 
	 * 8 - page setup (for printing) 
	 * 1 - open window 
	 * 4 - Save As 
	 * 10 - properties 
	 */
	 try{
			var PROMPT = 1; // 1 PROMPT & 2 DONT PROMPT USER 
			var oWebBrowser = document.getElementById("WebBrowser1");
			if(oWebBrowser == null)	{
				var sWebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
				parent.report.document.body.insertAdjacentHTML('beforeEnd', sWebBrowser); 
				oWebBrowser = document.getElementById("WebBrowser1");
			}
			oWebBrowser.ExecWB(OLECMDID,PROMPT);
	}
	catch(e){alert("Printing failed! " + e.message);}
}
function pr(){
    if (document.all){
	   parent.report.focus();
	   parent.report.print();
    }
}
function Send(){
	alert("Esta opcion no esta Activada.")	
}
function InConstruction(){
	alert("En construccion")	
}
function OpenPl(clase,getback,opener_form,left,top,id_fieldf,field_focus,winame,properties){//funcion agregada para poder abrir un pl desde el .div:GEB:20/12/2006
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;	
	var id		= eval("parent.form.document.linkf."+id_field+".value");
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../pl/nuc_expedientes.pl"+"?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"&getback="+getback+"&opener_form="+opener_form+"&field_focus="+field_focus+"&properties="+properties+"','','left="+left+",top="+top+",width=600,height=200,"+properties+"')";
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}
}
function OpenWindowPl(winame,comm,fields,values,field_id,properties){
	var cid		= "";
	var commands= comm.split(",");	
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var id_field= parent.list.document.linkl.id_field.value;	
	var id		= field_id;
	var today	= new Date();
	var mes		= today.getMonth()+1;
	var anio	= today.getYear();
	if(mes<10){mes="0"+mes;}
	var dia=days_in_month(anio,mes);
	var dt_vencimiento=anio+"-"+mes+"-"+dia;
	if (!openwindow[winame] || openwindow[winame].closed){
		//alert(commands[1]);
		if(commands[1]!="inmueble_" && commands[1]!="empresa_"){
			win ="window.open('../bin/"+commands[0]+".pl?lan="+lan+"&appid="+appid+"&clase="+commands[1]+"&id="+id+"&i8_nuc_id="+fields+"&dt_vencimiento="+dt_vencimiento+"&values="+values+"','"+commands[0]+commands[1]+"','left="+commands[2]+",top="+commands[3]+",width=100,height=100,"+properties+"')";
		}else{
			if(commands[1]=="inmueble_"){cid = "inmueble"}
			if(commands[1]=="empresa_"){cid = "empresa"}
			win ="window.open('../bin/"+commands[0]+".pl?lan="+lan+"&appid="+appid+"&clase="+cid+"&id="+id+"&i8_nuc_id="+fields+"&dt_vencimiento="+dt_vencimiento+"&values="+values+"','"+commands[0]+commands[1]+"','left="+commands[2]+",top="+commands[3]+",width=100,height=100,"+properties+"')";	
		}
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}
}
function OpenPl1(winame,comm,fields,values,properties){
	var commands	= comm.split(",");
	var lan		= document.form.lan.value;
	var appid	= document.form.appid.value;
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../bin/"+commands[0]+".pl?lan="+lan+"&appid="+appid+"&clase="+commands[1]+"&values="+values+"','"+commands[0]+commands[1]+"','left="+commands[2]+",top="+commands[3]+",width=100,height=100,"+properties+"')";
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}
}
function OpenSimplePl(winame,pl){//funcion agregada jueves 17 de mayo 2007:exclusivo para OPICO
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var clase	= parent.list.document.linkl.clase.value;
	var component	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;	
	var id		= eval("parent.form.document.linkf."+id_field+".value");
	
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../pl/"+pl+".pl"+"?lan="+lan+"&appid="+appid+"&id="+id+"&clase="+clase+"','"+winame+"','left=10,top=10,width=100,height=100,resizable=yes,scrollbars=yes,toolbar=no,menu=no,statusbar=no')";
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}

}
function OpenSimplePlf(winame,pl,cla){
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;	
	var id		= eval("parent.form.document.linkf."+id_field+".value");
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../pl/"+pl+".pl?lan="+lan+"&appid="+appid+"&id="+id+"','','left=10,top=100,width=100,height=100,resizable=yes,scrollbars=yes')";
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}
}
function OpenWinPl(winame,pl,cla){
	var lan		= parent.list.document.linkl.lan.value;
	var appid	= parent.list.document.linkl.appid.value;
	var id_field	= parent.list.document.linkl.id_field.value;	
	var id		= eval("parent.form.document.linkf."+id_field+".value");
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('../pl/"+pl+".pl?lan="+lan+"&appid="+appid+"&clase="+cla+"&id="+id+"','"+winame+"','left=100,top=100,width=200,height=200,resizable=yes,scrollbars=yes')";
		openwindow[winame]=eval(win);
	}
	else{openwindow[winame].focus()}
}
function days_in_month (y, m) {
     return 32 - new Date(y, m, 32).getDate();
}
function showBranch(branch){
	var objBranch = document.getElementById(branch).style;
	if(objBranch.display=="block")
		objBranch.display="none";
	else
		objBranch.display="block";
}
function swapFolder(img){
	objImg = document.getElementById(img);
	if(objImg.src.indexOf('/icons/{appid}/closed.gif')>-1)
		objImg.src = openImg.src;
	else
		objImg.src = closedImg.src;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////