﻿$(document).ready(
    function() {
        pageLoaded();
    }
);


function pageLoaded()
{
    var objDiv = document.getElementById("ctl00_txtUserEmail")
    
    if (objDiv != null)
    {
        if (objDiv.value == "")
            objDiv.value = "E-postadress";
        
        objDiv = document.getElementById("ctl00_txtPassword")
        
        if (objDiv.value == "")
        {
            objDiv = document.getElementById("ctl00_txtCoverPassword")
            objDiv.innerHTML = "Lösenord"
        }
        else
        {
            objDiv = document.getElementById("ctl00_txtCoverPassword")
            objDiv.innerHTML = ""
        }
    } 
}

function clearField(a_Inputfield)
{
    a_Inputfield.previousSibling.innerHTML = "";
}


function clearInput(a_Inputfield)
{
    if (a_Inputfield.firstChild.value == "E-postadress" || a_Inputfield.firstChild.value == "Sökord här..." || a_Inputfield.firstChild.value == "Din väns e-postadress")
        a_Inputfield.firstChild.value = "";
}

function hidePasswordCover(a_Inputfield)
{
    a_Inputfield.style.display = "none";
    a_Inputfield.nextSibling.focus();
}

var previousTag = null;
function textResize(a_size, objTag)
{    
    objTag.innerHTML = "A";
    
    if (previousTag == null)
        previousTag = document.getElementById("letterA");
           
    if (objTag != previousTag)
    {
        previousTag.innerHTML = "<a href=\"#\" onclick=\"return false;\">A</a>";
        previousTag = objTag;
    }       
    
    var lstTags = document.getElementsByTagName("p");    
    
    for (var i = 0; i < lstTags.length; i++)
    {        
        lstTags[i].style.fontSize = a_size + "px";
        lstTags[i].style.lineHeight = (a_size + 6) + "px";
    }   
}

var isIE = document.all;
var mouseX = 0;
var mouseY = 0;

function getMouseXY(e)
{
    if(!e) e = window.event||window.Event;
    
    if(e)
    {
        mouseX = isIE ? (e.clientX + document.documentElement.scrollLeft) : e.pageX;
        mouseY = isIE ? (e.clientY + document.documentElement.scrollTop) : e.pageY;
    }
}

if (!isIE)
    document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = getMouseXY;

function tellAFriend()
{
    var objDiv = document.getElementById("tellAFriend");
    
    if (objDiv != null)
    {
        objDiv.style.display = "block";
        objDiv.style.position = "absolute";
        objDiv.style.top = (mouseY + 10) + "px";
        objDiv.style.left = (mouseX-25) + "px";
    }
    else
        alert("Funktionen för \"Tipsa en vän\" saknas på denna sida. Anmäl gärna detta till support@malexnader.se");
}

function closeById(id)
{
    document.getElementById(id).style.display = "none";
}

function getNextSibling(startBrother){
  endBrother=startBrother.nextSibling;
  
  while(endBrother.nodeType!=1){
    endBrother = endBrother.nextSibling;
  }
  return endBrother;
  }

function showFormInfo(showInfo, objTag)
{   
    var objTag = getNextSibling(objTag.parentNode);
    if (!objTag.innerHTML.match("forminfobubbleTop") && showInfo)
    {
        alert("Informationstext saknas.")
        return false;
    }
    else if (!objTag.innerHTML.match("forminfobubbleTop"))
        return false;
    
    if (showInfo)
        objTag.style.display = "block";
    else
        objTag.style.display = "none"; 
    
    objTag.style.position = "absolute";
    objTag.style.top = (mouseY + 5) + "px";
    objTag.style.left = (mouseX + 10) + "px";    
}

function showComments()
{
    var objTag = document.getElementById("commentArea");
    objTag.style.display = "block";
}

function popupWindow(target, name, settings)
{
    window.open(target, name, settings, true);
}

var warnedOnce = false;
function checkNumberOfChars(objTextarea, maxLenght)
{
    if (parseInt(objTextarea.value.length) > (maxLenght-15) && !warnedOnce)
    {
        alert("Du har skrivit nu skrivit " + objTextarea.value.length + " tecken, max antal för den korta informationen är " + maxLenght +". Resten kommer att försvinna.");
        warnedOnce = true;
    }
}