//************************************************************************
//** To put a HTML inside the frame, use:
//** 
//** <body>
//** <script>MainWindow.DrawHeader();</script>
//** <!-- The page body follows from here -->
//** Here is your HTML
//** <!-- End of page body -->
//** <script>MainWindow.DrawFooter(true);</script>
//** </body>
//** 
//** To adjust the frame width, use
//** 
//** <script>MainWindow.DrawHeader(frame_width);</script>
//** 
//** where frame_width in pixels, or 0 (to fit the content);
//** 
//** If your page is not printable (e.g. dynamic), use
//**
//** <script>MainWindow.DrawFooter();</script>
//** 
//** instead.
//** 
//***********************************************************************
var DebugOutput=false;         //** set to true to have the HTML in the clipboard
var WebSiteRoot='/jgnss/';     //** Is updated in TMainWindow for test purpose
var WebShopRoot='/cgi-bin/jgnss/cgi?';
var UserParams;
var rat;
//if ( document.location.host.indexOf('javad.com') == -1 )
//   WebShopRoot = 'http://javad.com'+WebShopRoot;

try
{
    if ( document.domain != "javad.com" )
        document.domain = "javad.com"; //** for cross-domain JavaScript in frames
}
catch(e)
{
}

var FrameImagePath;            //** the path to the frame pictures. Is set in TMainWindow
//** Starting from '/' is recommended!

var MenuColumnWidth=90;       //** The width of the menu matrix column.
//** Adjust if the text does not fit.
var MenuAnimationDelay=10;     //** The delay between drawing/hiding rows
var MenuShiftDelay=150;        //** The delay to shift menu up or down
var CursorLeavesMenuDelay=300; //** Anti-multiple mouse over-out events
var MenuTotalRows;             //** Is calculated dynamically
var MenuAnimationRow=0;        //** Global counter of the currently showing/hiding row
var MenuInAnimationTimeout=0;  //** Timeout handle
var CursorLeavesMenuTimeout=0; //** Timeout handle
var MenuFrameItemSize=18;       //** Size of the pics that make the menu frame
var MouselessMode=false;       //** Detected automatically
var SessionTimeout = 7200000;   // Timeout to prompt relogin window
var PreventTimeout = 6900000;	// Timeout to prompt an offer to extend session
var KeepTheMenu = false;
var MenuPopupTimer;
var MenuPopupFlag = false;

var MenuCommentBox;

var DocumentHash='';           //** Firefox returns "#hash?search" as the hash :(
var DocumentSearch='';         //** it was my bug, should be ?search#hash, but nevertheless...
//***********************************************************************
DocumentHash = document.location.hash;
DocumentSearch = unescape(document.location.search);
//alert('Hash:'+DocumentHash+'\nSearch:'+DocumentSearch);
if ( DocumentHash.split('?').length>1 )
{
    DocumentSearch = '?'+DocumentHash.split('?')[1];
    DocumentHash = DocumentHash.split('?')[0];
}

//********************* WindowHandler *********************
//**
//** The class to handle window events by multiple handlers
//** The handler defined in the <body>, or otherwise before the first
//** call to this class, is called with the priority -1 (the first).
//*********************************************************


//{{{ registerNS
/**
 * registrates new namespace in window
 * @param nsName  - '.' splitted string to registrate javasscript namespce
 *                  example: com.javad.webshop.js.YouNameSpace
 *
 */
function registerNS(nsName)
{
    var nsParts = nsName.split(".");
    var root = window;

    for(var i=0; i<nsParts.length; i++)
    {
        if(typeof root[nsParts[i]] == "undefined")
            root[nsParts[i]] = new Object();

        root = root[nsParts[i]];
    }
    
}
//---------------------------------------------------------------------------}}}


//{{{ appendJS
/**
 * Include one script
 * @param srcJS  - source address of script
 * @param callback - callback function, it will be invoked after complete load( onload)
 */
function appendJS(srcJS, callback)
{
    var loaded = false;

    var script = document.createElement('script');
    var isIe           = !!(window.attachEvent && !window.opera);
    if (isIe)
    {
        script.setAttribute('src', srcJS);
        script.setAttribute('type', 'text/javascript');
    //under IE script.onload does not work... but withCSS it does work...
    } else {
        script.src = srcJS;
        script.type = 'text/javascript';
        script.onload = callback;
    }
    if (typeof script != "undefined")
    {
        var head = document.getElementsByTagName("head")[0];
        head.insertBefore(script, head.firstChild);
    }
}
//---------------------------------------------------------------------------}}}
if(location.href.indexOf("cgi-bin") == -1 && typeof($)=="undefined") appendJS("/jgnss/js-toolkits/jquery/jquery.js");

String.prototype.trim = function ()     { return this.replace(/^\s*|\s*$/g, ''); }
String.prototype.unws = function ()     { return this.replace(s/ /-/g, ''); }


function jaddEventListener(obj, action, func)
{
    if (notExists(obj))
        return false;

    if (obj.addEventListener)
    {
        obj.addEventListener(action,func, false);

    } else if (obj.attachEvent)
    {
        obj.attachEvent("on"+action, function(){ func.apply(obj, new Array()); });
    }
    return true;
}

/**
 * Checkings
 */
 isElement   = function( obj) { return (obj && obj.nodeType && obj.nodeType == 1) ? true : false; }
 isArray     = function( obj) { return (obj && obj.constructor === Array); }
 isFunction  = function( obj) { return (obj && obj.constructor === Function); }
 isRegExp    = function( obj) { return (obj && obj.constructor === RegExp); }
 isString    = function( obj) { return (typeof obj == 'string'); }
 isNumber    = function( obj) { return (typeof obj == 'number'); }
 isBoolean   = function( obj) { return (typeof obj == 'boolean'); },
 isObject    = function( obj) { return (obj && !(Ajax.isArray( obj) || Ajax.isFunction( obj) || Ajax.isSimple( obj))); },
 isNull      = function( obj) { return (obj === null); },
 isUndefined = function( obj) { return (obj === 'undefined' || obj === undefined || obj === 'unknown'); },
 //isSimple    = function( obj) { return (Ajax.isString( obj) || Ajax.isNumber( obj) || Ajax.isBoolean( obj) || Ajax.isRegExp( obj)); }
 notExists   = function (obj) { return (isUndefined( obj)) || (isNull( obj)); }
 isExists    = function (obj) { return !notExists(obj); }
 



//{{{ walk
/**
 * recursively walk through DOM (html)
  */
 //beta version, testing
function walk(obj, processFunction)
{
    //if (isUndefined(level)) level = 0;
    isExists(obj)
    {
        if ( !((isUndefined(obj.tagName))&&(isUndefined(obj.id))&&(!obj.nodeValue.trim().length)) )
        {
//            dLog("--"+obj.tagName+"::"+obj.id+"::"+obj.childNodes.length+"::"+obj.nodeValue+"::"+obj.length+"::"+obj.nodeName);
            if (isFunction(processFunction))
            {
                processFunction(obj);
            }
        }


        for (var i = 0; i<obj.childNodes.length; i++)
        {
            walk(obj.childNodes[i], processFunction);
        }
    }
}
//---------------------------------------------------------------------------}}}

//{{{ $dom
/**
 * recursively walk through DOM to find <b>the first</b> element with ID is equal to passed id
 * @param startEl - element within which, we must find element with ID is equal to id
 * @param id
  */
function $dom(startEl, id)
{
    if ( isExists(startEl) )
    {
        //if ( !((isUndefined(startEl.tagName))&&(isUndefined(startEl.id))&&(!startEl.nodeValue.trim().length)) )
        if ( !((isUndefined(startEl.tagName))&&(isUndefined(startEl.id)) ) )
        {
            if (startEl.id == id)
                return startEl;
        }

        var result = null;
        if ( notExists(startEl.childNodes))
            return result;
        for (var i = 0; i<startEl.childNodes.length; i++)
        {
            result = $dom(startEl.childNodes[i], id);
            if (result != null)
            {
                return result;
            }
        }
    }
    return null;
}
//---------------------------------------------------------------------------}}}


//**************** TEMPLATE *************** BEGIN ******************************

//{{{
/**
 * recursively walk through DOM (html) and apply to each element convertTemplateID
 * @param obj - DOM
 * @param PostfixID - replace "identificator_$" with "identificatorPostfixID"
  */
function convertAllTemplatedID(obj, postfixID)
{
    //if (isUndefined(level)) level = 0;
    if ( isExists(obj) )
    {
      if ( !((isUndefined(obj.tagName))&&(isUndefined(obj.id)) ) )

        {
//            dLog("--"+obj.tagName+"::"+obj.id+"::"+obj.childNodes.length+"::"+obj.nodeValue+"::"+obj.length+"::"+obj.nodeName);
            convertTemplateID(obj, postfixID);
//            dLog("--"+obj.tagName+"::"+obj.id+"::"+obj.childNodes.length+"::"+obj.nodeValue+"::"+obj.length+"::"+obj.nodeName);
        }

        if ( notExists(obj.childNodes))
            return;

        for (var i = 0; i<obj.childNodes.length; i++)
        {
            if ( isExists(obj.childNodes[i]))
                convertAllTemplatedID(obj.childNodes[i], postfixID);
        }
    }
}
//---------------------------------------------------------------------------}}}



//{{{ convertTemplateID
/**
 *converts templatesID for this obj.
 *ex. g.:
 *1)             <div id="content_$">  <div id="simplediv"></div> <div id="div_$"></div>  </div> this element is elem
 *2) convertTemplateID(elem, 2)
 *3) we will get <div id="content2">   <div id="simplediv"></div> <div id="div2" ></div>  </div>
 *
 *@param obj the obj for changing
 *@param postfixID
 */
function convertTemplateID(obj, postfixID)
{

    if (isExists(obj))
    {
        if (! isUndefined( obj.id))
        {
            obj.id = obj.id.replace(/_\$$/, postfixID);
        }
    }
}
//---------------------------------------------------------------------------}}}





