// JavaScript Document
/*function MenuVenta(Idioma){
  if(Idioma == 1)
  	var Texto = "[Opcional]";
  else
  	var Texto = "[Optional]";
  sub0=new Option(Texto,"0-100000000000000","defaultSelected");
  sub1=new Option("$500,000 - $1,000,000","500000-1000000");
  sub2=new Option("$1,000,001 - $2,000,000","1000001-2000000");
  sub3=new Option("$2,000,001 - $3,000,000","2000001-3000000");
  sub4=new Option("$3,000,001 - $4,000,000","3000001-4000000");
  sub5=new Option("$4,000,001 - $5,000,000","4000001-5000000");
  sub6=new Option("Mayor a $5,000,000","5000001-100000000000000");
  document.forms[0].Precio.options[0]=sub0;
  document.forms[0].Precio.options[1]=sub1;
  document.forms[0].Precio.options[2]=sub2;
  document.forms[0].Precio.options[3]=sub3;
  document.forms[0].Precio.options[4]=sub4;
  document.forms[0].Precio.options[5]=sub5;
  document.forms[0].Precio.options[6]=sub6;
  //alert(tab);
 }
 
function MenuRenta(Idioma){
   if(Idioma == 1)
  	var Texto = "[Opcional]";
  else
  	var Texto = "[Optional]";
  sub0=new Option(Texto,"0-100000000000000","defaultSelected");
  sub1=new Option("$5,000 - $10,000","5000-10000");
  sub2=new Option("$10,001 - $20,000","10001-20000");
  sub3=new Option("$20,001 - $30,000","20001-30000");
  sub4=new Option("$30,001 - $40,000","30001-40000");
  sub5=new Option("$40,001 - $50,000","40001-50000");
  sub6=new Option("Mayor a $50,000","50001-100000000000000");
  document.forms[0].Precio.options[0]=sub0;
  document.forms[0].Precio.options[1]=sub1;
  document.forms[0].Precio.options[2]=sub2;
  document.forms[0].Precio.options[3]=sub3;
  document.forms[0].Precio.options[4]=sub4;
  document.forms[0].Precio.options[5]=sub5;
  document.forms[0].Precio.options[6]=sub6;
  //alert(tab);
 }
 
 function combo(Idioma){
   var indice=document.forms[0].Operacion.selectedIndex;
   //alert(indice);
   if(indice==1) MenuVenta(Idioma);
   if(indice==2) MenuRenta(Idioma);
   //if(indice==3) menu3();
 }  */
 
 function MenuDefault(Idioma, Price){ //alert(Price);
  //alert(Price);
  //objCombo.Limpiar(document.getElementById('Select1'));
  $('#cmbPrecio').empty();
  if(Idioma == 1)
  	var Texto = "[Todos]";
  else
  	var Texto = "[Optional]";
  //alert("sasas");
  var oGroup = document.createElement('optgroup'); 
  var oSelect = document.getElementById('cmbPrecio'); 
  var oOption = document.createElement('option'); 
  oOption.value = "";
  oOption.innerHTML = "[Todos]"; 
  oSelect.appendChild(oOption);
  oGroup.label = 'Venta';  
  var oOption = document.createElement('option'); 
  oOption.value = "V-500000-1000000";
  oOption.innerHTML = "$500,000 - $1,000,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "V-1000001-2000000";
  oOption.innerHTML = "$1,000,001 - $2,000,000 MN"; 
  oGroup.appendChild(oOption);   
  oSelect.appendChild(oGroup); 
  /*oOption.value = "1000001-2000000";
  oOption.innerHTML = "$1,000,001 - $3,000,000"; 
  oGroup.appendChild(oOption);   
  oSelect.appendChild(oGroup); */
  var oOption = document.createElement('option'); 
  oOption.value = "V-2000001-3000000";
  oOption.innerHTML = "$2,000,001 - $3,000,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "V-3000001-4000000";
  oOption.innerHTML = "$3,000,001 - $4,000,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "V-4000001-5000000";
  oOption.innerHTML = "$4,000,001 - $5,000,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "V-5000001-100000000000000";
  oOption.innerHTML = "Mayor a $5,000,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  
   /*************Renta************************/
  var oGroup = document.createElement('optgroup'); 
  var oSelect = document.getElementById('Select1'); 
  oGroup.label = 'Renta';   
  var oOption = document.createElement('option'); 
  oOption.value = "R-5000-10000";
  oOption.innerHTML = "$5,000 - $10,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "R-10001-20000";
  oOption.innerHTML = "$10,001 - $20,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "R-20001-30000";
  oOption.innerHTML = "$20,001 - $30,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "R-30001-40000";
  oOption.innerHTML = "$30,001 - $40,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "R-40001-50000";
  oOption.innerHTML = "$40,001 - $50,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  var oOption = document.createElement('option'); 
  oOption.value = "R-50001-100000000000000";
  oOption.innerHTML = "Mayor a $50,000 MN"; 
  oGroup.appendChild(oOption);
  oSelect.appendChild(oGroup);
  //alert(Price);
  setTimeout('EstableceOpcion("#cmbPrecio", "'+Price+'")', 2000);  	
  // append the option group
 }
 
 function EstableceOpcion(Elemento, Valor){
	  $(Elemento).val(Valor);	 
 }
 
 function MenuVenta(Idioma, Price, Forma){
  if(Idioma == 1)
  	var Texto = "[Todos]";
  else
  	var Texto = "[Optional]";
  //Compara = document.forms[Forma].Precio.value;
 //alert("entre");
 $("#cmbPrecio").empty();
  sub0=new Option(Texto,"0-100000000000000",ValidarSeleccion("0-100000000000000", Price));
  sub1=new Option("Menor a $500,000 MN ","0-499999", ValidarSeleccion("0-499999", Price));
  sub2=new Option("$500,000 - $1,000,000 MN","500000-1000000", ValidarSeleccion("500000-1000000", Price));
  sub3=new Option("$1,000,001 - $2,000,000 MN","1000001-2000000", ValidarSeleccion("1000001-2000000", Price));
  sub4=new Option("$2,000,001 - $3,000,000 MN","2000001-3000000", ValidarSeleccion("2000001-3000000", Price));
  sub5=new Option("$3,000,001 - $4,000,000 MN","3000001-4000000", ValidarSeleccion("3000001-4000000", Price));
  sub6=new Option("$4,000,001 - $5,000,000 MN","4000001-5000000", ValidarSeleccion("4000001-5000000", Price));
  sub7=new Option("Mayor a $5,000,000 MN","5000001-100000000000000", ValidarSeleccion("5000001-100000000000000", Price));  
  document.getElementById('cmbPrecio').options[0]=sub0;
  document.getElementById('cmbPrecio').options[1]=sub1;
  document.getElementById('cmbPrecio').options[2]=sub2;
  document.getElementById('cmbPrecio').options[3]=sub3;
  document.getElementById('cmbPrecio').options[4]=sub4;
  document.getElementById('cmbPrecio').options[5]=sub5;
  document.getElementById('cmbPrecio').options[6]=sub6;
  document.getElementById('cmbPrecio').options[6]=sub7;
   $('#cmbPrecio').val(Price);
  //alert(tab);
 }
 
