var version4 = (navigator.appVersion.charAt(0) == "4"); 
var popupHandle;

function closePopup(){
	if(popupHandle != null && !popupHandle.closed)
		popupHandle.close();
}

function displayPopup(position,url,name,height,width,evnt) {
// position=1 POPUP: makes screen display up and/or left, down and/or right 
// depending on where cursor falls and size of window to open
// position=2 CENTER: makes screen fall in center
	var properties = "toolbar = 0, scrollbars = 1, location = 0, height = " + height;
	properties = properties + ", width=" + width;
	var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
	if(navigator.appName == "Microsoft Internet Explorer") {
		screenY = document.body.offsetHeight;
		screenX = window.screen.availWidth;
	}
	else {
		screenY = window.outerHeight
		screenX = window.outerWidth
	}
	if(position == 1)	{ // if POPUP not CENTER
		cursorX = evnt.screenX;
		cursorY = evnt.screenY;
		padAmtX = 10;
		padAmtY = 10;
		if((cursorY + height + padAmtY) > screenY) {
			// make sizes a negative number to move left/up
			padAmtY = (-30) + (height * -1);
			// if up or to left, make 30 as padding amount
		}
		if((cursorX + width + padAmtX) > screenX){
			padAmtX = (-30) + (width * -1);	
		// if up or to left, make 30 as padding amount
		}
		if(navigator.appName == "Microsoft Internet Explorer") {
			leftprop = cursorX + padAmtX;
			topprop = cursorY + padAmtY;
		}
		else {
			leftprop = (cursorX - pageXOffset + padAmtX);
			topprop = (cursorY - pageYOffset + padAmtY);
	   }
	}
	else{
	leftvar = (screenX - width) / 2;
	rightvar = (screenY - height) / 2;
		if(navigator.appName == "Microsoft Internet Explorer") {
			leftprop = leftvar;
			topprop = rightvar;
		}
		else {
			leftprop = (leftvar - pageXOffset);
			topprop = (rightvar - pageYOffset);
	   }
	}
	if(evnt != null) {
		properties = properties + ", left = " + leftprop;
		properties = properties + ", top = " + topprop;
	}
	closePopup();
	popupHandle = open(url,name,properties);
}

function dspPopUp(strName,iW,iH,TOP,LEFT,R,S,SC,T,TB,URL){
	var sF = "";

	if(navigator.appName == "Microsoft Internet Explorer") {
		screenY = document.body.offsetHeight;
		screenX = window.screen.availWidth;
	}
	else {
		screenY = window.outerHeight;
		screenX = window.outerWidth;
	}
	
	leftvar = (screenX - iW) / 2;
	rightvar = (screenY - iH) / 2;
	
	if(navigator.appName == "Microsoft Internet Explorer") {
		leftprop = leftvar;
		topprop = rightvar;
	}
	else {
		leftprop = (leftvar - pageXOffset);
		topprop = (rightvar - pageYOffset);
	}

	TOP = topprop;
	LEFT = leftprop;
	
	sF += iW?'width='+iW+',':'';
	sF += iH?'height='+iH+',':'';
	sF += R?'resizable='+R+',':'';
	sF += S?'status='+S+',':'';
	sF += SC?'scrollbars='+SC+',':'';
	sF += T?'titlebar='+T+',':'';
	sF += TB?'toolbar='+TB+',':'';
	sF += TB?'menubar='+TB+',':'';
	sF += TOP?'top='+TOP+',':'';
	sF += LEFT?'left='+LEFT+',':'';
	return window.open(URL?URL:'about:blank',strName?strName:'',sF).focus();
}

function popUp(URL, ancho, alto) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+ancho+",height="+alto+",left = 272,top = 224');");
}

function popUpCenter(URL, ancho, alto) {
	var winl = (screen.width-ancho)/2;
	var wint = (screen.height-alto)/2;
	var settings;
		
	day = new Date();
	id = day.getTime();

	settings ='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,';
	settings +='height='+alto+',';
	settings +='width='+ancho+',';
	settings +='top='+wint+',';
	settings +='left='+winl;

	eval("page" + id + " = window.open(URL, '" + id + "', '" + settings + "');");
}

