<!--
function check_foto_form() {
	var ProductFoto = document.getElementById('ProductFoto');
	var ActieFoto = document.getElementById('ActieFoto');
	
	if(!ProductFoto.checked) {
		if(!ActieFoto.checked) {
			ProductFoto.checked = 'checked';
		}
	}
	
}

function check_product_form() {
	if($('Titel').value == '') {
		alert('De Titel van een product is verplicht');
		return false;
	}
	if($('Actie').checked) {
		if($('Inleiding').innerText == '' || $('ActieText').innerText == '' || $('ActieTitel').value == '') {
			alert('Het product is een actie, maar niet alle verplichte velden voor een actie product zijn ingevuld.');
			return false;
		}
	}
	return true;
}

// BEELDBANK functions

// switch preview on selection input type="file": onchange="switchimage(this.id,'Preview');"

function switchimage(id, previewID) {

	inputfile = new Object();
	inputfile = document.getElementById(id);

	var imagepath = inputfile.value;

	if (imagepath != "") {

		imagetype = new Array(".gif",".jpg",".jpeg",".png");

		for (i=0;i<4;i++) {
			if (imagepath.toLowerCase().indexOf(imagetype[i]) > -1) {
				document.images[previewID].src = 'file:///'+imagepath;
			}
		}

	}

}

// reset preview to empty.gif selection input type="file": onchange="switchimage(this.id,'Preview','Foto');"

function resetimage(url, previewID, fotoID) {
	document.images[previewID].src = url;
	document.getElementById(fotoID).value = 'empty';
}

// adjust preview to max. 450px: img src="previewID" -> onload="adjustimagesize('Preview','Breedte', 450);"

function adjustimagesize(previewID, breedteID, maxwidth) {

	if (document.images[previewID].width > maxwidth) {
		document.images[previewID].width = maxwidth;
	}

	document.getElementById(breedteID).value = document.images[previewID].width;

}

// switch preview width: onclick="switchwidth('Preview','Breedte', 450);"

function switchwidth(previewID, breedteID, maxwidth) {
	var px = document.getElementById(breedteID).value;

	if (px > maxwidth) {
		px = maxwidth;
	}
	document.images[previewID].width = px;
	document.getElementById(breedteID).value = px;
}

// return HTML source for image, with/without align=left: onclick="returnSelected('http://www.images.com/img.gif');"

function returnSelected(imageurl, fieldID) {
	var text;

	if (document.radioform.imgalign[1].checked == true) {
		text = '<img src=\"'+imageurl+'\" align=\"left\" style=\"margin-right:10px\" />';
	} else if (document.radioform.imgalign[2].checked == true) {
		text = '<div align=center><img src=\"'+imageurl+'\" /></div><br />';
	} else if (document.radioform.imgalign[3].checked == true) {
		text = '<img src=\"'+imageurl+'\" align=\"right\" style=\"margin-left:10px\" />';
	} else {
		text = '<img src=\"'+imageurl+'\" /><br />';
	}

	window.opener.editor_insertHTML(fieldID,text);
	window.close();
}


// FORM functions
// -----------------------------------

// Make option in <select> disabled for IE, through class="disabled": onchange="checkDisabled(this);"

function checkDisabled(sel) {
	var opt = sel.options[sel.selectedIndex];
	if (opt.className == "disabled") {
		 sel.selectedIndex = -1;
	}
}

// Force maximal chars

function TrackCount(fieldObj,maxChars) {
	var diff = maxChars - fieldObj.value.length;
	if (diff < 0) {
		fieldObj.value = fieldObj.value.substring(0,maxChars);
		diff = maxChars - fieldObj.value.length;
	}
}

// Check for excess of maximal chars

function LimitText(fieldObj,maxChars) {
	var result = true;
	if (fieldObj.value.length >= maxChars)
		result = false;
	if (window.event)
		window.event.returnValue = result;
	return result;
}

// Force number input: onkeypress="IsCijfer(false);"

function IsCijfer(Decimaal) {
	if(!document.all) { return false; }
	var keypressed = window.event.keyCode;
	var ElementText  = window.event.srcElement.value ;
	if (keypressed == 45){
		if (ElementText.length!=0) {
		  window.event.keyCode = 0;
		}

	} else {
		if (Decimaal) {
			var Reg = /\./g;
			if (Reg.test(ElementText)) {
				if( (keypressed >= 48 && keypressed <= 57) == false) {
				  window.event.keyCode = 0;
				}
			} else {
				if ((keypressed >= 48 && keypressed <= 57 || keypressed == 46) == false) {
				  window.event.keyCode = 0;
				}
			}
		} else {
			if ((keypressed >= 48 && keypressed <= 57) == false) {
			window.event.keyCode = 0;
			}
		}
	}
}

