//
//(c)Copyright 2008 Nirupam Biswas (AppleGrew)
//
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var alwaysShowError = false; //See end of index.html and autoIframe() for its use.

// Handle all the FSCommand messages in a Flash movie.
function PortalHeader_DoFSCommand(command, args) {
        var PortalHeaderObj = isInternetExplorer ? document.all.PortalHeader : document.PortalHeader;
        //
        // Place your code here.
        //
        if(command=="loadNewHtml"){
                if ( window.frames["icontent"] ) {
                        var iframe = window.frames["icontent"];
                        iframe.location = args;
                }
        }
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
        document.write('<script language=\"VBScript\"\>\n');
        document.write('On Error Resume Next\n');
        document.write('Sub PortalHeader_FSCommand(ByVal command, ByVal args)\n');
        document.write('        Call PortalHeader_DoFSCommand(command, args)\n');
        document.write('End Sub\n');
        document.write('</script\>\n');
}
function showError(msg){
        document.getElementById('error-msg').innerHTML = msg;
        document.getElementById('iframeResize-error').style.display = "block";
}
function autoIframe(frameId){
        try{
                if(!alwaysShowError)
                        document.getElementById('iframeResize-error').style.display = "none";

                frame = document.getElementById(frameId);
                innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
                //Various sources over the internet recommended using body but none suggested using documentElement instead.
                //Using body works but the result is very ugly. The iFrame gets resized to 900+ pixels when it should be just
                //240 pixels! After 4 hours of hit-and-trail and sifting through the DOM browsers of Firefox and Opera I hit
                //upon documentElement. Aahhhhhhh, now its setteled at last. :-)
                var ht = parseInt(innerDoc.documentElement.scrollHeight);
                objToResize = (frame.style) ? frame.style : frame;
                objToResize.height = ( ht + 10 ) + "px";
        }
        catch(err){
                var msg = err.message;
                if(!frame)
                        msg = "No element with the id '" + frameId + "' found.";
                showError(msg);
        }
}
/*function adjustIFrameSize (iframeWindow) {
        var iframeElement;
        if (iframeWindow.document.height) {
                iframeElement = document.getElementById(iframeWindow.name);
                iframeElement.style.height = iframeWindow.document.height + 'px';
                //iframeElement.style.width = iframeWindow.document.width + 'px';
        }else if(iframeWindow.document.body.clientHeight){ //For Opera
                iframeElement = document.getElementById(iframeWindow.name);
                iframeElement.style.height = iframeWindow.document.body.clientHeight + 'px';
        }else if (document.all) {
                iframeElement = document.all[iframeWindow.name];
                if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') 
                {
                        iframeElement.style.height =    iframeWindow.document.documentElement.scrollHeight + 10 + 'px';
                        //iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
                }       else {
                        iframeElement.style.height = iframeWindow.document.body.scrollHeight + 10 + 'px';
                        //iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
                }
        }
        document.getElementById("icontent").style.height=(parseInt(iframeElement.style.height)+250)+"px";
}*/
function toggleErrMsg(){
        var errMsgBox = document.getElementById('error-msg');
        var errLink = document.getElementById('error-link');
        if(errMsgBox.style.display == "block"){
                errMsgBox.style.display = "none";
                errLink.innerHTML = "Show Error Message";
        }else{
                errMsgBox.style.display = "block";
                errLink.innerHTML = "Hide Error Message";
        }
}
function Submit(){
        var search_input = document.getElementById("search-input");
        if(trimAll(search_input.value)=="") return;
        showSearchTitle();
        var query = escape(search_input.value).replace(/\+/g, '%2B')
                        .replace(/\"/g,'%22')
                        .replace(/\'/g, '%27');                            
        //PortalHeader_DoFSCommand("loadNewHtml","search.html?cx=003101503653813750308%3A1kwuefatdd0&cof=FORID%3A10&q="+escape(search_input.value)+"+more:jdcbot&sa=Search");
        PortalHeader_DoFSCommand("loadNewHtml","search.php?q="+query);
}
function box_focused(box){
        if(box.value=="Search for...")
                box.value = "";
        box.style.color = "#000000";
}
function box_blurred(box){
        if(trimAll(box.value)==""){
                box.value = "Search for...";
                box.style.color = "#777777";
        }
}
function trimAll(sString){
        while (sString.substring(0,1) == ' ')
        {
                sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length-1, sString.length) == ' ')
        {
                sString = sString.substring(0,sString.length-1);
        }
        return sString;
}
