﻿function resizeIframe(pixels)
{
    var el = document.getElementById('scIframe');
    el.height = pixels;
}

//Event.observe(window, 'load', Onload, false);

function Onload() {
	//SetupGlobalSoeg();
}

/*
	Sgning - Start
*/
var globalSoegeord		= null;
var globalSoegSubmit	= null;

function SetupGlobalSoeg() {
	globalSoegeord		= $("globalSoegeord");
	globalSoegSubmit	= $("globalSoegSubmit");
	
	if (globalSoegeord != null) {
		Event.observe(globalSoegeord, "keypress", globalSoegeordKeypress, false);
	}
	
	if (globalSoegSubmit != null) {
		Event.observe(globalSoegSubmit, 'click', globalSearchButtonClick, false);
	}
}

function globalSearchButtonClick() {
	GlobalSearch();
	return false;
}

function globalSoegeordKeypress(event) {
	if (event.keyCode == Event.KEY_RETURN) {
		GlobalSearch();
		return false;
	}
	return true
}

function GlobalSearch() {
	var url = global_soegeurl;
	var qs = "?";

	var query = trimString($F(globalSoegeord));
	if (query == "") {
		alert(global_alertTomsoegning);
		globalSoegeord.focus();
		return;
	}
	else if (query.length <= 2) {
		alert(global_alertMinimumLaengde);
		globalSoegeord.focus();
		return;
	}
	qs += addToQs("q", query);
	qs += addToQs("from", "global");
	window.location = url + qs;

}

/*
	Sgning - End
*/

function trimString(str) {
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function addToQs(name, val) {
	if (val != "") {
		return name + "=" + val + "&";
	}
	return "";
}

function isValidEmail(str) {
	var re = new RegExp("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$");
	return (str.match(re) != null);
}

function openwin(pageToLoad, winName, width, height, center, scrollbars, resizable) {
	var xposition = (screen.width - width) / 2;
	var yposition = (screen.height - height) / 2;
	var toDO = "";
	toDO += "width=" + width + ",";
	toDO += "height=" + height + ",";
	toDO += "screenx=" + xposition + ",";
	toDO += "screeny=" + yposition + ",";
	toDO += "left=" + xposition + ",";
	toDO += "top=" + yposition + ",";
	toDO += "scrollbars=" + scrollbars + ",";
	toDO += "resizable=" + resizable + ",";
	toDO += "location=0,menubar=0,status=0,titlebar=0,toolbar=0,hotkeys=0,directories=0";
	window.open(pageToLoad, winName, toDO);
}


/* JSON parser */
var JSON = function () {
	var m = {
			'\b': '\\b',
			'\t': '\\t',
			'\n': '\\n',
			'\f': '\\f',
			'\r': '\\r',
			'"' : '\\"',
			'\\': '\\\\'
		},
		s = {
			'boolean': function (x) {
				return String(x);
			},
			number: function (x) {
				return isFinite(x) ? String(x) : 'null';
			},
			string: function (x) {
				if (/["\\\x00-\x1f]/.test(x)) {
					x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
						var c = m[b];
						if (c) {
							return c;
						}
						c = b.charCodeAt();
						return '\\u00' +
							Math.floor(c / 16).toString(16) +
							(c % 16).toString(16);
					});
				}
				return '"' + x + '"';
			},
			object: function (x) {
				if (x) {
					var a = [], b, f, i, l, v;
					if (x instanceof Array) {
						a[0] = '[';
						l = x.length;
						for (i = 0; i < l; i += 1) {
							v = x[i];
							f = s[typeof v];
							if (f) {
								v = f(v);
								if (typeof v == 'string') {
									if (b) {
										a[a.length] = ',';
									}
									a[a.length] = v;
									b = true;
								}
							}
						}
						a[a.length] = ']';
					} else if (x instanceof Object) {
						a[0] = '{';
						for (i in x) {
							v = x[i];
							f = s[typeof v];
							if (f) {
								v = f(v);
								if (typeof v == 'string') {
									if (b) {
										a[a.length] = ',';
									}
									a.push(s.string(i), ':', v);
									b = true;
								}
							}
						}
						a[a.length] = '}';
					} else {
						return;
					}
					return a.join('');
				}
				return 'null';
			}
		};
	return {
		copyright: '(c)2005 JSON.org',
		license: 'http://www.JSON.org/license.html',
		stringify: function (v) {
			var f = s[typeof v];
			if (f) {
				v = f(v);
				if (typeof v == 'string') {
					return v;
				}
			}
			return null;
		},
		parse: function (text) {
			try {
				return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
						text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
					eval('(' + text + ')');
			} catch (e) {
				return false;
			}
		}
	};
}();

function shortcut(el,subject)
{
    var obj = document.getElementById(el);
    
    if (obj.value != '')
    {
        location.href = obj.value;
    }
    else
    {
        alert('Du skal v\346lge ' + subject);
    }
}


