var SHOCKNEWS_VERSION = '13.1';

var onloadReady = false;

function WindowOnload(f) { 
 var prev = window.onload; 
 window.onload = function(){ if(prev)prev(); f(); }
} 

function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
  return new XMLHttpRequest();
 } else if(window.ActiveXObject) {
  return new ActiveXObject("Microsoft.XMLHTTP");
 } else {
  return false;
 }
}

function makePOSTRequest(url, parameters, endFunction) {
 http_request = false;
 if(window.XMLHttpRequest) { // Mozilla, Safari,...
  http_request = new XMLHttpRequest();
  if (http_request.overrideMimeType) { // set type accordingly to anticipated content type
   // http_request.overrideMimeType('text/xml');
   http_request.overrideMimeType('text/html');
  }
 } else if (window.ActiveXObject) { // IE
  try {
   http_request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e) {}
  }
 }
 if (!http_request) {
 alert('Cannot create XMLHTTP instance');
  return false;
 }
 http_request.onreadystatechange = endFunction;
 http_request.open('POST', url, true);
 http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 http_request.setRequestHeader("Content-length", parameters.length);
 http_request.setRequestHeader("Connection", "close");
 http_request.send(parameters);
}

function changeMessage(element, txt) {
 document.getElementById(element).innerHTML = txt;
}

function removeMessage(element) {
 document.getElementById(element).innerHTML = '';
}

function changeVersion(version) {
 document.versionForm.siteVersion.value = version;
 document.versionForm.submit();
}

function changeStatus(status) {
 document.statusForm.status.value = status;
 document.statusForm.submit();
}

function confirmUrl(message, url) { 
 if(confirm(message)) location.href = url; 
 return false;
} 

function submitEnter(myfield,e) {
 var keycode;
 if (window.event) keycode = window.event.keyCode;
 else if (e) keycode = e.which;
 else return true;
 if (keycode == 13) {
  myfield.form.submit();
 }else
  return true;
}

var vurdering_div;
function vurdering_click_ready() {
 if (getVurderingRequest.readyState == 4) { 
  document.getElementById(vurdering_div).innerHTML = '<nobr>' + language["evaluation_registered"] + '..</nobr>';
 }
}

function vurdering_click(destination, id, antal, div) {
 vurdering_div = div;
 if(document.getElementById(div)) {
  document.getElementById(div).innerHTML = '<div style="text-align: center;"><img src="'+FILE_PATH+'images/loading.gif" alt="" title="" border="0" /></div>';
  getVurderingRequest = getXmlHttpRequestObject();
  if(getVurderingRequest.readyState == 4 || getVurderingRequest.readyState == 0) {
   getVurderingRequest.open("GET", destination+'/'+id+'/'+antal, true);  
   getVurderingRequest.onreadystatechange = vurdering_click_ready;
   getVurderingRequest.send(null); 
  } 
 } 
}

function formPress(element) {
 return true;
}

function processForm(theform) {

  if(document.all || document.getElementById) {
   for (i = 0; i < theform.length; i++) {
    var tempobj = theform.elements[i];
    if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") tempobj.disabled = true;
   }
  }

}

function login_husk() {

  if(document.getElementById("login_check").checked) {
   if(!confirm(language["remember_login_question"])) {
    document.getElementById("login_check").checked = false;
   }
  }

}

function processSearch(value, std) {

  if(value == '' || value == std) {
   return false;
  }else{
   document.location.href = FILE_PATH + 'home/search/'+value;
   return false;
  }

}