//**************** TEMPLATE **************** END *******************************




function WindowHandlerItem(handler,priority)
{
    this.handler=handler;
    this.priority=priority;
}
function WindowHandler(event,obj)
{
    this.handlers = new Array();
    this.event    = event;
    this.obj      = obj;
}
WindowHandler.prototype.handlers;
WindowHandler.prototype.event;
WindowHandler.prototype.obj;
WindowHandler.prototype.add=function(handler,priority)
{
    //alert(this.event+' add!'+this.handlers.length);
    if ( this.handlers.length==0 )
    {
        if ( eval('window.'+this.event) )
            this.handlers[this.handlers.length] = new WindowHandlerItem(eval('window.'+this.event),-1);
        eval('window.'+this.event+'=function(){'+this.obj+'.run();}');
    }
    this.handlers[this.handlers.length] = new WindowHandlerItem(handler,priority);
}
WindowHandler.prototype.sort=function(a,b)
{
    return a.priority-b.priority;
}
WindowHandler.prototype.run=function()
{
    //alert(this.event+'!'+this.handlers.length);
    this.handlers.sort(this.sort);
    for ( var i in this.handlers )
    {
        //alert('Running '+this.event+' '+this.handlers[i].priority);
        this.handlers[i].handler();
    }
}

var WindowOnLoadHandler   = new WindowHandler('onload','WindowOnLoadHandler');
var WindowOnResizeHandler = new WindowHandler('onresize','WindowOnResizeHandler');
var WindowOnUnloadHandler = new WindowHandler('onunload','WindowOnUnloadHandler');
//**************** end of WindowHandler *******************

var IEHackForPNG=false;

if ( navigator.appVersion.search("MSIE") != -1 )
{
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ( true
        && (version >= 5.5)
        && (version < 7.0)
        //&& (document.body.filters)
        )
        {
        IEHackForPNG = true;
    }
}

function bkgdef(image,alpha)
{
    var s='';
    if ( IEHackForPNG && alpha )
    {
        s= ' style="background-image:url(\''+MainWindow.imageSpacer.src+'\');'
        +' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader'
        +'(src=\''+image.src+'\', sizingMethod=\'scale\');"';
    }
    else
        s= ' background="'+image.src+'" style="background-image:url(\''+image.src+'\');" ';
    return s;
}

function imgdef(image,width,height,alpha)
{
    if ( IEHackForPNG && alpha && width && height )
    {
        var s = "<div "
        + " style=\""+"width:"+width+"px; height:"+height+"px;font-size:1px;"
        + " filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
        + "(src=\'" + image.src + "\', sizingMethod='scale');\"></div>";
        return s;
    }
    else
    {
        if ( height ) height=' height='+height+' ';
        else height='';
        if ( width ) width=' width='+width+' ';
        else width='';
        var s='<img src="'+image.src+'"'+height+width+
        ' vspace=0 hspace=0 alt="" border=0>';
        return s;
    }
}

function heightdef(h)
{
    var s;
    if ( (''+(0+h)) == (''+h) )
        s = ' height='+h+' style="height:'+h+'px;" ';
    else
        s = ' height="'+h+'" style="height:'+h+';" ';
    return s;
}

function TPoint()
{
    this.left = 0;
    this.top  = 0;
}

function getCoords(el)
{
    //var isIE              = document.all ? 1 : 0;
    //var isDOM             = document.getElementById ? 1 : 0;
    var p = new TPoint();
    //if (isIE || isDOM )
    {
        while(el)
        {
            p.top += el.offsetTop;
            p.left += el.offsetLeft;
            el = el.offsetParent;
        }
    }
    //else
    //{
    //   p.left = el.pageX;
    //   p.top = el.pageY;
    //}
    return p;
}

var DisplayCounter=0;
var HideCounter=0;

var mi = '454850', md = '454850', mh = '454850';
var incmi = 460551, incmd = 131586, incmh = 458752;
//4540496;
var iid=null, itr=0;



function LightMenuUp() {
    var dec;
    window.clearTimeout(iid); iid=null;
    if(itr<2) {
        itr++;
        //alert(itr);

        dec = h2d(mi);
        mi = d2h(dec + 12*incmi);
        changeMenuItemColor("#"+ mi);

        dec = h2d(md);
        md = d2h(dec + 12*incmd);
        changeMenuDisabledColor("#"+ md);

        dec = h2d(mh);
        mh = d2h(dec + 12*incmh);
        changeMenuHeadColor("#"+ mh);

        if(iid==null) {
            iid = setTimeout(LightMenuUp, 1);
        }
    } else {
        iid=null;
        itr = 0;
        mi = '454850';
        md = '454850';
        mh = '454850';
    }

}


function LightMenuDown()
{
    itr=2;
    window.clearTimeout(iid); iid=null;
    changeMenuItemColor("#454850");
    changeMenuDisabledColor("#454850");
    changeMenuHeadColor("#454850");

}



function SetMenuAnimationPosition()
{
    var rowstohide = MenuTotalRows-MenuAnimationRow;
    if ( rowstohide )
    {
        var offset = Math.ceil(MainMenuTable.offsetHeight*rowstohide/MenuTotalRows);
        MainMenuTable.style.top = '-'+offset+'px';
    }
    else
        MainMenuTable.style.top = '0px';
//top.status = ''+MainMenuTable.offsetHeight+':'+MainMenuTable.style.top
//               +' '+rowstohide;
}

function DisplayMenuRow()
{
    CoverPage.pexec(true);
    CoverPage.lock();
    window.clearTimeout(MenuInAnimationTimeout);
    MenuInAnimationTimeout=0;

    if ( MenuAnimationRow<MenuTotalRows )
    {
        MenuAnimationRow++;
        SetMenuAnimationPosition();
    }

    if ( MenuAnimationRow<MenuTotalRows )
    {
        if ( MenuAnimationDelay )
            MenuInAnimationTimeout=window.setTimeout('DisplayMenuRow()',MenuAnimationDelay);
        else
            DisplayMenuRow();
    }
    else {

        ShowMenuComment.unlock();
        itr = 0; if(iid==null) iid = setTimeout(LightMenuUp, 50);
    }
    DisplayCounter++;
//top.status=DisplayCounter+':'+HideCounter;
}

function HideMenuRow()
{
    window.clearTimeout(MenuInAnimationTimeout);
    MenuInAnimationTimeout=0;



    ShowMenuComment.lock();
    HideMenuComment();

    if ( MenuAnimationRow>0 )
    {
        MenuAnimationRow--;
        SetMenuAnimationPosition();
    }

    if ( MenuAnimationRow>0 )
    {
        if ( MenuAnimationDelay )
            MenuInAnimationTimeout=window.setTimeout('HideMenuRow()',MenuAnimationDelay);
        else
            HideMenuRow();
    }
    else
    {
        KeepTheMenu = false;
        DisplayMenu.lock();
        MainMenuDiv.style.visibility="hidden";
        RedPepper.src = MainWindow.imageBacklight[0].src;
        CoverPage.unlock();
        CoverPage(false);

    }
    HideCounter++;
//top.status=DisplayCounter+':'+HideCounter;
}

function DisplayMenu()
{
    window.clearTimeout(CursorLeavesMenuTimeout);
    CursorLeavesMenuTimeout=0;
    if ( MenuAnimationRow>=MenuTotalRows ) return;

    var p = getCoords(document.getElementById("FrameTop"));
    var widthMenu = MenuMatrix.length*(MenuColumnWidth+MenuFrameItemSize)+MenuFrameItemSize; //MainMenuDiv.offsetWidth;
    MainMenuDiv.style.left = ''+(p.left+(FrameTop.offsetWidth-widthMenu)/2)+'px';
    MainMenuDiv.style.top  = ''+(MainWindow.heightTopArea)+'px';
    MenuCommentBox = document.getElementById("menu-comment");
    MenuCommentBox.style.width = widthMenu - 27;
    MenuCommentBox.style.left = ''+(p.left+(FrameTop.offsetWidth-widthMenu + 27)/2)+'px';
    MenuCommentBox.style.top = ''+(MainWindow.heightTopArea + MainMenuDiv.offsetHeight - 13)+'px';

    SetMenuAnimationPosition();

    MainMenuDiv.style.visibility="visible";

    if ( MouselessMode )
    {
        MainMenuDiv.onmouseout="";
        window.setTimeout(HideMenu,5000);
    }
    DisplayMenuRow();
    RedPepper.src = MainWindow.imageBacklight[1].src;
}

function _DisplayMenu() {
    return true;
}


function HideMenu()
{
    if ( MenuAnimationRow<=0 ) return false;
    window.clearTimeout(MenuInAnimationTimeout);
    LightMenuDown();
    MenuInAnimationTimeout=window.setTimeout('HideMenuRow()',MenuShiftDelay);
    return true;
}

function HideMenuDelayed()
{
    window.clearTimeout(CursorLeavesMenuTimeout);
    CursorLeavesMenuTimeout=window.setTimeout('HideMenu()',CursorLeavesMenuDelay);
}

function TMenuItem(name,link, comment)
{
    this.name = name;
    this.setLink(link);
    this.comment = comment;
}

TMenuItem.prototype.setLink=function(link)
{
    this.link = link;
    this.disabled = link=='#';
}

TMenuItem.prototype.name;
TMenuItem.prototype.comment;
TMenuItem.prototype.link;
TMenuItem.prototype.disabled;
TMenuItem.prototype.draw=function()
{
    var s = '';
    s += '<td nowrap valign=middle align=center class=menubg>';
    s += this.getHTML()+'</td>\n';
    return s;
}

TMenuItem.prototype.getComment=function()
{
    return this.comment;
}

