//*************************************************************************
// ThePortIFrameClient
// Customized: Steve Soares
// Original implementation: http://geekswithblogs.net/rashid/archive/2007/01/13/103518.aspx
//*************************************************************************
//
//*************************************************************************
// THIS IS THE UNOBFUSCATED FILE THAT WILL GET OUTPUT AS IFRAME.JS!!!
//*************************************************************************
var lastWidgetHeight=0;
function UpdatePageHeight()
{
    if (window.location.hash.length == 0) return;
    var frameId = getFrameId();
    if (frameId == '') return;
    var vph = getViewPortHeight();
    var actualHeight = getHeight();
    if ((Math.abs(actualHeight - lastWidgetHeight) > 10))/*||(Math.abs(actualHeight - 

lastWidgetHeight) < -5))*/
//    if (actualHeight != vph) //lastWidgetHeight)
    //if (true)
    {   
        var ch;
        var i=0;
        while ((i<window.location.href.length)&&(window.location.href.charAt(i)!='#')) {
          i++;
          }
        
        var hostUrl = window.location.href.substring(i+1);
        hostUrl += "#";
        hostUrl += 'WidgetID=' + frameId;
        hostUrl += '&';
        hostUrl += 'height=' + actualHeight.toString();
        try {
        if (window.parent.length>0)
          window.parent.location.href = hostUrl; 
        } catch(e) {}
        lastWidgetHeight = actualHeight;
    }
}


//*************************************************************************
//
//*************************************************************************
function getFrameId()
{
    var qs = parseQueryString(window.location.href);
    var frameId = qs["WidgetID"];

    var hashIndex = frameId.indexOf('#');

    if (hashIndex > -1)
    {
        frameId = frameId.substring(0, hashIndex);
    }

    return frameId;
}
/*
function getHeight()
{
    var height;
    var scrollHeight;
    var offsetHeight;

    if (document.height)
    {
        height = document.height;
    }
    else if (document.body)
    {
        if (document.body.scrollHeight)
        {
            height = scrollHeight = document.body.scrollHeight;
        }
        if (document.body.offsetHeight)
        {
            height = offsetHeight = document.body.offsetHeight;
        }

        if (scrollHeight && offsetHeight)
        {
            height = Math.max(scrollHeight, offsetHeight);
        }
    }

    return height;
}
*/


//*************************************************************************
//
//*************************************************************************
function getViewPortHeight()
{
    var height = 0;
    if (window.innerHeight) {
        height = window.innerHeight - 18;
      }
    else if ((document.documentElement) && (document.documentElement.clientHeight)) {
        height = document.documentElement.clientHeight;
        }
    else if ((document.body) && (document.body.clientHeight)){
        height = document.body.clientHeight;
        }
    return height;
}


//*************************************************************************
//
//*************************************************************************
function getHeight()
{
    var height = 0;
    var scrollHeight;
    var offsetHeight;
    if (document.all) {
      return(document.body.scrollHeight);
      }
    if (document.body){
      if (document.body.scrollHeight)
          height = scrollHeight = document.body.scrollHeight;
      if (document.body.offsetHeight)
          height = offsetHeight = document.body.offsetHeight;
      if (scrollHeight && offsetHeight)
          height = Math.max(scrollHeight, offsetHeight);
      }
    return height;
}


//*************************************************************************
//
//*************************************************************************
function parseQueryString(url)
{
    url = new String(url);
    var queryStringValues = new Object();
    var querystring = url.substring((url.indexOf('?') + 1), url.length);
    var querystringSplit = querystring.split('&');

    for (i = 0; i < querystringSplit.length; i++)
    {
        var pair = querystringSplit[i].split('=');
        var name = pair[0];
        var value = pair[1];

        queryStringValues[name] = value;
    }
    return queryStringValues;
}


//*************************************************************************
//
//*************************************************************************
window.onload = function(event)
{
  window.setInterval(UpdatePageHeight,500);
}
