﻿function documentWrite(someData) {
    document.writeln(someData);
}

// Kollar om en viss plugin existerar
// nameOfPlugin (string): namnet på pluginen, t.ex: "Flip4Mac"
function pluginExists(nameOfPlugin) {
    for (var i = 0; i < navigator.plugins.length; i++){
        if (navigator.plugins[i].name.indexOf(nameOfPlugin) != -1) {
            return true;
        }
    }    
    return false;
}

function trim(input) {
    if (input) {
        return input.replace(/^\s*/, "").replace(/\s*$/, "");
    } else {
        return "";
    }
}

// Lägg till en trim funktion till String
String.prototype.trim = function () {
    return trim(this.valueOf());
}


// 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;
}

function isValidEmail(input) {
    return input !== null && input.length > 0 && input.search(/^[A-Z0-9._%-+]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/gi) >= 0;
}

String.prototype.isEmail = function() {
    return isValidEmail(this.valueOf());
}

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);
}

function printObject(objectId, queryKey) {
    objectId = parseInt(objectId, 10);
    if (!isNaN(objectId) && objectId > 0) {        
        window.open("Print.aspx?" + queryKey + "=" + objectId, "_blank", "directories=0,scrollbars=1,status=0,toolbar=0,width=510,height=500");
    }
}

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="wmode" value="opaque" />'+
          '<param name="bgcolor" value="#ffffff" />' +
          '<param name="scale" value="noborder" />' +
          '<param name="allowScriptAccess" value="sameDomain" />' +
          '<embed src="' + moviePath  + '" width="' + width + '" height="' + height + '" wmode="opaque" quality="high" scale="noborder" allowScriptAccess="sameDomain" bgcolor="#ffffff" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed>'+
        '</object>';
}

function audioObject(fileUrl, mimeType) {
    return '<embed src="' + fileUrl + '" width="400" height="20" autoplay="true" loop="false" type="' + mimeType + '"></embed>';
}


function documentWriteln(output) {
    document.writeln(output);
}

function reloadPage() {
    document.location.href = document.location.href;
}

// För spamskydd
function sendMessage(username, hostname) {
    document.location.href = "mailto:" + username + "@" + hostname;
}

// För spamskydd
function getMail(username, hostname) {
    return username + "@" + hostname;
}

//Byter en bilds källbild
function swap(id, imgPath) {
    $("#" + id).attr("src", imgPath);
}

//
function windowHeight(){
	var alto= 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		alto= window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		alto= document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		alto= document.body.clientHeight;
	}
	return alto;
}

function SetWindowHeight()
{
    setTimeout(SetWindowHeightCallback, 0);
}
function SetWindowHeightCallback()
{
    var _windowHeight = windowHeight();
    var RefDiv = document.getElementById('Page');
    RefDiv.style.height = 'auto';
	var _height = RefDiv.offsetHeight;

    if(_height<_windowHeight)
    {
        RefDiv.style.height = _windowHeight + 'px';
    }
}

var _appPath = ""; // Sätts av ett startup-script
function mapPath(virtualPath) {
    return virtualPath.replace("~", _appPath);
}

function padLeft(input, length, padCharacter) {
    if (typeof(input) == "undefined" || input.length >= length) {
        return input;
    }
    var padList = [];
    for (i = 0; i < (length - input.length); i++) {
        padList.push(padCharacter);
    }
    return padList.join("") + input;
}

String.prototype.padLeft = function(length, padCharacter) {
    return padLeft(this.valueOf(), length, padCharacter);
}

function hide(selector) {
    $(selector).addClass("Hidden");
}
function show(selector) {
    $(selector).removeClass("Hidden");
}
function toggleHidden(selector) {
    $(selector).toggleClass("Hidden");
}

function displayFlashPlayer(sender, flashPlayerIframeId) {
    $("#" + flashPlayerIframeId).attr("src", $("#" + flashPlayerIframeId + "_src").val());
    $("#" + flashPlayerIframeId).removeClass("Hidden");
    $(sender).remove();
}