var Furniture = { 
 open: function(id) {
  win = window.open(FILE_PATH + "furniture/"+id, "moebel", "width=500,height=450");
 },
 search: function(text, category) {
  if(text != '' && text != ' ' && text != language["search_write_text"] + '..') {
   document.getElementById('moebler').innerHTML = '<br/><div class="box" style="padding-top: 10px; padding-bottom: 10px; text-align: center;"><img src="'+FILE_PATH+'images/loading.gif" alt="" title="' + language["please_wait"] + '.." border="0" style="margin-bottom: 3px;" /><br/>' + language["please_wait"] + '..</div>';
   getRequest = getXmlHttpRequestObject();
   if(getRequest.readyState == 4 || getRequest.readyState == 0) {
    getRequest.open("GET", FILE_PATH+"xml/furniture.php?mode=search&text="+text+"&category="+category, true);  
    getRequest.onreadystatechange = function() { if(getRequest.readyState == 4) { getContent = getRequest.responseText.split("%25%25"); document.getElementById('moebler_antal').innerHTML = getContent[0]; document.getElementById('moebler').innerHTML = getContent[1].replace(/%%file_path%%/g, FILE_PATH); } };
    getRequest.send(null); 
   } 
  }
 },
 submitEnter: function(myfield, e, category) {
  var keycode;
  if(window.event) {
   keycode = window.event.keyCode;
  }else if(e) {
   keycode = e.which;
  }else{
   return true;
  }
  if(keycode == 13) {
   Furniture.search(myfield.value, category);
  }else{
   return true;
  }
 }
};

function openJobInfo(jobId) {

 window.open(FILE_PATH + "staff/job_info/"+jobId, "staff_jobInfo"+jobId, "width=350,height=450,scrollbars=yes");

}

var Userconditions = {
 open: function() {
  con_win = window.open(FILE_PATH + "community/user_conditions", "user_conditions", "width=350,height=450,scrollbars=yes");
 }
};

var Admin = {
 News: {
  open: function(id) {
   if(id != '' && id != '0') {
    adm_win = window.open(FILE_PATH + "community/admin/news/" + id, "admin", "width=700,height=400,resizable=0");
   }else{
    adm_win = window.open(FILE_PATH + "community/admin/news/", "admin", "width=700,height=400,resizable=0");
   }
  }
 },
 open: function() {
  adm_win = window.open(FILE_PATH + "community/admin/", "admin", "width=700,height=400,resizable=0");
 }
};

clicked = false;
startWidth = 50;
function resizebox() {
 if(clicked == false) {
  for(i=1 ; 10>=i; i++) {
   newWidth = eval(startWidth + i*10)+'px';
   setTimeout("document.searchForm.words.style.width = '"+newWidth+"';", i*25);
  }
  clicked = true;
 }else{
  for(i=1 ; 10>=i; i++) {
   newWidth = eval((startWidth+100) - i*10)+'px';
   setTimeout("document.searchForm.words.style.width = '"+newWidth+"';", i*25);
  }
  clicked = false;
 }
}

function updateUser_ready() {
 if (getUserRequest.readyState == 4) { 
  try {
   getContent = getUserRequest.responseText.split("%25%25");
   if(getContent[0] && IsNumeric(getContent[0])) { 
    newMail         = getContent[0];
    newNotification = getContent[1];
    if(newMail != '0') {
     document.getElementById('antal_nye_breve').innerHTML = ' (<strong>'+newMail+'</strong>)';
    }
    if(newNotification != '') {
     newNotification = newNotification.split("%24%24");
     Notification.open(newNotification[0], newNotification[1]);
    }
   }else{
    location.reload(true);
   }
  } catch(err) {
   //
  }
 }
}

function updateUser() {
 if(document.getElementById('antal_nye_breve')) {
  getUserRequest = getXmlHttpRequestObject();
  if(getUserRequest.readyState == 4 || getUserRequest.readyState == 0) {
   getUserRequest.open("GET", FILE_PATH + "xml/opdater.php", true);  
   getUserRequest.onreadystatechange = updateUser_ready;
   getUserRequest.send(null); 
  } 
  setTimeout("updateUser()",45000); 
 } 
}

var markeringStatus = false;
function markerAlle(theElement) {
 var theForm = theElement.form, z = 0;
 if(markeringStatus == false) {
  for(z=0; z<theForm.length;z++){
   theForm[z].checked=true;
  }
  markeringStatus = true;
  theElement.value = language["unmark_all"];
 } else {
  for(z=0; z<theForm.length;z++){
   theForm[z].checked=false;
  }
  markeringStatus = false;
  theElement.value = language["mark_all"];
 }
}

