//Animated Collapsible DIV- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated Aug 1st, 07'. Fixed bug with "block" parameter not working when persist is enabled
//Updated June 27th, 07'. Added ability for a DIV to be initially expanded.

var uniquepageid=window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, "") //get current page path and name, used to uniquely identify this page for persistence feature

function animatedcollapse(divId, animatetime, persistexpand, initstate){
	this.divId=divId
	this.divObj=document.getElementById(divId)
	this.divObj.style.overflow="hidden"
	
	this.timelength=animatetime
	this.initstate=(typeof initstate!="undefined" && initstate=="block")? "block" : "contract"
	this.isExpanded=animatedcollapse.getCookie(uniquepageid+"-"+divId) //"yes" or "no", based on cookie value
	this.contentheight=parseInt(this.divObj.style.height)
	var thisobj=this
	if (isNaN(this.contentheight)){ //if no CSS "height" attribute explicitly defined, get DIV's height on window.load
		animatedcollapse.dotask(window, function(){thisobj._getheight(persistexpand)}, "load")
		if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
			this.divObj.style.visibility="hidden" //hide content (versus collapse) until we can get its height
	}
	else if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //just collapse content if CSS "height" attribute available
	if (persistexpand)
		animatedcollapse.dotask(window, function(){animatedcollapse.setCookie(uniquepageid+"-"+thisobj.divId, thisobj.isExpanded)}, "unload")
}

animatedcollapse.prototype._getheight=function(persistexpand){
	this.contentheight=this.divObj.offsetHeight
	if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes"){ //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //collapse content
		this.divObj.style.visibility="visible"
	}
	else //else if persistence is enabled AND this content should be expanded, define its CSS height value so slideup() has something to work with
		this.divObj.style.height=this.contentheight+"px"
}


animatedcollapse.prototype._slideengine=function(direction){
	var elapsed=new Date().getTime()-this.startTime //get time animation has run
	var thisobj=this
	if (elapsed<this.timelength){ //if time run is less than specified length
		var distancepercent=(direction=="down")? animatedcollapse.curveincrement(elapsed/this.timelength) : 1-animatedcollapse.curveincrement(elapsed/this.timelength)
	this.divObj.style.height=distancepercent * this.contentheight +"px"
	this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10)
	}
	else{ //if animation finished
		this.divObj.style.height=(direction=="down")? this.contentheight+"px" : 0
		this.isExpanded=(direction=="down")? "yes" : "no" //remember whether content is expanded or not
		this.runtimer=null
	}
}


animatedcollapse.prototype.slidedown=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==0){ //if content is collapsed
			this.startTime=new Date().getTime() //Set animation start time
			this._slideengine("down")
		}
	}
}

animatedcollapse.prototype.slideup=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==this.contentheight){ //if content is expanded
			this.startTime=new Date().getTime()
			this._slideengine("up")
		}
	}
}

animatedcollapse.prototype.slideit=function(){
	if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
		alert("Please wait until document has fully loaded then click again")
	else if (parseInt(this.divObj.style.height)==0)
		this.slidedown()
	else if (parseInt(this.divObj.style.height)==this.contentheight)
		this.slideup()
}

// -------------------------------------------------------------------
// A few utility functions below:
// -------------------------------------------------------------------

animatedcollapse.curveincrement=function(percent){
	return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
}


animatedcollapse.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
}

animatedcollapse.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

animatedcollapse.setCookie=function(name, value){
		document.cookie = name+"="+value
}

//-----------------------------------------------------------------------------------------

function leegOnFocus(veld, orgineel)

{

	if(veld.value == orgineel)

	{

		veld.value = '';

	}

}



function vervangOnBlur(veld, vervangdoor)

{

	if(veld.value == '')

	{

		veld.value = vervangdoor;

	}

}

function change(that, fgcolor, bgcolor)
{
	that.style.color = fgcolor;
	
	that.style.backgroundColor = bgcolor;
}


function showActiviteitToevoegen()
{
	document.getElementById('activiteittoevoegen').style.display = "block";
}

