nam_sw = new  Array;

function fenv()
{
	whost = location.host;

	var p = document.getElementById ( "b1" );
	if ( p )
	{
		if ( whost.indexOf("pymesnet") >= 0 )
		{
			// orange
			p.style.backgroundColor =  "#e90";
		}
		else
		{
			// green
			p.style.backgroundColor =  "#9c3";
		}
	}
}

function fload()
{
	getMemory();

	p = document.getElementById ( "b2" );
	if ( ! p )
	{
		p = document.getElementById ( "login" );
	}
	if ( p )
	{
		p.focus();
	}
}

function galert (x)
{
	switch ( x )
	{
            case  "f" :
                t = "fecha es en formato: aaaa-mm-dd \n" ;
        	break;
            case  "m" :
                t = "meses son en formato: aaaa-mm ";
		break;
            case  "fv" :
                t = "fecha es en formato: aaaa-mm-dd \n" +
                    "o dias a sumar como: +30 o +15";
        	break;
	    case "cco" :
		t = "centro de costo \n" +
		    "debe existir en Parametros: centros de costo" ;
        	break;
	    default:
        	t = "oops no " + x;
        }
	alert ( t );
}

function getMemory()
{
	d = document.cookie;
	lmax = d.length;

	l1=0;

	while ( l1 < lmax )
	{
		l2 = d.indexOf("=", l1);
		if ( l2 < l1 )  break;

		l3 = d.indexOf(";", l2);
		if  (l3 < l2 ) l3 = lmax;

		nam = d.substring(l1,l2);
		l2++;
		val = d.substring(l2, l3);

		p = document.getElementById ( nam );

          	if ( p  &&  ! p.value  &&  ! nam_sw [nam] )
                {
                        if ( ! document.all )
                                nam_sw [nam] = 1;

                        p.value=val;
                }
		l1 = l3+2;
	}
}

function ftercero()
{
	_fnew ( "gb6220", "&ope=cli" );
}

function fprod( )
{
	_fnew ( "gb6220", "&ope=ara");
}

function fabrev ( x )
{
	wlnk = x ?
		"&cta=" + x
	: 	"";

	_fnew ( "gb6220", "&ope=puc" + wlnk );
}

function fcco (x)
{
	cia = document.forms[0].cia.value;

	switch ( x )
	{
	    case  "inv":
		cco = document.f1.inv.value;
		tit = "bodega";
		break;
	    case  "bod":
		cco = document.f1.bod.value;
		tit = "bodega";
		break;
	    case  "sub":
		cco = document.f1.sub.value;
		tit = "centro de costo";
		break;
	    case  "cco":
		cco = document.f1.cco.value;
		tit = "centro de costo";
		break;
	    default:
		cco = "";
		tit = "centro de costo";
	}

	opc = "menubar=no,resizable=NO, width=500, height=400";

	cco ?
	y = window.open("../../gb/pgm/gb5020.cgi?cia="+cia+"&_pgm=mh6230-cco&_app=mh&ope=cargar&cod="+cco, tit, opc)
	:
	y = window.open("../../gb/pgm/gb5020.cgi?cia="+cia+"&_pgm=mh6230-cco&_app=mh", tit, opc);

        y.focus();
	y.title=pgm;
}

function fnewWin ( ope )
{
	// puede remplazar a ftercero y fprod
	_fnew ( "gb6220", "&ope=" + ope );
}

function  _fnew ( pgm, qry )
{
	wcia = document.forms[0].cia.value;
	wapp = pgm.substr(0,2);

	wlnk = "../../" + wapp + "/pgm/" + pgm + ".cgi?cia=" + wcia + qry ;

	wtxt = "width=400,height=700" +
                ",left=10,top=10" +
                ",toolbar=no,menubar=no" +
                ",scrollbars=yes,resizable=yes" ;

        y = window.open( wlnk, "auxil", wtxt );
        y.focus();
	y.title=pgm;
}
