// laat belegging zien
function show_belegging(prj)
{
	hide_beleggingen();
	document.getElementById(prj).style.display = "block";

}


// huidige belegging verbergen

function hide_beleggingen()
{
num = 0;
	for(i=1; i< 25; i++)
	{
		num++;
		prjid = "prj" + num;
		document.getElementById(prjid).style.display = "none";
	}
}

// popup voor foto's

function popup(url,winName) {
	W = 800;
	H = 625;
	X = screen.width/2-W/2; 
	Y = screen.height/2-H/2;

	winprops = 'height='+H+',width='+W+',top='+X+',left='+Y+',scrollbars=no';

	win = window.open(url, winName, winprops);
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}


// AJAX deel

var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
} 

function nextImg(url,id, max)
{
	imgnmr = id.substr((id.indexOf('=') +1));
	id = id + ","+max;
	if(parseFloat(imgnmr) <= parseFloat(max))
	{
		GetContent('foto', id);
	}
}
 
function prevImg(url,id, max)
{
	
	if(id.indexOf('=') > 0)
	{
		imgnmr = id.substr((id.indexOf('=') +1));
		if(imgnmr > 0)
		{	
			id = id + ","+max;
			GetContent('prevfoto', id);
		}
	}

}

function getImg(url, id, max)
{
	imgnmr = id.substr((id.indexOf('=') +1));
	id = id + ","+max;
	GetContent('foto', id);
}

function GetContent(url,id) {



urlid = id;

setimgprev = false;
setimgnxt = false;
	if(url == "foto")
	{
		
		url = "img_helper.php?woon_id="
		element ="ew_fotoframe";
		setimgnxt = true;
		if(id.indexOf(',') > 0)
		{
			urlid = id.substr(0, id.indexOf(','));
		}
	}
	else if(url == "prevfoto")
	{
		url = "img_helper.php?woon_id="
		element ="ew_fotoframe";
		setimgnxt = true;
		setimgprev = true;
		if(id.indexOf(',') > 0)
		{
			urlid = id.substr(0, id.indexOf(','));
		}
	}
	else if(url == "frfoto")
	{
		url = "img_helper.php?fotoType=fr&woon_id="
		element ="ew_fotoframe";
	}
	else if(url == "ewf")
	{
		url = "exclusiefwonenfrankrijk.php?woon_id="
		element = "woning";
	}
	else
	{
		url = "exclusiefwonen.php?woon_id="
		element = "woning";

	}
  http.open("GET", url+urlid, true);
  http.onreadystatechange=function() {
	   document.getElementById(element).innerHTML = "<center><img src='http://conductvastgoed.com/images/load.jpg' alt='Loading' /></center>";
    if(http.readyState == 4) {
      document.getElementById(element).innerHTML = http.responseText;
		if(setimgnxt)
		{
			max = '';
			if(id.indexOf(','))
			{
				max = ', \'' + id.substr(id.indexOf(',') +1) + '\'';
				
				id = id.substr(0, id.indexOf(','));
				
			}
			
			imgnmr = id.substr((id.indexOf('=') +1));
			if(setimgprev)
			{	
				i_nxt = imgnmr;
				i_nxt++;
				imgnmr--;
				i_prev = imgnmr;
			}
			else
			{
				i_prev = imgnmr;
				i_prev--;
				imgnmr++;
				i_nxt = imgnmr;
				
			}
			imgparam1 = id.substr(0, (id.indexOf('=')+1)) + i_prev;
			imgparam2 = id.substr(0, (id.indexOf('=')+1)) + i_nxt;
			
			
			document.getElementById('imgprev').href = 'javascript:prevImg(\'prevfoto\',\'' + imgparam1 + '\'' + max + ')';
			document.getElementById('imgnxt').href = 'javascript:nextImg(\'foto\',\'' + imgparam2 + '\'' + max + ')';
		}
    }
	else
	{
			   document.getElementById(element).innerHTML = "<center><img src='http://conductvastgoed.com/images/load.jpg' alt='Loading' /></center>";
	}
  }
  http.send(null);
}
