﻿/* Global Methods */
function getObj(name)
{
  if (document.getElementById)
  {
      this.obj = document.getElementById(name);
      this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
      this.obj = document.all[name];
      this.style = document.all[name].style;
  }
  else if (document.layers)
  {
      this.obj = document.layers[name];
      this.style = document.layers[name];
  }
}
function getElement(name)
{
  if (document.getElementById)
  {
      return document.getElementById(name);
  }
  else if (document.all)
  {
      return document.all[name];
  }
  else if (document.layers)
  {
      return document.layers[name];
  }
}
function getParentElement(name)
{
  if (parent.document.getElementById)
  {
      return parent.document.getElementById(name);
  }
  else if (document.all)
  {
      return parent.document.all[name];
  }
  else if (document.layers)
  {
      return parent.document.layers[name];
  }
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
function showParentSelectBoxes(){
	selects = parent.document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}
function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}


/* Popup Windows */
function ShowPopup(id, url, h, w, showclose)
{
    if (getElement(id) == null)
    {
        // Create the Popup Form
        CreatePopupForm(id,url,h,w,showclose);
    }
    
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
	
	getElement(id).style.width = arrayPageSize[0] + "px";
    getElement(id).style.height = (arrayPageSize[1] + 70) + "px";
    getElement('inn'+id).style.top =  20 + arrayPageScroll[1] + "px";
    
    hideSelectBoxes();
    
    new Effect.Appear(getElement(id), { duration: 0.2, from: 0.0, to: 0.8 });
    new Effect.Grow(getElement('inn' + id));
    setTimeout("AnimationComplete('" + id + "');",2000);
}
function CreatePopupForm(id,url,h,w,closebar)
{
    var objBody = document.getElementsByTagName("body").item(0);
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
	
    var ov = document.createElement("div");
    ov.setAttribute('id',id);
    ov.className = 'overlay';
    ov.style.display = 'none';
    objBody.appendChild(ov);
   
    var left = (arrayPageSize[0] - w)/2
    var br = document.createElement("div");
    br.setAttribute('id','inn' + id);
    br.className = 'popup';
    br.style.width = (w+10) + "px";
    br.style.height = h + "px";
    br.style.left = left + "px";
    br.style.display = 'none';
    
    var con = document.createElement("div");
    con.className = 'popcontent';
    
    if (closebar)
    {
        // Close Button
        var cls = document.createElement("div");
        cls.style.paddingTop = "4px";
        cls.style.paddingLeft = (w-75) + "px";
        
        var clsimg = document.createElement("img");
        clsimg.setAttribute('src','/Images/CloseLabel.gif');
        clsimg.setAttribute('alt','Close');
        clsimg.onclick = function() { HidePopup(id); return false; }
        cls.appendChild(clsimg);
        con.appendChild(cls)
    }
    
    // Loading Panel
    var ldg = document.createElement("div");
    ldg.setAttribute('id', 'ld' + id);
    ldg.style.width = (w+10) + "px";
    ldg.style.height = (h) + "px";
    
    var ldgimg = document.createElement("img");
    ldgimg.setAttribute('src','/Images/imgLoadingLarge.gif');
    ldgimg.setAttribute('alt','Loading');
    ldgimg.style.display = "block";
    ldgimg.style.marginTop = "100px";
    
    if (BrowserDetect.browser != "Explorer")
    {
        ldg.style.height = (h-100) + "px";
        ldgimg.style.marginLeft = ((w/2)-16) + "px";
    }
        
    ldg.appendChild(ldgimg);
    con.appendChild(ldg)
    
    // Form Panel
    var frm = document.createElement("div");
    frm.style.display = 'none';
    frm.style.backgroundColor = "#FFFFFF";
    frm.setAttribute('id', 'fm' + id);
    con.appendChild(frm)
    
    br.appendChild(con);
    objBody.appendChild(br);
    getElement('fm' + id).innerHTML = "<iframe src='" + url + "' scrolling='no' frameborder='no' style='width: " + w + "px;height: " + h + "px'></iframe>"
}

function AnimationComplete(id)
{
    getElement('ld' + id).style.display = 'none';
    getElement('fm' + id).style.display = 'block';
}
function HidePopup(id)
{
    new Effect.Shrink(getElement('inn' + id),{duration: 0.2});
	new Effect.Fade(id);
	
    getElement('ld' + id).style.display = 'block';
    getElement('fm' + id).style.display = 'none';
    setTimeout("showSelectBoxes()",1000);
}
function HideParentPopup(id)
{
    new Effect.Shrink(getParentElement('inn' + id),{duration: 0.2});
	new Effect.Fade(getParentElement(id));
	
    getParentElement('ld' + id).style.display = 'block';
    getParentElement('fm' + id).style.display = 'none';
    setTimeout("showParentSelectBoxes()",1000);
}


