var exId = '';
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  
  exA = document.getElementById("ex_"+exId);
  if (exA != "undefined" && exA != null)
  	exA.style.textDecoration = "none";
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	exId = MM_swapImage.arguments[0];

  exA = document.getElementById("ex_"+exId);
  if (exA != "undefined" && exA != null)
  	exA.style.textDecoration = "underline";
}

var currImg = new Array();
function initImg(x, targetImg)
{
	if (typeof(currImg[targetImg]) == "undefined")
	{
		currImg[targetImg] = x;
		document.getElementById(x).style.cursor = "default";
	}
}

function clickImg(selImg, targetImg)
{
	if (selImg.id != currImg[targetImg])
	{
		prevImg = document.getElementById(currImg[targetImg]);
		z = document.getElementById(targetImg);
		var tmp = selImg.id.split("_");
		var tmp2 = prevImg.id.split("_");
		prevImg.src = "./cms_file.php?fromDB="+tmp2[1]+"&width=74&height=48&filter0=crop";
		prevImg.style.cursor = "pointer";
		selImg.src = "./cms_file.php?fromDB="+tmp[1]+"&width=74&height=48&filter0=crop&filter1=grayscale";
		selImg.style.cursor = "default";
		z.src = "./cms_file.php?fromDB="+tmp[1]+"&maxWidth=484&maxHeight=308";
		currImg[targetImg] = selImg.id;
	}
}

var map = '';
var firstMarker = '';
function onLoadGooglemap(widget)
{
	map = widget.gmap;
	firstMarker = widget.item.markers[0].latitude+","+widget.item.markers[0].longitude;

	var ownMarker = false;
	for(var i in widget.item.markers)
	{
		if (widget.item.markers[i].linkedItem == g_category && widget.item.markers[i].linkedItemType == "item_cms_category")
		{
			ownMarker = widget.item.markers[i];
		}
	}

	GEvent.addListener(map, "infowindowopen", function()
	{
		var infoWindow = map.getInfoWindow();
		//var p = infoWindow.getPoint();
		var tmppoint = map.fromLatLngToContainerPixel(infoWindow.getPoint());
		tmppoint.y -= 150;
		map.panTo(map.fromContainerPixelToLatLng(tmppoint));
		//map.panTo(p);
	});

	if (ownMarker)
	{
		map.setCenter(ownMarker.gmarker.getPoint(), 13);

		var infoWindow = document.createElement("div");
		ownMarker.titleNode = document.createElement("span");
		ownMarker.titleNode.style.fontWeight = "bold"; 
		ownMarker.titleNode.appendChild(document.createTextNode(ownMarker.title));
		infoWindow.appendChild(ownMarker.titleNode);
		
		ownMarker.contentNode = document.createElement("div");
		ownMarker.contentNode.style.marginTop = "10px";
		ownMarker.contentNode.innerHTML = ownMarker.content;
		infoWindow.appendChild(ownMarker.contentNode);

		map.openInfoWindow(map.getCenter(), infoWindow);
	}
}

function emptyForm(formId)
{
	f = document.getElementById(formId);
	for (x in f.elements)
	{
		if (f.elements[x] != null)
		{
			if (f.elements[x].type == 'text' || f.elements[x].type == 'textarea')
				f.elements[x].value = '';
		}
	}
}

function onLoadForm(widget)
{
	widget.addEventListener("submitted", function()
	{
		emptyForm("contactForm");
		document.getElementById("submitbutton").style.visibility = "hidden";
		document.getElementById("formMessage").style.visibility = "visible";
	});
}

function reInitForm()
{
	document.getElementById("submitbutton").style.visibility = "visible";
	document.getElementById("formMessage").style.visibility = "hidden";
}

function onLoadPoll(widget)
{
	widget.addEventListener("beforeForm", function()
	{
		if (getCookie("sdkvoted"+widget.item.id))
			widget.showStatistics();
		return !getCookie("sdkvoted"+widget.item.id);
	});

	widget.addEventListener("submitted", function()
	{
		setCookie("sdkvoted"+widget.item.id, true, 365);
		document.getElementById("pollSucces").innerHTML = "<b>Bedankt voor uw stem.</b><br />";
		widget.showStatistics();
	});
}

function onLoadPollLock(widget)
{
	widget.addEventListener("beforeForm", function()
	{
		widget.showStatistics();
		return false;
	});
}