function showProductToevoegen()
{
	document.getElementById('producttoevoegen').style.display = "block";
}


function showLocatieToevoegen()
{
	document.getElementById('locatietoevoegen').style.display = "block";
}

function checkAbbos(number)
{
	if (document.getElementById("check_" + number).checked == true) {
		if (number >= 3) {
			document.getElementById("check_3").checked = true;
		}
		
		if (number > 3) {
			document.getElementById("check_3").checked = true;
		}
		
		if (number == 9)
		{
			document.getElementById("check_8").checked = true;
		}
	}
	else
	{
		if(number == 2)
		{
			for(var i = 3; i <= 10; i++)
			{
				document.getElementById("check_" + i).checked = false;
			}
		}
		if(number == 3)
		{
			for(var i = 4; i <= 10; i++)
			{
				document.getElementById("check_" + i).checked = false;
			}
		}
		if(number == 8)
		{
			document.getElementById("check_9").checked = false;
		}
	}
	
	return true;
}

function showMailer()
{
	document.getElementById("mailer").style.display = "block";
}

function switchPage(newValue)
{
	document.getElementById("hPagnum").value = newValue;
	document.getElementById("zoeken").submit.click();
}

function duplicateErven()
{
	document.filiaal.postStraat.value = document.filiaal.straat.value;
	document.filiaal.postHuisnummer.value = document.filiaal.huisnummer.value;
	document.filiaal.postHuisnummerToev.value = document.filiaal.huisnummerToev.value;
	document.filiaal.postPostcode.value = document.filiaal.postcode.value;
	document.filiaal.postWoonplaats.value = document.filiaal.woonplaats.value;
} 


////////////////////////////////////////////////////////
// Collapse - Contactpersoon
////////////////////////////////////////////////////////