/* funtioner til sgning */
function checkBoxes(el)
{
    if (el.id == 'check0' && el.checked)
    {
        for (var i = 1; i < 8; i++)
        {
            document.getElementById('check' + i).checked = false;
        }
    }
    if (el.id != 'check0' && el.checked)
    {
        document.getElementById('check0').checked = false;
    }
}

function globalCheckKey(e)
{
    if (e.keyCode == 13)
    {
        doGlobalSearch();
        return false;
    }

    return true;
}

function doGlobalSearch()
{
    var searchString = ''
    var categoryString = '';
    
    searchString = document.getElementById('globalSoegeord').value;
    
    if (searchString != '')
    {
        document.location.href='/Om_SDU/Om_dette_websted/Search.aspx?q=' + encodeURIComponent(searchString.replace(' ','+')) + categoryString;
    }
    return false;
}


function checkKey(e)
{
    if (e.keyCode == 13)
    {
        doSearch();
        return false;
    }

    return true;
}

function doSearch()
{
    var categoryString = '';
    /*    
    for (var i = 1; i < 8; i++)
    {
        if (document.getElementById('check' + i).checked)
        {
            categoryString += '&c=' + i;
        }    
    }
    */
    document.location.href='?q=' + document.getElementById('txtSearch').value + categoryString;
}


/* Bibliotek */

var searchUrls = new Array(2);

searchUrls[0] = 'url1';
searchUrls[1] = 'url2';

function bibSearch(lang)
{
    var searchPhrase = document.getElementById('booksearch').value;
	var usr = "WEBSERVER";
	if(lang == "en")
		usr = "WEBENGLISH";
    if (searchPhrase != '')
    {
        if (isRadioSelected())
        {
            if (document.getElementById('radio1').checked)
            {
                //document.location.href = "http://embla.bib.sdu.dk/webpac2/wgbroker.exe?new+-access+TOP.odin2_dan+search+open+GK+" + searchPhrase.replace(' ','+');
                //document.location.href = "/Bibliotek/Soegning/Katalog.aspx?search=" + encodeURIComponent(searchPhrase.replace(' ','+'));
				window.open("http://alvis-bib.sdu.dk/uhtbin/cgisirsi/x/SIRSI/0/57/5?searchdata1=" + encodeURIComponent(searchPhrase.replace(' ','+')) + "&user_id=" +  usr);
                //document.location.href = "/itua test/sdu iframe.aspx?search=" + searchPhrase.replace(' ','+');
                return false;
            }

            if (document.getElementById('radio2').checked)
            {
                //document.location.href = 'http://bifrost.bib.sdu.dk:9003/sfx_local/azlist/default?current_view=table&service=&perform=searchTitle&type=textSearch&letter_group=&pattern=' + searchPhrase.replace(' ','+') + '&textSearchType=contains';
                document.location.href = "/Bibliotek/Soegning/Elektroniske tidsskrifter.aspx?search=" + encodeURIComponent(searchPhrase.replace(' ','+'));
                return false;
            }
        }
        else
        {
            // hvis ingen valgt
            alert('fedjl');
            return false;
        }
    }
    else
    {
        alert(bib_search_empty);
        return false;
    }
}

function isRadioSelected()
{
    var isSelected = false;

    if (document.getElementById('radio1').checked || document.getElementById('radio2').checked)
    {
        isSelected = true;
    }

    return isSelected;
}

function bibcheckKey(e, lang)
{
    if (e.keyCode == 13)
    {
        bibSearch(lang);
        return false;
    }

    return true;
}
/** gsearch **/ 
function GSearchCheckKey(e, lang)
{
    if (e.keyCode == 13)
    {
        GSearch(lang);
        return false;
    }

    return true;
}

function GSearch(lang)
{
    var searchString = ''
	var query = "cx=015516048974061211780%3Aubz5h8ff4v4&cof=FORID%3A10%3BNB%3A1&ie=UTF-8&hl=" + lang + "&lr=lang_" + lang + "&q=";
    searchString = document.getElementById('globalSoegeord').value;
    if (searchString != '')
    {
        document.location.href='/Om_SDU/Om_dette_websted/SearchResults.aspx?' + query + encodeURIComponent(searchString.replace(/ /g,'+'));
    }
    return false;
}

/** font-size **/
var currentSize = 100;
var currentLine = 100;
function fontUp() {
    if (currentSize < 150) {
        currentSize = currentSize + 10;
        currentLine = currentLine + 10;
        setFont();
    }
}
function fontDown() {
    if (currentSize > 80) {
        currentSize = currentSize - 10;
        currentLine = currentLine - 10;
        setFont();
    }
}
function setFont() {
    document.getElementById('right').style.fontSize = currentSize + '%';
    document.getElementById('right').style.lineHeight = currentLine + '%';
}
/** font-size **/