var marker = '';
var directions = 'init';
function createPoint(inp)
{
	map.removeOverlay(marker);
	
	var x = document.getElementById(inp).value;
	var str = x.replace(/ /g,"+");
	var geocoder = new GClientGeocoder();

	geocoder.getLatLng(str, function(point) {
		if (!point)
			{ window.alert("Adres niet gevonden"); }
		else
		{
		    var icon = new GIcon();
		    icon.image = "http://localhost/sdk/www/images/sdk.gif";
		    icon.iconSize = new GSize(31, 48);
		    icon.iconAnchor = new GPoint(5, 49);
		    icon.infoWindowAnchor = new GPoint(5, 49);
		
			marker = new GMarker(point,
			{
				title: "Vertrekpunt",
				icon: icon,
				clickable: true,
				draggable: false
			});
			map.addOverlay(marker);

			directionsPanel = document.getElementById("routeDiv");
			if (directions == 'init')
				directions = new GDirections(map, directionsPanel);
  			directions.load("from: "+point.lat()+","+point.lng()+" to: "+firstMarker,
  				{
					"locale": "nl_NL"
				}
			);
			document.getElementById('printP').href = "http://maps.google.com/maps?f=d&hl=nl&geocode=" + 
													"&saddr=" + str +
													"&daddr=dillenburgstraat+25a+eindhoven&ie=UTF8&z=13&pw=2";
			document.getElementById('printP').style.display = "block";
			document.getElementById('routeDiv').style.display = "block";
		}
	});
}
/*function createPoint(inp)
{
	map.removeOverlay(marker);

	var point = new GLatLng();
	var point2 = new GLatLng()

	var x = document.getElementById(inp).value;
	var str = x.replace(/ /,"+");
	var geocoder = new GClientGeocoder();
	
	geocoder.getLatLng(str, function(tmppoint) {
		if (!tmppoint)
			{ window.alert("Adres niet gevonden"); }
		else
		{
			point = tmppoint;
		    var icon = new GIcon();
		    icon.image = "http://localhost/sdk/www/images/sdk.gif";
		    icon.iconSize = new GSize(31, 48);
		    icon.iconAnchor = new GPoint(5, 49);
		    icon.infoWindowAnchor = new GPoint(5, 49);
		
			marker = new GMarker(tmppoint,
			{
				title: "Vertrekpunt",
				icon: icon,
				clickable: true,
				draggable: false
			});
			map.addOverlay(marker);


			var geocoder2 = new GClientGeocoder();
			geocoder2.getLatLng("Dillenburgstraat+25a+Eindhoven", function(tmppoint2) {
				if (!tmppoint2)
					window.alert("Aankomst adres ongeldig");
				else
				{
					point2 = tmppoint2;
	
					directionsPanel = document.getElementById("routeDiv");
					if (directions == 'init')
						directions = new GDirections(map, directionsPanel);
						
					window.alert("from: "+point.lat()+","+point.lng()+" to: "+point2.lat()+","+point2.lng());
		  			directions.load("from: "+point.lat()+","+point.lng()+" to: "+point2.lat()+","+point2.lng(),
		  				{
							"locale": "nl_NL"
						}
					);
					document.getElementById('printP').style.display = "block";
				}
			});
		}
	});
}*/

function zmIn()
{
	map.zoomIn();
}

function zmOut()
{
	map.zoomOut();
}

function changeMapType(mapType)
{
	switch(mapType)
	{
	case "normal":
		map.setMapType(G_NORMAL_MAP);
		break;    
	case "satt":
		map.setMapType(G_SATELLITE_MAP);
		break;
	case "hybrid":
		map.setMapType(G_HYBRID_MAP);
		break;
	}
}

function mOver(m)
{
	document.getElementById(m).style.display = "none";
	document.getElementById(m+"_roll").style.display = "inline";
}

function mOut(m)
{
	document.getElementById(m).style.display = "inline";
	document.getElementById(m+"_roll").style.display = "none";
}


function onMoviePlayerSize(divId, width, height)
{
	var flash = getFlash(divId);
	flash.height = height;
}

function selectPage(num)
{
	var c = document.getElementById("currpage");
	var t = document.getElementById("totalpage");

	document.getElementById("minder").style.display = "block";
	document.getElementById("meer").style.display = "block";
	var x = document.getElementById("projectdiv_"+c.value);
	x.style.display = "none";
	
	c.value = Number(c.value) + Number(num);
	document.getElementById("projectdiv_"+c.value).style.display = "block";
	
	var max = c.value*6;
	var min = max - 5;
	if (min == 1)
	{
		document.getElementById("minder").style.display = "none";
	}
	if (c.value*6 > t.value)
	{
		document.getElementById("meer").style.display = "none";
		max = t.value;
	}
	var cell = document.getElementById("pagesIndex");
	cell.innerHTML = min + " - " + max + " van " + t.value;
}

function showPopup(btn, popupId)
{
	var popup = document.getElementById(popupId);
	
	if (popup.style.display != "block")
	{
		var x = getScreenPosX(btn) + btn.offsetWidth + 4;
		var y = getScreenPosY(btn)
				
		popup.style.left = x + "px";
		popup.style.top = y + "px";
		popup.style.display = "block";
	}
	else
	{
		popup.style.display = "none";
	}
	
	var links = popup.getElementsByTagName("a");
	
	for (var x = 0; x < links.length; x++)
	{
		links[x].attachEvent("onclick", function()
		{
			popup.style.display = "none";
		});
	}
}

function closePopup(popupId)
{
	document.getElementById(popupId).style.display = "none";
}

/*
function filterProjects(projectIds)
{
	for (x in projects)
	{
		projects[x] = false;
	}

	var tmp = '<ul>';
	for(var i=0; i < arguments.length; i++)
	{
		projects[arguments[i]] = true;
		tmp += '<li>' + arguments[i] + '</li>';
	}
	tmp += '</ul>';
	
	document.getElementById('debug').innerHTML = tmp;
	
	for (x in projects)
	{
		if (projects[x] == true)
		{
			document.getElementById(x).style.display = 'block';
		}
		else if (projects[x] == false)
		{
			document.getElementById(x).style.display = 'none';
		}
	}
}
*/
/*
function initLinePos()
{
	var posProj = document.getElementById('posProj');
	var posNews = document.getElementById('posNews');
	var projDiv = document.getElementById('projDiv');
	
	//window.alert(posProj.offsetTop + " " + posNews.offsetTop);
}*/