function popUpModalCenter(url, name, width, height){
	var winl = (screen.width-width)/2;
	var wint = (screen.height-height)/2;

	var features = '';
	features += " dialogWidth:"+width+"px;";
	features += " dialogHeight:"+height+"px;";
	features += " dialogTop:"+wint+"px;";
	features += " dialogLeft:"+winl+"px;";
	features += " edge: Raised;";
	features += " center: Yes;";
	features += " help: No;";
	features += " resizable: No;";
	features += " status: No;";
	
	var rtnEditarComisionista = showModalDialog(url, name, features);
}

function popUpModalCenterScroll(url, name, width, height){
	var winl = (screen.width-width)/2;
	var wint = (screen.height-height)/2;

	var features = '';
	features += " dialogWidth:"+width+"px;";
	features += " dialogHeight:"+height+"px;";
	features += " dialogTop:"+wint+"px;";
	features += " dialogLeft:"+winl+"px;";
	features += " edge: Raised;";
	features += " center: Yes;";
	features += " help: No;";
	features += " resizable: No;";
	features += " status: No;";
	
	var rtnEditarComisionista = showModalDialog(url, name, features);
}

function popUpCenterScroll(URL, ancho, alto) {
	var winl = (screen.width-ancho)/2;
	var wint = (screen.height-alto)/2;
	var settings;
		
	day = new Date();
	id = day.getTime();

	settings ='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,';
	settings +='height='+alto+',';
	settings +='width='+ancho+',';
	settings +='top='+wint+',';
	settings +='left='+winl;

	eval("page" + id + " = window.open(URL, '" + id + "', '" + settings + "');");
}

function sacarIndex(obj, valor){
	var longitud = obj.length;
	var i=0;
	for(i=0;i<longitud;i++){
		if(obj.options[i].value == valor){
	      break;
	   }
	}
	return i;	
}

function smodal(ventana,nomEmpresa){
	var retornoOperacion = showModalDialog(ventana, nomEmpresa, "dialogHeight:550px; dialogWidth:600px; help:no");

	if(retornoOperacion){
		//posiciono el indice de cmbRubro
    	document.frmOfertas.cmbRubro.options.selectedIndex = sacarIndex(document.frmOfertas.cmbRubro,retornoOperacion[0]);
		//cargo los valores de Clase en cmbGrupo
		cargarClase(document.frmOfertas.cmbRubro.value);
		
		//posiciono el indice de cmbGrupo
		document.frmOfertas.cmbGrupo.options.selectedIndex = sacarIndex(document.frmOfertas.cmbGrupo,retornoOperacion[1]);
		//cargo los valores de Clase en cmbCategori
		cargarCategoria(document.frmOfertas.cmbRubro.value,document.frmOfertas.cmbGrupo.value)
		
		//posiciono el indice de cmbCategoria
    	document.frmOfertas.cmbCategoria.options.selectedIndex = sacarIndex(document.frmOfertas.cmbCategoria,retornoOperacion[2]);

		document.frmOfertas.txtNombre.value = retornoOperacion[3];
		document.frmOfertas.txtDescripcion.value = retornoOperacion[4];
	}
}

function mandar(index){
	//dimensiono un array
	var vector = new Array();
	//asigno los valores de los hidden al array
    vector[0] = document.forms[index].hdnRubro.value;
    vector[1] = document.forms[index].hdnGrupo.value;
	vector[2] = document.forms[index].hdnCategoria.value;
	vector[3] = document.forms[index].hdnNombre.value;
	vector[4] = document.forms[index].hdnDescripcion.value;
	
    //retorno el array
	window.returnValue=vector;
    window.close();
}



function Salir(){
	window.opener.document.frmEmpresa.hdnRubroCod.value = document.frmOfertas.hdnRubroCod.value;
	window.opener.document.frmEmpresa.hdnGrupoCod.value = document.frmOfertas.hdnGrupoCod.value;
	window.opener.document.frmEmpresa.hdnCategoriaCod.value = document.frmOfertas.hdnCategoriaCod.value;
	close();
}
