﻿var title = "";

function toggleImage(pxl, it) {
  it.style.backgroundPosition = "0px " + pxl + "px";
}

function changeFrettaAr(ar) {
  var arin = document.getElementById("div_Arin").childNodes;
  for (i = 0; i < arin.length; i++) {
    if (arin[i].tagName == "DIV") {
      arin[i].style.display = "none";
    }
  }
  document.getElementById("div_Ar_" + ar).style.display = "block";
}


function AddEvent(tObject, tEvent, tFunc) {
  if (document.attachEvent) {
    tObject.attachEvent("on" + tEvent, tFunc);
  }
  else {
    tObject.addEventListener(tEvent, tFunc, false);
  }
}

function RemoveEvent(tObject, tEvent, tFunc) {
  if (document.detachEvent) {
    tObject.detachEvent(tEvent, tFunc);
  }
  else {
    tObject.removeEventListener(tEvent, tFunc, false);
  }
}









function setActiveStyleSheet(tTitle) {
  var i, a, main;
  for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if (a.getAttribute("title") == tTitle) {
        a.disabled = false;
      }
    }
  }
  title = tTitle;
  //setButtons(tTitle);
}

function window_load() {

    try {
        for (i = 0; i < 9; i++) {
            $('#Place_' + i).find('*').fadeTo(0, 0);
        }
        document.getElementById("divAllPlaces").style.display = "block";
        SetDefaultPlace();
    } catch (e) {
    }

  var cookie = readCookie("style");
  title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

//function setButtons(tTitle) {
//  var a = document.getElementById("imgA");
//  var aa = document.getElementById("imgAA");
//  switch (tTitle) {
//    case "Size2":
//      a.style.backgroundPosition = "0px 0px";
//      a.style.cursor = "pointer";
//      aa.style.backgroundPosition = "0px 0px";
//      aa.style.cursor = "pointer";
//      break;
//    case "Size3":
//      //a.style.backgroundPosition = "0px 0px";
//      a.style.cursor = "pointer";
//      //aa.style.backgroundPosition = "0px -28px";
//      aa.style.cursor = "default";
//      break;
//    default:
//      //a.style.backgroundPosition = "0px -28px";
//      a.style.cursor = "default";
//      //aa.style.backgroundPosition = "0px 0px";
//      aa.style.cursor = "pointer";
//  }
//}

function fontLarger() {
  if (title == "Size1" || title == "") {
    setActiveStyleSheet("Size2");
  } else {
    if (title == "Size2") {
      setActiveStyleSheet("Size3");
    }
  }
}
function fontSmaller() {
  if (title == "Size3") {
    setActiveStyleSheet("Size2");
  } else {
    if (title == "Size2") {
      setActiveStyleSheet("Size1");
    }
  }
}

function window_unload() {
  var title = getActiveStyleSheet();
  createCookie("style", title, 7);
}
function getPreferredStyleSheet() {
  var i, a;
  for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
      return a.getAttribute("title");
  }
  return null;
}
function getActiveStyleSheet() {
  var i, a;
  for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("title")
			&& !a.disabled) return a.getAttribute("title");
  }
  return null;
}
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 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 inpLeit_focus(e, o) {
  if (o.firstTime) { return }
  o.firstTime = true
  o.value = ""
}

function askrift(SID_ID, VEF_ID) {
  gluggi_askrift = window.open('http://nepal.vefurinn.is/fastar/postlistaskraning_1.asp?ASK_SID_ID=' + SID_ID + '&VEF_ID=' + VEF_ID, 'image', "toolbar=0,scrollbars=0,location=0,status=0,menubar=0,width=350,height=300");
}

var selectedPlace = -1;
var tOut;

function placeOver(itemNo) {
    for (i = 0; i < 9; i++) {
        $('#Place_' + i).find('*').stop();
        if (i == itemNo) {
            $('#Place_' + i).find('*').fadeTo(300, 1);
            selectedPlace = i;
        } else {
            $('#Place_' + i).find('*').fadeTo(300, 0);
        }
    }
}

function placeOff(itemNo) {
    selectedPlace = -1;
    tOut=window.setTimeout("SetDefaultPlace()", 1000);
    //$('#Place_' + itemNo).find('*').fadeTo(300, 0);
}

function SetDefaultPlace() {
    if (selectedPlace == -1) {
        placeOver(defPlace);
    }
}

    

