﻿var sh_listen = function(win, cb){
        var l = win.setInterval(function(){
            if (win.location.hash.length > 0){
                window.clearInterval(l);
                var msg = win.location.hash.substring(1);
                win.location.hash = '';
                if (cb) cb(msg);
            }
        }, 250);
};

function shMakeListen(){
sh_listen(
    window,
    function(msg){
        var myArr = msg.split("=");
		if (myArr[0] == "setHeight"){document.getElementById("shakhesFrame").style.height = myArr[1] + "px";}
    });
}

function shCallFrame(){
   var frame = document.getElementById("shakhesFrame");
   if (frame.style.height.length < 1){
   var currentLocation = location.href;
   var hashIndex = currentLocation.indexOf('#');

   if (hashIndex > -1)
     {
        currentLocation = currentLocation.substring(0, hashIndex);
     }

   frame.contentWindow.location = frame.src + '#' + currentLocation;
   shMakeListen();
   }
}

function loadShakhes(df,tw,tb,tf,fc,bc,db,ec,oc,pr){
document.write("<iframe width='" + tw + "' onload='shCallFrame()' frameborder='0' height='20' scrolling='no' src='http://www.metalsview.com/shakhes.aspx?df=" + df + "&tw=" + tw + "&tb=" + tb + "&tf=" + tf + "&fc=" + fc + "&bc=" + bc + "&db=" + db + "&ec=" + ec + "&oc=" + oc + "&pr=" + pr + "' id='shakhesFrame'></iframe>");
}

