
// AJAX-variabler

   var xmlHttp_load_content_main
   var xmlHttp_load_content_main_advertisment
   var xmlHttp_load_content_main_offer
   var xmlHttp_load_form_admin_menu
   var xmlHttp_load_form_admin_advertisment
   var xmlHttp_load_form_admin_offer
   var xmlHttp_load_content_main_registration
   var xmlHttp_changeBranchEmployees
   var xmlHttp_saveStatistics

// spara statistik

   function saveStatistics(saveUserName, saveVisitPath) {
      
      xmlHttp_saveStatistics = GetXmlHttpObject();
      
      if (xmlHttp_saveStatistics == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var strUrl="save_statistics.php";
      strUrl=strUrl+"?saveUserName=" + saveUserName;
      strUrl=strUrl+"&saveVisitPath=" + saveVisitPath;
      
      strUrl=strUrl+"&sid="+Math.random();
      
      xmlHttp_saveStatistics.onreadystatechange = stateChangedSaveStatistics;
      xmlHttp_saveStatistics.open("GET", strUrl, true);
      xmlHttp_saveStatistics.send(null);
      
   }

   function stateChangedSaveStatistics() {
   
      if (xmlHttp_saveStatistics.readyState == 4){
         
         
         
      }
      
   }

// Ladda en ny meny för adminsidan för menyer

   function form_admin_menu_show_menu() {
      
      xmlHttp_load_form_admin_menu = GetXmlHttpObject();
      
      if (xmlHttp_load_form_admin_menu == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var url="form_admin_menu.php";
      url=url+"?menuId=" + document.getElementById('form_admin_menu_menu').value;
      
      url=url+"&sid="+Math.random();
      
      xmlHttp_load_form_admin_menu.onreadystatechange = stateChangedLoadFormAdminMenu;
      xmlHttp_load_form_admin_menu.open("GET", url, true);
      xmlHttp_load_form_admin_menu.send(null);
      
   }



   function stateChangedLoadFormAdminMenu() {
   
      if (xmlHttp_load_form_admin_menu.readyState == 4){
         
         document.getElementById('content_main').innerHTML = xmlHttp_load_form_admin_menu.responseText;
         
      }
      
   }

// Ladda en annons för adminsidan för annonser

   function form_admin_menu_show_advertisment() {
      
      xmlHttp_load_form_admin_advertisment = GetXmlHttpObject();
      
      if (xmlHttp_load_form_admin_advertisment == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var url="form_admin_advertisment.php";
      url=url+"?advertismentId=" + document.getElementById('form_admin_advertisment_advertisment').value;
      
      url=url+"&sid="+Math.random();
      
      xmlHttp_load_form_admin_advertisment.onreadystatechange = stateChangedLoadFormAdminAdvertisment;
      xmlHttp_load_form_admin_advertisment.open("GET", url, true);
      xmlHttp_load_form_admin_advertisment.send(null);
      
   }

   function stateChangedLoadFormAdminAdvertisment() {
   
      if (xmlHttp_load_form_admin_advertisment.readyState == 4){
         
         document.getElementById('content_main').innerHTML = xmlHttp_load_form_admin_advertisment.responseText;
         
      }
      
   }

// Ladda en förmån för adminsidan för fömåner

   function form_admin_menu_show_offer() {
      
      xmlHttp_load_form_admin_offer = GetXmlHttpObject();
      
      if (xmlHttp_load_form_admin_offer == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var url="form_admin_offers.php";
      url=url+"?offerId=" + document.getElementById('form_admin_offers_offer').value;
      
      url=url+"&sid="+Math.random();
      
      xmlHttp_load_form_admin_offer.onreadystatechange = stateChangedLoadFormAdminOffer;
      xmlHttp_load_form_admin_offer.open("GET", url, true);
      xmlHttp_load_form_admin_offer.send(null);
      
   }

   function stateChangedLoadFormAdminOffer() {
   
      if (xmlHttp_load_form_admin_offer.readyState == 4){
         
         document.getElementById('content_main').innerHTML = xmlHttp_load_form_admin_offer.responseText;
         
      }
      
   }



// Hämta ny huvudsida via AJAX
   
   function loadContentMain(contentId) {
      
      xmlHttp_load_content_main = GetXmlHttpObject();
      
      if (xmlHttp_load_content_main == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var url="index_ajax_get_content_main.php";
      url=url+"?contentId=" + contentId;
      
      url=url+"&sid="+Math.random();
      
      xmlHttp_load_content_main.onreadystatechange = stateChangedLoadContentMain;
      xmlHttp_load_content_main.open("GET", url, true);
      xmlHttp_load_content_main.send(null);
      
   }

   function stateChangedLoadContentMain() {
      
      if (xmlHttp_load_content_main.readyState == 4){
         
         document.getElementById('content_main').innerHTML = xmlHttp_load_content_main.responseText;
         
      }
      
   }

// Hämta ny huvudsida via AJAX - intresseanmälan
   
   function loadContentMain_registration(contentId, form_registration_company, form_registration_organisationNumber, form_registration_zipCode, form_registration_city, form_registration_firstName, form_registration_lastName, form_registration_branchId, form_registration_numberOfEmployees, form_registration_address, form_registration_customerNumber, form_registration_phoneNumber, form_registration_mobilePhoneNumber, form_registration_email, form_registration_numberOfCards, form_registration_contactId, felmeddelande){
      
      xmlHttp_load_content_main_registration = GetXmlHttpObject();
      
      if (xmlHttp_load_content_main_registration == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var urlStr="index_ajax_get_content_main_registration.php";
      urlStr=urlStr+"?contentId=" + contentId;
      urlStr=urlStr+"&form_registration_company=" + form_registration_company;
      urlStr=urlStr+"&form_registration_organisationNumber=" + form_registration_organisationNumber;
      urlStr=urlStr+"&form_registration_phoneNumber=" + form_registration_phoneNumber;
      urlStr=urlStr+"&form_registration_zipCode=" + form_registration_zipCode;
      urlStr=urlStr+"&form_registration_city=" + form_registration_city;
      urlStr=urlStr+"&form_registration_firstName=" + form_registration_firstName;
      urlStr=urlStr+"&form_registration_lastName=" + form_registration_lastName;
      urlStr=urlStr+"&form_registration_branchId=" + form_registration_branchId;
      urlStr=urlStr+"&form_registration_numberOfEmployees=" + form_registration_numberOfEmployees;
      urlStr=urlStr+"&form_registration_address=" + form_registration_address;
      urlStr=urlStr+"&form_registration_customerNumber=" + form_registration_customerNumber;
      urlStr=urlStr+"&form_registration_mobilePhoneNumber=" + form_registration_mobilePhoneNumber;
      urlStr=urlStr+"&form_registration_email=" + form_registration_email;
      urlStr=urlStr+"&form_registration_numberOfCards=" + form_registration_numberOfCards;
      urlStr=urlStr+"&form_registration_contactId=" + form_registration_contactId;
      urlStr=urlStr+"&felmeddelande=" + felmeddelande;
      
      
      urlStr=urlStr+"&sid="+Math.random();
      
      xmlHttp_load_content_main_registration.onreadystatechange = stateChangedLoadContentMain_registration;
      xmlHttp_load_content_main_registration.open("GET", urlStr, true);
      xmlHttp_load_content_main_registration.send(null);
      
   }

   function stateChangedLoadContentMain_registration() {
      
      if (xmlHttp_load_content_main_registration.readyState == 4){
         
         document.getElementById('content_main').innerHTML = xmlHttp_load_content_main_registration.responseText;
         
      }
      
   }
// Hämta ny huvudsida via AJAX - annonser
   
   function loadContentMain_advertisment(contentId, advertismentId){
      
      xmlHttp_load_content_main_advertisment = GetXmlHttpObject();
      
      if (xmlHttp_load_content_main_advertisment == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var url="index_ajax_get_content_main_advertisment.php";
      url=url+"?contentId=" + contentId;
      url=url+"&advertismentId=" + advertismentId;
      
      url=url+"&sid="+Math.random();
      
      xmlHttp_load_content_main_advertisment.onreadystatechange = stateChangedLoadContentMain_advertisment;
      xmlHttp_load_content_main_advertisment.open("GET", url, true);
      xmlHttp_load_content_main_advertisment.send(null);
      
   }

   function stateChangedLoadContentMain_advertisment() {
   
      if (xmlHttp_load_content_main_advertisment.readyState == 4){
         
         document.getElementById('content_main').innerHTML = xmlHttp_load_content_main_advertisment.responseText;
         
      }
      
   }
   
// Hämta ny huvudsida via AJAX - förmåner
   
   function loadContentMain_offer(contentId){
      
      xmlHttp_load_content_main_offer = GetXmlHttpObject();
      
      if (xmlHttp_load_content_main_offer == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var url="index_ajax_get_content_main_offer.php";
      url=url+"?contentId=" + contentId;
      
      url=url+"&sid="+Math.random();
      
      xmlHttp_load_content_main_offer.onreadystatechange = stateChangedLoadContentMain_offer;
      xmlHttp_load_content_main_offer.open("GET", url, true);
      xmlHttp_load_content_main_offer.send(null);
      
   }

   function stateChangedLoadContentMain_offer() {
   
      if (xmlHttp_load_content_main_offer.readyState == 4){
         
         document.getElementById('content_main').innerHTML = xmlHttp_load_content_main_offer.responseText;
         
      }
      
   }

// Uppdatera anställda på filialen via AJAX
   
   function changeBranchEmployees(){
      
      xmlHttp_changeBranchEmployees = GetXmlHttpObject();
      
      if (xmlHttp_changeBranchEmployees == null) {
         
         alert ("Your browser does not support AJAX!");
         
         return;
         
      }
      
      var strUrl="index_ajax_get_anstallda.php";
      strUrl=strUrl+"?branchId=" + document.getElementById('form_registration_branchId').value;
      
      strUrl=strUrl+"&sid="+Math.random();
      
      xmlHttp_changeBranchEmployees.onreadystatechange = stateChangedChangeBranchEmployees;
      xmlHttp_changeBranchEmployees.open("GET", strUrl, true);
      xmlHttp_changeBranchEmployees.send(null);
      
   }

   function stateChangedChangeBranchEmployees() {
      
      if (xmlHttp_changeBranchEmployees.readyState == 4){
         
         document.getElementById('form_registration_div_anstallda').innerHTML = xmlHttp_changeBranchEmployees.responseText;
         
      }
      
   }

   function GetXmlHttpObject(){
      
      var xmlHttp = null;
      
      try {
         
         // Firefox, Opera 8.0+, Safari
         
         xmlHttp=new XMLHttpRequest();
         
      } catch (e) {
         
         // Internet Explorer
         
         try {
            
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            
         }  catch (E)  {
            
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            
         }
         
      }
      
      return xmlHttp;
   }

   function logOutUser () {
      
      var d = new Date();
      document.cookie = "logged_in_user='';expires=" + d.toGMTString() + ";" + ";";

      var ReferURL = window.location.host;
      window.location.href = "http://" + window.location.host + "/" + "index.php";
      //var ReferURL = "index.php";
      //Window.location.href = ReferURL;
      
   }
   
