var submenu;

function Submenu(id){
	element = document.getElementById(id+'-submenu');
	images	= document.getElementById(id+'-image');
	
	if (element.style.display != '')
	{		
		if(submenu != null)
		{
		 	document.getElementById(submenu+'-submenu').style.display = 'none';
			document.getElementById(submenu+'-image').src ='/images/menu1.png';		
		}
	
		submenu = id;
		images.src ='/images/menu3.png';
		element.style.display = '';	
	}
	else{	
		submenu = null;
		images.src ='/images/menu1.png';
		element.style.display = 'none';
	}
}

var subsubmenu;
function Subsubmenu(id){
	table = document.getElementById(id);
	
	if(table.style.display == 'none')
	{
		if (subsubmenu != null) {		
			document.getElementById(subsubmenu).style.display = 'none';
		}
		
		subsubmenu = id;
		table.style.display = '';
	} else{		
		table.style.display = 'none';
	}
}

function ChangeColor(id, color){
  if (typeof id == "string") id = document.getElementById(id);
  if (typeof id == "object") id.style.color = color;
}

function SetValue(id, value){
	input = document.getElementById(id);
	
	if (input.value == "" || input.value == "E-mail" || input.value == "Wachtwoord") 
	{
		input.value = value;
	}
}

function getPageSizeWithScroll(){

	if( window.innerWidth && window.scrollMaxX){
		xWithScroll = window.innerWidth + window.scrollMaxX - 17;
	}else{
		xWithScroll = document.body.offsetWidth;
	}
	
	if(document.documentElement.clientHeight > document.body.offsetHeight){
		yWithScroll = document.documentElement.clientHeight;
	}else{
		yWithScroll = document.body.offsetHeight;
	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

/*
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}
*/

function setwidthandheight(box){
	var wh = getPageSizeWithScroll();	
	box.style.height	= wh['1']+'px';	
	box.style.width		= wh['0']+'px';	
//	alert('hoogte:' + wh['1'] + ' breedte: ' + wh['0']);
}

onresize = function(){
	box = document.getElementById('layer');
	setwidthandheight(box);
}

function Lightbox(content, widthtable, marginleft, marginheight){
	box = document.getElementById('layer');
	setwidthandheight(box);
	box.style.display	='block';
	document.getElementById('layertable').style.display='block';
	
	if( marginleft === undefined){
		if(widthtable != undefined){
			marginleft = Math.round(screen.availWidth/2) - Math.round(widthtable/2);
		}
		else{
			marginleft = Math.round(screen.availWidth/3);
		}		
	}
	
	if( marginheight === undefined){
		if (window.pageYOffset) {
			marginheight = Math.round(window.pageYOffset + 100);
		} else {
			marginheight = Math.round(document.documentElement.scrollTop + 100);
		}		
	}

	table = document.getElementById('layertable');
	table.width	= '';
	if(widthtable != undefined){table.width	= widthtable +'px';}	
	table.style.left	= marginleft +'px';
	table.style.top		= marginheight +'px';
	document.getElementById('lightcontent').innerHTML = '<br>' + content;
}

function haalCookie(){

	if(document.cookie.length > 0){

		if(document.cookie.match('MamiyaWebshop=ingelogd')){
			document.getElementById('inloggen').style.display = 'none';
		}else if(document.cookie.match('MamiyaWebshop=uitgelogd')){
				document.getElementById('inloggen').style.display = 'block';
		}

	}
}



//Winkelwagen

var xmlHttp1
function winkelwagen(wwid){
	
	xmlHttp1=GetXmlHttpObject();
	if (xmlHttp1==null)
	 {
	 alert ("Browser does not support HTTP Request");
	 return
	 } 
	var d= new Date(); 
	 
	var url="/winkelwagen.php";
	url = url +"?id="+ wwid;
	url=url+"&sid="+d.getTime();
	xmlHttp1.onreadystatechange=stateChanged1;
	xmlHttp1.open("GET",url,true)
	xmlHttp1.send(null)
} 
	
function stateChanged1() 
{ 
 if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete")
 { 
 document.getElementById("wwagen").innerHTML=xmlHttp1.responseText;
 } 
} 
	
function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
 {
 objXMLHttp=new XMLHttpRequest()
 }
else if (window.ActiveXObject)
 {
 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
 }
return objXMLHttp	
}

//FUNCTIES TBV HET VALIDEREN VAN FORMULIEREN!
 
 function truefalse(veld, roodzwart){
	
	var input = document.getElementById(veld);
	var label = document.getElementById('label' + veld);
	
	if(roodzwart == true){
	
		input.style.borderColor = "#D30020";
		label.style.color="#D30020";
	}
	else{	
		input.style.borderColor = "#D9D9D9";
		label.style.color="black";	
	}
}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){	   
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){	   
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){		
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){		
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){		
		return false
	 }

	 return true					
}