function MenuRenta(Idioma, Price, Forma){
   if(Idioma == 1)
  	var Texto = "[Todos]";
  else
  	var Texto = "[Optional]";
	//alert(Price);
 $("#cmbPrecio").empty();
  sub0=new Option(Texto,"0-100000000000000",ValidarSeleccion("0-100000000000000", Price));
  sub1=new Option("Menor a $5,000 MN","0-4999",ValidarSeleccion("0-4999", Price));
  sub2=new Option("$5,000 - $10,000 MN","5000-10000",ValidarSeleccion("5000-10000", Price));
  sub3=new Option("$10,001 - $20,000 MN","10001-20000",ValidarSeleccion("10001-20000", Price));
  sub4=new Option("$20,001 - $30,000 MN","20001-30000",ValidarSeleccion("20001-30000", Price));
  sub5=new Option("$30,001 - $40,000 MN","30001-40000",ValidarSeleccion("30001-40000", Price));
  sub6=new Option("$40,001 - $50,000 MN","40001-50000",ValidarSeleccion("40001-50000", Price));
  sub7=new Option("Mayor a $50,000 MN","50001-100000000000000",ValidarSeleccion("50001-100000000000000", Price));
  document.getElementById('cmbPrecio').options[0]=sub0;
  document.getElementById('cmbPrecio').options[1]=sub1;
  document.getElementById('cmbPrecio').options[2]=sub2;
  document.getElementById('cmbPrecio').options[3]=sub3;
  document.getElementById('cmbPrecio').options[4]=sub4;
  document.getElementById('cmbPrecio').options[5]=sub5;
  document.getElementById('cmbPrecio').options[6]=sub6;
  document.getElementById('cmbPrecio').options[6]=sub7;
   $('#cmbPrecio').val(Price);
  //alert(tab);
 }
 
 function combo(Idioma, Price, Forma){
   //alert(Forma);
   //var indice2=document.forms[0].Operacion.selectedIndex;
   //alert(indice2);
  $('#cmbPrecio').empty();
  var valor = $("#cmbOperacion").val();;
   //alert(indice);
   if(valor == "0") MenuDefault(Idioma, Price);
   if(valor == "Venta") MenuVenta(Idioma, Price, Forma);
   if(valor == "Renta") MenuRenta(Idioma, Price, Forma);
   //if(indice==3) menu3();
 } 
 
 function combo2(Idioma, Price, Forma){
   //alert(Forma);
   //var indice2=document.forms[0].Operacion.selectedIndex;
   //alert(indice2);
  $('#Select1').empty();
  var indice=document.forms[Forma].Operacion.selectedIndex;
   //alert(indice);
   if(indice==0) MenuDefault(Idioma, Price);
   if(indice==1) MenuVenta(Idioma, Price, Forma);
   if(indice==2) MenuRenta(Idioma, Price, Forma);
   //if(indice==3) menu3();
 } 
 
  function ValidarSeleccion(Cadena1, Cadena2){
	 if(Cadena1 == Cadena2)
	 	return "defaultSelected";
	else
		return "";
}

