// SANKI.JS

function _id(id)
{
  return document.getElementById(id);
}
/*function findPos(obj)
{
	var curleft = curtop = 0;
  if (obj.offsetParent)
  {
    do
    {
		  curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
	return [curleft,curtop];
}*/

function prepare_hover(collection,hover_func,leave_func,move_func)
{
  var i,temp;
  for(i=0;i<collection.length;i++)
  {
    temp = collection[i].getElementsByTagName('img');
    collection[i].base = temp[0];
    collection[i].hover = temp[1];
    collection[i].i = i;
    if(hover_func) collection[i].onmouseover = eval(hover_func);
    else collection[i].onmouseover = function() { this.base.style.display = 'none'; this.hover.style.display = 'block'; };
    if(leave_func) collection[i].onmouseout = eval(leave_func);
    else collection[i].onmouseout = function() { this.hover.style.display = 'none'; this.base.style.display = 'block'; };
    if(move_func) collection[i].onmousemove = eval(move_func);
  }
}

// de la Beau's blog (hartshorne.ca)
/*function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}*/

 function winSize()
{
  var myWidth = 0, myHeight = 0;
  //myHeight = document.body.clientHeight > window.innerHeight ? document.body.clientHeight : window.innerHeight;
  
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  /*if(typeof( window.innerWidth ) == 'number' && document.body && document.body.clientHeight)
  {
    myHeight = document.body.clientHeight > window.innerHeight ? document.body.clientHeight : window.innerHeight;
  }
  /*window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );*/
  var size = new Array();
  size[1] = myWidth;
  size[2] = myHeight;
  //alert(size[1] + ',' + size[2]);
  return size;
}

function absValLeft(x)
{
  var width = 753;
  var ww = winSize()[1];
  var t;
  t = ww > width ? (ww - width) / 2 : 0;
  return t + x;
}


function open_popup(mode,contents,popup_id)
{
  if(popup_id == null) popup_id = 'popup';
  //if(bgpage_id == null) bgpage_id = 'bg';
  
  var popup = _id(popup_id);
  //var bgpage = _id(bgpage_id);
  
  //bgpage.style.display = 'block';
  //popup.style.display = 'block';
  if(mode == 'html')
  {
    popup.innerHTML = contents;
  }
  else if(mode == 'ajax')
  {
    // daca avem parametri GET in contents atunci ii vom separa in array
    
    /*if(contents.indexOf('?'))
    {
      var x,i;
      var vars = new Array();
      var p = contents.indexOf('?') + 1;
      st = contents.substr(p);
      while(st != '')
      {
        x = st.indexOf('=')
        i = st.substr(0,x-1);
        st = st.substr(x+1);
        x = st.indexOf('&');
        if(!x)
        {
          vars[i] = st;
          st = '';
        }
        else vars[i] = st.substr(0,x-1);
        st = st.substr(x+1);
      }
    }
    else var vars = false;*/
  
    ajax_loadContent(popup_id,contents);
  }
  popup.style.display = 'block';

}