TMenuItem.prototype.getHTML=function(id)
{
    if (this.link&&this.link.length>2&&this.link.charAt(0)!='/'&&this.link.substr(0,5)!='http:')
        this.link = WebSiteRoot+this.link;
    if ( this.disabled )
        return "<div onmouseover=\"HideMenuComment();return false;\" class=\"menudisabled\">"+
        this.name.toUpperCase()+
        "</div>";
    else
        return "<div onmouseout=\"HideMenuCommentDelayed();return false;\" onmouseover=\"ShowMenuComment.pexec(this);return false;\"  class=\"menuitem\"><a href=\""+this.link+ "\">"+
        this.name.toUpperCase()+
        "</a><span style=\"display:none;\">" + this.comment + "</span></div>";
}

function TMenuArray(name,array)
{
    this.name = name;
    this.array = array;
}
TMenuArray.prototype.name;
TMenuArray.prototype.array;
TMenuArray.prototype.draw=function()
{
    return '<td class="menuhead" nowrap valign=middle align=center>'+this.name.toUpperCase()+'</td>\n';
}

var MenuMatrix = new Array(
    new TMenuArray("Products",
        new Array(
            new TMenuItem("OEM","products/oem/", "Learn about OEM board-level products and order")
            ,new TMenuItem("Receivers","products/receivers/",  "Learn about TRIUMPH-1, TRIUMPH-4X, ALPHA, DELTA, SIGMA, GISmore, etc. and order")
            ,new TMenuItem("Antennas","products/antennas/",  "Learn about antennas, smart antenna, gyro-integrated antenna and order")
            ,new TMenuItem("Software","products/software/", "Learn about Justin, Giodis, Tracy/Victor, Carlson Software and order")
            ,new TMenuItem("Accessories","products/accessories/", "Learn about external modems, cables, RTK caddy, RTK umbrella, etc. and order")
            ))
    ,  new TMenuArray("Support",
        new Array(
            new TMenuItem("Activate",WebShopRoot+"Action=DrawMyOAFs","Locate your OAF files for your JAVAD GNSS products and load them into your receivers") //"#"
            ,new TMenuItem("Update","support/update.html","Locate the latest firmware for your JAVAD GNSS receivers and load them into your receivers") //
            ,new TMenuItem("Upgrade",WebShopRoot+"Action=DrawReceiverTool","Purchase upgrades for your JAVAD GNSS receivers")
            ,new TMenuItem("Advanced","support/advanced/", "View GPS, GLONASS, SBAS and Galileo satellites availability. Learn and use our GNSS data analysis tools")
            ,new TMenuItem("Publications","support/manuals.html", "Download user manuals, data sheets, technical information, and presentations")
            ))
    ,  new TMenuArray("Sales",
        new Array(
            new TMenuItem("Dealers","sales/dealers/index.html", "View our world-wide dealers' network")
            ,new TMenuItem("Options","products/options/index.html","Learn JAVAD GNSS receiver options and terminologies")
            ,new TMenuItem("Prices","sales/prices/pricing.html","Learn about our pricing policies")
            ,new TMenuItem("Events",WebShopRoot+"Action=DrawEvents","Learn about our events and conferences that we participate")
            ,new TMenuItem("Arts&Slides","sales/pictures/","Download our artwork to design your own advertisements and presentations")
            ))
    ,  new TMenuArray("Javad",
        new Array(
            new TMenuItem("Contact","javad/contact/","View our addresses and how to contact us")
            ,new TMenuItem("News","javad/news/","Read our news and press releases")
            ,new TMenuItem("WEB","javad/web/","View recent changes to our website and RSS subscribe to get instant notifications")
            ,new TMenuItem("Photos",WebShopRoot+"Action=DrawPhotoGallery","View photos of our funs and parties")
            //,new TMenuItem("Photos",WebShopRoot+"Action=DrawPhotoGallery","View photos of our funs and parties")
            ,new TMenuItem("JNS","http://www.javad.com/jns/index.html","To support our previous Javad Navigation Systems customers")
            ))
    ,  new TMenuArray("My",
        new Array(
            new TMenuItem("Login","#","Register/Login to order products and get access to private pages.")
            ,new TMenuItem("Profile",WebShopRoot+"Action=Members","Private area for your account")
            ,new TMenuItem("Cart",WebShopRoot+"Action=ReCount","Access your shopping cart when ordering products")
            ,new TMenuItem("Orders",WebShopRoot+"Action=DrawOrderManager","Access and review the status of your orders")
            ,new TMenuItem("Questions",WebShopRoot+"Action=DrawQuestionManager","Ask us questions and view our answers from over 20 highly qualified specialists (including Javad himself). It is much better than e-mails, or phone calls")
            ))
    );

function MenuArrayUpdateItem(i,j)
{
    MainMenuTable.rows[3+j*2].cells[1+2*i].innerHTML = MenuMatrix[i].array[j].getHTML();
}

function DrawMenuItemCallback(i,j)
{
    var s='';
    if ( MenuMatrix[i].array.length > j )
        s += MenuMatrix[i].array[j].draw();
    else
        s += '<td class="menudisabled">&nbsp;</td>\n';
    return s;
}

function OpenMenuRow(height)
{
    var s='';
    if ( height )
        s += '<tr height='+height+' style="height:'+height+'px">';
    else
        s += '<tr>';
    return s;
}

function CloseMenuRow()
{
    var s='';
    s += '</tr>\n';
    return s;
}

function DrawOneRow(draw,need_separator)
{
    var s='';
    s += OpenMenuRow(24);
    MenuTotalRows++;
    s += '<td'+bkgdef(MainWindow.imageMenuLeft,true)+'></td>';
    for (var i=0; i<MenuMatrix.length; i++ )
    {
        s += eval(draw);
        if ( i<MenuMatrix.length-1)
            s += '<td'+bkgdef(MainWindow.imageMenuMiddle)+'></td>';
    }

    s += '<td'+bkgdef(MainWindow.imageMenuRight,true)+'></td>';
    s += CloseMenuRow();

    if ( need_separator )
    {
        s += OpenMenuRow(6);
        MenuTotalRows++;
        s += '<td'+bkgdef(MainWindow.imageMenuLeft,true)+'></td>';
        for (var i=0; i<MenuMatrix.length; i++ )
        {
            s += '<td'+bkgdef(MainWindow.imageMenuPin)+'></td>';
            if ( i<MenuMatrix.length-1)
                s += '<td'+bkgdef(MainWindow.imageMenuMiddle)+'></td>';
        }
        s += '<td'+bkgdef(MainWindow.imageMenuRight,true)+'></td>';
        s += CloseMenuRow();
    }
    return s;
}

function getPopupMenuHTML()
{
    var s='';

    // Determine the number of rows
    var MenuRows=0;
    for (var i=0; i<MenuMatrix.length; i++ )
    {
        if ( MenuMatrix[i].array.length > MenuRows )
            MenuRows = MenuMatrix[i].array.length;

    }

    s += '<table id="MainMenuTable" cellpadding=0 cellspacing=0 border=0 style="position:relative;left:0;top:0;">';
    s += '<colgroup>'
    +'<col width='+MenuFrameItemSize+'>'
    +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
    +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
    +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
    +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
    +'<col width='+MenuColumnWidth+'>'
    +'<col width='+MenuFrameItemSize+'>'
    +'</colgroup>';

    MenuTotalRows = 0;

    // The top of the frame
    s += OpenMenuRow(MenuFrameItemSize);
    MenuTotalRows++;
    s += '<td>'+imgdef(MainWindow.imageMenuLeftTop,MenuFrameItemSize,MenuFrameItemSize,true)+'</td>';
    for (var i=0; i<MenuMatrix.length; i++ )
    {
        s += '<td'+bkgdef(MainWindow.imageMenuTop,true)+'</td>\n';
        if ( i<MenuMatrix.length-1)
            s += '<td>'+imgdef(MainWindow.imageMenuTopMiddle,MenuFrameItemSize,MenuFrameItemSize,true)+'</td>';
    }
    s += '<td>'+imgdef(MainWindow.imageMenuRightTop,MenuFrameItemSize,MenuFrameItemSize,true)+'</td>';
    s += CloseMenuRow();

    // The first row: top level menus with separator
    s += DrawOneRow("MenuMatrix[i].draw()",true);

    // The second level menu rows
    for (var j=0; j<MenuRows; j++ )
    {
        s += DrawOneRow("DrawMenuItemCallback(i,"+j+")",j<MenuRows-1);
    }
   
    // The bottom of the frame
    s += OpenMenuRow(MenuFrameItemSize);
    MenuTotalRows++;
    s += '<td>'+imgdef(MainWindow.imageMenuLeftBottom,MenuFrameItemSize,MenuFrameItemSize,true)+'</td>';
    for (var i=0; i<MenuMatrix.length; i++ )
    {
        s += '<td'+bkgdef(MainWindow.imageMenuBottom,true)+'></td>\n';
        if ( i<MenuMatrix.length-1)
            s += '<td>'+imgdef(MainWindow.imageMenuBottomMiddle,MenuFrameItemSize,MenuFrameItemSize,true)+'</td>';
    }
    s += '<td>'+imgdef(MainWindow.imageMenuRightBottom,MenuFrameItemSize,MenuFrameItemSize,true)+'</td>';
    s += CloseMenuRow();
    s += '</table>\n';
    return s;
}

function DrawPopupMenu()
{
    var s='';
    s+="<div id=\"cover-layer\"></div><div id=\"menu-comment\" style=\" display: none; height:0px; width: 500px; overflow: hidden; z-index: 99;position: absolute;left:0px;top:0px;clip:rect(0px auto auto auto);\"><script>Black7Box.open(\"menu-comment-inner\")</script><div style=\"color: #FFFF00;\" id=\"menu-comment-text\">Here should be a comment on menu item</div><script>Black7Box.close()</script></div>";


   
    s +=
    '<div id="MainMenuDiv" style="'+
    'visibility:hidden;'+
    'position: absolute;'+
    'left:0px;'+
    'top:0px;'+
    'z-index:100;'+
    'clip:rect(0px auto auto auto);'+
    'overflow:hidden;'+
    '" '+
    ' onmouseover="MouselessMode=false;DisplayMenu.pexec();"'+
    ' onmouseout="HideMenuDelayed();"'+
    '>';
    s += getPopupMenuHTML();
    s += '</div>';
    return s;
}