Array.prototype.inArray=function(search_phrase){for(var i=0; i<this.length; i++){if(search_phrase==this[i]){return true;}}return false;}
var fileExtensions = new Array("gif", "jpg", "jpeg", "png", "bmp");

function showImage(sValue, eId, eImg) {
 if(sValue == "") {
  eId.style.backgroundImage = 'url('+eImg+')';
 }else{
  var aParts = sValue.split( "/" );
  var iParts = aParts.length;
  if(iParts >= 1) {
   var sFile = aParts[ iParts - 1 ];
   var aFile = sFile.split( "." );
   if( aFile.length == 2) {
    sName = aFile[0];
    sExt = aFile[1].toLowerCase();
    if(fileExtensions.inArray(sExt)) {
     eId.style.backgroundImage = 'url('+sValue+')';
    }
   }
  }
 }
}

var oDiv;

var Notification = { 
 create: function(heading, text) {
  notificationHTML = '<div class="notification_table"><div class="background"></div><table class="table" border="0" cellpadding="0" cellspacing="0"><tr><td class="cell"><center><div id="notification_header"><a href="javascript: Notification.close();" id="notification_close" title="' + language["notification_close"] + '"></a>'+heading+'</div><div id="notification_text">'+text+'</div><div id="notification_bottom"></div></center></td></tr></table></div>';
  return notificationHTML;
 },
 open: function(heading, text) {
  if(!oDiv) {
   oDiv = document.createElement("DIV"); 
   top.document.body.appendChild(oDiv);
  }
  oDiv.innerHTML = Notification.create(stripslashes(heading), stripslashes(text));
 },
 close: function() {
  top.document.body.removeChild(oDiv);
  oDiv = false;
 }
};

function getVar(name) {
 get_string = document.location.search;         
 return_value = '';
         
 do { //This loop is made to catch all instances of any get variable.
  name_index = get_string.indexOf(name + '=');
            
  if(name_index != -1) {
   get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
   end_of_value = get_string.indexOf('&');
   if(end_of_value != -1)                
    value = get_string.substr(0, end_of_value);                
   else                
    value = get_string;                
   if(return_value == '' || value == '')
    return_value += value;
   else
    return_value += ', ' + value;
  }
 } 
 while(name_index != -1)
  //Restores all the blank spaces.
  space = return_value.indexOf('+');
  while(space != -1) { 
   return_value = return_value.substr(0, space) + ' ' + 
   return_value.substr(space + 1, return_value.length);
   space = return_value.indexOf('+');
  }      
  return(return_value);        
}

