//FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,
//             UseParensForNegativeNumbers, GroupDigits)
//======================================================================


function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "." + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

function VerificarSelecciones()
{
	var i;
	var objSel;
	elementosSeleccion=new Array(3);
	elementosSeleccion[0]="tipoOferta";
	elementosSeleccion[1]="tipoInmueble";
	elementosSeleccion[2]="precio";
	for(i=0;i<elementosSeleccion.length;i++)
	{
		//alert(elementosSeleccion[i]);
		
		//alert(document.getElementById(elementosSeleccion[i]));
		objSel=document.getElementById(elementosSeleccion[i]);
		if (objSel && objSel.value<=-1)
		{
			alert("Es necesario llevar a cabo todos los pasos previamente.");
			return false;
			break;
		}
	}
	return true;
}

/*
var preciosTipoInmueble=new Array(5);
preciosTipoInmueble[1]=new Array(5);
preciosTipoInmueble[1][1]=500;
preciosTipoInmueble[1][2]=2*500;
preciosTipoInmueble[1][3]=3*500;
preciosTipoInmueble[1][4]=4*500;
preciosTipoInmueble[2]=new Array(5);
preciosTipoInmueble[2][1]=500;
preciosTipoInmueble[2][2]=2*500;
preciosTipoInmueble[2][3]=3*500;
preciosTipoInmueble[2][4]=4*500;
preciosTipoInmueble[3]=new Array(5);
preciosTipoInmueble[3][1]=500;
preciosTipoInmueble[3][2]=2*500;
preciosTipoInmueble[3][3]=3*500;
preciosTipoInmueble[3][4]=4*500;
preciosTipoInmueble[4]=new Array(5);
preciosTipoInmueble[4][1]=500;
preciosTipoInmueble[4][2]=2*500;
preciosTipoInmueble[4][3]=3*500;
preciosTipoInmueble[4][4]=4*500;
document.write(preciosTipoInmueble[1][2]);
*/
function cambiarPreciosSeleccion(id, tipo)
{

	var nTipos=5; //>> nϊmero de tipos de elementos (inmuebles)
	var nPrecios=10;  //>> nϊmero de precios a mostrar
	var objeto=document.getElementById(id);
	var preciosTipoInmueble=new Array(nTipos);
		
	var precioBase, incrementoPrecio;
	var i,j;
	i=0;
	j=0;
	//>> Sin tipo
	
	if (tipo==-1)
	{
		objeto.length=0; //>> Vaciamos la lista
		objeto.options[0]=new Option("Seleccione una Oferta", -1);
		return;	
	}
	else
	{
	//>> Tipo venta
	if (tipo==1)
	{
		precioBase=100000;
		incremento=50000;
	}
	//>> Tipo alquiler
	else if (tipo==2)
	{
		precioBase=150;
		incremento=100;
	}
	//>> Tipo traspaso
	else if (tipo==3)
	{
		precioBase=10000;
		incremento=5000;
	}
	//>> Tipo compartir
	else if (tipo==4)
	{
		precioBase=100;
		incremento=100;
	}
	
	for(i=0;i<nTipos;i++)
	{
		preciosTipoInmueble[i]=new Array(nPrecios);
		for(j=0;j<nPrecios;j++)
		    preciosTipoInmueble[i][j]=new Option("  Hasta "+ FormatNumber(precioBase+incremento*j,0,0,0,1) +"  ", (precioBase+incremento*j));
		//alert(i);
		
	preciosTipoInmueble[i][j]=new Option("  Mαs de "+ FormatNumber(precioBase+incremento*(j-1),0,0,0,1) +" ", 0);
	//preciosTipoInmueble[i][j]=new Option("Vicentin", 0);
	}

	objeto.length=0; //>> Vaciamos la lista
		for(j=0;j<nPrecios;j++)
		{
			objeto.options[nPrecios-j]=preciosTipoInmueble[tipo-1][j];
			//alert(objeto.options[j].value);
		}
		
			objeto.options[nPrecios-j]=preciosTipoInmueble[tipo-1][j];
		
		objeto.options[nPrecios-j].selected=true;

/*
	preciosTipoInmueble[1]=new Array(5);
	preciosTipoInmueble[1][1]=new Option("Hasta 500 ", "500","defaultSelected");
	preciosTipoInmueble[1][2]=new Option("Hasta 1000 ", "1000");
	preciosTipoInmueble[1][3]=new Option("Hasta 1500 ", "1500");
	preciosTipoInmueble[1][4]=new Option("Hasta 2000 ", "2000");
	preciosTipoInmueble[2]=new Array(5);
	preciosTipoInmueble[2][1]=new Option("Hasta 500 ", "500","defaultSelected");
	preciosTipoInmueble[2][2]=new Option("Hasta 1000 ", "1000");
	preciosTipoInmueble[2][3]=new Option("Hasta 1500 ", "1500");
	preciosTipoInmueble[2][4]=new Option("Hasta 2000 ", "2000");
	preciosTipoInmueble[3]=new Array(5);
	preciosTipoInmueble[3][1]=new Option("Hasta 500 ", "500","defaultSelected");
	preciosTipoInmueble[3][2]=new Option("Hasta 1000 ", "1000");
	preciosTipoInmueble[3][3]=new Option("Hasta 1500 ", "1500");
	preciosTipoInmueble[3][4]=new Option("Hasta 2000 ", "2000");
	preciosTipoInmueble[4]=new Array(5);
	preciosTipoInmueble[4][1]=new Option("Hasta 500 ", "500","defaultSelected");
	preciosTipoInmueble[4][2]=new Option("Hasta 1000 ", "1000");
	preciosTipoInmueble[4][3]=new Option("Hasta 1500 ", "1500");
	preciosTipoInmueble[4][4]=new Option("Hasta 2000 ", "2000");
*/
	//preciosTipoInmueble[1]=new Option("dfgsdfgsdfgsdf", "!!!","defaultSelected");
/*
	objeto.options[1]=preciosTipoInmueble[tipo][2];
	objeto.options[2]=preciosTipoInmueble[tipo][3];
	objeto.options[3]=preciosTipoInmueble[tipo][4];
*/
}
}

function cambiarTiposOferta(id, tipo)
{
	var objeto=document.getElementById(id);
			
	var i;
	i=0;
		
	//>> Sin tipo
	if (tipo==-1)
	{
		objeto.length=0; //>> Vaciamos la lista
		objeto.options[0]=new Option("Seleccione un Inmueble", -1);
		return;		
	}
	else
	{
	//>> Tipo Obra nueva
		if (tipo==9)
		{	
			objeto.length=0;
			for(i=1;i<ofertasObraNueva.length+1;i++)
			{
				objeto.options[i-1] = ofertasObraNueva[i-1];
			}
		}
	//>> Otro tipo
		else
		{
			objeto.length=0;
			for(i=1;i<(ofertas2Mano.length)+1;i++)
			{
				objeto.options[i-1] = ofertas2Mano[i-1];
			}
		}
	}
}
