﻿/* Iframe */

/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:

var PreviousValue = 0;
var iframeids = ["myframe"]
var readjustValue = 0;
var i = 0;
//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide = "yes"

function SetIframeHeight(iframeids, Nexusheight) {
    var theFrame = $("myframe", parent.document.body);
    //var iframe = parent.document.getElementById(iframeids);
    //if (iframe.contentDocument != null) {
        //alert("rahul"); 
        //alert(iframe.contentDocument.documentElement.scrollHeight);
        //alert(iframe.contentDocument.offsetHeight);

        
        
    //}
    //alert($(document.body).height());
    //alert("ff:" + $(document).height());
    //var height = theFrame.height($(document.body).height() + 30);
    //alert(height);
    resizeIframe(iframeids, Nexusheight);
    if (Nexusheight != "undefined") {
        PreviousValue = Nexusheight;
    }
}

var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight = parseFloat(getFFVersion) >= 0.1 ? 0 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
function resizeCaller() {
    var dyniframe = new Array()
    for (i = 0; i < iframeids.length; i++) {
    
        if (document.getElementById)
            resizeIframe(iframeids[i])
        //reveal iframe for lower end browsers? (see var above):
        if ((document.all || document.getElementById) && iframehide == "no") {
            var tempobj = document.all ? document.all[iframeids[i]] : document.getElementById(iframeids[i])
            tempobj.style.display = "block"
        }
    }
}

function readjustIframe(loadevt) {
    var crossevt = (window.event) ? event : loadevt
    var iframeroot = (crossevt.currentTarget) ? crossevt.currentTarget : crossevt.srcElement
    if (iframeroot) {
        var iframeid = iframeroot.id;
        
            //resizeIframe(iframeid, readjustValue);
        
    }
}

function resizeIframe(frameid, Nexusheight) {
    
    if (PreviousValue != 0) {
        Nexusheight = PreviousValue;
    }
    currentfr = document.getElementById(frameid);
    if (currentfr == null) {
        currentfr = parent.document.getElementById(frameid);
        
    }
    
    if (currentfr && !window.opera) {
        currentfr.style.display = "block";
        //if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
        if (navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[0] == "Firefox") {
            
            if (Nexusheight != undefined) {
                //if (screen.height > Nexusheight) {
                    //currentfr.height = screen.height + "px";
               // }
                //else {
                  //  if (Nexusheight == 984) {
                      // currentfr.height = Nexusheight + 15 + "px";
                   // }
                   //else {
                        currentfr.height = Nexusheight + "px";
                   // }
                //}
                
            }
        }
      
        else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
        {
           // if (screen.height > currentfr.Document.body.scrollHeight) {
              //  currentfr.height = screen.height + "px";
            //}
            //else {
                currentfr.height = currentfr.Document.body.scrollHeight + "px";
            //}
            //currentfr.height = currentfr.Document.body.scrollHeight;
            //alert(currentfr.height);
            }
            else if (navigator.userAgent.substring(navigator.userAgent.indexOf("Safari")).split("/")[0] == "Safari") {
           
                if (Nexusheight != undefined) {
                    //if (screen.height > Nexusheight) {
                    //currentfr.height = screen.height + "px";
                    // }
                    //else {
                    //  if (Nexusheight == 984) {
                    // currentfr.height = Nexusheight + 15 + "px";
                    // }
                    //else {
                    currentfr.height = Nexusheight + 18 + "px";
                    // }
                    //}

                }
            }
        if (currentfr.addEventListener) {
            
            currentfr.addEventListener("load", readjustIframe, false)
        }
        else if (currentfr.attachEvent) {
            currentfr.detachEvent("onload", readjustIframe) // Bug fix line
            currentfr.attachEvent("onload", readjustIframe)
        }
    }

}



function loadintoIframe(iframeid, url, height) {
    readjustValue = height;
    if (document.getElementById) {
        if (document.getElementById(iframeid) != null) {
            document.getElementById(iframeid).src = url
        }
        else {
            var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[0];
            
            if (getFFVersion != "Firefox") {
            
            top.document.getElementById(iframeid).height = height;
            
                
            }
            else 
            {
                    
                    top.document.getElementById(iframeid).height = height;
            }
            
        }
    }
    return false;
}

function loadintoIframe2(iframeid, url, height2) {
    readjustValue = height2;
    if (document.getElementById) {
        if (document.getElementById(iframeid) != null) {
            document.getElementById(iframeid).src = url
        }
        else {
            var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[0];
            //alert(getFFVersion);
            if (getFFVersion != "Firefox") 
            {   
                            top.document.getElementById(iframeid).height = Number(top.document.getElementById(iframeid).height)+Number(height2);              
            }
            else
            {   
                top.document.getElementById(iframeid).height = Number(top.document.getElementById(iframeid).height)+Number(height2);                    
            }            
        }
    }
    return false;
}

//if (window.addEventListener)
//    window.addEventListener("load", resizeCaller, false)
//else if (window.attachEvent)
//    window.attachEvent("onload", resizeCaller)
//else
//    window.onload = resizeCaller
