// addtoMand: voegt het product (id) toe aan de winkelmand. Verhoogt het aantal met 1 als het al in de winkelmand zit
function addToMand(id) {
	ajaxObj.call("file=mybic_classes.inc.php&class=AddToMand&id="+id, ajaxAddToMand);
}

function ajaxAddToMand(response) {
	if (response) {
		document.location.reload();
	}
}

// updateMand: loopt de aantallen in de winkelmand na en slaat de wijzigingen op in de session-variabele

function updateMand() {
	var allInputFields = document.getElementsByTagName("input");	
	var allIDs = "";
	var allValues = "";
	for (var i=0; i<allInputFields.length; i++) {
		if (allInputFields[i].id.indexOf("txtProdAantal") != -1) {
			allIDs += allInputFields[i].id.substr(13) + "|";
			allValues += allInputFields[i].value + "|";			
		}	
	}		
	
	ajaxObj.call("file=mybic_classes.inc.php&class=UpdateMand&ids="+allIDs+"&values="+allValues, ajaxUpdateMand);
}

function ajaxUpdateMand(response) {
	if (response) {
		document.location.reload();		
	}
}

function deletefromMand(id) {
	document.getElementById("txtProdAantal"+id).value = 0;
	updateMand();
}

function clearInputField(id,standardvalue) {
   if(document.getElementById(id).value == standardvalue) {
      document.getElementById(id).value = '';
   }
}

function fillInputField(id,standardvalue) {
   if(document.getElementById(id).value == '') {
      document.getElementById(id).value = standardvalue;
   }
}

function checkDoubleName(varValue, varID) {
   ajaxObj.call("file=mybic_classes.inc.php&class=CheckDoubleName&id="+varID+"&value="+varValue, ajaxDoubleName);
}

function ajaxDoubleName(response) {
   
   /*
   if(response) {
      nameAvailable = 'true';
   } else {
      nameAvailable = 'false';
   }
   */
   
   if (response) {
      nameAvailable = response.available;
   }
  
   if(nameAvailable == 'false') { alert('Deze gebruikersnaam is al bezet.'); }
   
   return nameAvailable;
}

function updateMandExt() {
	var allInputFields = document.getElementsByTagName("input");	
	var allIDs = "";
	var allValues = "";
	for (var i=0; i<allInputFields.length; i++) {
		if (allInputFields[i].id.indexOf("txtProdAantal") != -1) {
			allIDs += allInputFields[i].id.substr(13) + "|";
			allValues += allInputFields[i].value + "|";			
		}	
	}		
	
	ajaxObj.call("file=mybic_classes.inc.php&class=UpdateMand&ids="+allIDs+"&values="+allValues, ajaxUpdateMandExt);
}

function ajaxUpdateMandExt(response) {
	if (response) {
		window.location.href = 'index.php?id=3&step=overzicht';		
	}
}

function jsToggle(id) {
    if (document.getElementById(id).className=="hidden") {
        document.getElementById(id).className="show"
    } else {
    	  document.getElementById(id).className="hidden"
    }
}

