var popUp; 

function OpenCalendar(idname, postBack)
{
	popUp = window.open('../DesktopModules/Calendario.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=220,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}		


function NewWindow(url, w, h) 
{
  if (w > screen.width || h > screen.width)
  {
    if (w > screen.width && h <= screen.height)
    {
      var nw = screen.width - 70;
      var nh = parseInt(h) + 36
    }
    if (h > screen.height && w <= screen.width)
    {
      var nh = screen.height - 70;
      var nw = parseInt(w) + 36
    }
    if (w > screen.width && h > screen.height)
    {
      var nh = screen.height - 70;
      var nw = screen.width - 70;
    }

    window.open(url,"_blank","width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=yes,resizable=yes");

  }
  else
  {
    var nh = parseInt(h) + 25;
    var nw = parseInt(w) + 25;
    window.open(url,"_blank","width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=no,resizable=no");
  }
}

function NewWindow2(url, nombre, w, h) 
{
  if (w > screen.width || h > screen.width)
  {
    if (w > screen.width && h <= screen.height)
    {
      var nw = screen.width - 70;
      var nh = parseInt(h) + 36
    }
    if (h > screen.height && w <= screen.width)
    {
      var nh = screen.height - 70;
      var nw = parseInt(w) + 36
    }
    if (w > screen.width && h > screen.height)
    {
      var nh = screen.height - 70;
      var nw = screen.width - 70;
    }

    window.open(url, nombre,"width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=yes,resizable=yes");

  }
  else
  {
    var nh = parseInt(h) + 25;
    var nw = parseInt(w) + 25;
    window.open(url, nombre,"width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=yes,resizable=no");
  }
}

function NewWindow2_Sin(url, nombre, w, h) 
{
  if (w > screen.width || h > screen.width)
  {
    if (w > screen.width && h <= screen.height)
    {
      var nw = screen.width - 70;
      var nh = parseInt(h) + 36
    }
    if (h > screen.height && w <= screen.width)
    {
      var nh = screen.height - 70;
      var nw = parseInt(w) + 36
    }
    if (w > screen.width && h > screen.height)
    {
      var nh = screen.height - 70;
      var nw = screen.width - 70;
    }

    window.open(url, nombre,"width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=no,resizable=yes");

  }
  else
  {
    var nh = parseInt(h) + 25;
    var nw = parseInt(w) + 25;
    window.open(url, nombre,"width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=no,resizable=no");
  }
}


function Ayuda(url, nombre, w) 
{
	var nw = parseInt(w);
	var donde = screen.width - nw;
    window.open(url, nombre, "width=" + nw + ",height=" + screen.height + ",left=" + donde + ",top=0,scrollbars=yes,resizable=yes");
}

function seleccionarDeseleccionarTodos (chkVal, idVal) {
  var frm = document.forms[0];
  // loop through all elements
  for (i=0; i<frm.length; i++) {
	// Look for our Header Templates Checkbox
	if (idVal.indexOf ("SeleccionarTodos") != -1) {
	// Check if main checkbox is checked, then select or deselect datagrid checkboxes
	  if(chkVal == true) {
		frm.elements[i].checked = true;
	  }
	  else {
		frm.elements[i].checked = false;
	  }
	// Work here with the Item Templates multiple checkboxes
	}
	else
	if (idVal.indexOf("SeleccionarEste") != -1) {
	// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
	  if(frm.elements[i].checked == false) {
		frm.elements[1].checked = false;
	   // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
	  }
	}
  }
}

function doHourglass()
{
  document.body.style.cursor = 'wait';
}

function NewWindow3(url, nombre, w, h) 
{
  if (w > screen.width || h > screen.width)
  {
    if (w > screen.width && h <= screen.height)
    {
      var nw = screen.width - 70;
      var nh = parseInt(h) + 36
    }
    if (h > screen.height && w <= screen.width)
    {
      var nh = screen.height - 70;
      var nw = parseInt(w) + 36
    }
    if (w > screen.width && h > screen.height)
    {
      var nh = screen.height - 70;
      var nw = screen.width - 70;
    }

    window.open(url, nombre, "width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=yes,resizable=yes");

  }
  else
  {
    var nh = parseInt(h) + 25;
    var nw = parseInt(w) + 25;
    window.open(url,nombre,"width=" + nw + ",height=" + nh + ",left=0,top=0,scrollbars=no,resizable=no");
  }
}

function ocultarMostrarDiv(muestra, nombre){

	var elemDiv = document.getElementById(nombre);
	
    if (elemDiv) 
    {
		if (muestra)
		{
			elemDiv.style.display = 'block';
			elemDiv.style.visibility = 'visible';
		}
		else
		{
			elemDiv.style.display = 'none';
			elemDiv.style.visibility = 'hidden';
		
		}
	}
}	

function ocultarMostrarDiv2(evt, muestra, nombre){

	var elemDiv = document.getElementById(nombre);
	
    if (elemDiv) 
    {
		if (muestra)
		{
			//elemDiv.style.display = 'block';
			elemDiv.style.visibility = 'visible';
            e_event = (window.event) ? window.event : evt;
            i_scrollX = (window.event) ? document.body.scrollLeft : window.scrollX
            i_scrollY = (window.event) ? document.body.scrollTop : window.scrollY
            posX = e_event.clientX + 10 + i_scrollX;
            posY = e_event.clientY;
            elemDiv.style.top = posY;
            elemDiv.style.left = posX;
            elemDiv.style.position = 'absolute';
            //alert(elemDiv.style.left);
		}
		else
		{
			//elemDiv.style.display = 'none';
			elemDiv.style.visibility = 'hidden';
		
		}
	}
}	

function saludo(){
 var todaysdate = new Date();
    thehour = todaysdate.getHours(); 
    saludo="Buenas ";
    if (thehour > 20) 
        display = "Noches"; 
    else 
    if (thehour >12) 
        display = "Tardes"; 
    else {
        display = "Dias"; 
        saludo = "Buenos ";
    }

    return saludo + display + "!!"; 
}

function showHideDiv(showHide) {
	for(i=0;i < showHideDiv.arguments.length;i++){
		o_showHide = document.getElementById(showHideDiv.arguments[i])
		s_showHide = (o_showHide.style.display!="") ? o_showHide.style.display : "none";
		o_showHide.style.display = (s_showHide=="none") ? (o_showHide.nodeName=="SPAN") ? "inline" : "block" : "none";
	}
}

    function mostrarPopup(datos){
            var elemDiv = document.getElementById("tarifasPopup")
            document.getElementById("tarifasUpdate").innerHTML = datos;
            e_event = window.event;
            posX = e_event.clientX - 300; 
            posY = e_event.clientY;
  
            elemDiv.style.top = posY+"px";
            elemDiv.style.left = posX+"px";
            if(elemDiv.style.display=="none" ||elemDiv.style.display=="")
                showHideDiv("tarifasPopup");
    }

    function armarTablaConDatos(valor){
            var datos = "<table width='100%' border='1' bordercolor='#99ccff' bgcolor='#99ccff' cellspacing='0' cellpadding='0' class='cajaColorDePrueba'>";
            datos+="<tr><td><table width='100%' class='leftLink' bgcolor='#cce6ff'>";
            datos += "<tr><td align=right>";
            datos+= "<A class='commandButton' onclick=\"showHideDiv('tarifasPopup');return false;\" href='#'>Cerrar</A>"; 
            datos+= "</td><tr>";
            datos+= "<tr><td class='itemObsCharter'>" + valor + "</td></tr>";
            datos+= "</table></td></tr></table>";
            return datos;
    }

function agrandarImagen(imagen, ancho, alto){
    
    imagen.setAttribute('width', ancho);
    imagen.setAttribute('height', alto);
}

//***********************************
    var lobservaciones = new Array();
    var lpromociones = new Array();

    function agregarPromocion(id, xpromocion){
        var item = new Array(2);
        item[0] = id;
        item[1] = xpromocion;
        lpromociones.push(item);
        return 0;
    }
    
    function agregarObservacion(id, xobservaciones){
        var item = new Array(2);
        item[0] = id;
        item[1] = xobservaciones;
        lobservaciones.push(item);
        return 0;
    }
    
    function observaciones(id){
        var item;
        var xobservaciones = "";
        var datos = "";
        for (i=0; i<lobservaciones.length; i++){
            item = lobservaciones[i];
            if (item[0] == id){
                xobservaciones = item[1];
                break;
            }
        }
        if (xobservaciones != "")
            datos = armarTablaConDatos(xobservaciones);
        return datos;
    }
    
    function promocion(id){
        var item;
        var xpromocion = "";
        var datos = "";
        for (i=0; i<lpromociones.length; i++){
            item = lpromociones[i];
            if (item[0] == id){
                xpromocion = item[1];
                break;
            }
        }
        
        if (xpromocion != "")
            datos = armarTablaConDatos(xpromocion);
        
        return datos;
    }
    
    
    function verObservaciones(id){
        var datos = observaciones(id);
        if (datos != "")
            mostrarPopup(datos);
    }

    function verPromocion(id){
        var datos = promocion(id);
        if (datos != "")
          mostrarPopup(datos);
    }
