// Ajax Request
function AjaxObject(){

  var XObject;

  if (window.ActiveXObject)
	 XObject = new ActiveXObject("Microsoft.XMLHTTP");
	else
	 XObject = new XMLHttpRequest();

  return XObject;

};


// This function shows the help-screen
function ShowHelp(SectionKey){

 var ScreenWidth    = screen.width;
 var ScreenHeight   = screen.height;
 var WindowName     = "HelpDesk";
 var WindowHref     = "http://nl.visit-it.com/content/visit.helpdesk.php?section=" + SectionKey;
 var WindowWidth    = 484;
 var WindowHeight   = 390;
 var WindowDistX    = ((ScreenWidth  - WindowWidth ) / 2);
 var WindowDistY    = ((ScreenHeight - WindowHeight) / 2);
 var WindowDistTop  = ((ScreenHeight - WindowHeight) / 2);
 var WindowDistLeft = (((ScreenWidth - WindowWidth ) / 2) - 71);

 window.open("" + WindowHref + "", "" + WindowName + "", "width=" + WindowWidth + ", height=" + WindowHeight + ", toolbar=0, scrollbars=0, location=0, status=0, menubar=0, resizable=0, screenX=" + WindowDistX + ", screenY=" + WindowDistY + ", top=" + WindowDistTop + ", left=" + WindowDistLeft + "");

};


// This function shows the help-screen
function ShowAction(DataId){

 var ScreenWidth    = screen.width;
 var ScreenHeight   = screen.height;
 var WindowName     = "HelpDesk";
 var WindowHref     = "http://nl.visit-it.com/content/visit.actionscreen.php?dataid=" + DataId;
 var WindowWidth    = 484;
 var WindowHeight   = 390;
 var WindowDistX    = ((ScreenWidth  - WindowWidth ) / 2);
 var WindowDistY    = ((ScreenHeight - WindowHeight) / 2);
 var WindowDistTop  = ((ScreenHeight - WindowHeight) / 2);
 var WindowDistLeft = (((ScreenWidth - WindowWidth ) / 2) - 71);

 window.open("" + WindowHref + "", "" + WindowName + "", "width=" + WindowWidth + ", height=" + WindowHeight + ", toolbar=0, scrollbars=0, location=0, status=0, menubar=0, resizable=0, screenX=" + WindowDistX + ", screenY=" + WindowDistY + ", top=" + WindowDistTop + ", left=" + WindowDistLeft + "");

};


// This function adds a products to the customers Cart
function ShopBasketAdd(ProductId, UserId, SessionId){

 var ShopBasket        = document.getElementById("credits_basket");
 var ShopBasketRequest = AjaxObject();
 var ShopBasketRandom  = Math.random();
 var ShopBasketAction  = "add";
 var ShopBasketScript  = "scripts/visit.shop.basket.php?rand=" + ShopBasketRandom + "&action=" + ShopBasketAction + "&SessionId=" + SessionId;
 
 ShopBasketRequest.open("POST", ShopBasketScript);
 ShopBasketRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ShopBasketRequest.onreadystatechange = function() {

  if (ShopBasketRequest.readyState == 4 && ShopBasketRequest.status == 200) {

   if(ShopBasketRequest.responseText == "soldout")
    alert("Het products is helaas uitverkocht.");
   else if(ShopBasketRequest.responseText == "overflow")
    alert("De totaalwaarde van de artikelen in je mandje, is hoger dan je Saldo!");
   else if(ShopBasketRequest.responseText == "exists")
    alert("Dit artikel staat al in je winkelmandje!");
   else if(ShopBasketRequest.responseText == "debet")
    alert("Je saldo is te laag om dit artikel te kunnen kopen!");
   else if(ShopBasketRequest.responseText == "true")
    ShopBasket.innerHTML  = "Product toegevoegd!";
   else
    ShopBasket.innerHTML  = ShopBasketRequest.responseText;

   //ShopBasketList(UserId, SessionId);
   if(ShopBasketRequest.responseText == "true")
    window.location = 'http://nl.visit-it.com/ivisit/enjoys/basket'; // window.location + "/basket";

  }

 };

 ShopBasketRequest.send("ProductId=" + ProductId + "&UserId=" + UserId + "&SessionId=" + SessionId);

 scrollTo(0,0);
 
};


