 function openPhotoView(obj,filephoto) {
    if (document.getElementById) {
        positionObj(document.getElementById(obj), 'b_PhotoViewPopup');
        document.getElementById('b_PhotoViewPopup').style.display = 'block';
		document.getElementById('photorooms').src = filephoto; 
    }
}

function closePhotoView() {
    if (document.getElementById) {
        document.getElementById('b_PhotoViewPopup').style.display = "none";
		document.getElementById('photorooms').src = '/files/organizers/vuoto.jpg'; 
        // return false;
    }
}

function positionObj (p, el){
	if (document.getElementById){
		var e = document.getElementById(el);
        var bw = getBrowserWidth();

		var l=0; var t=0;
		aTag = p;
		do {
			aTag = aTag.offsetParent;
			l += aTag.offsetLeft;
			t += aTag.offsetTop;
		} while (aTag.offsetParent && aTag.tagName != 'body');
		var left =  p.offsetLeft + l;

		// this should be replaced by something generic.
		// for some reason e.style.width is emptly, so
		// i cannot read the width of this element

		var width = 300;
		if (left + width > bw){
			left = bw-width-30;
		}

		var top = p.offsetTop + t + p.offsetHeight + 2;
        e.style.position = 'absolute'
		e.style.left = left+'px';
		e.style.top = top+'px';
	}
}

function getBrowserWidth(){
  var w = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    w = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    w = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    w = document.body.clientWidth;
  }
  return w;
}

function getBrowserHeight(){
  var h = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    h = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    h = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    h = document.body.clientHeight;
  }
  return h;
}
