/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */
var GB_DONE = false;

var ie=(document.all);
var ns=(document.layers);
var ns6=(document.getElementById && !ie);
var calculate=ns? "" : "px";

function GB_show(caption, url, height, width, parameters)
{
  var GB_ANIMATION;
  GB_HEIGHT = height;
  GB_WIDTH = width;
  $("#GB_window").remove(); 
  if(url!="password.shtm")
  {
    $(document.body)
    
	/* alt-title Close to Finnish Sulje */
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_font'></div>"
        + "<img src='images/user/icon/close_16x16.png' title='Sulje' id='imgClose' alt='Sulje'/></div>");
    $("#GB_window img").click(GB_hide);
    /*$("#GB_overlay").click(GB_hide);*/
    $(window).resize(GB_position);
   }
   else
   {
       $(document.body)
     
      .append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_font'></div>"
        + "</div>");
    $(window).resize(GB_position); 
   }
  

  $("#GB_frame").remove();
  /*added by jijo on dec 29 2009 , to pass parameters to popup */
  /*edited by jijo on feb 10 2010 , parameters passed in an object  */
  
  if(parameters != ''){
  var appendStr = '';
	for (k in parameters)  {
		appendStr+='&'+k+'='+parameters[k];
	}
	//alert(appendStr.substring(1));
	appendStr = appendStr.substring(1);
	url =url+"?"+appendStr;
  }
 
 
  /************************/
  $("#GB_window").append("<iframe style='background:F9F1DF' id='GB_frame' src='"+url+"'></iframe>");

  $("#GB_font").html(caption);
  $("#GB_overlay").show();

  /*added by lalit */
 /* if(url =="uploadimage.shtm")
		GB_position();
  else*/
		GB_position();

  if(GB_ANIMATION)
    $("#GB_window").slideDown("fast");
  else
    $("#GB_window").show();
}

function GB_hide() {
  $("#GB_window,#GB_overlay").hide();
}

function GB_position() {
  var de = document.documentElement;
  var winw = GB_WIDTH;
  var winh = GB_HEIGHT;

	if(navigator.appName ==  "Microsoft Internet Explorer")
	{
		var bHeight = parseInt(document.documentElement.clientHeight)/2;
	}else
	{
		var bHeight = parseInt(window.innerHeight)/2;
	}

	var agent=navigator.userAgent.toLowerCase();
	if (ie)
	{
		documentHeight = (centerElement().offsetHeight)/2+centerElement().scrollTop-(winh/2);
	}
	else if (ns)
	{
		documentHeight=window.innerHeight/2 + window.pageYOffset-( winh/2 );
	}
	else if (ns6)
	{
		documentHeight=self.innerHeight/2+window.pageYOffset-(winh/2);
	}
	if(documentHeight < 0)
	{
		var toppos = documentHeight + 100 + "px";
	}
	else
	{
		var toppos = documentHeight+calculate;
	}

	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
    left: ((w - GB_WIDTH)/2)+"px",top: toppos });


  $("#GB_frame").css("height",GB_HEIGHT-20 +"px");

  var arrayPageSizeWithScroll =	getPageSizeWithScroll();
    $("#GB_overlay").css("height",arrayPageSizeWithScroll[1] +"px");
	//popup.top = documentHeight+calculate;
	setTimeout("GB_position()",100);

}

function centerElement(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


//Added By Lalit for getting the page height with scrollbar on Monday, April 20, 2009
function getPageSizeWithScroll(){

	if (window.innerHeight && window.scrollMaxY) 
	{
	// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else 
	if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
	return arrayPageSizeWithScroll;
}




