function get(obj) {
    if (!$('#artikelid2').val() || $('#artikelid2').val() == 0){
        alert('Selecteer eerst je maat.');
        return false;
    }
      document.getElementById('modal').innerHTML = "<img src='/images/loading-bar.gif'>";
      Popup.showModal('modal',null,null);
      var poststr = "Aantal=" + encodeURI( obj.Aantal.value ) +
                    "&ArtikelID=" + $('#artikelid2').val() +
                    "&Omschrijving=" + encodeURI( obj.Omschrijving.value ) +
                "&Prijs=" + encodeURI( obj.Prijs.value );
      $(function() {
      $.ajax({
          type: 'POST',
          url: '/chart/add',
          data: poststr,
          success: getMandje
      });

      function getMandje(){
      $.get('/getpage.php?page=mandje', function(data) {
          $('#inhoud-winkelmandje-home').html(data);
          Popup.hide('modal');
          window.location.replace("/chart");
        });
      }
      });

}

function getCloudImageSize(file) {
    $('.cloud-zoom img').css('visibility', "hidden");
    $.get('/getpage.php?page=cloudImageSize&file='+ file, function(data) {
        //$('.cloud-zoom img').attr('style', "display:block;" + data);
        $('.cloud-zoom img').attr('style', data);
    });
}

function getArtikelVoorraad(id)
{
    vid = $('#artikelid_orig').val();
    $.get('/getpage.php?page=voorraad&vartikelid='+ vid +'&artikelid='+ id, function(data) {
        $('#voorraad').html(data);
    });
}

function selectArtikel(id) {
    if(id == 'anders') {
        $('#artikelid2').val('');
        $('#voorraad').html('');
        //popup
        productInfo($('#artikelid_orig').val());
    }
    else if(id != '') {
        $('#artikelid2').val(id);
        //alert(id);
        getArtikelVoorraad(id);
    }
    else {
        $('#artikelid2').val('');
        $('#voorraad').html('');
    }
}

function switchTab(elementID, className, boxClassName) {
    $('.'+className+'-active').removeClass(className+'-active');
    $('#'+elementID+'-tab').addClass(className+'-active');
    $('.'+boxClassName).css('display', 'none');
    $('#'+elementID+'-box').css('display', 'block');
}

function makeGETRequest(url, parameters) {
  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 = alertContents2;
  http_request.open('GET', 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 alertContents2() {
  if (http_request.readyState == 4) {
     if (http_request.status == 200) {
        //alert(http_request.responseText);
        result = http_request.responseText;
        Popup.hide('modal_load');
        document.getElementById('modal').innerHTML = result;
        Popup.showModal('modal',null,null);return false;

     } else {
        alert('There was a problem with the request.');
     }
  }
}

function productInfo(product) {
  document.getElementById('modal_load').innerHTML = "<img src='/images/loading-bar.gif'>";
  Popup.showModal('modal_load',null,null);
  makeGETRequest('/getpage.php?page=informatie_aanvraag&product=' + product,"?a");
}
var regexp = / /g;
function verzenden2(){
    if(document.forms['productinfo'].naam.value.replace(regexp,"") == ""){
        alert('Voer alstublieft uw naam in.');
        document.forms['productinfo'].naam.focus();
        return false;
    }
    if(document.forms['productinfo'].mail.value.replace(regexp,"") == ""){
        alert('Voer alstublieft uw e-mailadres in.');
        document.forms['productinfo'].mail.focus();
        return false;
    }
    if(document.forms['productinfo'].mail.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
        alert('U heeft een ongeldig e-mailadres ingevuld.');
        document.forms['productinfo'].mail.focus();
        return false;
    }
    document.forms['productinfo'].submit();
}

function imageSwap(imgElement, imageSRC, style) {
    $('img', imgElement).attr('src', '');
    $('img', imgElement).attr('src', imageSRC);
    if(style == '') {
        style = 'height:auto;width:auto;';
    }
    $('img', imgElement).attr('style', style);
}
