// IMAGE PRELOADER
var myimages=new Array()
function preloadimages(){
  for (i=0;i<preloadimages.arguments.length;i++){
    myimages[i]=new Image()
    myimages[i].src=preloadimages.arguments[i]
  }
}

preloadimages("http://office.avantimes.nl/nl/images/forward.jpg", "http://office.avantimes.nl/nl/images/forward_inactive.jpg", "http://office.avantimes.nl/nl/images/backward.jpg", "http://office.avantimes.nl/nl/images/backward_inactive.jpg");

// CHANGEOBJECT TBV INLOGFORMULIER IN FRONTPAGE.PHP
var newobject_id = '';
function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  newObject.value = '';
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  newobject_id = newObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  setTimeout("document.getElementById(newobject_id).focus()", 50);
}

// KEYEVENT LISTER (ENTER KEY) TBV ORDERFORM IN WEBSHOP.PHP / SHOPPINGCART
function sc_keyevent(e,id) {
  e = e || window.event;
  var code = e.keyCode || e.which;
  if(code == 13) {
    sc_change(id);
  }
}

// NEWSLETTER DE FRONTPAGE
function newsletter() {
  var xmlHttp_newsletter;
  try {  
    xmlHttp_newsletter=new XMLHttpRequest();  
  }
  catch (e) {
    try  {
    xmlHttp_newsletter=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp_newsletter=new ActiveXObject("Microsoft.XMLHTTP");      
	  }
      catch (e) {
        alert("Your browser does not support AJAX!");
		return false;
	  }
	}
  }
  xmlHttp_newsletter.onreadystatechange=function() {
    if(xmlHttp_newsletter.readyState==4) {
	  document.getElementById('newsletter_div').innerHTML = xmlHttp_newsletter.responseText;
	}
  }
  xmlHttp_newsletter.open("GET","nl/newsletter_ajax.php?newsletter_email="+document.getElementById('newsletter_email').value,true);
  xmlHttp_newsletter.send(null);  
}

// CONTACTME OP DE FRONTPAGE
function contactme() {
  var xmlHttp_contactme;
  try {  
    xmlHttp_contactme=new XMLHttpRequest();  
  }
  catch (e) {
    try  {
    xmlHttp_contactme=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp_contactme=new ActiveXObject("Microsoft.XMLHTTP");      
	  }
      catch (e) {
        alert("Your browser does not support AJAX!");
		return false;
	  }
	}
  }
  xmlHttp_contactme.onreadystatechange=function() {
    if(xmlHttp_contactme.readyState==4) {
	  document.getElementById('contactme_div').innerHTML = xmlHttp_contactme.responseText;
	}
  }
  xmlHttp_contactme.open("GET","nl/contactme_ajax.php?name_company="+document.getElementById('name_company').value+"&tel_email="+document.getElementById('tel_email').value,true);
  xmlHttp_contactme.send(null);  
}

// STUKHOEVEELHEID VERANDEREN VOOR EEN PRODUCT IN WEBSHOP.PHP / SHOPPINGCART
function sc_change(id) {
  var xmlHttp_sc_change;
  try {  
    xmlHttp_sc_change=new XMLHttpRequest();  
  }
  catch (e) {
    try  {
    xmlHttp_sc_change=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp_sc_change=new ActiveXObject("Microsoft.XMLHTTP");      
	  }
      catch (e) {
        alert("Your browser does not support AJAX!");
		return false;
	  }
	}
  }
  xmlHttp_sc_change.onreadystatechange=function() {
    if(xmlHttp_sc_change.readyState==4) {
	  document.getElementById('row'+id).innerHTML = xmlHttp_sc_change.responseText;
	  sc_sum();
	}
  }
  var amount = document.getElementById('input'+id).value;
  xmlHttp_sc_change.open("GET","nl/shoppingcart_ajax.php?action=change&product_id="+id+"&amount="+amount,true);
  xmlHttp_sc_change.send(null);  
}

