﻿// JScript File
  // width to resize large images to
var maxWidth=100;
  // height to resize large images to
var maxHeight=100;
  // valid file types
var fileTypes=["bmp","gif","png","jpg","jpeg"];
  // the id of the preview image tag
var outImage="previewField";
  // what to display when the image is not valid
var defaultPic="spacer.gif";

/***** DO NOT EDIT BELOW *****/

function preview(what){
  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  globalPic=new Image();
  if (i<fileTypes.length) globalPic.src=source;
  else {
    globalPic.src=defaultPic;
    alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
  }
  setTimeout("applyChanges()",200);
}
var globalPic;
function applyChanges(){
  var field=document.getElementById(outImage);
  var x=parseInt(globalPic.width);
  var y=parseInt(globalPic.height);
  if (x>maxWidth) {
    y*=maxWidth/x;
    x=maxWidth;
  }
  if (y>maxHeight) {
    x*=maxHeight/y;
    y=maxHeight;
  }
  field.style.display=(x<1 || y<1)?"none":"";
  field.src=globalPic.src;
  field.width=x;
  field.height=y;
}
// JScript File
var oldgridSelectedColor;

function setMouseOverColor(element)
{
    oldgridSelectedColor = element.style.backgroundColor;
    element.style.backgroundColor='#FFE188';//color onmouseover
   // element.style.cursor='hand';
   // element.style.textDecoration='underline';
}

