﻿function initPage(){
	clearInputs();
	submitHover();
	checkSeOgsaa();
//	fixDropDownsForIE();
}
//function fixDropDownsForIE() {
//    var elements = document.getElementsByTagName("select")
//    for (i = 0; i < elements.length; i++) {
//        elements[i].className = 'select-dropdown-fixed';
//    }
//}
function checkSeOgsaa() {
    var seogsaa = document.getElementById("seogsaa");
    if (seogsaa) {
        if (seogsaa.innerText == "") {
            var seogsaadiv = document.getElementById("seogsaadiv");
            seogsaadiv.style.display = 'none';
        }
    }
}
function clearInputs(){
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if (inputs[i].type == "text")
		{
		    inputs[i].onfocus = function() {
		        value = this.value;
		        if (this.value == "Titel, beskrivelse etc." || this.value == "ABC123456789" || this.value == "Søg efter ...")
		            this.value = "";
		    }
			inputs[i].onblur = function ()
			{
			    if (this.value == "" && (value == "Titel, beskrivelse etc." || value == "ABC123456789" || value == "Søg efter ..."))
					this.value = value;
				value = "";
			}
		}
    }
}
function submitHover(){
	/*var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)  {
		if (inputs[i].className == "submit-button")  {
			inputs[i].onmouseover = function()
			{
			this.src = this.src.replace(".png", "-hover.png");
			}
			inputs[i].onmouseout = function()
			{
			this.src = this.src.replace("-hover.png", ".png");
			}
		}
	}*/
	
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)  {
		if (inputs[i].className == "submit-button")  {
			inputs[i].onmouseover = function()
			{
				if (this.className.indexOf("hover") == -1)
				{
					this.className += " hover";
				}
			}
			inputs[i].onmouseout = function ()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}

if (window.addEventListener){
	window.addEventListener("load", initPage, false);
} else if (window.attachEvent){
	window.attachEvent("onload", initPage);
}

function FixSpots() {
// first check if we have a spot-row object
    var spotsrow = $('#sport-row');
    if (spotsrow) {
    // find the heighest spot
        var heighestSpot = 0;
        jQuery.each($('.spot', spotsrow), function() {
            var spotElement = $(this)[0];
            if (spotElement) {
                if (spotElement.offsetHeight > heighestSpot)
                    heighestSpot = spotElement.offsetHeight
            }
        });

        jQuery.each($('.spot', spotsrow), function() {
            $(this).height(heighestSpot);
            var headHeight = 0;
            var headElement = $('.head', $(this))[0];
            if (headElement)
                headHeight = headElement.offsetHeight;
            var spotCont = $('.spot-cont', $(this));
            var spotText = $('.spot-text', spotCont);
            var spotInner = $('.inner', spotText);
            // if the spot got a head section, this should be considered for content height
            if (headHeight > 0) {
                var spotContHeight = heighestSpot - headHeight;
                var imageElement = $('.spot_image', $(spotCont))[0];
                if (imageElement == null) {
                    spotText.height(spotContHeight);
                    spotInner.height(spotContHeight);
                } else {
                    spotCont.height(spotContHeight);
                }
            } else {
                spotCont.height(heighestSpot);
                spotText.height(spotContHeight);
            }
        });
    }
}
$(document).ready(function() {
    FixSpots();
    if ($.browser.msie) {
        $('select.select-dropdown-fixed').each(function() {
            dropdown_menu_hack(this);
        });
    }
});
function AddVacancyToCookie(vacancyID, list) {
    $('#gem-annonce-gem').hide();
    var vacancyList = readCookie("vacancylist"+list);
    //alert(vacancyList);
    if (vacancyList) {
        if (vacancyList.indexOf(vacancyID) == -1) {
            vacancyList += "," + vacancyID;
        }
    } else {
        vacancyList = vacancyID;
    }
    createCookie("vacancylist" + list, vacancyList, 30);
    
    $('#gem-annonce-gemt').show();
    
}

function GetVacanciesFromCookie(list) {
    var vacancyList = readCookie("vacancylist" + list);
    // alert(vacancyList);
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}


//** FROM OLD ODENSE **//

function checkEnter(e, caller) //e is event object passed from function invocation
{

    var characterCode //literal character code will be stored in this variable

    if (e && e.which || e.which == 0) { //if which property of event object is supported (NN4)

        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
    {
        if (document.all) {
            e.returnValue = false;
            e.cancel = true;
        }
        else {
            e.preventDefault();
        }
        var obj = document.getElementById(caller);
        if (obj) {

            if (obj.click) {
                obj.click();
            }
        }
        return false
    }
    else {
        return true
    }

}

function OxySearch(searchnode, searchStr, site, client, proxystylesheet, output) {
    var searchStr = encodeURIComponent(searchStr);
    location.href = searchnode + '?q=' + searchStr + '&site=' + site + '&client=' + client + '&proxystylesheet=' + proxystylesheet + '&output=' + output;
}

function JobFokusSearch(searchPage) {
    var jobArea = document.getElementById('JobArea').value;
    var jobCategory = document.getElementById('JobCategory').value;
    var department = document.getElementById('Department').value;
    var jobTime = document.getElementById('JobTime').value;
    var vacancyID = document.getElementById('VacancyID').value;
    var searchText = encodeURIComponent(document.getElementById('SearchText').value);

    location.href = searchPage + "?VacancyID=" + vacancyID + "&SearchText=" + searchText + "&JobArea=" + jobArea + "&JobCategory=" + jobCategory + "&department=" + department + "&JobTime=" + jobTime;
}

function NulstilSogeboks() {
    var soegeForm = $('#soegeForm');
    jQuery.each($("input[type='text']", soegeForm), function() {
        $(this).val("");
    });
    jQuery.each($("select", soegeForm), function() {
        $(this).trigger("change");
    });
    
}

