
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		HtmlLinkMenu_01_over = newImage("images/HtmlLinkMenu_01-over.gif");
		HtmlLinkMenu_02_over = newImage("images/HtmlLinkMenu_02-over.gif");
		HtmlLinkMenu_03_over = newImage("images/HtmlLinkMenu_03-over.gif");
		HtmlLinkMenu_04_over = newImage("images/HtmlLinkMenu_04-over.gif");
		HtmlLinkMenu_05_over = newImage("images/HtmlLinkMenu_05-over.gif");
		HtmlLinkMenu_06_over = newImage("images/HtmlLinkMenu_06-over.gif");
		HtmlLinkMenu_07_over = newImage("images/HtmlLinkMenu_07-over.gif");
		preloadFlag = true;
	}
}
function openDemoFilmpje()
{
	openCenteredWindow( 'DemoFilm.html', 940, 621, '', '' );
}
function openRoute()
{
	openCenteredWindow( 'Route.html', 750, 536, '', 'menubar=yes' );
}
function openLiveHelpdesk()
{
	openCenteredWindow( 'Componenten/LiveHelpdesk/Paginas/Client.aspx', 750, 420, '', 'menubar=no' );
}
function openCenteredWindow(url, width, height, name, parms) {
   var left = Math.floor( (screen.availWidth - width) / 2);
   var top = Math.floor( (screen.availHeight - height - 30) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   //alert(  "width:" + width + ", h:" + height );
   var win = window.open(url, name, winParms);
   return win;
}

//var maxWinW = 775;
//var maxWinH = 536;
var screenW = screen.width;
var screenH = screen.height;
//alert( screenW );
function checkFotoWidth( img, maxw )
{
	if( maxw==undefined)
		maxw = 200;
	//alert(img.width);
	if(img.width>maxw || ( img.style.cursor == "hand" && img.width==maxw ))
	{
		if( img.width > screenW ) winW = screenW;
		else winW = img.width;
		
		if( img.height > screenH ) winH = screenH;
		else winH = img.height;
		
		img.width=maxw;
		img.style.cursor = "hand";
		
		img.onclick= function(){ openCenteredWindow( "Dialogs/ZoomWin.aspx?img="+this.src, winW, winH, '', 'resizable=1' ); }
		//alert("adding onclick);
	}
}

function objToString( obj, toonUndefined ) {
   var ret = "";
   
   ret += "tagName : " + obj.tagName + "\n";
   ret += "id : " + obj.id + "\n";   
   
   for (var prop in obj)
   {
		if( toonUndefined==false && this[prop]==undefined )
			continue;
		ret += " " + prop + " is " + this[prop] + " - ";// ";\n";
   }
   return ret;
} 

function addOnloadFunction( func, args )
{
	if( isUserFireFox()==true )
	{
		var fonl = window.onload;
		window.onload = function(){ 
			//alert("in onload");
			if(args!=undefined)
				func( args ); 
			else
				func();
			if( fonl != undefined )
				fonl();
		}
	}
	else
	{
		var fonl = document.body.onload;
		document.body.onload = function(){ 
			if(args!=undefined)
				func( args ); 
			else
				func();
			if( fonl != undefined )
				fonl();
		}
	}
}

function CancelBubble(e)
{
	if (!e) var e = window.event;
	if (e.stopPropagation) 
		e.stopPropagation();
	else
		event.cancelBubble = true;
}

function addToFavs( productID )
{
	CancelBubble();
	this.location.href = this.location.href + "&opt3=add2favs&productid=" + productID;
}
function isIE()
{
	return ( document.all?true:false );
}
function isUserFireFox()
{
	return( navigator.userAgent.indexOf("Firefox")>0 );
}


 //-------- IMAGESLIDE ---------------------
var zoomWachtID = "";
var zoomResetted = false;
 function doZoom( url )
{
	zoomWachtID = setTimeout( "startZoom('" + url + "')", 200 );
}
function startZoom(url)
{
	if( zoomWachtID != "" )
	{
		zoomResetted = false;
		var img = document.getElementById( "zoomImg" );
		//img.style.display = "none";
		img.style.visibility = "hidden";
		img.onload = positionFoto;
		img.src = url;
	}
}
function reset( )
{
	zoomResetted = true;
	clearTimeout( zoomWachtID );
	zoomWachtID = "";
	var img = document.getElementById( "zoomImg" );
	img.style.visibility = "hidden";
	if(isUserFireFox()==false)
		img.clearAttributes();
	//alert( document.getElementById( "zoomDiv" ).style.top );
	document.getElementById( "zoomDiv" ).style.top = "-2000px";
}
var origW = 0;
var origH = 0;
function positionFoto()
{
	if( zoomResetted == true )
		return;
	var maxW = imageSlide_maxW;//775;
	var maxH = imageSlide_maxH;//mouseY - 12;// 500;
	var img = document.getElementById( "zoomImg" );
	origW = img.width;
	origH = img.height;
	if(img.width<=1)
	{
		//setTimeout( "positionFoto()", 300 );
		return;
	}
	
	var fotoW = img.width;
	var fotoH = img.height;
	var screenW = screen.availWidth;
	var screenH = screen.availHeight;
	
	var ratio = parseFloat(img.width) / parseFloat(img.height);
	if( img.width > img.height )
	{
		//horizontale foto
		if( img.width > maxW && (img.width / ratio) < maxH)
		{
			img.width = maxW;
			fotoW = maxW;
			img.height = img.width / ratio;
			//alert("hor foto, height:" + img.height + " / ratio:" + ratio);
		}
		else
		{
			img.height = maxH;
			fotoH = maxH;
			img.width = img.height * ratio;
		}
	}
	else
	{
		//verticale foto
		if( img.height > maxH && (img.height * ratio)<maxW)
		{
			img.height = maxH;
			fotoH = maxH;
			img.width = img.height * ratio;
		}
		else
		{
			img.width = maxW;
			fotoW = maxW;
			img.height = img.width / ratio;
		}
	}
	
	img.style.cursor = "hand";
	img.style.border = "2px solid black";
	img.onclick = openZoom;
	img.onmouseout = reset;
	img.style.visibility = "visible";
	document.getElementById( "zoomDiv" ).style.top = "0px";
}
function getMouseY(e) {
	var tempY = 0;
	if (!e)
		e = window.event||window.Event;
	//alert(e.pageY);
	if (isIE()) { // grab the x-y pos.s if browser is IE
		tempY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		tempY = e.pageY;
	}  
	// catch possible negative values in NS4
	if (tempY < 0){tempY = 0}  
	return tempY;
}
function openZoom()
{
	var img = document.getElementById( "zoomImg" );
	img.galleryimg = "false";
	var url = "Dialogs/ZoomWin.aspx?img=" + img.src;
	var win = openCenteredWindow(  url, origW, origH, '' );
}
/*function openZoomFromUrl( url, w, h )
{
	var img = document.getElementById( "zoomImg" );
	var url = "Dialogs/ZoomWin.aspx?img=" + url;
	var win = openCenteredWindow(  url, w, h, '' );
}
function openZoomFromUrl( url, w, h )
{
	alert( url );
	var url = "Dialogs/ZoomWinImageSlide.aspx?img=" + url;
	var win = openCenteredWindow(  url, w, h, '' );
}*/
function openScreenshots()
{
	openZoomFromUrl( "public/imageslide/Screenshots/", "ScreenShot0.jpg", 0 );
}
var imageSlideOpenWin;
function openZoomFromUrl( folder, foto, fotoNr )
{

	//alert( folder + " : " + fotoNr );
	/*var maxW = 800;// 1024;
	var maxH = 600;// 768;
	var w = screen.availWidth-10;//-50;
	var h = screen.availHeight-37;//-80;
	if( w > maxW )
	{
		w = maxW;
		h = maxH;
	}*/
	var vensterwidth = 766;// w-30;
	var vensterheight = 580;// h-50;
	var url = "Dialogs/ZoomWinImageSlide.aspx?folder=" + folder + "&width=" + vensterwidth + "&height=" + vensterheight + "&startFoto=" + foto + "&startNr=" + fotoNr;
	
	var w = vensterwidth+4;
	var h = vensterheight+ 35;

	//alert("w:" + screen.availWidth + ", h:" + h );
	//var win = window.open(url, '', "left=0, top=0, width=" + w + ",height=" + h + ", resizable=yes");
	var imageSlideOpenWin = openCenteredWindow(  url, w, h, '', 'resizable=yes' );
}
//-------- END IMAGESLIDE

//-------- FACTUREN

function openFactuur( factuurID, isPDF)
{
	if( isPDF==true )
	{
		//location.href="FileDownloader.aspx?file=" + escape( "Componenten/Facturatie/Paginas/FactuurPDF.aspx?id="+factuurID );
		location.href="Componenten/Facturatie/Paginas/FactuurPDF.aspx?id="+factuurID;
	//openCenteredWindow( "Componenten/Facturatie/Paginas/FactuurPDF.aspx?id="+factuurID, 810, 536, '', 'menubar=yes, resizable=1, scrollbars=1' );
	}
	else
	{
	openCenteredWindow( "Componenten/Facturatie/Paginas/FactuurView.aspx?id="+factuurID, 810, 536, '', 'menubar=yes, resizable=1, scrollbars=1' );
	}
}


