//** Para que las páginas siempre tengan los marcos **//

//Función que llama a la index si no están los marcos cargados
function CargarIndex()
{
    if (frameElement == null)//solo si no están cargados los frames
    {
        var CurrentPage = document.location.pathname;
        var ja = new Array(); 

        ja = CurrentPage.split("/"); 
        
        var cont = new Number();
      //  cont = ja.length - 3; //para que funcione en local
          cont = ja.length - 2;
        var ruta = "";
        while (cont != 0)
        {
            ruta = ruta + "../";
            cont = cont - 1;
        }
        var index = window.open(ruta + "index.html?frame_contenido=" + CurrentPage, "_self");
    }
} 

//Función que se llama desde la index
function CargarFrames()
{
    var url = location.href;
    var index = url.indexOf("=");
    if (index != -1){
        var pagina = url.substring(index + 1,url.length);        
        window.parent.Contenido.location.reload(pagina);
    }
}

//******************** Función para comprobar que un mail sea válido ********************

function CompruebaMail(ValueMail) {

  var reMail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

  if (reMail.test(ValueMail)) {

    return true;

  } else {

    alert("' " + ValueMail + " '\nno es una dirección de correo válida.");
    return false;

  }

}

//**************** Función para comprobar que un campo no esté en blanco ****************

function CompruebaBlanco(NombreCampo, ValueCampo) {

  if (ValueCampo == "") {

    alert("El campo ' " + NombreCampo + " ' es obligatorio");
    return false;

  } else {

    return true;

  }

}


//****************************** Función para abrir las FOTOS *******************************

function VerFoto (strRuta, strFileName, Nombre_Foto, stAncho, stAlto)	{
    
    
    //var stMyURL = "../../files/images/DB/Productos/" + strFileName;
    var stMyURL = strRuta + "files/images/DB/Productos/" + strFileName;
    
    var img = new Image();	
	img.src = stMyURL;
	
    var Ancho, Alto;
    
    Ancho = parseInt(stAncho);
    Alto = parseInt(stAlto);

    if (Ancho>640) Ancho=640;
    if (Alto>640)  Alto=640;

    var CoordenadaX = (screen.width - Ancho) / 3;
    var CoordenadaY = (screen.height - Alto) / 3;

	var Propiedades = 'width=' + Ancho + ',height=' + Alto + ',top=' + CoordenadaY + ',left=' + CoordenadaX;
  
	var win = window.open('', '', Propiedades);
	var doc = win.document;
	doc.open();		
//	win.document.write("<html><head><title>" + Nombre_Foto + "</title></head><body background='" + stMyURL +"' style='background-repeat:no-repeat;'></body></html>");
	win.document.write("<html><head><title>"
	                    + Nombre_Foto + 
	                    "</title></head><body><img name='imagen' align='top' alt='Producto' src='" 
	                    + stMyURL + 
	                    "' ></body></html>");
	//doc.imagen.reload();
	
	win.document.close();
	
}
//************************** Función para que el TreeView se muestre en el nodo seleccionado **************************

    function LoadEvent()
    { 
        try 
        {   
            var elem = document.getElementById("ctl00_cphMain_tvwFamilias_SelectedNode");   
            if(elem != null )   
            {     
                var node = document.getElementById(elem.value);     
                if(node != null)     
                {       
                    node.scrollIntoView(true);       
                    ctl00_cphMain_pnlTree_Familias.scrollLeft = 0;     
                }   
            } 
        } 
        catch(oException) 
        {}
    }
    // -->
    
//** Registro de visitas **//
    
    function Analytics()
    {
        _uacct = "UA-2764353-1";
        urchinTracker();
}


//****************************** Función para abrir popup *******************************

function NuevaVentana (MyURL, MyNombre, Ancho, Alto, PosX, PosY, Botones, CampoURL, BarraEstado, MenuNavegador, Scrolls, Redimensionable) {

  if (PosX == "c") {
    var CoordenadaX = (screen.width - Ancho) / 2;
  } else {
    var CoordenadaX = PosX;
  }

  if (PosY == "c") {
    var CoordenadaY = (screen.height - Alto) / 2;
  } else {
    var CoordenadaY = PosY;
  }

  Propiedades = 'width=' + Ancho + ',height=' + Alto + ',top=' + CoordenadaY + ',left=' + CoordenadaX +
                ',toolbar=' + Botones + ',location=' + CampoURL + ',status=' + BarraEstado +
                ',menubar=' + MenuNavegador + ',scrollbars=' + Scrolls + ',resizable=' + Redimensionable;

  win = window.open(MyURL, MyNombre, Propiedades);

  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}

function Ventana (MyURL, MyNombre, Ancho, Alto) 
{
  var CoordenadaX = (screen.width - Ancho) / 2;

  var CoordenadaY = (screen.height - Alto) / 2;

  Propiedades = 'width=' + Ancho + ',height=' + Alto + ',top=' + CoordenadaY + ',left=' + CoordenadaX ;

  win = window.open(MyURL, MyNombre, Propiedades);

  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}

/****************************** Ventana Emergente **********************************/

