var xmlHttp;
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
 } 
}
function showActive(str) { 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="rssWidgetActivate.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function showMenu(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="rssWidgetMenu1.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedMenu;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function showHtml(element, html, sroll, height) 
{ 

var el= document.getElementById("copyright");
if (el!=null) {
 el.style.top="10px";
}
 document.getElementById(element).innerHTML="<iframe id='id_'"+element+" frameborder=0 onload='adjustMyFrameSize(\"id_"+element+"\");' scrolling="+scroll+" width=100% height='" +height+"px' src='"+html+"'/>";
 var elem='id_'+element;
 adjustMyFrameSize(elem);
}

 function getElement(aID)
    {
        return (document.getElementById) ?
            document.getElementById(aID) : document.all[aID];
    }

    function getIFrameDocument(aID){ 
        var rv = null; 
        var frame=getElement(aID);
        // if contentDocument exists, W3C compliant (e.g. Mozilla) 

        if (frame.contentDocument)
            rv = frame.contentDocument;
        else // bad IE  ;)

            rv = document.frames[aID].document;
        return rv;
    }

    function adjustMyFrameHeight(frame)
    {
        var frame = getElement(frame);
        var frameDoc = getIFrameDocument(frame);
        frame.height = frameDoc.body.offsetHeight;
    }


function stateChangedMenu() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  document.getElementById("menuPlace").innerHTML=xmlHttp.responseText;
 } 
}

function showWidget(str)
{ 

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }

 var url="rssWidgetList1.php";
 url=url+"?cat="+str;
 url=url+"&sid="+Math.random();
 xmlHttp.onreadystatechange=stateChangedWidget;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}



function stateChangedWidget() { 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
// alert (xmlHttp.responseText);
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = xmlHttp.responseText;
document.getElementById('widgetPlace').appendChild (newScript);
update('widgetPlace', xmlHttp.responseText) ;
 } 
}

function update(element, html) {
document.getElementById(element).innerHTML=html;
var re = /<script\b[\s\S]*?>([\s\S]*?)<\//ig;
var match;
while (match = re.exec(html)) {
eval(match[1]);
}
}; 

/*
http://bytes.com/groups/javascript/513633-innerhtml-script-tag

var d =
document.getElementById('divContents').getElements ByTagName("script")
var t = d.length
for (var x=0;x<t;x++){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.text = d[x].text;
document.getElementById('divContents').appendChild (newScript);
}

function update(element, html) {
document.getElementById(element).innerHTML=html;
var re = /<script\b[\s\S]*?>([\s\S]*?)<\//ig;
var match;
while (match = re.exec(html)) {
eval(match[1]);
}
}; 

*/

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function adjustFrameHeight(frame) {
                var height;
                var offsetH = document.body.offsetHeight;
                var innerDocScrollH = null;

                if (typeof(frame.contentDocument) != 'undefined' || typeof(frame.contentWindow) != 'undefined')
                {
                   // very special way to get the height from IE on Windows!
                   // note that the above special way of testing for undefined variables is necessary for older browsers
                  // (IE 5.5 Mac) to not choke on the undefined variables.
                  var innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
                  innerDocScrollH = (innerDoc != null) ? innerDoc.body.scrollHeight : null;
                }
                if (document.all && innerDocScrollH != null)                {
                        // IE on Windows only
                        height = innerDocScrollH;
                } else  {
                        // every other browser!
                        height = offsetH;
                }
         return height;
     }

//http://bugs.sakaiproject.org/jira/browse/SPO-5
function adjustMyFrameSize (id) {
        // run the script only if this window's name matches the id parameter
        // this tells us that the iframe in parent by the name of 'id' is the one who spawned us
        if (typeof window.name != "undefined" && id != window.name) return;

        var frame = parent.document.getElementById(id);
        if (frame)        {
                // reset the scroll
                parent.window.scrollTo(0,0);
                var objToResize = (frame.style) ? frame.style : frame;
                // here we fudge to get a little bigger
                var newHeight = adjustFrameHeight(id);
alert(id+" "+newHeight);
                // but not too big!
                if (newHeight > 32760) newHeight = 32760;
                // capture my current scroll position
                var scroll = findScroll();
                // resize parent frame (this resets the scroll as well)
                objToResize.height=newHeight + "px";
                // reset the scroll, unless it was y=0)
                if (scroll[1] > 0) {
                        var position = findPosition(frame);
                        parent.window.scrollTo(position[0]+scroll[0], position[1]+scroll[1]);
                }
        }
}

