var remember="";
var openRows=new Array();
var yPos=0;

function makeDaysOfMonth(){
	var i = 0;
	this[i++] = 0; 
	this[i++] = 31;
	this[i++] = 29;
	this[i++] = 31;
	this[i++] = 30;
	this[i++] = 31;
	this[i++] = 30;
	this[i++] = 31;
	this[i++] = 31;
	this[i++] = 30;
	this[i++] = 31;
	this[i++] = 30;
	this[i  ] = 31;
	this.length = i;
}

function calcAge(dd, mm, yy){
	var t, mon, day, year, DD, MM, YY, age;
	var MTB = new makeDaysOfMonth();
	YY   = parseInt(yy);
	MM   = parseInt(mm);
	DD   = parseInt(dd);
	if (MTB[MM] < DD || DD < 1) return -1;
	t    = new Date();
	year = t.getFullYear();
	mon  = t.getMonth() + 1;
	day  = t.getDate();
	if (MM == 2 && DD == 29){
		if (!(((YY % 4 == 0) && (YY % 100 != 0)) || (YY % 400 == 0))){
			return -1;
		}
	}
	age = year - YY;
	if ((MM > mon) || (MM == mon && day < DD)) age --;
	return age;
}

function isInteger(s){   
	var i;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function showConfectie(c){
	hideObject(currConf);
	showObject(c);
	currConf=c;
}

function saveForm(){
	document.obj.submit();	
}

function showStep(s){
	var x= new getObj(s);
	if(x.style.display=="none"){
		showObject(s)
		openRows.push(s);
		document["btn_"+s].src="images/img_down.gif";
	}
	else{
		hideObject(s)
		removeItem(s)
		document["btn_"+s].src="images/img_right.gif";
	}
}


function removeItem(s){
	for(i=0;i<openRows.length;i++){
		if(openRows[i]==s){
			openRows.splice(i);
		}
	}
}
function setPage(){
	for(i=0;i<openRows.length;i++){
		showStep(openRows[i]);
	}
	setPageTop(yPos);
}

//function showStep(s){
//	showObject(s);
//	hideObject(currStep);
//	currStep=s;
//}

function setGeboorteDatum(day, month, year){
	document.forms['obj'].Geboortedatum.value =  month + '/' + day + '/'  + year;
	var age=calcAge(day, month, year);
	currLeeftijd=age;
	setElements();
}

function setElements(){
	if(currLeeftijd<14){
		showConfectie("kind_confectie");
		hideObject('snorbaard');
	}
	else if(document.forms['obj'].Geslacht[0].checked){
		showConfectie("man_confectie");
		showObject('snorbaard');
	}
	else if(document.forms['obj'].Geslacht[1].checked){
		showConfectie("vrouw_confectie");
		hideObject('snorbaard');
	}
	if(document.forms['obj'].Geslacht[1].checked){
		showObject('bhmaat');
	}
	else{
		hideObject('bhmaat');
	}
}

function showGegevens(){
	document.getElementById("fotos_tab").className = "tabinact";
	document.getElementById("gegevens_tab").className = "tabact";
	showObject("gegevens");
	hideObject("fotos");
	showObject("btn_bewaar");
}

function showObject(o){
	var x = new getObj(o);
	x.style.display = 'block';
}

function hideObject(o){
	var x = new getObj(o);
	x.style.display = 'none';
}

function showFotos(){
	document.getElementById("fotos_tab").className = "tabact";
	document.getElementById("gegevens_tab").className = "tabinact2";
	showObject("fotos");
	hideObject("gegevens");
	hideObject("btn_bewaar");
	scroll(0,0);
}


function showPersonalia(){
	//saveForm();
	showObject("personalia");
	//hideObject("kenmerken");
	//hideObject("interesses");
}

function showKenmerken(){
	//saveForm();
	//if(checkPersonalia()){
		//hideObject("personalia");
		showObject("kenmerken");
		//hideObject("interesses");
	//}
}
function showInteresses(){
	//saveForm();
	//if(checkPersonalia()){
		//if(checkKenmerken()){
			//hideObject("personalia");
			//hideObject("kenmerken");
			showObject("interesses");
		//}
	//}
}
function checkVerplicht(){
	if(checkPersonalia()){
		if(checkKenmerken()){
			if(checkFotos()){
				saveForm();
			}
		}
	}	
}
function getObj(name){
	if (document.getElementById){
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
	}
	else if (document.all){
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
	}
	else if (document.layers){
	   if (document.layers[name]){
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else{
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 	}
}



function checkPersonalia(){
	if (document.obj.Voornaam.value == ''){
 		alert("U heeft geen voornaam ingevuld");
 		document.obj.Voornaam.focus();
     }
	else if (document.obj.Geslacht[0].checked == false && document.obj.Geslacht[1].checked == false){
 		alert("U heeft geen geslacht ingevuld");
 		document.obj.geslacht.focus();
    }
	else if (document.obj.Achternaam.value == ''){
 		alert("U heeft geen achternaam ingevuld");
 		document.obj.Achternaam.focus();
    }
	else if (document.obj.Adres_Straat.value == ''){
 		alert("U heeft geen straat ingevuld");
 		document.obj.Adres_Straat.focus();
    }
	else if (document.obj.Tel_1.value == ''){
 		alert("U heeft geen telefoonnummer ingevuld");
		showKenmerken();
 		document.obj.Confectie.focus();
	}
/*	else if (document.obj.Adres_Huisnummer.value == ''){
 		alert("U heeft geen huisnummer ingevuld");
 		document.obj.Adres_Huisnummer.focus();
    }*/
	else if (document.obj.Adres_Postcode.value == ''){
 		alert("U heeft geen postcode ingevuld");
 		document.obj.Adres_Postcode.focus();
    }
	else if (document.obj.Adres_Plaats.value == ''){
 		alert("U heeft geen plaats ingevuld");
 		document.obj.Adres_Plaats.focus();
    }
	else if (!checkMail(document.obj.Email.value)){
 		alert("U heeft geen (geldig) email adres ingevuld");
 		document.obj.Email.focus();
    }
	else if (document.obj.Geboortedatum.value == ''){
 		alert("U heeft geen geboortedatum ingevuld");
 		document.obj.Geboortedatum.focus();
    }
	else{
		return true;
	}
}


function checkKenmerken(){
	if (document.obj.Lengte.value == ''){
 		alert("U heeft geen lengte ingevuld");
		showKenmerken();
 		document.obj.Lengte.focus();
    }
	else if (!isInteger(document.obj.Lengte.value)){
 		alert("U heeft een onjuiste lengte ingevuld.");
		showKenmerken();
 		document.obj.Lengte.focus();
    }

	
	else if (document.obj.Schoen.value == ''){
 		alert("U heeft geen schoenmaat ingevuld");
		showKenmerken();
 		document.obj.Schoen.focus();
	}

	else if (!isInteger(document.obj.Bovenwijdte.value)){
 		alert("U heeft een onjuiste bovenwijdte ingevuld.");
		showKenmerken();
 		document.obj.Bovenwijdte.focus();
    }
	else if (!isInteger(document.obj.Taille.value)){
 		alert("U heeft een onjuiste taille maat ingevuld.");
		showKenmerken();
 		document.obj.Taille.focus();
    }
	else if (!isInteger(document.obj.Heup.value)){
 		alert("U heeft een onjuiste heup maat ingevuld.");
		showKenmerken();
 		document.obj.Heup.focus();
    }
	else if (!isInteger(document.obj.Boord.value)){
 		alert("U heeft een onjuiste boord maat ingevuld.");
		showKenmerken();
 		document.obj.Boord.focus();
    }
	else if (!isInteger(document.obj.Hoofd.value)){
 		alert("U heeft een onjuiste hoofd maat ingevuld.");
		showKenmerken();
 		document.obj.Hoofd.focus();
    }


	else if (document.obj.Ogen.value == ''){
 		alert("U heeft geen kleur ogen ingevuld");
		showKenmerken();
 		document.obj.Ogen.focus();
	}
	else if (document.obj.Haarkleur.value == ''){
 		alert("U heeft geen kleur haar ingevuld");
		showKenmerken();
 		document.obj.Haarkleur.focus();
	}
	else if (document.obj.Haarlengte.value == ''){
 		alert("U heeft geen haarlengte ingevuld");
		showKenmerken();
 		document.obj.Haarlengte.focus();
	}
	else if (document.obj.Look.value == ''){
 		alert("U heeft geen look ingevuld");
		showKenmerken();
 		document.obj.Look.focus();
	}
	else{
		return true;
	}
}
function checkFotos(){
	if (noofpics<3){
 		alert("U moet 3 of meer foto's insturen");
	}
	else{
		return true;
	}
}

function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email))return true;
	else return false;
}

function setConfectieValue(v){
	document.obj.Confectie.value=v;
}

function setIframeHeight(ifr,pageHeight){
	var x = new getObj(ifr);
	x.style.height = (pageHeight)+"px";
}