function catswindows(mensaje,width,height,title) 
{
//PARAMETROS:
    // name, es la imagen que se va a poner de fondo en la página que se abrirá
    // width y height, las dimensiones que llegara a tener la ventana


// VARIABLES
    // winheight y winwidth las dimensiones que tendrá la ventana de un inicio

 var winheight=50
 var winwidth=50
 var cat=null

 step=1;
 
 // POSICION
 LeftPosition=(screen.width)?(screen.width-width)/2:100;
 TopPosition=(screen.height)?(screen.height-height)/2:100;
 
 if (document.layers)
  {paramstp="height="+height+",width="+width+",top="+TopPosition+
   ",left="+LeftPosition+",scrollbars=no,location=no"+
   ",directories=no,status=no,menubar=no,toolbar=no,resizable=no"}
 else
  {paramstp="height="+winheight+",width="+winwidth+",top="+TopPosition+
  ",left="+LeftPosition+",scrollbars=no,location=no"+
  ",directories=no,status=no,menubar=no,toolbar=no,resizable=no"}

 cat=window.open("","cat",paramstp);
   
// if (document.all)
//  {
   string="<html><title>"+title+"</title><body topmargin=0 leftmargin=0 bgcolor=#eeeeee>";
   //MIENTRAS SE CARGA
   string1="<div id=loadintxt style='position:absolute;width:100%;top:45%;visibility:visible;'></div>";
   //MENSAJE QUE SE LE PASA COMO PARAMETRO
   string2="<div id=errtxt>"+mensaje+"</div>";
   string3='</b'+'ody></h'+'tml>';


   cat.document.writeln(string);
   cat.document.writeln(string1);
   cat.document.writeln(string2);
   cat.document.writeln(string3);
   
   x=y=step;
   while (x | y)
   {
    cat.resizeBy (x, y);
	 if (cat.document.body.clientWidth >= width) x=0;
	 if (cat.document.body.clientHeight >= height) y=0;
   }

 return;
}

function CloseCatWin()
 {if(cat!=null && cat.open)cat.close()}
 
function VentanaPosicion(title,mensaje,
                        width,height,ID_elemento) 
{
//PARAMETROS:
    // name, es la imagen que se va a poner de fondo en la página que se abrirá
    // width y height, las dimensiones que llegara a tener la ventana


// VARIABLES
    // winheight y winwidth las dimensiones que tendrá la ventana de un inicio

 var winheight=50
 var winwidth=50
 var cat=null

 step=1;
 
 // POSICION
 //LeftPosition=(screen.width)?(screen.width-width)/2:100;
 //TopPosition=(screen.height)?(screen.height-height)/2:100;
 var elem = document.getElementById(ID_elemento);
// LeftPosition=25;//(screen.width)?(screen.width-width)/1:100;
// TopPosition=(screen.height)?(screen.height-height)/1:1;
  
 var Left=parseInt(elem.style.left);
 var Top=parseInt(elem.style.top);
 
LeftPosition =(Left)/1;
TopPosition=(Top)/1;


LeftPosition = (screen.width) ? (screen.width-width)/2 : 0; 
TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
 

 
  paramstp="height="+winheight+",width="+winwidth+",top="+TopPosition+",left="+LeftPosition;


 cat=window.open("","cat",paramstp);


   string="<html><title>"+title+"</title><body topmargin=0 leftmargin=0 bgcolor=#eeeeee>";
   string2="<div id=errtxt>"+mensaje+"</div>";
   string3='</b'+'ody></h'+'tml>';


   cat.document.writeln(string);
   cat.document.writeln(string2);
   cat.document.writeln(string3);
   
   x=y=step;
   while (x | y)
   {
    cat.resizeBy (x, y);
	 if (cat.document.body.clientWidth >= width) x=0;
	 if (cat.document.body.clientHeight >= height) y=0;
   }
 return;
}

//función para rotar imagenes
var slideCache = new Array();
function RunSlideShow(pictureName,imageFiles,displaySecs)
{
    var imageSeparator = imageFiles.indexOf(";");
    var nextImage = imageFiles.substring(0,imageSeparator);

    if (document.all)
    {
        document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
        document.getElementById(pictureName).filters.blendTrans.Apply();
    }
    document.getElementById(pictureName).src = nextImage;

    if (document.all)
    {
        document.getElementById(pictureName).filters.blendTrans.Play();
    }
    var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)
                                    + ';' + nextImage;

    setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"',"+displaySecs+")",
                                displaySecs*1000);
    // Caché la nueva imagen para mejorar el rendimiento.
    imageSeparator = futureImages.indexOf(";");
    nextImage = futureImages.substring(0,imageSeparator);
    if (slideCache[nextImage] == null) 
    {
        slideCache[nextImage] = new Image;
        slideCache[nextImage].src = nextImage;   
    }
}

//función para rotar imagenes y parpadear label
var slideCache_LV = new Array();
function RunSlideShow_LabelVisibility(pictureName,object_ID,imageFiles,displaySecs)
{
    var imageSeparator = imageFiles.indexOf(";");
    var nextImage = imageFiles.substring(0,imageSeparator);

    if (document.all)
    {
        document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
        document.getElementById(pictureName).filters.blendTrans.Apply();
    }
    document.getElementById(pictureName).src = nextImage;

    if (document.all)
    {
        document.getElementById(pictureName).filters.blendTrans.Play();
    }
    var futureImages= imageFiles.substring(imageSeparator+1,imageFiles.length)
                                    + ';' + nextImage;

    setTimeout("RunSlideShow_LabelVisibility('"+pictureName+"','"+object_ID+"','"+futureImages+"',"+displaySecs+")",
                                displaySecs*1000);
    // Caché la nueva imagen para mejorar el rendimiento.
    imageSeparator = futureImages.indexOf(";");
    nextImage = futureImages.substring(0,imageSeparator);
    if (slideCache[nextImage] == null) 
    {
        slideCache_LV[nextImage] = new Image;
        slideCache_LV[nextImage].src = nextImage;   
    }
    
    var object_style = document.getElementById(object_ID).style;   
    if (object_style.visibility == 'visible')
    {
        object_style.visibility = 'hidden';
    }
    else 
    {
        object_style.visibility = 'visible';
    }
}
//function mostrar_mensaje(mensaje)
//{
//    window.alert(mensaje);
//}
//-->