function TMainWindow_header(frame_width)
{
    if ( (''+(0+frame_width)) == (''+frame_width) )
        this.widthPage = frame_width;
    else 
        frame_width = 0;
      
    if ( DocumentHash == '#'+this.NoFrameHash )
    {
    }
    else if ( DocumentHash == '#'+this.PrintHash )
    {
        document.writeln('<a name="'+this.PrintHash+'"></a>');
        document.writeln('<table align=center cellspacing=0 cellpadding=8 border=0 width="100%"><tr><td>&nbsp;</td>');
        if ( frame_width )
            document.writeln('<td id="DocumentWindow" valign=top width='+frame_width+'>');
        else
            document.writeln('<td id="DocumentWindow" valign=top width='+this.widthMainColumn+'>');
    }
    else
    {
        // The biggest issue below is that the "height" attribute is not supported by
        // strict HTML anymore!
        document.body.style.backgroundImage = "url('"+this.imageMiddleBackground.src+"')";
        document.body.style.backgroundAttachment = "fixed";
        document.body.style.fontSize = "62.5%";
        // Browser window background
        document.writeln('<table width="100%" height="100%" cellpadding=0 cellspacing=0 border=0><tr >');
        document.writeln('<td width="50%"'+bkgdef(this.imageSideBackground)+' ></td>');
        document.writeln('<td align=center valign=top>');
        // Main table
        document.writeln('<table id="watchme"  height="100%" align=center cellpadding=0 cellspacing=0 border=0 '+
            ((this.widthPage)?'width='+this.widthPage:'')+
            '>');

        // Navigation bar
        document.writeln('<tr '+heightdef(this.heightTopArea)+' class="whitebg">');

        document.write('<td' + bkgdef(this.imageLeftMiddle) + '>&nbsp;</td><td valign=top style="padding-top:4px;">');
        document.writeln('<table width="100%"'+heightdef(this.heightTopArea)+' cellpadding=0 cellspacing=0 border=0 >');
        document.writeln('<colgroup><col width="2%"><col width="31%"><col width="34%"><col width="31%"><col width="2%"></colgroup>');
        document.writeln('<tr style="background-color:#FFFFFF;">');
        document.writeln('<td>&nbsp;</td>');
        document.writeln('<td align=left valign=middle><a onfocus="blur();" href="'+WebSiteRoot+'">'+imgdef(this.imageLogo)+'</a></td>');
        document.writeln('<td id="FrameTop" align=center valign=middle onmouseover="MouselessMode=false;DisplayMenu.pexec();"  onmouseout="HideMenuDelayed();"><img id=RedPepper src="'+this.imageBacklight[0].src+'" border=0 alt="" usemap="#peppermap"><map id="peppermap" name="peppermap"><area shape="circle" coords="160,25,20" onmouseover="InvokeMenuTimer();MouselessMode=false;DisplayMenu.pexec();KeepTheMenu=true;" onmouseout="KillMenuTimer();" /></map></td>');
        document.writeln('<td align="right" valign="middle"><div style="float: right;" id="LogonArea" class="logondiv"></div></td>');
//        document.writeln('<td><div style="float: left;" align="left" ><ul class="lang-switcher"><li class="list"><a class="link" href="javascript:chlang(\'en\')"><span id="en-lang"></span></a></li><li><a href="javascript:chlang(\'ru\')"><span id="ru-lang"></span></a></li></ul></div></td>');
        document.writeln('</tr>');
        document.writeln('</table>');
        document.writeln('<td' + bkgdef(this.imageRightMiddle) + '></td></td>');

        document.write('</tr>');
      
        // Top frame row
      
        //document.writeln('<tr '+bkgdef(this.imageMiddleTop)+' '+heightdef(this.heightFrame)+'>');
        //document.writeln('<tr  '+bkgdef(this.imageMiddleTop)+' '+heightdef(0)+'>');
        //document.writeln('<td width='+this.widthFrame+' align=left valign=top>'+imgdef(this.imageLeftTop)+'</td>');
        // Top level menu
        //document.write('<td id="FrameTop" align=center valign=middle>');
        /*document.write('<table cellpadding=0 cellspacing=0 border=0 onmouseover="MouselessMode=false;DisplayMenu.pexec();" onmouseout="HideMenuDelayed();" onclick="MouselessMode=true;DisplayMenu.pexec();">');
      document.writeln('<colgroup>'
                      +'<col width='+MenuFrameItemSize+'>'
                      +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
                      +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
                      +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
                      +'<col width='+MenuColumnWidth+'><col width='+MenuFrameItemSize+'>'
                      +'<col width='+MenuColumnWidth+'>'
                      +'<col width='+MenuFrameItemSize+'>'
                      +'</colgroup><tr><td></td>');
        */
        /*
      for ( var i=0; i<MenuMatrix.length; i++ )
      {
         document.writeln('<td id=TopMenuItem'+i+'>'+imgdef(this.imagesMenuDisabled[i])+'</td><td></td>');
      }*/
        //document.writeln('</td>');//document.writeln('</tr></table></td>');
        //document.writeln('<td width='+this.widthFrame+' align=right valign=top>'+imgdef(this.imageRightTop)+'</td>');
        //document.writeln('</tr>');
           
        // End of Top frame row

        // Left frame column
        document.writeln('<tr>');
        document.writeln('<td '+bkgdef(this.imageLeftMiddle)+'></td>');

        // The document area
        document.write('<td id="DocumentWindow" valign=top>'+
            '<table width="100%"'+
            ' border=0'+
            ' cellpadding='+this.widthGap+
            ' cellspacing=0'+
            '><tr><td valign=top style="padding-top:0px;">');
    }
}

function TMainWindow_footer(printable)
{
    if ( DocumentHash == '#'+this.NoFrameHash )
    {
    }
    else if ( DocumentHash == '#'+this.PrintHash )
    {
        document.writeln('</td></tr>');
        document.writeln('<tr><td ></td><td valign=middle align=left class="copyright">'+this.Copyright+'</td><td></td></tr>');
        document.writeln('</table>');
    }
    else
    {
        // End of document area
        document.write('</td></tr>');
        document.writeln('</table></td>');
        // Right frame column
        document.writeln('<td '+bkgdef(this.imageRightMiddle)+'>&nbsp;</td>');
        document.writeln('</tr>');
        // page corner
        document.writeln('<tr '+heightdef(this.heightPageCorner)+'>');
        document.writeln('<td '+bkgdef(this.imageLeftMiddle)+'>&nbsp;</td>');
        document.write('<td align=right valign="top" >');
        document.writeln('<table'+bkgdef(this.imagePageCorner)+' width='+this.widthPageCorner+' cellpadding=0 cellspacing=0 border=0'+heightdef(this.heightPageCorner)+'><tr>');
        document.write('<td align=right style="padding-right:15px;">');
        if ( printable )
        {
            document.write('<a id=PrintItLink onfocus="blur();" href="#'+this.PrintHash+'" target=_blank onmouseout="top.status=\'\';return true;" onmouseover="top.status=\'Printable version of the page\';return true;">');
            document.write('<img  border=0 alt="Print this page" width='+this.widthPrinter+' src="'+this.imagePrinter.src+'">');
            document.write('</a>');
        }
        document.writeln('</td></tr></table></td>');
        document.writeln('<td '+bkgdef(this.imageRightMiddle)+'>&nbsp;</td>');
        document.writeln('</tr>');
        // Bottom frame row
        document.writeln('<tr '+bkgdef(this.imageMiddleBottom)+' '+heightdef(this.heightFrame)+'>');
        document.writeln('<td width='+this.widthFrame+' align=left valign=top>'+imgdef(this.imageLeftBottom)+'</td>');
      
        document.writeln('<td><table width="100%" '+heightdef(this.heightFrame)+' cellspacing=0 cellpadding=0 border=0><tr>');
        document.writeln('<td valign=middle align=left class="copyright">'+this.Copyright+'</td>');
        document.writeln('<td valign=middle align=right>&nbsp;</td>');
        document.writeln('<td valign=middle align=right width=38>&nbsp;</td>');
        document.writeln('</tr></table></td>');


        document.writeln('<td width='+this.widthFrame+' align=right valign=top>'+imgdef(this.imageRightBottom)+'</td>');
        document.writeln('</tr>');
        // End of Bottom frame row
        document.writeln('</table>');
        // End of browser background
        document.writeln('</td>');
        document.writeln('<td width="50%"'+bkgdef(this.imageSideBackground)+'></td>');
        document.writeln('</tr></table>');
      
        document.writeln(DrawPopupMenu());

        UserInfoCallback.add(setLogonWindow);
        UserInfoCallback.add(setPopupMenuItems);

        updateUserParams();

    }
    if ( DebugOutput )
    {
        document.write('<textarea id="holdtext" style="display:none;"></textarea>');
        holdtext.innerText=document.body.outerHTML+'\n';
        Copied = holdtext.createTextRange();
        Copied.execCommand("Copy");
    }
}

function updateUserParams() {
    
    try {
        $(function() {
            try {
                if(UserParams == null || typeof(UserParams)==undefined) {
                    $.getScript(WebShopRoot+"Action=UserInfo");
                }
            }
            catch(e){}
        });
    } catch(e) {
        window.setTimeout(updateUserParams, 1000);        
    }    
}


function TImage(url)
{
    var img = new Image();
    img.src = url;
    return img;
}

