//<![CDATA]
var max_foto = 16; //if changed, change also the ordermail.php $max_foto
window.onload = reset_hidden;

function reset_hidden() {
	var hidden = document.getElementsByTagName('input');
	for (var i=0; i<hidden.length; i++) {
		if (hidden[i].getAttribute('type') == 'hidden') { 
			hidden[i].value = 1; 
		}
	}
}

function AddFoto(id,tag) {
    var Fotosi = document.getElementById('fotos');
	var Fotos = Fotosi.value;
	
	if (Fotos < max_foto) {
		if(! document.getElementById && document.createElement) { return; }
		
		var inhere = document.getElementById(id);
		var thetag = document.createElement(tag);
		Fotos++;
		
		var tagidname = 'foto'+Fotos;
		
		thetag.setAttribute('id',tagidname);

		for(i=0;i<6;i++) {
			switch(i) {
				case 0:
					var inpname = "nummer";
					var fronttxt = document.createTextNode("Nummer:");
					break;
				case 1:
					var inpname = "aantal";
					var fronttxt = document.createTextNode("Aantal:");
					break;
				case 2:
					var inpname = "afmeting";
					var fronttxt = document.createTextNode("Afmeting:");
					var backtxt = document.createTextNode("cm ");
					break;
				case 3:
					var fronttxt = document.createTextNode("Tint:");
					var backtxt = document.createTextNode(" ");
					var inpname = "tint";
					break;
				case 4:
					var inpname = "product";
					var fronttxt = document.createTextNode("Prod:");
					var backtxt = document.createTextNode(" ");
					break;
				case 5:
					var inpname = "opmerking";
					var fronttxt = document.createTextNode("Opmerking:");
					var backtxt = document.createTextNode("");
					type = "text";
					break;					
				default:
					break;
			}
			
			if (i<2) {
				var backtxt = document.createTextNode(" ");
				type = "text";
				size = "3";
				maxlength = "5";
			}
			
			name = String(inpname + Fotos);
			
			if(i==2) {
				var inpnummer = document.createElement("select");
				inpnummer.name = name;
				inpnummer.options[0] = new Option("10 x 10","10x10");
				inpnummer.options[1] = new Option("10 x 15","10x15");
				inpnummer.options[2] = new Option("13 x 13","13x13");
				inpnummer.options[3] = new Option("13 x 18","13x18");
				inpnummer.options[4] = new Option("15 x 15","15x15");
				inpnummer.options[5] = new Option("15 x 21","15x21");
				inpnummer.options[6] = new Option("20 x 20","20x20");
				inpnummer.options[7] = new Option("20 x 30","20x30");
				inpnummer.options[8] = new Option("25 x 25","25x25");
				inpnummer.options[9] = new Option("25 x 38","25x38");
				inpnummer.options[10] = new Option("30 x 30","30x30");
				inpnummer.options[11] = new Option("30 x 40","30x40");
				inpnummer.options[12] = new Option("30 x 45","30x45");
				inpnummer.options[13] = new Option("40 x 40","40x40");
				inpnummer.options[14] = new Option("40 x 60","40x60");
				inpnummer.options[15] = new Option("50 x 50","50x50");
				inpnummer.options[16] = new Option("50 x 75","50x75");
			} else if(i==3) {
				var inpnummer = document.createElement("select");
				inpnummer.name = name;
				inpnummer.options[0] = new Option("Kleur","kleur");
				inpnummer.options[1] = new Option("Zwart\/Wit","zwartwit");
			} else if(i==4) {
				var inpnummer = document.createElement("select");
				inpnummer.name = name;
				inpnummer.options[0] = new Option("Papier","papier");
				inpnummer.options[1] = new Option("Canvas","canvas");
			} else {
				var inpnummer = document.createElement("input");
				inpnummer.name = name;
				inpnummer.type = type;
			
				if(i<2) {
					inpnummer.size = size;
					inpnummer.maxLength = maxlength;
				}
			}
			
			thetag.appendChild(fronttxt);
			thetag.appendChild(inpnummer);
			thetag.appendChild(backtxt);
		}
		inhere.appendChild(thetag);
	}
	else if (Fotos == max_foto){
		var inhere = document.getElementById(id);
		var txt = document.createTextNode("Maximaal "+max_foto+" foto's tegelijk, vul dit formulier opnieuw in om meer foto's te bestellen.");
		var thetag = document.createElement(tag);
		Fotos++;
		var tagidname = 'foto'+Fotos;
		thetag.setAttribute('id',tagidname);
		thetag.appendChild(txt);
		inhere.appendChild(thetag);
    }
	Fotosi.value = Fotos;		
} // function AddFoto()

function RemoveLine(id,tag) {
    var Fotosi = document.getElementById('fotos');
	var Fotos = Fotosi.value;
	
	if (Fotos > max_foto) {
		if(! document.getElementById) { return; }
		RemoveItem(id, Fotos);
		Fotos--;
		RemoveItem(id, Fotos);
		Fotos--;
	} else if (Fotos > 1) {
		if(! document.getElementById) { return; }
		RemoveItem(id,Fotos);
		Fotos--;
	}
	Fotosi.value = Fotos;
} //function RemoveLine()

function RemoveItem(elem,nummer) {
	var fromhere = document.getElementById(elem);
	var tagname = 'foto'+nummer;
	var oldtag = document.getElementById(tagname);
	fromhere.removeChild(oldtag);
}
//]]>