// EEN PRODUCT TOEVOEVOEGEN VOOR VERGELIJKING IN PRODUCT.PHP
function Compare(product_id, action) {
  var xmlHttp_Compare;
  try {  
    xmlHttp_Compare=new XMLHttpRequest();  
  }
  catch (e) {
    try  {
    xmlHttp_Compare=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp_Compare=new ActiveXObject("Microsoft.XMLHTTP");      
	  }
      catch (e) {
        alert("Your browser does not support AJAX!");
		return false;
	  }
	}
  }
  xmlHttp_Compare.onreadystatechange=function() {
    if(xmlHttp_Compare.readyState==4) {
	  if(xmlHttp_Compare.responseText == "error1") {
	    window.alert("Error 1 has occured")
	  }
	  else if(xmlHttp_Compare.responseText == "error2") {
	    window.alert("Error 2 has occured")
	  }
	  else if(xmlHttp_Compare.responseText == "error3") {
	    window.alert("Error 3 has occured")
	  }
	  else {
        compare.innerHTML = xmlHttp_Compare.responseText;
	  }
    }
  }
  xmlHttp_Compare.open("GET","nl/compare.php?action="+action+"&product_id="+product_id,true);
  xmlHttp_Compare.send(null);  
}

// EEN PRODUCT TOEVOEGEN IN DE SHOPPINCART IN PRODUCT.PHP
function sc_add(product_id) {
  var xmlHttp_sc_add;
  try {  
    xmlHttp_sc_add=new XMLHttpRequest();  
  }
  catch (e) {
    try  {
    xmlHttp_sc_add=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp_sc_add=new ActiveXObject("Microsoft.XMLHTTP");      
	  }
      catch (e) {
        alert("Your browser does not support AJAX!");
		return false;
	  }
	}
  }
  xmlHttp_sc_add.onreadystatechange=function() {
    if(xmlHttp_sc_add.readyState==4) {
	  shoppingcart.innerHTML = xmlHttp_sc_add.responseText;
	  window.alert("Toegevoegd aan winkelwagen.");
    }
  }
  xmlHttp_sc_add.open("GET","nl/shoppingcart_ajax.php?action=add&product_id="+product_id,true);
  xmlHttp_sc_add.send(null);  
}

// WINKELWAGEN LINK EN DYNAMICTOOLTIP WINKELWAGEN WEERGEVEN IN INDEX.PHP
function sc_show() {
  var xmlHttp_sc_show;
  try {  
    xmlHttp_sc_show=new XMLHttpRequest();  
  }
  catch (e) {
    try  {
    xmlHttp_sc_show=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp_sc_show=new ActiveXObject("Microsoft.XMLHTTP");      
	  }
      catch (e) {
        alert("Your browser does not support AJAX!");
		return false;
	  }
	}
  }
  xmlHttp_sc_show.onreadystatechange=function() {
    if(xmlHttp_sc_show.readyState==4) {
	  shoppingcart.innerHTML = xmlHttp_sc_show.responseText;
    }
  }
  xmlHttp_sc_show.open("GET","nl/shoppingcart_ajax.php?action=show",true);
  xmlHttp_sc_show.send(null);  
}

// TOTALEN UITREKENEN IN WEBSHOP.PHP / SHOPPINGCART
function sc_sum() {
  var xmlHttp_sc_sum;
  try {  
    xmlHttp_sc_sum=new XMLHttpRequest();  
  }
  catch (e) {
    try  {
    xmlHttp_sc_sum=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttp_sc_sum=new ActiveXObject("Microsoft.XMLHTTP");      
	  }
      catch (e) {
        alert("Your browser does not support AJAX!");
		return false;
	  }
	}
  }
  xmlHttp_sc_sum.onreadystatechange=function() {
    if(xmlHttp_sc_sum.readyState==4) {
	totals.innerHTML = xmlHttp_sc_sum.responseText;
	sc_show();
    }
  }
  xmlHttp_sc_sum.open("GET","nl/shoppingcart_ajax.php?action=sum",true);
  xmlHttp_sc_sum.send(null);  
}