function CambiaFoto(RutaImagen){ //alert(RutaImagen);
	$("img#FotoPrincipal").attr("src", RutaImagen);
}

function FormatoDinero(cantidad){
	Cadena = cantidad.split(".");

	Val = Cadena[0];//Enteros
	Val = String(Val);
	Val2 = Cadena[1];//Decimales
	
	for(i=0;i<Val.length;i++)
		Val = Val.replace(",","");
	if(Val2)
		for(i=0;i<Val2.length;i++)
			Val2 = Val2.replace(",","");

    Val = "" + Val;
    var output = "";  // inicializo variable de salida
    for (var i=0; i < Val.length; i++) {//inicio for
      if (i != 0 && (Val.length - i) % 3 == 0) output += ",";
      output += Val.charAt(i);
    }//fin for
    if(!Val2){
   		Val = output;
		return Val;
	}
   	else{
		//Dec = "0."+Cadena[1];
		//Dec = parseFloat(Dec);
		//Dec = RedondeaDecimales(Dec, 2);		
		//Dec = String(Dec);
		//CharDec = Dec.charAt(2) + Dec.charAt(3);		
		Dec = Cadena[1];
		if(Dec.length>2)
			CharDec = Dec.charAt(0) + Dec.charAt(1);
		else
			CharDec = Dec;
		Salida = output + "."+CharDec;
		return Salida;
	}
}

function LlenarPorcentaje(PO, P, indice){
         var Elemento;

         if (PO == "")
             PO = 100;
         if (P == "")
             P = 30;

         for (var i = 0; i < document.form1.length; i++){
              Elemento = document.form1.elements[i];
              if (Elemento.type.slice(0,6) == 'select'){
                  if (Elemento.name == 'PorcentajeOriginal['+ indice +']'){
                      LlenarConNumeros(Elemento, 1, 100, false, PO*1);
                  }else{
                      if(Elemento.name == 'Porcentaje['+ indice +']')
                         LlenarConNumeros(Elemento, 1, 100, false, P*1);
                  }
              }
         }
}

function LlenarPorcentaje2(PO, P){
         var Elemento;
		 var indice = 0;
         if (PO == "")
             PO = 100;
         if (P == "")
             P = 30;
				
         for (var i = 0; i < document.form1.length; i++){
              Elemento = document.form1.elements[i];
              if (Elemento.type.slice(0,6) == 'select'){	
                  if (Elemento.name == 'NuevoPorcentajeOriginal[' + indice + ']'){
                      LlenarConNumeros(Elemento, 1, 100, false, PO*1);
                  }else{
                      if(Elemento.name == 'NuevoPorcentaje[' + indice + ']')
                         LlenarConNumeros(Elemento, 1, 100, false, P*1);
                  }
              }
         }
}

function EliminarBotonFoto(IdFoto){
         document.form1.EliminarFoto.value = IdFoto;
         document.form1.submit();
}

function EliminarProducto(){
         if (confirm("¿Está seguro de eliminar este producto?")){
             document.form1.ControlEliminar.value=1;
             document.form1.submit();
         }
}

function MuestraRyV(){
	//alert(Nombre);
	var Checkbox = document.form1.RyV;
	//alert(Checkbox);
	var TablaRyV = document.getElementById("RyV_T");	
	
	if(Checkbox.checked == true)
		TablaRyV.style.display = 'block';
	else
		TablaRyV.style.display = 'none';	
	
}

function MuestraJaus(){
	//alert(Nombre);
	var Checkbox = document.form1.Jaus;
	//alert(Checkbox);	
	var TablaJaus = document.getElementById("Jaus_T");	
	
	if(Checkbox.checked == true)
		TablaJaus.style.display = 'block';
	else
		TablaJaus.style.display = 'none';	
	
}

function MuestraExterno(){
	//alert(Nombre);
	var Checkbox = document.form1.Externo;
	//alert(Checkbox);	
	var TablaExterno = document.getElementById("Externo_T");	
	
	if(Checkbox.checked == true)
		TablaExterno.style.display = 'block';
	else
		TablaExterno.style.display = 'none';	
	
}

function MuestraErp(){
	//alert(Nombre);
	var Checkbox = document.form1.Erp;
	//alert(Checkbox);	
	var TablaErp = document.getElementById("Erp_T");	
	
	if(Checkbox.checked == true)
		TablaErp.style.display = 'block';
	else
		TablaErp.style.display = 'none';	
	
}

function MuestraCrm(){
	//alert(Nombre);
	var Checkbox = document.form1.Crm;
	//alert(Checkbox);	
	var TablaCrm = document.getElementById("Crm_T");	
	
	if(Checkbox.checked == true)
		TablaCrm.style.display = 'block';
	else
		TablaCrm.style.display = 'none';	
	
}

function MuestraBic(){
	//alert(Nombre);
	var Checkbox = document.form1.Bic;
	//alert(Checkbox);	
	var TablaBic = document.getElementById("Bic_T");	
	
	if(Checkbox.checked == true)
		TablaBic.style.display = 'block';
	else
		TablaBic.style.display = 'none';	
	
}