// This function remoces a products to the customers Cart
function ShopBasketRemove(ProductId, UserId, SessionId){

 var ShopBasket        = document.getElementById("credits_basket");
 var ShopBasketRequest = AjaxObject();
 var ShopBasketRandom  = Math.random();
 var ShopBasketAction  = "remove";
 var ShopBasketScript  = "scripts/visit.shop.basket.php?rand=" + ShopBasketRandom + "&action=" + ShopBasketAction + "&SessionId=" + SessionId;

 ShopBasketRequest.open("POST", ShopBasketScript);
 ShopBasketRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ShopBasketRequest.onreadystatechange = function() {

  if (ShopBasketRequest.readyState == 4 && ShopBasketRequest.status == 200) {

   if(ShopBasketRequest.responseText == "true")
    window.location = window.location;
   else
    ShopBasket.innerHTML  = ShopBasketRequest.responseText;

   ShopBasketList(UserId, SessionId)
   
  }

 };

 ShopBasketRequest.send("ProductId=" + ProductId + "&UserId=" + UserId + "&SessionId=" + SessionId);

 scrollTo(0,0);

};


// This function list the products in the customers Cart
function ShopBasketList(UserId, SessionId){

 var ShopBasket        = document.getElementById("credits_basket");
 var ShopBasketRequest = AjaxObject();
 var ShopBasketRandom  = Math.random();
 var ShopBasketAction  = "list";
 var ShopBasketScript  = "scripts/visit.shop.basket.php?rand=" + ShopBasketRandom + "&action=" + ShopBasketAction + "&SessionId=" + SessionId;

 ShopBasketRequest.open("POST", ShopBasketScript);
 ShopBasketRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ShopBasketRequest.onreadystatechange = function() {

  if (ShopBasketRequest.readyState == 4 && ShopBasketRequest.status == 200) {
   ShopBasket.innerHTML  = ShopBasketRequest.responseText;
  }

 };

 ShopBasketRequest.send("UserId=" + UserId + "&SessionId=" + SessionId);

 scrollTo(0,0);

};


function ShopBasketValidate(UserId, SessionId){

 var ShopBasketRequest = AjaxObject();
 var ShopBasketRandom  = Math.random();
 var ShopBasketAction  = "validate";
 var ShopBasketScript  = "scripts/visit.shop.basket.php?rand=" + ShopBasketRandom + "&action=" + ShopBasketAction + "&SessionId=" + SessionId;

 var ShopBasketGender    = document.address.gender.value;
 var ShopBasketFirstname = document.address.firstname.value;
 var ShopBasketLastname  = document.address.lastname.value;
 var ShopBasketAddress   = document.address.street.value;
 var ShopBasketZipcode   = document.address.zipcode.value;
 var ShopBasketPlace     = document.address.place.value;
 var ShopBasketBirthdayD = document.address.birthday_d.value;
 var ShopBasketBirthdayM = document.address.birthday_m.value;
 var ShopBasketBirthdayY = document.address.birthday_y.value;
 
 ShopBasketRequest.open("POST", ShopBasketScript);
 ShopBasketRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ShopBasketRequest.onreadystatechange = function() {

  if (ShopBasketRequest.readyState == 4 && ShopBasketRequest.status == 200) {

   if(ShopBasketRequest.responseText == "true")
    document.address.submit();
   else
    alert(ShopBasketRequest.responseText);

  }

 };

 ShopBasketRequest.send("UserId=" + UserId + "&SessionId=" + SessionId + "&gender=" + ShopBasketGender + "&firstname=" + ShopBasketFirstname + "&lastname=" + ShopBasketLastname  + "&address=" + ShopBasketAddress + "&zipcode=" + ShopBasketZipcode + "&place=" + ShopBasketPlace + "&birthday_d=" + ShopBasketBirthdayD + "&birthday_m=" + ShopBasketBirthdayM + "&birthday_y=" + ShopBasketBirthdayY + "");

 scrollTo(0,0);

};


