/************************************************ 
 * By Bengt J Lindstrom
 ************************************************/
/*
 * Start The Menu Class
 */
function Menu() {
    this.menuItems = new Array();
    this.foldout = false;
    this.addMenuItem = Menu_addMenuItem;
    this.create = Menu_create;
    return this;
}

function Menu_addMenuItem(item) {
    if (item.active || (item.submenu && item.submenu.foldout)) {
        this.foldout = true;
    }   
    this.menuItems.push(item);
}

function Menu_create(level) {
    var i, l = 0;
    if (level) {
        l = level;
    }
    if (l == 0) {
        document.writeln('<table border="0" cellspacing="0" cellpadding="0">');
        document.writeln('<tr><td><img src="/global/img/menu/divider_top.gif"></td></tr>');
    }
    for (i=0; i < this.menuItems.length; i++) {
        var c = 'menu_level_'+l;
        var item = this.menuItems[i];
        if (item.active){
            c = c + ' menu_item_active';
        }
        document.writeln('<tr class="'+c+'"><td height="17"><span class="menu_level_'+l+'_indent">');
        if (l == 0){
            var img;
            if (item.submenu && item.submenu.foldout) {
                img = "/global/img/menu/arrow_open.gif";
            } else {
                img = "/global/img/menu/arrow.gif";
            }           
            document.writeln('<img src="'+img+'">');
        } else {
            document.writeln('&#187;');
        }
        if (item.active) {
            document.writeln(item.label);
        } else {
            document.writeln('<a href="'+item.href+'" class="'+c+'">'+item.label+'</a>');
        }
        document.writeln('</span></td></tr>');
        if (item.submenu && (item.submenu.foldout || item.active)) {
            item.submenu.create(l + 1);
        }
        if (l == 0) {
            document.writeln('<tr><td><img src="/global/img/menu/divider.gif"></td></tr>');
        }
    }
    if (l == 0) {
        document.writeln('</table>');
    }
}
/*
 * The MenuItem Class
 */
function MenuItem(label, href, submenu) {
    this.label = label;
    this.href = href;
    this.submenu = null;
    this.active = false;
    this.testIfActive = MenuItem_testIfActive;
    if (submenu) {
        this.submenu = submenu;
    }
    this.testIfActive();
    if (this.active && submenu) {
        this.submenu.foldout = true;
    }
    return this;
}

function MenuItem_testIfActive() {
    var url = this.href;
    if (url.charAt(0) == '/') {
        url = location.protocol + "//" + location.hostname + url;
    } else if (url.indexOf("://") == -1) {
        url = location.protocol + "//" + location.hostname + location.pathname.substring(0, location.pathname.lastIndexOf("/", location.pathname.length)+1) + url;
    }
    if (url == location.href) {
        this.active = true;
    }
}

/************************************************ 
 * By Farshad Varahram
 ************************************************/
/*
 * Start The Jump 
 */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/************************************************ 
 * By Farshad Varahram
 ************************************************/

function openWin(siteToOpen, isArticle)
{
    if(isArticle)
        window.open(siteToOpen+ ".html", "ALMI", "height=480, width=640, scrollbars=1, menubar=0")
    else
        window.open(siteToOpen+ ".html", "ALMI", "height=480, width=640, scrollbars=0, menubar=0")
}

function printWin()
{
    window.print()
}

function closeWin()
{
    window.close()
}

/************************************************ 
 * By Farshad Varahram
 ************************************************/

function openWinra(siteToOpen, isArticle, word)
{   var queryStr = "";
    if(word != null)
    {
        queryStr = "?word=" + word + "#" + word.substring(0,1);        
    }    
            
    if(isArticle)
        window.open(siteToOpen+ ".html", "ALMI", "height=480, width=820, scrollbars=1, menubar=0")
    else   
        window.open(siteToOpen+ ".html" + queryStr, "ALMI", "height=480, width=820, scrollbars=0, menubar=0");
}

function printWin()
{
    window.print()
}

function closeWin()
{
    window.close()
}

/************************************************ 
 * By Gustav Cedervall Megatron
Tar bort aktiverings fält runt Flash.
Lägg till Load koden för i den berörda artikel.
 ************************************************/

function load(movieName, movieWidth, movieHeight, backColour, version) { 
document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + version + ",0,0,0\" width=\"" + movieWidth + "\" height=\"" + movieHeight + "\">"); 
document.write("<param name=movie value=\"" + movieName + "\">"); 
document.write("<param name=menu value=false>"); 
document.write("<param name=quality value=high>"); 
document.write("<param name=wmode value=transparent>"); 
document.write("<param name=scale value=exactfit />"); 
document.write("<PARAM NAME=bgcolor VALUE=#" + backColour + ">"); 
document.write("<embed src=\"" + movieName + "\" menu=false wmode=transparent quality=high  bgcolor=#" + backColour + " pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"" + movieWidth + "\" height=\"" + movieHeight + "\">"); 
document.write("</embed></object>"); 
}

/************************************************ 
 * By Gustav Cedervall Megatron
Validering samt skicka mail i från ALMI stockholm webbplats.
 ************************************************/

    function submitForm()
    {
        if(validateForm())
            document.forms["contactForm"].submit();
    }
    
    
    function clearForm()
    {
       document.forms["contactForm"].reset();
    }
    
    function validateForm()
    {
        var form = document.forms["contactForm"];        
        var test = /[*]+/;
        var value;
        
        for(i = 0; i < form.length; i++)
        {
            value = form.elements[i].value
        
            if(value == "")
            {
                alert("Inget fält får vara tomt");
                return false;
            }
            else if(value.match(test))
            {
                alert("Otillåtet tecken");
                return false;
            }
        }
        
        return true;
    }