ddaccordion.init({
	headerclass: "mycontactpersoon", //Shared CSS class name of headers group
	contentclass: "opencontactpersoon", //Shared CSS class name of contents group
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [1], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openpet"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "slow", //speed of animation: "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isclicked){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

////////////////////////////////////////////////////////
// Collapse - News
////////////////////////////////////////////////////////

ddaccordion.init({
	headerclass: "collapse_news", //Shared CSS class name of headers group
	contentclass: "opennewsdetail", //Shared CSS class name of contents group
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [1], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openpet"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "slow", //speed of animation: "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isclicked){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

////////////////////////////////////////////////////////
// Collapse - Metaal Nieuws
////////////////////////////////////////////////////////

ddaccordion.init({
	headerclass: "collapse_metaalnieuws", //Shared CSS class name of headers group
	contentclass: "opennieuwsdetail", //Shared CSS class name of contents group
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["", "openpet"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "slow", //speed of animation: "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isclicked){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})



////////////////////////////////////////////////////////
// Form validation
////////////////////////////////////////////////////////

// Registreren

function validateReg_stap2()
{
	var returnval = true;
	
	document.getElementById("formerror").style.height = "auto";
	
	//Bedrijfsnaam
	if(document.reg_stap2.bedrijfsnaam.value == "")
	{
		document.getElementById("bedrijfsnaam").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("bedrijfsnaam").style.color = "black";
	}
	
	//Straat
	if(document.reg_stap2.straat.value == "")
	{
		document.getElementById("straat").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("straat").style.color = "black";
	}
	
	//Huisnummer
	if(document.reg_stap2.huisnummer.value == "")
	{
		document.getElementById("huisnummer").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("huisnummer").style.color = "black";
	}
	
	//Postcode
	if(document.reg_stap2.postcode.value == "")
	{
		document.getElementById("postcode").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("postcode").style.color = "black";
	}
	
	//Woonplaats
	if(document.reg_stap2.bedrijf_woonplaats.value == "")
	{
		document.getElementById("bedrijf_woonplaats").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("bedrijf_woonplaats").style.color = "black";
	}
		
	//Voorletters
	if(document.reg_stap2.voorletters.value == "")
	{
		document.getElementById("voorletters").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("voorletters").style.color = "black";
	}
	
	//Achternaam
	if(document.reg_stap2.achternaam.value == "")
	{
		document.getElementById("achternaam").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("achternaam").style.color = "black";
	}

	//E-mail
	if(document.reg_stap2.email.value == "")
	{
		document.getElementById("email").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("email").style.color = "black";
	}

	//Bevestig E-mail
	if(document.reg_stap2.bevestig_email.value == "")
	{
		document.getElementById("bevestig_email").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("bevestig_email").style.color = "black";
	}

	//Voorwaarden
	if(document.reg_stap2.voorwaarden.checked == false)
	{
		document.getElementById("voorwaarden").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("voorwaarden").style.color = "black";
	}


	if(!returnval)
	{
		document.getElementById("formerror").innerHTML = "Een of meerdere velden zijn niet of niet juist ingevoerd. Controleer de rood gemarkeerde velden probeer het opnieuw.<br /><br />";
	}
	return returnval;
}


// Registreren Persoon

function validatePers_reg_stap2()
{
	var returnval = true;
	
	document.getElementById("formerror").style.height = "auto";

	//Voorletters
	if(document.reg_stap2.voorletters.value == "")
	{
		document.getElementById("voorletters").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("voorletters").style.color = "black";
	}
	
	//Achternaam
	if(document.reg_stap2.achternaam.value == "")
	{
		document.getElementById("achternaam").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("achternaam").style.color = "black";
	}

	//E-mail
	if(document.reg_stap2.email.value == "")
	{
		document.getElementById("email").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("email").style.color = "black";
	}

	//Bevestig E-mail
	if(document.reg_stap2.bevestig_email.value == "")
	{
		document.getElementById("bevestig_email").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("bevestig_email").style.color = "black";
	}

	//Voorwaarden
	if(document.reg_stap2.voorwaarden.checked == false)
	{
		document.getElementById("voorwaarden").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("voorwaarden").style.color = "black";
	}

	if(!returnval)
	{
		document.getElementById("formerror").innerHTML = "Een of meerdere velden zijn niet of niet juist ingevoerd. Controleer de rood gemarkeerde velden probeer het opnieuw.<br /><br />";
	}
	return returnval;
}


function validateBedrijfmutatie()
{
	var returnval = true;
	
	document.getElementById("formerror").style.height = "auto";
	
	if(document.bedrijfsgegevens.naam.value == "")
	{
		document.getElementById("bedrijfsnaamlabel").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("bedrijfsnaamlabel").style.color = "black";
	}
	
	if(document.bedrijfsgegevens.branche.value == "")
	{
		document.getElementById("branchelabel").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("branchelabel").style.color = "black";
	}
	
	if(!returnval)
	{
		document.getElementById("formerror").innerHTML = "Een of meerdere velden zijn niet of niet juist ingevoerd. Controleer de rood gemarkeerde velden probeer het opnieuw.<br /><br />";
	}
	return returnval;
}

//Bedrijfsactiviteit

function validateBedrijfmutatieActiviteit()
{
	var returnval = true;
	
	document.getElementById("formerror").style.height = "auto";
	
	if(document.toevoegen.activiteit.value == "")
	{
		document.getElementById("bedrijfsactiviteit").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("bedrijfsactiviteit").style.color = "black";
	}
	
	if(!returnval)
	{
		document.getElementById("formerror2").innerHTML = "Er is geen waarde ingevuld.<br /><br />";
	}
	return returnval;
}

//Bewerk Filiaal

function validateFiliaalMutatie()
{
	var returnval = true;
	
	document.getElementById("formerror").style.height = "auto";
	
	// Straatnaam
	if(document.filiaal.straat.value == "")
	{
		document.getElementById("straat").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("straat").style.color = "black";
	}
	
	//Huisnummer 
	if(document.filiaal.huisnummer.value == "")
	{
		document.getElementById("huisnummer").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("huisnummer").style.color = "black";
	}
	
	//Postcode
	if(document.filiaal.postcode.value == "")
	{
		document.getElementById("postcode").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("postcode").style.color = "black";
	}
	
	//Woonplaats
	if(document.filiaal.woonplaats.value == "")
	{
		document.getElementById("woonplaats").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("woonplaats").style.color = "black";
	}
	
	
	//Email
	
	checkEmail = document.filiaal.email.value;
	
	if((checkEmail.indexOf('@') < 0) && ((checkEmail.charAt(checkEmail.length-5) != '.') && (checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')) == false)
 	{
		document.getElementById("email").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("email").style.color = "black";
	}
		
	if(!returnval)
	{
		document.getElementById("formerror").innerHTML = "Er is geen waarde ingevuld.<br /><br />";
	}
	
	
	return returnval;
}

//Contactpersoon

function validateBedrijfmutatieActiviteit()
{
	var returnval = true;
	
	document.getElementById("formerror").style.height = "auto";
	
	if(document.toevoegen.activiteit.value == "")
	{
		document.getElementById("bedrijfsactiviteit").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("bedrijfsactiviteit").style.color = "black";
	}
	
	checkEmail = document.filiaal.email.value;
	if((checkEmail.indexOf('@') < 0) && ((checkEmail.charAt(checkEmail.length-5) != '.') && (checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')) == false)
 	{
		document.getElementById("email").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("email").style.color = "black";
	}
	
	if(!returnval)
	{
		document.getElementById("formerror2").innerHTML = "Er is geen waarde ingevuld.<br /><br />";
	}
	return returnval;
}

function validateContactpersoonmutatie()
{
	var returnval = true;
	
	document.getElementById("formerror").style.height = "auto";
	if(document.contactpersoon.voorletters.value == "")
	{
		document.getElementById("voorletters").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("voorletters").style.color = "black";
	}
	
	if(document.contactpersoon.achternaam.value == "")
	{
		document.getElementById("achternaam").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("achternaam").style.color = "black";
	}
	
	var regexp = new RegExp("^[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$");
	
	if((document.contactpersoon.email.value == "") || (regexp.exec(document.contactpersoon.email.value) == null))
	{
		document.getElementById("email").style.color = "red";
		returnval = false;
	}
	else
	{
		document.getElementById("email").style.color = "black";
	}
	
	if(!returnval)
	{
		document.getElementById("formerror").innerHTML = "Er is geen waarde ingevuld.<br /><br />";
	}
	return returnval;
}

function nieuwType()
{
	document.getElementById("linkNieuw").style.display = "none";
	document.getElementById("formNieuw").style.display = "inline";
}

function dimSelect(dimType)
{
	switch(dimType)
	{
		case 'xhy':
			document.getElementById("xlabel").innerHTML = "X";
			document.getElementById("hlabel").innerHTML = "H";
			document.getElementById("ylabel").innerHTML = "Y";
			document.getElementById("hlabel").style.display = "inline";
			document.getElementById("htextbox").style.display = "inline";
			break;
			
		case 'xo':
			document.getElementById("xlabel").innerHTML = "&Oslash;";
			document.getElementById("ylabel").innerHTML = "L";
			document.getElementById("hlabel").style.display = "none";
			document.getElementById("htextbox").style.display = "none";
			break;
	}
}

function toggleDL(state)
{
	if(state == true)
	{
		document.getElementById("h").style.display = "none";
		document.getElementById("labelH").style.display = "none";
		document.getElementById("labelX").innerHTML = "D";
		document.getElementById("labelY").innerHTML = "L";
	}
	else
	{
		document.getElementById("h").style.display = "inline";
		document.getElementById("labelH").style.display = "inline";
		document.getElementById("labelX").innerHTML = "X";
		document.getElementById("labelY").innerHTML = "Y";
	}
}

function toggleUitzendbureau()
{
	if(document.getElementById("chkDooruitzendbureau").checked == false)
	{
		document.getElementById("bedrijfsnaam").innerHTML = "Bedrijfsnaam";
		document.getElementById("trBedrijfsomschrijving").style.display = "none";
	}
	else
	{
		document.getElementById("bedrijfsnaam").innerHTML = "Uitzendbureau";
		document.getElementById("trBedrijfsomschrijving").style.display = "table-row";
	}
}
