﻿function openWindow(url, width, height) {
    return window.open(url, "_blank", "directories=0,height=" + height + ",width=" + width + ",location=0,scrollbars=1,status=0,toolbar=0", true);
}

// Lägg till en trim-funktion till String
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

// Jämför en sträng med en annan och returner om de är lika eller ej
// valfri andra parameter: ignoreCase (default false)
String.prototype.equals = function(other) {        
    if (this.valueOf().length != other.toString().length) {
        return false;
    }
    var a = this.toString();
    var b = other.toString();
    if (arguments.length > 1 && arguments[1]) {
        // Case insensitive
        a = a.toLowerCase();
        b = b.toLowerCase();   
    }
    
    for (var i = 0; i < a.length; i++) {
        if (a.charAt(i) != b.charAt(i)) {
            return false;
        }
    }
    
    return true;
}

// Flash object för startsidan
function flash(moviePath, width, height) {
    var output = "";
    output += "<object width='" + width + "' height='" + height + "' type=\"application/x-shockwave-flash\" data=\"" + moviePath + "\">";
    output += "<param name=\"movie\" value=\"" + moviePath + "\" />";
    output += "<param name=\"src\" value=\"" + moviePath + "\" />";
    output += "<param name=\"loop\" value=\"true\" />";
    output += "<param name=\"quality\" value=\"high\" />";         
    output += "<param name=\"bgcolor\" value=\"white\" />";                       
    output += "<param name=\"wmode\" value=\"opaque\" />";                           
    output += "</object>";
    return output;
}

function flashObject(moviePath, width, height) {
    return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '">'+
          '<param name="movie" value="' + moviePath  + '" />'+
          '<param name="quality" value="high" />'+
          '<param name="menu" value="false" />'+
          '<param name="loop" value="true" />'+
          '<param name="wmode" value="opaque" />'+
          '<embed src="' + moviePath  + '" width="' + width + '" height="' + height + '" loop="true" wmode="opaque" quality="high" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>'+
        '</object>';
}

function documentWriteln(output) {
    document.writeln(output);
}

function documentWrite(output) {
    document.write(output);
}

function flashPopup(moviePath, width, height) {
    document.writeln("<object style=\"width:" + width + "px;height:" + height + "px;display:block;margin:0 auto;\" type=\"application/x-shockwave-flash\" data=\"" + moviePath + "\">");
    document.writeln("<param name=\"movie\" value=\"" + moviePath + "\" />");
    document.writeln("<param name=\"src\" value=\"" + moviePath + "\" />");
    document.writeln("<param name=\"loop\" value=\"false\" />");
    document.writeln("<param name=\"quality\" value=\"high\" />");         
    document.writeln("<param name=\"bgcolor\" value=\"Black\" />");                       
    document.writeln("<param name=\"WMode\" value=\"Opaque\" />");                           
    document.writeln("</object>");
}

function sendMessage(username) {
    document.location.href = "mailto:" + username + "@teknomedia.se";
}

function rsrcEmail(username) {
    return username + "@teknomedia.se";
}

function getPageHeight() {
    var de = document.documentElement;	
    var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;	        
	
    if (window.innerHeight && window.scrollMaxY) {	
        yScroll = window.innerHeight + window.scrollMaxY;
        var deff = document.documentElement;		
        var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
        yScroll -= (window.innerHeight - hff);
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        yScroll = document.body.scrollHeight;		
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;		
    }
  	
    return (yScroll < h ? h : yScroll);
}

// Visa stor bild onmouseover (anropas från personalsidan)

function showBigImage(e,sender,id,src,infoText, caption, show) {
    var posx = 0;
    var posy = 0;
    var ie7=document.all && window.XMLHttpRequest && !window.opera;
    
    if (e.clientX || e.clientY) {
    
        if ($.browser.msie) {
            if (sender.offsetParent) {
                posx = sender.offsetLeft;
                while (sender = sender.offsetParent) {
                    posx += sender.offsetLeft;
                }
            }            
        } else {
            posx = sender.offsetLeft;
        }
        posx += 150 + 20;
        
        if ($.browser.safari) {
            posy = document.body.scrollTop;
        } else {
            posy = document.documentElement.scrollTop;
        }
            posy += 50;
        
    } else if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    
    //alert("MSIE:" + $.browser.msie + "Opera:" + $.browser.opera + "Safari:" + $.browser.safari);
    //alert(src);    
    //alert("Pos X = "  + posx + " Pos Y = " + posy ); 
    //alert(sender.parentNode.offsetLeft);
    //document.write("<h3>Test</h3>");
    //console.log("(x = %d, offsetX = %d, y = %d, offsetY = %d)", e.clientX, e.offsetX, e.clientY, e.offsetY);
    
    if (show == 1) {
        $("#" + id).css("visibility", "visible");
        $("#" + id + " img:first-child").attr("src", src);
        $("#" + id).css("top", posy + "px");
        $("#" + id).css("left", posx + "px");
        
        $("#" + id + " div.Text p.Info").html(infoText);
        $("#" + id + " div.Text p.Caption").html(caption);
        
        //console.log(src);

        
    } else if (show == 0) {
        $("#" + id).css("visibility", "hidden");
        $("#" + id + " img:first-child").attr("src", "http://www.teknomedia.se/grafik/ajax-loader.gif");
    }
}

function toggleHidden(elementId) {
    $("#" + elementId).toggleClass("Hidden");
}