// This function makes the final order from the customers Cart
function ShopBasketOrder(UserId, SessionId){

 document.getElementById("basket_button").value = 'loading ..';
 // alert("De bestelling word nu verzonden, dit kan enkele seconden duren..");
 
 var ShopBasket        = document.getElementById("credits_basket");
 var ShopBasketRequest = AjaxObject();
 var ShopBasketRandom  = Math.random();
 var ShopBasketAction  = "order";
 var ShopBasketScript  = "scripts/visit.shop.basket.php?rand=" + ShopBasketRandom + "&action=" + ShopBasketAction + "&SessionId=" + SessionId;

 ShopBasketRequest.open("POST", ShopBasketScript);
 ShopBasketRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ShopBasketRequest.onreadystatechange = function() {

  if (ShopBasketRequest.readyState == 4 && ShopBasketRequest.status == 200) {
   document.order.submit();
  }

  //ShopBasketList(UserId, SessionId);
  
 };

 ShopBasketRequest.send("UserId=" + UserId + "&SessionId=" + SessionId);

 scrollTo(0,0);

};

// This function shows the radioplayer
function OpenRadiostation(RadioKey,RadioUrl,RadioWidth,RadioHeight){

 var ScreenWidth    = screen.width;
 var ScreenHeight   = screen.height;
 var WindowName     = "RadioPlayer";

 if(RadioUrl == "" || RadioUrl != "" && RadioWidth == 0){
	var WindowHref = "http://nl.visit-it.com/content/mediaplayer.php?listen_to="+RadioKey+"&type=radio";
 } else {
	var WindowHref = RadioUrl;
 }

 if(RadioWidth == "" || RadioWidth == 0 || RadioHeight == "" || RadioHeight == 0){
  var WindowWidth	 =	384;
  var WindowHeight =	302;
 } else {
  var WindowWidth	 =	RadioWidth;
  var WindowHeight =	RadioHeight;
 }

 var WindowDistX    = ((ScreenWidth  - WindowWidth ) / 2);
 var WindowDistY    = ((ScreenHeight - WindowHeight) / 2);
 var WindowDistTop  = ((ScreenHeight - WindowHeight) / 2);
 var WindowDistLeft = (((ScreenWidth - WindowWidth ) / 2) - 71);

 window.open("" + WindowHref + "", "" + WindowName + "", "width=" + WindowWidth + ", height=" + WindowHeight + ", toolbar=0, scrollbars=0, location=0, status=0, menubar=0, resizable=0, screenX=" + WindowDistX + ", screenY=" + WindowDistY + ", top=" + WindowDistTop + ", left=" + WindowDistLeft + "");

};


// This function counts the bytes in a formfield
function CheckResponseLength(){

 var ResponseMax    = 140;
 var ResponseCount  = document.getElementById("message_counter");
 var ResponseField  = document.response.Message;
 var ResponseLength = ResponseField.value.length;
 
 if (ResponseLength <= ResponseMax)
  ResponseCount.innerHTML = ResponseMax - ResponseLength;

 if (ResponseLength >= ResponseMax)
  ResponseField.value = ResponseField.value.substring(0, ResponseMax);

};


// This function counts the bytes in a formfield
function CheckForwardLength(){

 var ResponseMax    = 140;
 var ResponseCount  = document.getElementById("forward_counter");
 var ResponseField  = document.forward.Message;
 var ResponseLength = ResponseField.value.length;

 if (ResponseLength <= ResponseMax)
  ResponseCount.innerHTML = ResponseMax - ResponseLength;

 if (ResponseLength >= ResponseMax)
  ResponseField.value = ResponseField.value.substring(0, ResponseMax);

};