function TMainWindow()
{
    if ( document.location.pathname.substring(1,7)=='.jgnss' )
        WebSiteRoot = '/.jgnss/';
    FrameImagePath = WebSiteRoot+'frame/';
    this.widthFrame=30;
    this.heightFrame=30;
    this.widthLogo=150;
    this.heightLogo=25;
    this.widthGap=8; // the gap between the frame and its content
    this.heightTopArea=50;
    this.heightPageCorner=14;
    this.widthPageCorner=170;
    this.widthPrinter=18;
    this.widthDocument = 640;
    this.widthHotSpot=326;
    //this.widthPage = this.widthDocument+2*this.widthFrame+2*this.widthGap;
    this.widthPage = 1024; //Just fits 1280 screen width
    this.widthDocument = this.widthPage-(2*this.widthFrame+2*this.widthGap);

    // The following can be used for the page layout
    this.widthMainColumn  = Math.round(0.72*(this.widthDocument-2*this.widthGap));
    this.widthSmallColumn = this.widthDocument-2*this.widthGap-this.widthMainColumn;
    this.widthColumnGap   = 2*this.widthGap;
  
    this.PrintHash = 'PrintIt';
    this.NoFrameHash = 'NoFrame';
    this.Copyright = 'Copyright&copy;&nbsp;JAVAD&nbsp;GNSS&nbsp;Inc. All&nbsp;rights&nbsp;reserved.';

    // Preload images

    this.imageSpacer = TImage(FrameImagePath+'spacer.gif');
    /*
   this.imageLeftTop      = TImage(FrameImagePath+'frame_tl.png');
   this.imageMiddleTop    = TImage(FrameImagePath+'frame_tm.png');
   this.imageRightTop     = TImage(FrameImagePath+'frame_tr.png');
   this.imageLeftMiddle   = TImage(FrameImagePath+'frame_ml.png');
   this.imageRightMiddle  = TImage(FrameImagePath+'frame_mr.png');
   this.imageLeftBottom   = TImage(FrameImagePath+'frame_bl.png');
   this.imageMiddleBottom = TImage(FrameImagePath+'frame_bm.png');
   this.imageRightBottom  = TImage(FrameImagePath+'frame_br.png');
*/

    this.imageLeftTop      = TImage(FrameImagePath+'spacer.gif');
    this.imageMiddleTop    = TImage(FrameImagePath+'frame_tm.png');
    this.imageRightTop     = TImage(FrameImagePath+'spacer.gif');
    this.imageLeftMiddle   = TImage(FrameImagePath+'frame_ml1.png');
    this.imageRightMiddle  = TImage(FrameImagePath+'frame_mr1.png');
    this.imageLeftBottom   = TImage(FrameImagePath+'frame_bl1.png');
    this.imageMiddleBottom = TImage(FrameImagePath+'frame_bm1.png');
    this.imageRightBottom  =TImage(FrameImagePath+'frame_br1.png');
 
   
    this.imageLogo       = TImage(FrameImagePath+'logo-ani1.gif');
    this.imageJNSLogo    = TImage(FrameImagePath+'JNS_logo.png');
    this.imageBacklight = new Array();
    //this.imageBacklight[0]  = TImage(FrameImagePath+'backlight_red.png');
    //this.imageBacklight[1]  = TImage(FrameImagePath+'backlight_grey.png');

    //   this.imageBacklight[0]  = TImage(FrameImagePath+'red_pepper2.png');
    this.imageBacklight[0]  = TImage(FrameImagePath+'red_pepper.png');
    this.imageBacklight[1]  = TImage(FrameImagePath+'gray_pepper.png');


    var bkg_no;
    bkg_no = Math.round(2*Math.random());
   
    this.imageMiddleBackground = TImage(FrameImagePath+'spacer.gif');
    bkg_no = Math.round(2*Math.random());
    bkg_no = 2;
    this.imageSideBackground   = TImage(FrameImagePath+'bkg'+bkg_no+'1.png');

    //this.imagePageCorner = TImage(FrameImagePath+'pagecorner.png');
    this.imagePageCorner = TImage(FrameImagePath+'spacer.gif');
    this.imagePrinter    = TImage(FrameImagePath+'printer1.gif');

    this.imageMenuMiddleRow    = TImage(FrameImagePath+'menu-middle-row.png');

    var sfx = '-dg';
    this.imageMenuLeft         = TImage(FrameImagePath+'menu-left'+sfx+'.png');
    this.imageMenuMiddle       = TImage(FrameImagePath+'menu-mid'+sfx+'.png');
    this.imageMenuRight        = TImage(FrameImagePath+'menu-right'+sfx+'.png');

    this.imageMenuLeftBottom   = TImage(FrameImagePath+'menu-lb'+sfx+'.png');
    this.imageMenuRightBottom  = TImage(FrameImagePath+'menu-rb'+sfx+'.png');
    this.imageMenuBottom       = TImage(FrameImagePath+'menu-bottom'+sfx+'.png');
    this.imageMenuBottomMiddle = TImage(FrameImagePath+'menu-mb'+sfx+'.png');

    this.imageMenuLeftTop   = TImage(FrameImagePath+'menu-lt'+sfx+'.png');
    this.imageMenuRightTop  = TImage(FrameImagePath+'menu-rt'+sfx+'.png');
    this.imageMenuTop       = TImage(FrameImagePath+'menu-top'+sfx+'.png');
    this.imageMenuTopMiddle = TImage(FrameImagePath+'menu-mt'+sfx+'.png');

    this.imageMenuPin          = TImage(FrameImagePath+'pin'+sfx+'.png');

    this.imagesMenuDisabled = new Array();
    for ( var i=0; i<MenuMatrix.length; i++ )
    {
        this.imagesMenuDisabled[i] = TImage(FrameImagePath+'menu-'+(i+1)+'d.png');
    }

    this.DrawHeader = TMainWindow_header;
    this.DrawFooter = TMainWindow_footer;
}

function Email(address,a_domain)
{
    var domain = 'javad.com';
    if ( a_domain != null ) domain = a_domain;
    domain = '@'+domain;
    document.write('<a'
        +' onmouseover="top.status=\'Send e-mail to <'+address+domain+'>\';return true"'
        +' onmouseout="top.status=\'\';return true"'
        +'href="mailto:'+address+domain+'">'+address+domain+'</a>');
}

var MainWindow=new TMainWindow();

function StartMainColumn()
{
    document.write('<table id="ColumnsTable" name="ColumnsTable" cellpadding=0 cellspacing=0 border=0 width="100%" height="100%"><tr height="100%"><td width='+MainWindow.widthMainColumn+' valign=top>');
}

function StartSecondColumn()
{
    if ( DocumentHash != '#'+MainWindow.PrintHash )
        document.write('</td><td><img width='+MainWindow.widthColumnGap+' height=1 src="'+MainWindow.imageSpacer.src+'"></td><td height="100%" width='+MainWindow.widthSmallColumn+' valign=top>');
    else
        document.write('</td></tr><tr><td><img height='+MainWindow.widthColumnGap+' width=1 src="'+MainWindow.imageSpacer.src+'"></td></tr><tr><td valign=top>');
}

function CloseDocument()
{
    document.writeln('</td></tr></table></div>');
}

var ColumnsTableOriginalOffset=0;
var ColumnIFrameId='';
function ColumnIFrameResize(test)
{
    if ( test ) alert(test);
    if ( typeof(ColumnsTable)!='undefined' && ColumnIFrameId !='' )
    {
        if ( DocumentHash == '#'+MainWindow.PrintHash )
        {
        }
        else
        {
            if ( ColumnsTableOriginalOffset==0 )
                ColumnsTableOriginalOffset = ColumnsTable.offsetHeight;
            else
                ColumnsTable.style.height = ColumnsTableOriginalOffset+'px';
            var p1 = getCoords(ColumnsTable);
            var p2 = getCoords(DocumentWindow);
            var height = 0;
	    if (DocumentWindow.offsetHeight > 0)
		{
			try {
			height = DocumentWindow.offsetHeight-2*MainWindow.widthGap-(p1.top-p2.top);
			} catch(jex){}
		}
            
	    if ( document.getElementById )
                document.getElementById(ColumnIFrameId).style.height=height+'px';
	    else
	   ColumnsTable.style.height = height+'px'; 
        }
    }
}

function DrawIFrame(src,id,cls)
{
    var width=MainWindow.widthSmallColumn;
    if ( DocumentHash == '#'+MainWindow.PrintHash )
    {
        width=MainWindow.widthMainColumn;
    }
    else // here I disabled IFrame for print version!
    {
        ColumnIFrameId=id;
        document.writeln('<iframe onload="ColumnIFrameResize();" height="500" width='+width+' id="'+id+'" src="'+src+'" class="'+cls+'" ALLOWTRANSPARENCY=true scrolling="auto">'+
            'Your browser does not support IFRAME. Click <a href="'+src+'" target=_blank>here</a> to see its content.'+
            '</iframe>');

        WindowOnLoadHandler.add(ColumnIFrameResize,0);
        WindowOnResizeHandler.add(ColumnIFrameResize,0);
    }
}

var GreyBox =
{
    image_tl: null,
    image_tr: null,
    image_bl: null,
    image_br: null,
    open: function()
    {
        if ( this.image_tl==null ) this.image_tl = new TImage(FrameImagePath+'corner_grey8tl.gif');
        if ( this.image_tr==null ) this.image_tr = new TImage(FrameImagePath+'corner_grey8tr.gif');
        document.write(
            '<div class="lightgreyBox">'+
            '<div class="lightgreyBoxHeader" style="background: url('+this.image_tr.src+') 100% 0 no-repeat;">'+
            '<div style="background: url('+this.image_tl.src+') 0 0 no-repeat;"></div></div>'+
            '<div class="lightgreyBoxContent">'
            );

    },
    close: function()
    {
        if ( this.image_bl==null ) this.image_bl = new TImage(FrameImagePath+'corner_grey8bl.gif');
        if ( this.image_br==null ) this.image_br = new TImage(FrameImagePath+'corner_grey8br.gif');
        document.write(
            '</div>'+
            '<div class="lightgreyBoxFooter" style="background: url('+this.image_br.src+') 100% 0 no-repeat;">'+
            '<div style="background: url('+this.image_bl.src+') 0 0 no-repeat;"></div></div>'+
            '</div>'
            );
    },
    stop: function()
    {
        document.write('</div></div>');
    }
}