function in_array(needle, haystack, strict) { 
 var found = false, key, strict = !!strict; 
 for(key in haystack) { 
  if((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) { 
   found = true; break; 
  } 
 } 
 return found; 
}

function addslashes(str) {
 str = str.replace(/\'/g,'\\\'');
 str = str.replace(/\"/g,'\\"');
 str = str.replace(/\\/g,'\\\\');
 str = str.replace(/\0/g,'\\0');
 return str;
}

function stripslashes(str) {
 str = str.replace(/\\'/g,'\'');
 str = str.replace(/\\"/g,'"');
 str = str.replace(/\\\\/g,'\\');
 str = str.replace(/\\0/g,'\0');
 return str;
}

function insertAtCursor(myField, myValue) {
 if(document.selection) { //IE support
  myField.focus();
  sel = document.selection.createRange();
  sel.text = myValue;
 }else if(myField.selectionStart || myField.selectionStart == "0") { //MOZILLA/NETSCAPE support
  var startPos = myField.selectionStart;
  var endPos = myField.selectionEnd;
  myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
 }else{
  myField.value += myValue;
 }
}

var SNcountDown = {

 id            : '',
 hours_id      : '',
 minutes_id    : '',
 seconds_id    : '',
 message       : '',
 finalMessage  : '',
 startDate     : '',
 endDate       : '',
 seconds       : '',

 init: function() {
  SNcountDown.seconds = (SNcountDown.endDate - SNcountDown.startDate) / 1000;
  ID = window.setTimeout("SNcountDown.update();", 500);
 },

 update: function() {
  if(SNcountDown.seconds > 0){
   SNcountDown.seconds--;
   var hours = SNcountDown.seconds/3600; 
   hours = Math.floor(hours);
   var minutes = SNcountDown.seconds - (hours*3600);
   minutes = minutes/60;
   minutes = Math.floor(minutes);
   var seconds = SNcountDown.seconds - (hours*3600) - (minutes*60);

    if(hours > 0) {
     document.getElementById(SNcountDown.id).innerHTML = "<strong>"+hours+"</strong> t, <strong>"+minutes+"</strong> m, <strong>"+seconds+"</strong> sek. tilbage";
    }else if(minutes > 0) {
     document.getElementById(SNcountDown.id).innerHTML = "<strong>"+minutes+"</strong> min. og <strong>"+seconds+"</strong> sek. tilbage";
    }else{
     document.getElementById(SNcountDown.id).innerHTML = "<strong>"+seconds+"</strong> sekunder tilbage";
    }

   ID = window.setTimeout("SNcountDown.update();",1000);

  }else{

   if(SNcountDown.id != '') {
    document.getElementById(SNcountDown.id).innerHTML = SNcountDown.finalMessage;
   }

  }
 }
};

var countDown = {

 id            : '',
 days_id       : '',
 hours_id      : '',
 minutes_id    : '',
 seconds_id    : '',
 message       : '',
 finalMessage  : '',
 finalUrl      : '',
 startDate     : '',
 endDate       : '',
 seconds       : '',

 init: function() {
  countDown.seconds = (countDown.endDate - countDown.startDate) / 1000;
  ID = window.setTimeout("countDown.update();", 500);
 },

 update: function() {
  if(countDown.seconds > 0){
   countDown.seconds--;
   var days = countDown.seconds/86400;
   days = Math.floor(days);
   var days_word = language["days"];
   if(days == 1)days_word = language["day"];
   var hours = countDown.seconds - (countDown.id != '' || countDown.days_id != '' ? (days*86400) : 0); 
   hours = hours/3600; 
   hours = Math.floor(hours);
   var hours_word = language["hours"];
   if(hours == 1)hours_word = language["hour"];
   var minutes = countDown.seconds - (countDown.id != '' || countDown.days_id != '' ? (days*86400) : 0) - (hours*3600);
   minutes = minutes/60;
   minutes = Math.floor(minutes);
   var seconds = countDown.seconds - (countDown.id != '' || countDown.days_id != '' ? (days*86400) : 0) - (hours*3600) - (minutes*60);

   if(countDown.id != '') {

    if(days > 0) {
     document.getElementById(countDown.id).innerHTML = countDown.message + days+" "+days_word+", "+hours+" "+hours_word+", "+minutes+" " + language["minutes"] + " " + language["and"].toLowerCase() + " "+seconds+" " + language["seconds"];
    }else if(hours > 0) {
     document.getElementById(countDown.id).innerHTML = countDown.message + hours+" "+hours_word+", "+minutes+" " + language["minutes"] + " " + language["and"].toLowerCase() + " "+seconds+" " + language["seconds"];
    }else if(minutes > 0) {
     document.getElementById(countDown.id).innerHTML = countDown.message + minutes+" " + language["minutes"] + " " + language["and"].toLowerCase() + " "+seconds+" " + language["seconds"];
    }else{
     document.getElementById(countDown.id).innerHTML = countDown.message + seconds+" " + language["seconds"];
    }

   }else if(countDown.days_id != '' || countDown.hours_id != '' || countDown.minutes_id != '' || countDown.seconds_id != '') {
    if(countDown.days_id != '') {
     document.getElementById(countDown.days_id).value = days;
    }
    if(countDown.hours_id != '') {
     document.getElementById(countDown.hours_id).value = hours;
    }
    if(countDown.minutes_id != '') {
     document.getElementById(countDown.minutes_id).value = minutes;
    }
    if(countDown.seconds_id != '') {
     document.getElementById(countDown.seconds_id).value = seconds;
    }
   }

   ID = window.setTimeout("countDown.update();",1000);
  }else{

   if(countDown.finalUrl != '') {
    location.href = countDown.finalUrl.replace("%%file_path%%", FILE_PATH);
   }

   if(countDown.id != '') {
    document.getElementById(countDown.id).innerHTML = countDown.finalMessage;
   }

  }
 }
};

function updateSNonlineAmount(amount) {

 if(document.getElementById('count_shocknews_online'))
  document.getElementById('count_shocknews_online').innerHTML = amount;

 if(document.getElementById('count_tagwall_online1'))
  document.getElementById('count_tagwall_online1').innerHTML = amount;

 if(document.getElementById('count_tagwall_online2'))
  document.getElementById('count_tagwall_online2').innerHTML = amount;

}

function setcookie(name, value, expires, path, domain, secure) { 
 expires instanceof Date ? expires = expires.toGMTString() : typeof(expires) == 'number' && (expires = (new Date(+(new Date) + expires * 1e3)).toGMTString()); 
 var r = [name + "=" + escape(value)], s, i; 
 for(i in s = {expires: expires, path: path, domain: domain}){ 
  s[i] && r.push(i + "=" + s[i]); } 
 return secure && r.push("secure"), document.cookie = r.join(";"), true; 
}

function IsNumeric(sText) {

   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }

   return IsNumber;
   
}

var windowState = (function(){
 var readScroll = {scrollLeft:0,scrollTop:0};
 var readSize = {clientWidth:0,clientHeight:0};
 var readScrollX = 'scrollLeft';
 var readScrollY = 'scrollTop';
 var readWidth = 'clientWidth';
 var readHeight = 'clientHeight';
 function otherWindowTest(obj) {
  if((document.compatMode)&&(document.compatMode == 'CSS1Compat')&&(document.documentElement)) {
   return document.documentElement;
  }else if(document.body) {
   return document.body;
  }else{
   return obj;
  }
 };
 if((typeof this.innerHeight == 'number')&&(typeof this.innerWidth == 'number')) {
  readSize = this;
  readWidth = 'innerWidth';
  readHeight = 'innerHeight';
 }else{
  readSize = otherWindowTest(readSize);
 }
 if((typeof this.pageYOffset == 'number')&&(typeof this.pageXOffset == 'number')) {
  readScroll = this;
  readScrollY = 'pageYOffset';
  readScrollX = 'pageXOffset';
 }else{
  readScroll = otherWindowTest(readScroll);
 }
 return {
  getScrollX:function() {
   return (readScroll[readScrollX]||0);
  },
  getScrollY:function() {
   return (readScroll[readScrollY]||0);
  },
  getWidth:function() {
   return (readSize[readWidth]||0);
  },
  getHeight:function() {
   return (readSize[readHeight]||0);
  }
 };
})();

var overlayDiv;
var myImage;

var lightbox = {
 display: function(url) {
  if(!overlayDiv && !myImage && onloadReady) { 
   overlayDiv = document.createElement("div"); 
   overlayDiv.id = "lightbox_overlay"; 
   document.body.appendChild(overlayDiv); 
   document.getElementById('lightbox_overlay').onclick = lightbox.hide;
   myImage = document.createElement("img");
   myImage.setAttribute('src', url);
   myImage.setAttribute('id', 'lightbox_image');
   myImage.style.left = Math.round(windowState.getScrollX()+((windowState.getWidth()-myImage.width)/2)) + "px";
   myImage.style.top  = Math.round(windowState.getScrollY()+((windowState.getHeight()-myImage.height)/2)) + "px";
   document.body.appendChild(myImage);
   document.getElementById('lightbox_image').onclick = lightbox.hide;
  }
 },
 hide: function() {
  document.body.removeChild(overlayDiv);
  overlayDiv = false;
  document.body.removeChild(myImage);
  myImage = false;
 }
};

var mobile = {
 navigate: function(url) {
  location.href = url;
 }
};

WindowOnload(function() { if(document.getElementById('newsContainer')){ setTimeout('newsScroll()',10000); } if(document.getElementById('antal_nye_breve')){ updateUser(); } onloadReady = true; });