// CHECK INPUT IN WEBSHOP.PHP / CUST_INFO
function check_cust_info() {
  var complete = 1;
  if (typeof(document.cust_info.elements.company.value) == 'undefined' || document.cust_info.elements.company.value === null || document.cust_info.elements.company.value == "") {
    document.cust_info.elements.company.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.name.value) == 'undefined' || document.cust_info.elements.name.value === null || document.cust_info.elements.name.value == "") {
    document.cust_info.elements.name.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.surname.value) == 'undefined' || document.cust_info.elements.surname.value === null || document.cust_info.elements.surname.value == "") {
    document.cust_info.elements.surname.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.address.value) == 'undefined' || document.cust_info.elements.address.value === null || document.cust_info.elements.address.value == "") {
    document.cust_info.elements.address.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.zip.value) == 'undefined' || document.cust_info.elements.zip.value === null || document.cust_info.elements.zip.value == "") {
    document.cust_info.elements.zip.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.city.value) == 'undefined' || document.cust_info.elements.city.value === null || document.cust_info.elements.city.value == "") {
    document.cust_info.elements.city.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.phone.value) == 'undefined' || document.cust_info.elements.phone.value === null || document.cust_info.elements.phone.value == "") {
    document.cust_info.elements.phone.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.email.value) == 'undefined' || document.cust_info.elements.email.value === null || document.cust_info.elements.email.value == "") {
    document.cust_info.elements.email.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.del_company.value) == 'undefined' || document.cust_info.elements.del_company.value === null || document.cust_info.elements.del_company.value == "") {
    document.cust_info.elements.del_company.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.del_contact.value) == 'undefined' || document.cust_info.elements.del_contact.value === null || document.cust_info.elements.del_contact.value == "") {
    document.cust_info.elements.del_contact.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.del_address.value) == 'undefined' || document.cust_info.elements.del_address.value === null || document.cust_info.elements.del_address.value == "") {
    document.cust_info.elements.del_address.style.background = '#F5C6C6';
	complete = 0;
  } 
  if (typeof(document.cust_info.elements.del_zip.value) == 'undefined' || document.cust_info.elements.del_zip.value === null || document.cust_info.elements.del_zip.value == "") {
    document.cust_info.elements.del_zip.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.del_city.value) == 'undefined' || document.cust_info.elements.del_city.value === null || document.cust_info.elements.del_city.value == "") {
    document.cust_info.elements.del_city.style.background = '#F5C6C6';
	complete = 0;
  } 
  if (typeof(document.cust_info.elements.bil_company.value) == 'undefined' || document.cust_info.elements.bil_company.value === null || document.cust_info.elements.bil_company.value == "") {
    document.cust_info.elements.bil_company.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.bil_contact.value) == 'undefined' || document.cust_info.elements.bil_contact.value === null || document.cust_info.elements.bil_contact.value == "") {
    document.cust_info.elements.bil_contact.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.bil_address.value) == 'undefined' || document.cust_info.elements.bil_address.value === null || document.cust_info.elements.bil_address.value == "") {
    document.cust_info.elements.bil_address.style.background = '#F5C6C6';
	complete = 0;
  } 
  if (typeof(document.cust_info.elements.bil_zip.value) == 'undefined' || document.cust_info.elements.bil_zip.value === null || document.cust_info.elements.bil_zip.value == "") {
    document.cust_info.elements.bil_zip.style.background = '#F5C6C6';
	complete = 0;
  }
  if (typeof(document.cust_info.elements.bil_city.value) == 'undefined' || document.cust_info.elements.bil_city.value === null || document.cust_info.elements.bil_city.value == "") {
    document.cust_info.elements.bil_city.style.background = '#F5C6C6';
	complete = 0;
  } 
  if (document.cust_info.elements.conditions.checked == false) {
    conditions_label.style.color = '#E25A5A';
	document.all.conditions_iframe.style.border = 'solid 1 #E25A5A';
	complete = 0;
  } 
  
  if (complete == 1) {
    document.cust_info.submit();
  }
}

// INPUT COPY IN WEBSHOP.PHP / CUST_INFO
function make_del_equivalent() {
  document.cust_info.elements.del_company.value = document.cust_info.elements.company.value;
  document.cust_info.elements.del_contact.value = document.cust_info.elements.name.value + ' ' + document.cust_info.elements.surname.value;
  document.cust_info.elements.del_address.value = document.cust_info.elements.address.value;
  document.cust_info.elements.del_zip.value = document.cust_info.elements.zip.value;
  document.cust_info.elements.del_city.value = document.cust_info.elements.city.value;
  document.cust_info.elements.del_country.value = document.cust_info.elements.country.value;
}

// INPUT COPY IN WEBSHOP.PHP / CUST_INFO
function make_bil_equivalent() {
  document.cust_info.elements.bil_company.value = document.cust_info.elements.company.value;
  document.cust_info.elements.bil_contact.value = document.cust_info.elements.name.value + ' ' + document.cust_info.elements.surname.value;
  document.cust_info.elements.bil_address.value = document.cust_info.elements.address.value;
  document.cust_info.elements.bil_zip.value = document.cust_info.elements.zip.value;
  document.cust_info.elements.bil_city.value = document.cust_info.elements.city.value;
  document.cust_info.elements.bil_country.value = document.cust_info.elements.country.value;
}