var Black7Box =
{
    image_tl: null,
    image_tr: null,
    image_bl: null,
    image_br: null,
    open: function(id, suffix)
    {
        var idparam = "";
        if(suffix==null) suffix="trans.png";
        if ( this.image_tl==null || suffix!="" ) this.image_tl = new TImage(FrameImagePath+'corner_black78tl' + suffix);
        if ( this.image_tr==null || suffix!="" ) this.image_tr = new TImage(FrameImagePath+'corner_black78tr' + suffix);
        if ( this.image_bl==null || suffix!="" ) this.image_bl = new TImage(FrameImagePath+'corner_black78bl' + suffix);
        if ( this.image_br==null || suffix!="" ) this.image_br = new TImage(FrameImagePath+'corner_black78br' + suffix);
/*
        if ( this.image_tl==null || suffix!="" ) this.image_tl = new TImage(FrameImagePath+'corner_greytltrans.gif');
        if ( this.image_tr==null || suffix!="" ) this.image_tr = new TImage(FrameImagePath+'corner_greytrtrans.gif');
        if ( this.image_bl==null || suffix!="" ) this.image_bl = new TImage(FrameImagePath+'corner_greybltrans.gif');
        if ( this.image_br==null || suffix!="" ) this.image_br = new TImage(FrameImagePath+'corner_greybrtrans.gif');
*/

        if ( id!=null ) var idparam = 'id="' + id + '"';

        var str='';
        str+='<div ' + idparam + '  style="width: 100%;">';
        str+='<table  border="0" cellpadding="0" cellspacing="0">';
        str+='<tr>';
        str+='<td><img src="' + this.image_tl.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<td style="width:100%;background: #454850;"><\/td>';
//        str+='<td style="width:100%;background: #4d4d4d;"><\/td>';
        str+='<td><img src="' + this.image_tr.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<\/tr>';
        str+='<tr>';
        str+='<td style="background: #454850;"><\/td>';
        str+='<td style="background: #454850;color: #8EC74B;">';
//        str+='<td style="background: #4d4d4d;"><\/td>';
//        str+='<td style="background: #4d4d4d;color: #8EC74B;">';

        document.write(str);

    },
    close: function()
    {
        var str='';
        str+='<\/td>';
        str+='<td style="background: #454850;"><\/td>';
//        str+='<td style="background: #4d4d4d;"><\/td>';
        str+='<\/tr>';
        str+='<tr>';
        str+='<td><img src="' + this.image_bl.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<td style="width:100%; background: #454850;"><\/td>';
//        str+='<td style="width:100%; background: #4d4d4d;"><\/td>';
        str+='<td><img src="' + this.image_br.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<\/tr>';
        str+='<\/table>';
        str+='<\/div>';


        document.write(str );
    },
    stop: function()
    {

        var str='';
        str+='<\/td>';
        str+='<td style="background: #454850;"><\/td>';
//        str+='<td style="background: #4d4d4d;"><\/td>';
        str+='<\/tr>';
        str+='<\/table>';
        str+='<\/div>';
        document.write(str);
    }
}


var LightBox =
{
    image_tl: null,
    image_tr: null,
    image_bl: null,
    image_br: null,
    open: function(id, suffix)
    {
        var idparam = "";
        if(suffix==null) suffix="trans.png";
        if ( this.image_tl==null || suffix!="" ) this.image_tl = new TImage(FrameImagePath+'corner_light8tl' + suffix);
        if ( this.image_tr==null || suffix!="" ) this.image_tr = new TImage(FrameImagePath+'corner_light8tr' + suffix);
        if ( this.image_bl==null || suffix!="" ) this.image_bl = new TImage(FrameImagePath+'corner_light8bl' + suffix);
        if ( this.image_br==null || suffix!="" ) this.image_br = new TImage(FrameImagePath+'corner_light8br' + suffix);

        if ( id!=null ) var idparam = 'id="' + id + '"';

        var str='';
        str+='<div ' + idparam + '  style="width: 100%;">';
        str+='<table  border="0" cellpadding="0" cellspacing="0">';
        str+='<tr>';
        str+='<td><img src="' + this.image_tl.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<td style="width:100%;background: #e9e8e3;"><\/td>';
        str+='<td><img src="' + this.image_tr.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<\/tr>';
        str+='<tr>';
        str+='<td style="background: #e9e8e3;"><\/td>';
        str+='<td style="background: #e9e8e3;color: #8EC74B;">';

        document.write(str);

    },
    close: function()
    {
        var str='';
        str+='<\/td>';
        str+='<td style="background: #e9e8e3;"><\/td>';
        str+='<\/tr>';
        str+='<tr>';
        str+='<td><img src="' + this.image_bl.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<td style="width:100%; background: #e9e8e3;"><\/td>';
        str+='<td><img src="' + this.image_br.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<\/tr>';
        str+='<\/table>';
        str+='<\/div>';


        document.write(str );
    },
    stop: function()
    {

        var str='';
        str+='<\/td>';
        str+='<td style="background: #e9e8e3;"><\/td>';
        str+='<\/tr>';
        str+='<\/table>';
        str+='<\/div>';
        document.write(str);
    }
}

var LightBox3D =
{
    image_l: null,
    image_r: null,
    open: function(id)
    {
        var idparam = "";
        if ( this.image_l==null ) this.image_l = new TImage(FrameImagePath+'GreyCutStart.png');
        if ( this.image_r==null ) this.image_r = new TImage(FrameImagePath+'GreyCutEnd.png');

        if ( id!=null ) var idparam = 'id="' + id + '"';

        var str='';
        str+='<div ' + idparam + '  style="width: 100%;">';
        str+='<table  border="0" cellpadding="0" cellspacing="0">';
        str+='<tr >';
        str+='<td><img src="' + this.image_l.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<td width="100%" style="height:30px; color:#8EC74B; background-image:url(/jgnss/frame/GreyMiddle.png);" background="/jgnss/frame/GreyMiddle.png">';
        document.write(str);
    },
    close: function()
    {
        var str='';
        str+='<\/td>';
        str+='<td><img src="' + this.image_r.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<\/tr>';
        str+='<\/table>';
        str+='<\/div>';
        document.write(str );
    }
}

var Black7Box3D =
{
    image_l: null,
    image_r: null,
    open: function(id)
    {
        var idparam = "";
        if ( this.image_l==null ) this.image_l = new TImage(FrameImagePath+'Black7RoundedStart.png');
        if ( this.image_r==null ) this.image_r = new TImage(FrameImagePath+'Black7RoundedEnd.png');
//        if ( this.image_l==null ) this.image_l = new TImage(FrameImagePath+'Black7CutStart.png');
//        if ( this.image_r==null ) this.image_r = new TImage(FrameImagePath+'Black7CutEnd.png');

        if ( id!=null ) var idparam = 'id="' + id + '"';

        var str='';
        str+='<div ' + idparam + '  style="width: 100%;">';
        str+='<table  border="0" cellpadding="0" cellspacing="0">';
        str+='<tr >';
        str+='<td><img src="' + this.image_l.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<td width="100%" style="height:30px; color:#8EC74B; background-image:url(/jgnss/frame/Black7Middle.png);" background="/jgnss/frame/Black7Middle.png">';
        document.write(str);
    },
    close: function()
    {
        var str='';
        str+='<\/td>';
        str+='<td><img src="' + this.image_r.src + '" border="0" alt="" style="background: transparent;" \/><\/td>';
        str+='<\/tr>';
        str+='<\/table>';
        str+='<\/div>';
        document.write(str );
    }
}

var GreenBox =
{
    image_tl: null,
    image_tr: null,
    image_bl: null,
    image_br: null,
    open: function()
    {
        if ( this.image_tl==null ) this.image_tl = new TImage(FrameImagePath+'corner_green8tl.gif');
        if ( this.image_tr==null ) this.image_tr = new TImage(FrameImagePath+'corner_green8tr.gif');
        document.write(
            '<div class="lightgreenBox">'+
            '<div class="lightgreenBoxHeader" style="background: url('+this.image_tr.src+') 100% 0 no-repeat;">'+
            '<div style="background: url('+this.image_tl.src+') 0 0 no-repeat;"></div></div>'+
            '<div class="lightgreenBoxContent">'
            );

    },
    close: function()
    {
        if ( this.image_bl==null ) this.image_bl = new TImage(FrameImagePath+'corner_green8bl.gif');
        if ( this.image_br==null ) this.image_br = new TImage(FrameImagePath+'corner_green8br.gif');
        document.write(
            '</div>'+
            '<div class="lightgreenBoxFooter" style="background: url('+this.image_br.src+') 100% 0 no-repeat;">'+
            '<div style="background: url('+this.image_bl.src+') 0 0 no-repeat;"></div></div>'+
            '</div>'
            );
    },
    stop: function()
    {
        document.write('</div></div>');
    }
}


