/**
 * @author Anna Nordin
 */
window.onload = function() {
    var loginBtn = document.getElementById('loginBtn');
    var loginForm = document.getElementById('loginForm');
    if(loginForm != null)
    {
        loginForm.onfocus = function() {
            clean(loginForm,'Användarnamn')
        };
    }
    if(loginBtn != null)
    {
        loginBtn.onclick = function() {
            //checkLogin(loginForm.username.value, loginForm.password.value);
        }
    }
}

function checkLogin(username, password) {
    if(username == "Användarnamn")
        alert("Felaktigt användarnamn!");
    if(password == "Lösenord")
        alert("Felaktigt lösenord!");

    return false;
}

function clean(input,match)
{
    if (input.value == match) {
        input.value = "";
    }
}

function cleanDefaultValues(formElement,array) {
    for(var i = 0; i < array.length; ++i)
    {
        if(i % 2 == 0)
        {
            var e = formElement.elements[array[i]];
            if(e.value == array[i + 1])
                e.value = "";
			
        }
    }
    return true;
}

function setInnerText(elementName,text)
{
    document.getElementById(elementName).innerHTML = text;
}

function showEditArea(elementName,selectElement,fetchFromElementName)
{
    var textArea = document.getElementById(elementName);
    var index = selectElement.options[selectElement.selectedIndex].value;
    var txt = document.getElementById(fetchFromElementName + index).innerHTML;
	
    textArea.innerHTML = txt;
}

function showElement(selectElement,arrayOfElementNames)
{
    for(var i = 0; i < selectElement.options.length; ++i)
    {
        var temp = document.getElementById(arrayOfElementNames[i]);
        temp.style.display = "none";
		
        if(i == selectElement.selectedIndex - 1)
            temp.style.display = "block";
    }
}

function popupWindow(url, height, width) {
    if(!height)
        height = 500;
    if(!width)
        width = 500;
    newwindow=window.open(url,'name','height=' + height + ',width=' + width + ',scrollbars=1,menubar=1');
    if (window.focus) {
        newwindow.focus()
    }
    return false;
}