// Form validation: onsubmit="MM_validateForm('Email','','RisEmail');return document.MM_returnValue;"

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' moet een e-mailadres bevatten.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' moet een nummer bevatten.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' moet een nummer bevatten tussen '+min+' en '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is verplicht.\n'; }
  } if (errors) alert('De volgende fout(en) doen zich voor:\n'+errors);
  document.MM_returnValue = (errors == '');
}


// RANDOM functions
// -----------------------------------

// Change border color: onmouseover="borderit(this,red);"

function borderit(which,color){
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById){
		which.style.borderColor=color;
	}
}

// Collpase/expand table: onclick="collapse_expand('overzicht');"

function collapse_expand(tableid) {
	document.getElementById(tableid).style.display = ("block" == document.getElementById(tableid).style.display ? "none" : "block");
}

// Hide/display field when value == valueShow: onchange="toggleFieldDisplay(this.selectedIndex, 2, 'NieuwePlaatsNaam');"

function toggleFieldDisplay (value, valueShow, fieldID) {

	field = document.getElementById(fieldID);

	if (value == valueShow) {
		field.style.display = '';
		field.focus();
	} else {
		field.style.display = 'none';
	}

}

// Jump to date view: onclick="dateJump('http://www.domain.com/admin/prodcuten/cat/6);"

function catJump(url) {
	var catID = document.catselector.ProductCatID.options[document.catselector.ProductCatID.selectedIndex].value;
	
	location.href = url + '/' + catID;
	
	return false;
}

// Jump to date view: onclick="dateJump('http://www.domain.com/admin/stats_pages/2005/06);"

function dateJump(url) {
	var monthyear = document.dateselector.monthyear.options[document.dateselector.monthyear.selectedIndex].value;
	
	location.href = url + '/' + monthyear;
	
	return false;
}

// Help box:
function toggle_help(id) {
	if($(id)) {
		if($(id).style.display != 'block') {
			$(id).style.display = 'block';
		} else {
			$(id).style.display = 'none';
		}
	} else {
		alert('could not find element: '+id+'!');
	}
	return false;
}

// Product Kenmerken:
function add_kenmerk(name, value) {
	if(!name) { name = ''; }
	if(!value) { value =''; }
	
	var table = $('product-kenmerken').getElementsByTagName('tbody')[0];
	
	// the nodes:
	var tr = Builder.node('tr');
	var th = Builder.node('th');
	var td = Builder.node('td', { width: 260 });
	var image_td = Builder.node('td');
	var naam_input = Builder.node('input', { type: 'text', name: 'kenmerk_naam[]', value: name, className: 'kenmerk' });
	var waarde_input = Builder.node('input', { type: 'text', name: 'kenmerk_waarde[]', value: value, className: 'text' });
	var del_image = Builder.node('img', { style: 'cursor: pointer', onclick: 'del_kenmerk(this)', src: baseurl+'/img/admin/delete.gif', width: '19', height: '19', alt: 'Verwijder dit kenmerk', title: 'Verwijder dit kenmerk', className: 'noborder' });
	
	// connect the children:
	th.appendChild(naam_input);
	td.appendChild(waarde_input);
	image_td.appendChild(del_image);
	tr.appendChild(th);
	tr.appendChild(td);
	tr.appendChild(image_td);
	table.appendChild(tr);
	
}

function del_kenmerk(element) {
	$('product-kenmerken').deleteRow(element.parentNode.parentNode.rowIndex);
}

function del_all_kenmerken() {
	var numrows = $('product-kenmerken').rows.length;
	var loops = 0;
	while($('product-kenmerken').rows.length > 4) {
		$('kenmerken-body').removeChild($('kenmerken-body').firstChild);
	}
}

function getSet(e) {
	var id = e.options[e.selectedIndex].value;
	if(id == -1) { e.selectedIndex = 0; return false; }
	var request = {
		method: 'post',
		postBody: 'action=productset&id='+id,
		onSuccess: setSet
	}
	new Ajax.Request('http://www.tegetel.nl/request.php', request);
	e.selectedIndex = 0;
}

function setSet(t) {
	if(t.responseText != 'error') {
		if(t.responseText == 'nonefound') {
			alert('Het gekozen product heeft geen kenmerken');
		} else {
			var lines = t.responseText.split("\n");
			if(lines.length > 0) {
				del_all_kenmerken();
				for(var i=0; i<lines.length; i++) {
					var line = lines[i].split("\t");
					//message += line[0]+' = '+line[1]+"\n";
					add_kenmerk(line[0], line[1])
				}
			}
		}
	}
}

//-->