var MessageBox =
{
    img_dir: null,
    box_rb: null,
    box_lb: null,
    box_corner_tl: null,
    box_corner_tr: null,
    box_tm: null,
    box_bm: null,
    box_corner_bl: null,
    box_corner_br: null,
    pixel: null,
    color: null,
    //color: "#f6f7fd",

    open: function(name, align, attr)
    {
        if ( this.color         == null ) this.color         = '#fafbfb';
        if ( this.pixel         == null ) this.pixel         = new TImage("/jgnss/crm/images/transparent_pixel.gif");
        if ( this.img_dir       == null ) this.img_dir       = "/jgnss/crm/images/general/";
        if ( this.box_lb        == null ) this.box_lb        = new TImage(this.img_dir+"box_lb.gif");
        if ( this.box_rb        == null ) this.box_rb        = new TImage(this.img_dir+"box_rb.gif");
        if ( this.box_corner_tl == null ) this.box_corner_tl = new TImage(this.img_dir+"box_corner_tl.gif");
        if ( this.box_corner_tr == null ) this.box_corner_tr = new TImage(this.img_dir+"box_corner_tr.gif");
        if ( this.box_tm        == null ) this.box_tm        = new TImage(this.img_dir+"box_tm.gif");

        if ( align != ''          ) align = ' align="'+align+'" ';
        if ( attr  == 'max-height') attr = ' height="100%" ';
          else attr = '';

      document.writeln('<table cellspacing="0" cellpadding="0" border="0" '+attr+' width="100%" style="background-color:#e7e8ee;">');
      document.writeln('<tr style="height:8px;" height="8">');
      document.writeln('<td valign="top"><img src="'+this.box_corner_tl.src+'"></td>');
      document.writeln('<td valign="top" width="100%" style="background-image: url('+this.box_tm.src+');" background="'+this.box_tm.src+'"><img border="0" src="'+this.pixel.src+'"></td>');
      document.writeln('<td valign="top"><img src="'+this.box_corner_tr.src+'"></td>');
      document.writeln('</tr>');

      document.writeln('<tr style="background-color:'+this.color+';">');
      document.writeln('<td valign="bottom" width="8" style="background-image: url('+this.box_lb.src+');" background="'+this.box_lb.src+'"><img border="0" src="'+this.pixel.src+'" height="1"></td>');
      document.writeln('<td style="font-size:8pt;" valign="middle" '+align+' width="100%"><b>'+name+'</b></td>');
      document.writeln('<td valign="bottom" width="8" style="background-image: url('+this.box_rb.src+');" background="'+this.box_rb.src+'"><img border="0" src="'+this.pixel.src+'" height="1">');
      document.writeln('</tr>');

      if(name != "")
        {
          document.writeln('<tr style="background-color:#fafbfb;">');
          document.writeln('<td colspan="3" valign="top" width="100%" style="background-image: url('+this.box_tm.src+');" background="'+this.box_tm.src+'"><img border="0" src="'+this.pixel.src+'"></td>');
          document.writeln('</tr>');
        }

      document.writeln('<tr style="background-color:#fafbfb;"'+attr+'>');
      document.writeln('<td valign="bottom" width="8" style="background-image: url('+this.box_lb.src+');" background="'+this.box_lb.src+'"><img border="0" src="'+this.pixel.src+'" height="1"></td>');
      document.writeln('<td valign="top" width="100%">');
    },
    close: function()
    {
        if ( this.color         == null ) this.color         = '#fafbfb';
        if ( this.pixel         == null ) this.pixel         = new TImage("/jgnss/crm/images/transparent_pixel.gif");
        if ( this.img_dir       == null ) this.img_dir       = "/jgnss/crm/images/general/";
        if ( this.box_rb        == null ) this.box_rb        = new TImage(this.img_dir+"box_rb.gif");
        if ( this.box_corner_bl == null ) this.box_corner_bl = new TImage(this.img_dir+"box_corner_bl.gif");
        if ( this.box_corner_br == null ) this.box_corner_br = new TImage(this.img_dir+"box_corner_br.gif");
        if ( this.box_bm        == null ) this.box_bm        = new TImage(this.img_dir+"box_bm.gif");

      document.writeln('</td>');
      document.writeln('<td valign="bottom" width="8" style="background-image: url('+this.box_rb.src+');" background="'+this.box_rb.src+'"><img border="0" src="'+this.pixel.src+'" height="1"></td>');
      document.writeln('</tr>');
      document.writeln('<tr style="background-color:#fafbfb;height:8px;" height="8">');
      document.writeln('<td valign="bottom"><img src="'+this.box_corner_bl.src+'"></td>');
      document.writeln('<td valign="bottom" width="100%" style="background-image: url('+this.box_bm.src+');" background="'+this.box_bm.src+'"><img border="0" src="'+this.pixel.src+'" height="1"></td>');
      document.writeln('<td valign="bottom"><img src="'+this.box_corner_br.src+'"></td>');
      document.writeln('</tr>');
      document.writeln('</table>');
    }
}

function MakeProductLinks(Tabs, QuickLinks)
  {
    document.writeln('<table cellspacing="0" cellpadding="0" border="0" width="100%">');
    document.writeln('<tr>');
    document.writeln('<td>');

    MessageBox.open('','');
    document.writeln('<table cellspacing="0" cellpadding="2" border="0" width="100%" style="background-color:#e7e8ee;">');

    for(var i=0; i<Tabs.length; i++)
      {
       if( '?'+Tabs[i].name != DocumentSearch && Tabs[i].name != '')
         {
              document.writeln('<tr style="background-color:#fafbfb;">');
              document.writeln('<td align="center" width="36">');
              document.writeln('<img src="'+Tabs[i].icon+'"/>');
              document.writeln('</td>');
              document.writeln('<td class="productRow" align="left">');
              document.writeln('<a href="'+Tabs[i].link+'" target=_top style="color:#454850">'+Tabs[i].name+'</a></td></tr>');
              document.writeln('</td>');
              document.writeln('</tr>');
         }
      }

    document.writeln('</table>');
    MessageBox.close();

    document.writeln('</td>');
    document.writeln('</tr>');
    document.writeln('<tr style="height:4px;">');
    document.writeln('<td valign="top"></td>');
    document.writeln('</tr>');
    document.writeln('<tr>');
    document.writeln('<td valign="top">');

    MessageBox.open('','');
    document.writeln('<table cellspacing="0" cellpadding="2" border="0" width="100%" style="background-color:#e7e8ee;">');
      for( var i=0; i < QuickLinks.length; i++)
            {
              var item = QuickLinks[i]; 
              document.writeln('<tr style="background-color:#fafbfb;">');
              document.writeln('<td class="productRow" align="center" width="36">');
              document.writeln('<img src="'+item.icon+'"/>');
              document.writeln('</td>');
              document.writeln('<td class="productRow">');
              document.writeln('<a href="'+item.link+'" target="_blank" style="color:#454850">'+item.name+'</a>');
              document.writeln('</td>');
              document.writeln('</tr>');
            }
    document.writeln('</table>');

    MessageBox.close();
    document.writeln('</td>');
    document.writeln('</tr>');
    document.writeln('</table>');
  }

function MakeHeader(text,level,id)
{
    if ( !level ) level = 'h1';
    if ( !id ) id = '';
    else
    {
        id = 'id="'+id+'"';
    }
    //document.writeln('<table cellpadding=0 cellspacing=0 border=0 width="100%"><tr><td class="'+level+'"><scr'+'ipt>Black7Box.open();</scr'+'ipt><center>'+text+'</center><scr'+'ipt>Black7Box.close();</scr'+'ipt></td></tr></table>');
    document.writeln('<div '+id+' class="'+level+'" style="width:100%;margin-bottom:8px;margin-top:4px;"><scr'+'ipt>Black7Box.open();</scr'+'ipt><center>'+text+'</center><scr'+'ipt>Black7Box.close();</scr'+'ipt></div>');
}

function SwapButtonColors(b,up)
{
    /*
   if ( up )
   {
      b.style.borderTopColor = "#6B6E76";
      b.style.borderLeftColor = "#6B6E76";
      b.style.borderBottomColor = "#2C2D30";
      b.style.borderRightColor = "#2C2D30";
   }
   else
   {
      b.style.borderTopColor = "#2C2D30";
      b.style.borderLeftColor = "#2C2D30";
      b.style.borderBottomColor = "#6B6E76";
      b.style.borderRightColor = "#6B6E76";
   }
*/
    if ( up )
    {
        b.style.color="#FFFFFF";
        b.style.backgroundColor="#454850";
    }
    else
    {
        b.style.color="#454850";
        b.style.backgroundColor="#FFFF00";
    }
}


var UserInfoCallback = 
{
    funcs: new Array(),
    add: function(f)
    {
        //if ( this.funcs.length == 0 )
        //document.writeln('<iframe style="position:absolute;left:0;top:0;height:0;width:0;border:0;padding:0;margin:0;visibility:hidden;" src="'+WebShopRoot+'Action=UserInfo'+'#'+MainWindow.NoFrameHash+'"></iframe>');
        this.funcs[this.funcs.length] = f;
    },
    call: function (pars)
    {
        for (var i in this.funcs )
            this.funcs[i](pars);
    }
}

function makeGreyButton(text,action,width)
{
    var s = '';
    if ( width ) width='style="width:'+width+'px;"';
    else         width='';
    s += '<span onclick="'+action+';return false;" class="greybutton" '+width+' onmouseover="SwapButtonColors(this,false);" onmouseout="SwapButtonColors(this,true);">'+text+'</span>';
    return s;
}

function setLogonWindow(pars)
{
    if ( pars.Status )
    //LogonArea.innerHTML='Welcome, '+pars.FirstName+' '+pars.LastName+'!'
    {
        document.getElementById("LogonArea").innerHTML='Welcome, '+pars.FirstName+' '+pars.LastName+'!'+((pars.Status=="Customer")?'':'<br>'+pars.Status)
        //+'<br>'+makeGreyButton('LOGOUT',"top.location='"+WebShopRoot+"Action=Logout'")
        ;
        deferredAuthConfirmation();
    }
    else
    {
        document.getElementById("LogonArea").innerHTML="";
    }
}