function setMouseOutColor(element)
{
    element.style.backgroundColor=oldgridSelectedColor;
    element.style.textDecoration='none'; //mouseoute #E9E9E9
}

    function addEvent(obj ,evt, fnc)
      {
        if (obj.addEventListener)
          obj.addEventListener(evt,fnc,false);
        else if (obj.attachEvent)
          obj.attachEvent('on'+evt,fnc);
        else
          return false;
        return true;
      }

      function removeEvent(obj ,evt, fnc)
      {
        if (obj.removeEventListener)
          obj.removeEventListener(evt,fnc,false);
        else if (obj.detachEvent)
          obj.detachEvent('on'+evt,fnc);
        else
          return false;
        return true;
      }

      //----------

      function appendElement(node,tag,id,htm)
      {
        var ne = document.createElement(tag);
        if(id) ne.id = id;
        if(htm) ne.innerHTML = htm;
        node.appendChild(ne);
      }
           function hidePopup(p)
      {
        greyout(false);
        document.getElementById(p).style.display = 'none';
      }

      //----------

      function greyout(d,z)
      {
        var obj = document.getElementById('greyout');
        if(!obj)
        {
          appendElement(document.body,'div','greyout');
          obj = document.getElementById('greyout');
          obj.style.position = 'absolute';
          obj.style.top = '0px';
          obj.style.left = '0px';
          obj.style.background = '#111';
          obj.style.opacity = '.5';
          obj.style.filter = 'alpha(opacity=50)';
        }
        if(d)
        {
          if(!z){ z - 50 }
          obj.style.zIndex = z;
          obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight);
          obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth);
         
          obj.style.display = 'block';
          addEvent(window,'resize',greyoutResize);
        }
        else
        {
          obj.style.display = 'none';    
          removeEvent(window,'resize',greyoutResize);
        }
      }
      
      function greyoutResize()
      {
        var obj = document.getElementById('greyout');
        obj.style.height = document.body.clientHeight+'px';
        obj.style.width  = document.body.clientWidth+'px';
        obj.style.height = Math.max(document.body.scrollHeight,document.body.clientHeight)+'px';
        obj.style.width  = Math.max(document.body.scrollWidth,document.body.clientWidth)+'px';
     
      }
    
      //----------
      
       //// Ventanas Modales //////
    /// Mostrar Detallle////
    /// Parametros  
    ///p (Popup)
    ///Ventana (Archivo a Mostrar)
    // Id (Parametro de Buqueda///
    
    /// Mostrar Popup Orden///
    //Parametros
    //p (Popup)
     // Ventana (Archivo a Mostrar)
    //Orden (Parametro Busqueda)
    /// Mostrar Popup Ventanas///
    //Parametros
    //p (Popup)
     // Ventana (Archivo a Mostrar)
      function showPopupImagen(p,id)
      {
        //greyout(true);
         var MyArgs = new Array("1");
        var WinSettings = "center:yes;resizable:no;dialogHeight:500px;dialogWidth:520px"
        var vMS=window.showModalDialog("../Sitio/ImagenDetalle.aspx?op=Prod&id="+id, MyArgs, WinSettings);
       if (vMS) { 
            greyout(false);
            }
        
      }
      
       function showModalImagen(p,id,Prov)
      {
        //greyout(true);
         var MyArgs = new Array("1");
        var WinSettings = "center:yes;resizable:no;dialogHeight:600px;dialogWidth:520px"
        var vMS=window.showModalDialog("ImagenDetalle.aspx?op=Prov&id="+id+"&iProv="+Prov, MyArgs, WinSettings);
       if (vMS) { 
            greyout(false);
            }
        
      }
       function showPopupModificarOrden(Ventana,Id,Ejercicio)
      {
      window.open(Ventana+'ID='+Id+'&Ejercicio='+Ejercicio, 'dispwin1','width=850,height=900,scrollbars=yes,menubar=no');
    //  window.location.href=Ventana+'ID='+Id+'&Ejercicio='+Ejercicio;
      }
      
      function showPopupModificarProducto(Ventana,Id)
      {
      window.open(Ventana+'ID='+Id, 'dispwin1','width=550,height=350,scrollbars=yes,menubar=no');
      }
      function showPopuAddProducto(busqueda,filtro){
       window.open('ModProductoProveedor.aspx?op=Add&busqueda='+busqueda+'&filtro='+filtro, 'dispwin1','width=600,height=400,scrollbars=yes,menubar=no');
      }
      
      function showImagenProductoProveedor(id,prod)
      {
        
      window.open("UploadImageByProduct.aspx?id="+id+"&prod="+prod, 'dispwin1','width=600,height=500,scrollbars=yes,menubar=no');
    
      }
      function showImagenProductoGaleria(id,prod)
      {
        
      window.open("ImagenGaleria.aspx?id="+id+"&prod="+prod, 'dispwin1','width=600,height=500,scrollbars=yes,menubar=no');
    
      }
      function showModificarProductoProveedor(id)
      {
        
      window.open("ModProductoProveedor.aspx?op=Mod&id="+id, 'dispwin1','width=600,height=400,scrollbars=yes,menubar=no');
     
      }
      
      function showPopupModificarAccesos(Ventana,Id)
      {
      window.open(Ventana+'ID='+Id, 'dispwin1','width=750,height=600,scrollbars=yes,menubar=no');
      }
     
      
       
      
    
     
 
   function SelectAll(id) {
        var frm = document.forms[0];
        for (i=0;i<frm.elements.length;i++) {
            if (frm.elements[i].type == "checkbox") {
                frm.elements[i].checked = document.getElementById(id).checked;
            }
        }
    } 
     function expandcollapse(obj,row)
    {
        var div = document.getElementById(obj);
        var img = document.getElementById('img' + obj);
        
        if (div.style.display == "none")
        {
            div.style.display = "block";
            if (row == 'alt')
            {
               img.src = "../images/minus.gif";
            }
            else
            {
                img.src = "../images/minus.gif";
            }
            img.alt = "Ocultar Detalle";
        }
        else
        {
            div.style.display = "none";
            if (row == 'alt')
            {
                 img.src = "../images/plus.gif";
            }
            else
            {
                 img.src = "../images/plus.gif";
            }
            img.alt = "Mostrar Detalle";
        }
    }
    
    function ClosePopup(){
     window.close();
    }
    function ClosePupopReload(){
     self.opener.location=self.opener.location.href;
      self.close();     
    }
    function CloseAndRelocate(Ventana){
      window.opener.location.href=Ventana;
      self.close();
    }
   		function KeySortDropDownList_onkeypress (dropdownlist,caseSensitive) {
  // check the keypressBuffer attribute is defined on the dropdownlist
  var undefined; 
  if (dropdownlist.keypressBuffer == undefined) { 
    dropdownlist.keypressBuffer = ''; 
  } 
  // get the key that was pressed 
  var key = String.fromCharCode(window.event.keyCode); 
  dropdownlist.keypressBuffer += key;
  if (!caseSensitive) {
    // convert buffer to lowercase
    dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
  }
  // find if it is the start of any of the options 
  var optionsLength = dropdownlist.options.length; 
  for (var n=0; n < optionsLength; n++) { 
    var optionText = dropdownlist.options[n].text; 
    if (!caseSensitive) {
      optionText = optionText.toLowerCase();
    }
    if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
      dropdownlist.selectedIndex = n; 
      return false; // cancel the default behavior since 
                    // we have selected our own value 
    } 
  } 
  // reset initial key to be inline with default behavior 
  dropdownlist.keypressBuffer = key; 
  return true; // give default behavior 
}

function ValidateCheck(id) {
        var frm = document.forms[0];
        for (i=0;i<frm.elements.length;i++) {
            if (frm.elements[i].type == "checkbox") {
               if(!frm.elements[i].checked){
                 alert('Debes Seleccionar Opcion Activar Todos \n Para Activar Uno o Mas Productos');
                 return false;
               }else{
                  return true;
               }
            }
        }
        
    }
		
		
		
		

     






   
      
      



