/*
* (c) PrismaStar 
*  Script for open windon AO selector  
*/

// Config for Main div
var iMainWidth = 891;
var iMainHeight = (IsIE() ? 670 : 650); // IE-> 670px; FF + ALL -> 650px
var iFrameHeight = (IsIE() ? iMainHeight - 20 : 630); // IE ; FF + ALL
var iBorder = "1px solid #000";
var iBackgroundColor = "#fff";
var oSetAttribId = "id";
var oSetAttribValue = "MainAO";
var oSetBGAttribValue="BGFilter";
var loaded = 0;
var iFrameborder = 0;
// Config for iframe
var sURLAO = "http://production.answeroil.com/jessops/"; // URL where AO slector!


// Is browser IE
function IsIE()
{
  if (navigator.appName.indexOf("Microsoft")!=-1)
    return true;
  else
    return false;
}

//window.onload = IsIE;

// This function hidden window with selector
function hideSelector()
{
  var oBody = document.getElementsByTagName("body")[0];
  var oBGFilter2 = document.getElementById("BGFilter");
  var oIframe = document.getElementById("MainAO");
  //oBody.removeChild(oIframe); 
  oBGFilter2.style.visibility='hidden';
  oIframe.style.visibility='hidden';
}
function createBGFilter()
{
  var oBGFilter = document.createElement('div');
  oBGFilter.setAttribute(oSetAttribId, oSetBGAttribValue);  
  oBGFilter.style.backgroundColor = "#000";
  oBGFilter.style.border = 0;  
  oBGFilter.style.width = "100%";
  var bgheight = getPageSizeWithScroll();
  //alert(bgheight);
  oBGFilter.style.height = bgheight + 'px';
  oBGFilter.style.position = "absolute";
  oBGFilter.style.top = "0px";
  oBGFilter.style.left = "0px";
  oBGFilter.style.zIndex = 9997;
  document.getElementsByTagName("body")[0].appendChild(oBGFilter);
}                                               
// function for cerate main div
function CreateMainDiv()
{
  var oMainDiv = document.createElement('div');
  oMainDiv.setAttribute(oSetAttribId, oSetAttribValue);  
  oMainDiv.style.backgroundColor = iBackgroundColor;
  oMainDiv.style.border = iBorder;  
  oMainDiv.style.width = iMainWidth + "px";
  oMainDiv.style.height = iMainHeight + "px";
  oMainDiv.style.zIndex = 9999;
  document.getElementsByTagName("body")[0].appendChild(oMainDiv);
  
  var iWidth = 0;
  var oDetail = oMainDiv.style;  
  PositionMainDiv(oDetail);
  oDetail.display = 'block';
}

// Function for create div where is closed
function CreateCloseDiv()
{
  var oDivClose = document.createElement('div');
  oDivClose.style.border = "0px none";
  oDivClose.style.margin = "0 2px 0 0";
  oDivClose.setAttribute("style","float:right; margin: 0 2px 0 0;");  
  oDivClose.style.styleFloat = "right";
  oDivClose.innerHTML = "<a href=\"javascript:hideSelector();\" style=\"font-size: 0.9em; text-decoration: none;\" >CLOSE&nbsp;<img src=http://www.jessops.com/images/close.gif /></a>";
  document.getElementById('MainAO').appendChild(oDivClose);
}

// Function create iframe with AO selector
function CreateIframe()
{
  // Defualt const for parametrs iframe 
  var iAOWidth = 890; // width iframe
  var iAOHeight = this.iFrameHeight; // height iframe
  var sScrolling = "no"; // scrolling "on" or "yes"
  var iFrameborder = 0; // frame border default is 0
  
  var oIframe = document.createElement('iframe'); // Element iframe
  oIframe.setAttribute('src', this.sURLAO); // URL with ao selectro
  oIframe.setAttribute('id', 'SelectorFrame'); // ID irame
  oIframe.setAttribute('width', iAOWidth); // width iframe
  oIframe.setAttribute('height', iAOHeight); // height iframe
  oIframe.setAttribute('scrolling', sScrolling); // scrolling "on" or "yes"
  oIframe.setAttribute('frameborder', iFrameborder); // frame border default is 0
  oIframe.style.border = "0px none";
  document.getElementById("MainAO").appendChild(oIframe);
}

// Function for show Selector
function showSelector()
{
	if(loaded==0)
	{
	createBGFilter();
    CreateMainDiv();
    CreateCloseDiv();
    CreateIframe();
    loaded=1;
	}
	else
	{
      var oIframe = document.getElementById("MainAO");
      var oBGFilter2 = document.getElementById("BGFilter");
      PositionMainDiv(oIframe.style);
      oBGFilter2.style.visibility='visible';
	  oIframe.style.visibility='visible';
	}
}

function PositionMainDiv(oDiv)
{
  if (parseInt(navigator.appVersion)>3)
  {
    if (navigator.appName.indexOf("Microsoft")!=-1)
    {
      iWidth = document.body.offsetWidth;
      oDiv.top = "60px";
    }
    else
    {
    iWidth = window.innerWidth;
    }
  }

  // Styls iframe
  iWidth = (iWidth / 2) - 450;
  oDiv.display = "none";
  oDiv.position = "absolute";
  
  if(oDiv.top == 0)
  oDiv.top = "60px";
  
  oDiv.left = iWidth + "px";
  oDiv.display = "block";

}

function getPageSizeWithScroll(){
  if (parseInt(navigator.appVersion)>3) 
  {
     if (navigator.appName=="Netscape") 
     {
        bgheight = window.innerHeight + window.scrollMaxY;
     }
     if (navigator.appName.indexOf("Microsoft")!=-1) 
     {
       bgheight =  (document.height || document.body.offsetHeight);//( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight );
     }else     {
        bgheight = window.innerHeight + window.scrollMaxY;
     }
  }
return bgheight;
  } 