function setPopupMenuItems(pars)
{
    if ( pars.Status )
    {
        MenuMatrix[4].array[0].name = "Logout";
        MenuMatrix[4].array[0].setLink(WebShopRoot+"Action=Logout");
        MenuMatrix[4].array[1].setLink(WebShopRoot+"Action=Members");
        MenuMatrix[4].array[3].setLink(WebShopRoot+"Action=DrawOrderManager&initFromCurrentSavez=on");
        MenuMatrix[4].array[4].setLink(WebShopRoot+"Action=DrawQuestionManager&initFromCurrentSavez=on");

        MenuArrayUpdateItem(4,0);
        MenuArrayUpdateItem(4,1);
        MenuArrayUpdateItem(4,3);
        MenuArrayUpdateItem(4,4);
    }
    else
    {
        MenuMatrix[4].array[0].name = "Login";
        MenuMatrix[4].array[0].setLink(WebShopRoot+"Action=Login");
        MenuMatrix[4].array[1].setLink(WebShopRoot+"Action=Members");
        MenuMatrix[4].array[3].setLink(WebShopRoot+"Action=DrawOrderManager&initFromCurrentSavez=on");
        MenuMatrix[4].array[4].setLink(WebShopRoot+"Action=DrawQuestionManager&initFromCurrentSavez=on");

        MenuArrayUpdateItem(4,0);
        MenuArrayUpdateItem(4,1);
        MenuArrayUpdateItem(4,3);
        MenuArrayUpdateItem(4,4);
    }
}

function setUserInfo(pars)
{

    UserParams = pars;
    UserInfoCallback.call(pars);
}

function deferredAuthConfirmation() {
    window.clearTimeout(rat);
    rat = window.setTimeout("requestAuthConfirmation(false)", PreventTimeout);
}

function requestAuthConfirmation(b) {
    var obj, winH, winW, divname="auth-submit";

    if(b==true)
    {
        obj = document.getElementById("auth-extend");
        if(obj!=null) obj.style.display = "none";
    }
    else
    {
        obj = document.getElementById("auth-submit");
        if(obj!=null) obj.style.display = "none";
        divname = "auth-extend";
        window.clearTimeout(rat);
        rat = window.setTimeout("requestAuthConfirmation(true)", (SessionTimeout - PreventTimeout));
    }
 
    if(navigator.appName=="Opera")
    {
        winW = window.innerWidth;
        winH = window.innerHeight;
    }
    if(navigator.appName=="Netscape")
    {
        winW = window.innerWidth;
        winH = window.innerHeight;
    }
    if(navigator.appName.indexOf("Microsoft")!=-1)
    {
        winW = document.body.offsetWidth - 20;
        winH = document.body.offsetHeight + 10;
    }

    if( document.getElementById("cover-page") )
    {

        obj =  document.getElementById("cover-page");

        if(navigator.appName.indexOf("Microsoft")!=-1)
        {
            obj.style.width  = winW;
            obj.style.height = winH;
        }
        else
        {
            obj.style.width = '100%';
            obj.style.height = '100%';
        }
       
        obj.style.display = "block";
    }

    if(document.getElementById("auth-confirm"))
    {
        obj = document.getElementById("auth-confirm");
        obj.style.width = "300px";
        obj.style.display = "block";
        obj.style.top = winH/2 - 100;
        obj.style.left = winW/2 - 150;
    //alert(winH+"x"+winW);
    }

    if(document.getElementById(divname))
    {
        obj = document.getElementById(divname);
        obj.style.display = "block";
    }

}


function confirmAuthority(b) {
    //b==true means relogin, b==false means session extension
    window.clearTimeout(rat);
    var formname;
    b ? formname = "re-login" : formname = "extend-session";

    var formdata = $("#" + formname).serialize();
    if(b) {
        $("#login-failure-notice").hide();
        var x = $.post("/cgi-bin/jgnss/cgi", formdata,
        function(data) {
            $("#auth-confirm").hide();
            $("#auth-extend").hide();
            $("#auth-submit").hide();
            $("#cover-page").hide();

            if(data == "login success") {
                $("#login-failure-notice").hide();
                deferredAuthConfirmation();
                $.getScript("/cgi-bin/jgnss/cgi?Action=UserInfo");
            } else {
                $("#login-failure-notice").show();
                requestAuthConfirmation(true);
            }

        }, "text");
    }

    if(!b) $.get("/cgi-bin/jgnss/cgi", formdata,
        function(data) {
            $("#auth-confirm").hide();
            $("#auth-extend").hide();
            $("#auth-submit").hide();
            $("#cover-page").hide();
        }, "script");

}







if ( false )
{
    /************ Debug dynamic menu *************/
    function Simulate_setUserInfo()
    {
        var pars = new Object();
        pars.urlPrivate = "/";
        pars.allowPrivate = true;
        pars.FirstName = "Firstname";
        pars.LastName = "Lastname";
        pars.Status = "Manager";
        setUserInfo(pars);
    }

    window.setTimeout('Simulate_setUserInfo()',3000);
/************* end of Debug dynamic menu ********/
}

function d2h(d) {
    return d.toString(16);
}
function h2d(h) {
    return parseInt(h,16);
}

function dummyfunc() {}
function LightMenuUpKeeper() {} 
LightMenuUpKeeper = LightMenuUp;
LightMenuUp = dummyfunc;
LightMenuDown = dummyfunc;

function handleKeyPress(evt) {
    evt = (evt) ? evt : ((event) ? event : null);
    deferredAuthConfirmation();
}

//document.onkeyup = handleKeyPress;
//

var tht;

function ShowMenuComment(el) {

    clearTimeout(HideMenuTimeout);

    var cmt = document.getElementById("menu-comment-text");
    cmt.innerHTML = el.lastChild.innerHTML;

    if(MenuCommentBox.style.display=="") return false;
    MenuCommentBox.style.display = "";
    tht = 0;
    EnlargeMenuComment();

    return 0;
}



function HideMenuComment() {

    MenuCommentBox.style.display = "none";

}

var HideMenuTimeout;
function HideMenuCommentDelayed() {

    HideMenuTimeout = setTimeout(HideMenuComment, 1000);

}


function EnlargeMenuComment() {

    tht =  tht + 2;
    MenuCommentBox.style.height = tht + "px";
    mcbt = setTimeout(EnlargeMenuComment, 0.1);
 
    if(tht > 55) {
        clearTimeout(mcbt);
    }

}

var CoverPageUseFlag = true;

function setCoverPageUseFlag(b) {

    CoverPageUseFlag = b;

}

function CoverPage(b) {
    if(!CoverPageUseFlag) return;



    var obj;

    if( document.getElementById("cover-layer") )
    {
        obj =  document.getElementById("cover-layer");

        obj.style.width  = document.getElementById("DocumentWindow").offsetWidth;
        obj.style.height = document.getElementById("DocumentWindow").offsetHeight;
        obj.style.top  = getXY(document.getElementById("DocumentWindow"))[1];
        obj.style.left = getXY(document.getElementById("DocumentWindow"))[0];

       
    }

    
    if(b==false) document.getElementById("cover-layer").style.display = "none";
    else document.getElementById("cover-layer").style.display = "block";
}




function getXY( oElement )
{
    var xReturnValue = 0;
    var yReturnValue = 0;
    while( oElement != null ) {
        xReturnValue += oElement.offsetLeft;
        yReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return new Array(xReturnValue, yReturnValue);
}


function InvokeMenuTimer() {
    MenuPopupTimer = window.setTimeout(
        function() {
            DisplayMenu.unlock();DisplayMenu.pexec();
        },
        200);
}

function KillMenuTimer() {
    window.clearTimeout(MenuPopupTimer);
}

/* Permitted execution of a function.
 * Released to let functions to lock
 * each other. Sadly, just limited
 * number of args can be passed over */

Function.prototype.pexec =  function(arg1, arg2, arg3) {
    if(!this.pexecflag) return;
    this(arg1, arg2, arg3);
}


/* Locks pexec execution of a function */
Function.prototype.lock =  function() {
    this.pexecflag=false;
}

/* Unlocks pexec execution of a function */
Function.prototype.unlock =  function() {
    this.pexecflag=true;
}


function showInfo(posX, posY, id) {
          var cssObj = {
        'position' : 'absolute',
        'display' : 'block'
      }
}


/********************************/
/* Javad GNSS jQuery extensions */
/********************************/

/* Tooltip extension */
if(typeof($)!="undefined") { (function($) {
        $.tooltip = {

            tooltipcss : {
                'position': 'absolute',
                'display' : 'block',
                'top' : '0',
                'left' : '0',
                'padding' : '1',
                'width' : '200px',
                'background-color' : '#EDEDED',
                'border-width': '1px',
                'border-style': 'solid',
                'border-color': '#696969'
            },

            smfr : 0,
            classname : "tooltip",
            current : new Object(),

            showtooltip : function(event, el) {
                $.tooltip.hidetooltip.unlock();

                $("." + $.tooltip.classname).hide();
                el = $(this);
                var tooltip = $("#" + el.attr("id") + " ~ ." + $.tooltip.classname + ":first");
                tooltip.css($.tooltip.tooltipcss);
                tooltip.css("top", event.pageY + 10);
                tooltip.css("left", event.pageX);
            },

            hidetooltip : function(id) {
                var tooltip = $("#" + id + " ~ ." + $.tooltip.classname + ":first");
                tooltip.hide();
            }
        }

        $.fn.extend({
            tooltip : function(classname) {

                if(classname!=null) $.tooltip.classname = classname;
                this.each(function(el) {
                    el = $(this);
                    el.mouseover($.tooltip.showtooltip);
                    el.mouseout(function() {
                        window.setTimeout("$.tooltip.hidetooltip.pexec('"+ this.id +"')", 500);
                    });

                    var tooltip = $("#" + el.attr("id") + " ~ ." + $.tooltip.classname + ":first");
                    tooltip.hide();
                    tooltip.mouseover(
                        function() {
                            $.tooltip.hidetooltip.lock();
                            $(this).mouseout(function(event) {
                                var tly = $(this).position().top;
                                var bry = $(this).position().top + $(this).height();
                                var tlx = $(this).position().left;
                                var brx = $(this).position().left + $(this).width();
                                if( tlx < event.pageX && brx > event.pageX && tly < event.pageY && bry > event.pageY) 
                                    return;

                                $(this).hide(); $(this).die();
                            });
                        }
                        );
                });
                return this;
            }
            });

    })(jQuery);}
/* END Tooltip extension */


function chlang(l) {

  $.cookie('Lang', l, { path: '/', expires: 10 });
  location.reload();

}
