/*--------------------------------------------------------------- 
	Sitestudio Pro | Ajax
--------------------------------------------------------------- */
	function loadXMLDocWeb(method,url,dataToSend,container)
	{
		ajaxContainer=container;
		document.getElementById(ajaxContainer).innerHTML = '';
		if (window.XMLHttpRequest){ // code for Mozilla, etc.
		  xmlhttp=new XMLHttpRequest()
		  xmlhttp.onreadystatechange=fillContainerWeb
		  xmlhttp.open(method,url,true)
		  xmlhttp.setRequestHeader("Cache-Control", "no-cache");
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		  xmlhttp.setRequestHeader('Connection', 'close');
		  xmlhttp.send(dataToSend)
		} else if (window.ActiveXObject){ // code for IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			if (xmlhttp){
				xmlhttp.onreadystatechange=fillContainerWeb
				xmlhttp.open(method,url,true)
				xmlhttp.setRequestHeader("Cache-Control", "no-cache");
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader('Connection', 'close');
				xmlhttp.send(dataToSend)
			}
		}
	}

	// Functie nadat AJAX geladen is
	function fillContainerWeb()
	{
		if (xmlhttp.readyState==4){ // if xmlhttp shows "loaded"
			if (xmlhttp.status==200){ // if "OK"
				eval(xmlhttp.responseText);
			} else {
				document.getElementById(ajaxContainer).innerHTML='error loading';
			}
		}
	}
	
	function checkArea(value)
	{
		if(value!=""){
			loadXMLDocWeb("POST",siteURL+"inc_ajax.php","country="+value,'saveContainer');
		} 
	}
	
	
	function submitReactionForm()
	{
		postString = "inpObjectName="+document.getElementById("inpObjectName").value.replace(/&/g,"_ampsign_");;
		postString+= "&inpGender="+document.getElementById("inpGender").value.replace(/&/g,"_ampsign_");;
		postString+= "&inpName="+document.getElementById("inpName").value.replace(/&/g,"_ampsign_");;
		postString+= "&inpEmailAddress="+document.getElementById("inpEmailAddress").value.replace(/&/g,"_ampsign_");;
		postString+= "&inpPhoneNumber="+document.getElementById("inpPhoneNumber").value.replace(/&/g,"_ampsign_");;
		postString+= "&inpRemarks="+document.getElementById("inpRemarks").value.replace(/&/g,"_ampsign_");;
		postString+= "&inpEmailTo="+document.getElementById("inpEmailTo").value.replace(/&/g,"_ampsign_");;
		postString+= "&objectReaction=true";
		loadXMLDocWeb("POST",siteURL+"inc_ajax.php",postString,'saveContainer');
	}
	
	function checkMemberForm()
	{
		validForm = true;
		document.getElementById('formError').style.display = 'none';
		if(validateTextElement(document.getElementById('inpUserName'))){}
		if(validateTextElement(document.getElementById('inpUserPassword'))){}
		if(validateTextElement(document.getElementById('inpFirstName'))){}
		if(validateTextElement(document.getElementById('inpLastName'))){}
		if(validateEmailElement(document.getElementById('inpEmailAddress'))){}
		if(validateTextElement(document.getElementById('inpCompanyName'))){}
		if(validateTextElement(document.getElementById('inpAddress'))){}
		if(validateTextElement(document.getElementById('inpZipCode'))){}
		if(validateTextElement(document.getElementById('inpCity'))){}
		if(validateTextElement(document.getElementById('inpCountry'))){}
		if(validateTextElement(document.getElementById('inpPhoneNumber'))){}
		if(validForm==true){
			postString = "inpUserName="+document.getElementById("inpUserName").value.replace(/&/g,"_ampsign_");
			postString+= "&inpUserPassword="+document.getElementById("inpUserPassword").value.replace(/&/g,"_ampsign_");
			postString+= "&inpFirstName="+document.getElementById("inpFirstName").value.replace(/&/g,"_ampsign_");
			postString+= "&inpMiddleName="+document.getElementById("inpMiddleName").value.replace(/&/g,"_ampsign_");
			postString+= "&inpLastName="+document.getElementById("inpLastName").value.replace(/&/g,"_ampsign_");
			postString+= "&inpEmailAddress="+document.getElementById("inpEmailAddress").value.replace(/&/g,"_ampsign_");
			postString+= "&inpCompanyName="+document.getElementById("inpCompanyName").value.replace(/&/g,"_ampsign_");
			postString+= "&inpAddress="+document.getElementById("inpAddress").value.replace(/&/g,"_ampsign_");
			postString+= "&inpZipCode="+document.getElementById("inpZipCode").value.replace(/&/g,"_ampsign_");
			postString+= "&inpCity="+document.getElementById("inpCity").value.replace(/&/g,"_ampsign_");
			postString+= "&inpCountry="+document.getElementById("inpCountry").value.replace(/&/g,"_ampsign_");
			postString+= "&inpPhoneNumber="+document.getElementById("inpPhoneNumber").value.replace(/&/g,"_ampsign_");
			postString+= "&inpPersonId="+document.getElementById("inpPersonId").value.replace(/&/g,"_ampsign_");
			postString+= "&membershipSettings=true";
			loadXMLDocWeb("POST",siteURL+"inc_ajax.php",postString,'saveContainer');
		} else {
			document.getElementById('formError').style.display = '';
		}
	}
	
	function removeAsset(id)
	{
		var r=confirm("Weet u zeker dat u dit item wilt verwijderen")
		if (r==true){
				document.getElementById("inpAssetId").value = id;
				document.getElementById("removeAssetForm").submit();
		}
	}
	
	
	function imagePreview(path)
	{
		filePreviewtypes = ".jpg,jpeg,.gif";
		filecheck=path.substring(path.length-4,path.length);
		if (!filePreviewtypes.match(filecheck)){
			document.getElementById('previewImage').src = siteURL+'template/img/product_no_image.jpg';	
		} else {
			document.getElementById('previewImage').src = path;
		}
	}
	
	function deleteFile(file,folder)
	{
		var r=confirm("Weet u zeker dat u dit bestand wilt verwijderen")
		if (r==true){
			document.getElementById('myFileList').innerHTML = 'Bezig met verwerken...';
			document.getElementById('previewImage').src = siteURL+'template/img/product_no_image.jpg';
			postString = "deleteFile=true";
			postString+= "&file="+file;
			postString+= "&folder="+folder;
			loadXMLDocWeb("POST",siteURL+"inc_ajax.php",postString,'saveContainer');
		}
	}
	
	
	function submitFile()
	{
		document.getElementById('myFileList').innerHTML = 'Bezig met verwerken...';
		document.getElementById('previewImage').src = siteURL+'template/img/product_no_image.jpg';
		document.getElementById('inpWebUploadFile').value = "";
	}
	
	function checkWebFileType()
	{
		validFile = true;
		filetypes = ".jpg,jpeg,.gif,.pdf,.doc,.xls,.JPG,JPEG,.GIF,.PDF,.DOC,.XLS";
		obj=document.getElementById('inpWebUploadFile').value;
		if(obj!=""){
			filecheck=obj.substring(obj.length-4,obj.length);
			if (!filetypes.match(filecheck)){
				validFile = false;
			}
		}
		if(validFile==true){
		} else {
			document.getElementById('inpWebUploadFile').value = "";
			alert("Dit type bestand is niet toegestaan");
		}
	}
	
	function submitNewAsset()
	{
		validForm = true;
		document.getElementById('formError').style.display = 'none';
		if(validateTextElement(document.getElementById('inpProductName'))){}
		if(validateTextElement(document.getElementById('inpCity'))){}
		if(validateTextElement(document.getElementById('inpCountry'))){}
		if(validateTextElement(document.getElementById('inpArea'))){}
		if(validateTextElement(document.getElementById('inpDescription'))){}
		if(validateTextElement(document.getElementById('inpPrice'))){}
		if(validateTextElement(document.getElementById('inpDelivery'))){}
		if(validateTextElement(document.getElementById('inpStatus'))){}
		if(validateTextElement(document.getElementById('inpType'))){}
		if(validateTextElement(document.getElementById('inpConstructionType'))){}
		if(validateTextElement(document.getElementById('inpYear'))){}
		if(document.getElementById('inpImageMain').value==''){
			validForm = false;
			alert("er is nog geen hoofd afbeelding geselecteerd");
		}
		if(document.getElementById('inpImage1').value==''){
			validForm = false;
			alert("Selecteer ten minste 1 afbeelding");
		}
		if(validForm==true){
			document.getElementById('addNewAssetForm').submit();
		} else {
			document.getElementById('formError').style.display = '';
		}
	}
	
	
	
	//valideer text elementen
	function validateTextElement(theFormElement) 
	{
		theFormElement.className = theFormElement.className.replace('_error','') 
		if(theFormElement.value.length==0){
			theFormElement.className+='_error';
			validForm=false;
		} 
	}
	
	//Valideer e-mail velden
	function validateEmailElement(theFormElement)
	{
		theFormElement.className = theFormElement.className.replace('_error','');
		if (theFormElement.value.length >0) {
			i=theFormElement.value.indexOf("@")
			j=theFormElement.value.indexOf(".",i)
			k=theFormElement.value.indexOf(",")
			kk=theFormElement.value.indexOf(" ")
			jj=theFormElement.value.lastIndexOf(".")+1
			len=theFormElement.value.length
				
			if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)){
			} else {
				theFormElement.className+='_error';
				validForm = false;
			}
		 } else {
			theFormElement.className+='_error';
			validForm = false;
		}
	}
	

