function get_select_value(select)
{
  var sel_idx=select.selectedIndex;

  return select.options[sel_idx].value;
}

function get_select_text(select)
{
  var sel_idx=select.selectedIndex;

  return select.options[sel_idx].text;
}

function isempty(x)
{
  return typeof(x) == "undefined" || x == "";
}
function parse_search(search)
{
  var search=search.substr(1);
  var array_key_val=search.split("&");
  var key_val=new Array(array_key_val.length);
  for ( i=0; i<array_key_val.length; i++ ) {
    array_key_val[i]=array_key_val[i].replace(/\+/g, " ");
    this_key_val=array_key_val[i].split("=");
    if ( this_key_val.length == 2 ) {
      key=unescape(this_key_val[0]);
      val=unescape(this_key_val[1]);
      key_val[key]=val;
    }
  }
  return key_val;
}


function write_img_th(src, bg, limit)
{
  if ( typeof(bg) == "undefined" ) {
    bg="000000";
  }
  if ( typeof(limit) == "undefined" ) {
    limit=100;
  }
  var path_src="images/"+src;
  var img=new Image();
  img.src=path_src;
  if ( img.height < img.width )
    var dim_limiter='width="'+limit+'"';
  else
    var dim_limiter='height="'+limit+'"';

  //alert(src+"|"+img.width+"|"+img.height+"|"+dim_limiter);
  var str=
  '<a href="#" onclick="show_img(event, \''+path_src+'\', \''+bg+'\', '+limit+')">'+
    '<img  src="thumbnails/'+src+'" '+dim_limiter+' border="0" alt="click to enlarge">'+
    '</a>';
  //alert(str);
  document.write(str);
}

function show_img(event, src, bg, limit)
{
  var img_id="IM_"+src;
  var img=document.getElementById(img_id);
  if ( img != null )
    return false;

  img=document.createElement("IMG");
  var img_div=document.createElement("DIV");
  img_div.style.top=event.clientY+"px";
  img_div.style.left=event.clientX+"px";
  img_div.style.width=img.width+"px";
  img_div.style.height=(img.height+20)+"px";
  img_div.style.position="absolute";
  img_div.style.padding="5px";
  img_div.style.background="#"+bg;
  img_div.style.color="#ffffff";
  img_div.style.zIndex=1000;
  img_div.style.cursor="hand";
  img_div.style.border="black 1px solid";
  img_div.id="DIV_"+src;
  //alert(img_div.style.cssText);
  img.id=img_id;
  //alert(img.src);
  img.src=src;
  //alert(img.width+"x"+img.height);
  var img_factor=img.width > img.height ? img.width/limit : img.height/limit;
  img.width /= img_factor;
  img.height /= img_factor;
  img.enlarge=img_enlarge;
  img.count=0;
  img.max_count=10;
  img.factor=Math.pow(img_factor, 1/img.max_count);
  img.timer=setInterval("enlarge('"+img.id+"')", 100);
  //alert(img.src);
  var pel=document.createElement("P");
  pel.style.textAlign="center";
  pel.style.lineHeight="10px";
  pel.style.height="10px";
  pel.style.width="60px";
  pel.style.textAlign="center";
  pel.style.fontSize="7pt";
  var textel=document.createTextNode("Click to close");
  pel.appendChild(textel);
  img_div.appendChild(pel.cloneNode(true));
  img_div.appendChild(img);
  img_div.appendChild(pel);
  img_div.onclick=close_div;
  document.body.appendChild(img_div);

  return true;
}

function close_div(e)
{
  if ( typeof(e) != "undefined" )
    event=e;
  var t=get_e_target(event);
  if ( t )
    document.body.removeChild(t);
}
function close_div_keypress(e)
{
  if ( typeof(e) != "undefined" )
    event=e;
  var t=get_e_target(event);
  if ( t )
  document.body.removeChild(t);
}

function enlarge(img_id)
{
  var id=document.getElementById(img_id);
  /*if ( !id.complete && id.count%5 == 0)
    alert(id.complete);*/
  if ( id && id.complete ) {
    if ( id.count++ < id.max_count )
      id.enlarge();
    else
      clearTimeout(id.timer);
  }
}

function img_enlarge()
{
  //alert(this.count);
  var parent=this.parentNode;
  var left=parseInt(parent.style.left)-this.width *(this.factor-1)/2;
  left = left >=0 ? left : 0;
  parent.style.left= left+"px";
  var top= (0.8*(parseInt(parent.style.top) -this.height*(this.factor-1)/2));
  top = top >=0 ? top : 0;
  parent.style.top= top+"px";
  this.width *= this.factor;
  this.height *= this.factor;
  
}

document.onerror=null_fn;

function null_fn()
{
  alert('hola');
}