// This function adds a message to the responses
function ResponseAdd(){

 var ResponseForm    = document.response;

 ResponseForm.Message.disabled	=	true;
 ResponseForm.Submit.disabled		=	true;
 ResponseForm.Submit.value      = 'Loading..';
 
 var SessionId       = ResponseForm.SessionId.value;
 var UserId          = ResponseForm.UserId.value;
 var Page            = ResponseForm.Page.value;
 var FullUrl         = ResponseForm.FullUrl.value;
 var Hex             = ResponseForm.Hex.value;
 var Message         = ResponseForm.Message;
 var Message         = Message.value;
 
 var ResponseRequest = AjaxObject();
 var ResponseRandom  = Math.random();
 var ResponseScript  = "scripts/visit.post.response.php?rand=" + ResponseRandom + "&SessionId=" + SessionId;

 ResponseRequest.open("POST", ResponseScript);
 ResponseRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ResponseRequest.onreadystatechange = function() {

  if (ResponseRequest.readyState == 4 && ResponseRequest.status == 200) {

   if(ResponseRequest.responseText == "true")
    window.location = window.location;
   else
    alert('Niet alle velden zijn ingevuld!');

   ResponseForm.Message.disabled	=	false;
   ResponseForm.Submit.disabled		=	false;
   ResponseForm.Submit.value      = 'Plaatsen';

  }

 };

 ResponseRequest.send("Page=" + Page + "&Hex=" + Hex + "&Message=" + Message + "&UserId=" + UserId + "&SessionId=" + SessionId + "&FullUrl=" + FullUrl);

};


// This function adds a message to the responses
function ForwardSend(){

 var ForwardForm     = document.forward;

 ForwardForm.Message.disabled	=	true;
 ForwardForm.Submit.disabled	=	true;
 ForwardForm.Submit.value     = 'Loading..';
 
 var SessionId       = ForwardForm.SessionId.value;
 var PageUrl         = ForwardForm.PageUrl.value;

 var Name1           = ForwardForm.Name1.value;
 var Name2           = ForwardForm.Name2.value;
 var Email           = ForwardForm.Email.value;
 var Message         = ForwardForm.Message.value;
 
 var ForwardRequest = AjaxObject();
 var ForwardRandom  = Math.random();
 var ForwardScript  = "scripts/visit.post.forward.php?rand=" + ForwardRandom + "&SessionId=" + SessionId;

 ForwardRequest.open("POST", ForwardScript);
 ForwardRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 ForwardRequest.onreadystatechange = function() {

  if (ForwardRequest.readyState == 4 && ForwardRequest.status == 200) {

   if(ForwardRequest.responseText == "true"){
    alert('Het artikel is succesvol naar ' + Name2 + ' verstuurd!');
    window.location = window.location;
   } else {
    alert('Niet alle velden zijn ingevuld!');
   }
   
  ForwardForm.Message.disabled	=	false;
  ForwardForm.Submit.disabled	  =	false;
  ForwardForm.Submit.value      = 'Versturen';
 
  }

 };

 ForwardRequest.send("PageUrl=" + PageUrl + "&SessionId=" + SessionId + "&Name1=" + Name1 + "&Name2=" + Name2 + "&Email=" + Email + "&Message=" + Message);

};


// This function updates the paperframe (on homepage > ./content/visit.home.php)
function UpdatePaper(PaperKey){

 StopClock();
 
 var Paper        = document.getElementById("paper_load");
 var PaperRequest = AjaxObject();
 var PaperRandom  = Math.random();
 var PaperScript  = "content/visit.home_load.php?rand=" + PaperRandom + "&paperkey=" + PaperKey;

 PaperRequest.open("GET", PaperScript);
 PaperRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 PaperRequest.onreadystatechange = function() {

 if (PaperRequest.readyState == 4 && PaperRequest.status == 200 && PaperRequest.responseText != "error") {
  Paper.innerHTML  = PaperRequest.responseText;
  Clock();
 }

 };

 PaperRequest.send(null);
 setTimeout('UpdatePaper("'+PaperKey+'")', 120000);

};

