﻿/* -------------------------------------
TABLE OF CONTENTS						|
										|
1.  init()								|
2.  HideContent()						|
3.  ShowContent()						|
4.  ReverseContentDisplay()				|
5.  changeFontSize()					|
6.  fontsizeCookie()					|
7.  CreatePrintWindow()					|
8.  MM_preloadImages()					|
9. createCookie()						|
10. readCookie()						|
11. eraseCookie()						|
12. getURLParam()						|
13. SetBodyHeight()						|
14. getTagFromIdentifierAndTitle()		|
15. CreateRoundCorners()				|
---------------------------------------- */

// Define all ID's which should be have a dynamic font size
// Specify the defaults (default, min and max font size) in the function changeFontSize();
// Also specify which ID's have font sizes which deviate from the default font sizes
// At least copy and paste the variable content to the function fontsizeCookie();
var contents = new Array("titel","description");

/* Function loaded in the body of the website */
function init()
{
	// Function to preload images
	// MM_preloadImages('/Style%20Library/Images/image1.jpg','/Style%20Library/Images/image2.jpg')
	MM_preloadImages('','');
	
	// Set right font size
	fontsizeCookie();

	//set body height
	SetBodyHeight();	
}

// Function to hide a DIV or multiple DIV's (display:none;)
// This function can be called by using the code: HideContent('#ID of DIV','#ID of DIV',etc);
function HideContent(d)
{
	if(d.length < 1)
	{
		return;
	}
	document.getElementById(d).style.display = "none";
}

// Function to sohw a DIV or multiple DIV's (display:block;)
// This function can be called by using the code: ShowContent('#ID of DIV','#ID of DIV',etc);
function ShowContent(d)
{
	if(d.length < 1)
	{
		return;
	}
	document.getElementById(d).style.display = "block";
}

// Function to Reverse the display style of a DIV or multiple DIV's
// Display:none becomes display:block & display:block becomes display:none
// This function can be called by using the code: ReverseContentDisplay('#ID of DIV','#ID of DIV',etc);
function ReverseContentDisplay(d)
{
	//var div = document.getElementsByTagName(d);
	if(d.length < 1)
	{
		return;
	}
	if(document.getElementById(d).style.display == "none")
	{
		document.getElementById(d).style.display = "block";
	}
	else
	{
		document.getElementById(d).style.display = "none";
	}
}

// Function to change the Font Size at the web site
// The default Font Sizes (normal, min and max font size) can be set in this function
// with the variables --> var default_min_size, var default_size, var default_max_size

// All ID's which should be have a dynamic (other) font size like title can be set at
// the top of this JavaScript file by --> var contents = new Array("titel","introductie","content");

// Also specify which ID's have font sizes which deviate from the default font sizes
// At least copy and paste the variable content to the function fontsizeCookie();

// This function can be called with:
// decrease font size: <a href="javascript:changeFontSize(-1,contents)">
// reset font size: <a href="javascript:changeFontSize(0,contents)">
// increase font size: <a href="javascript:changeFontSize(1,contents)">

function changeFontSize(inc,contents)
{
	var size; var minsize; var maxsize;
	
	//--set default font sizes for web pages --//
	var default_min_size = 8; //minimum font size
	var default_size = 11; //normal font size
	var default_max_size = 16; //maximum font size

	//--set specific font sizes for some DIV's with unique ID's--//
	// new array("name of ID",min font size,normal font size for reset,max font size)
	// var specific_sizes = new Array("titel",11,14,19,"description",8,11,18);
	var specific_sizes = new Array("titel",11,14,19,"description",8,11,18);

	if(inc>1) // check if cookieFontSize is set
	{
		if(contents != 'paragraph' && document.getElementById(contents) && !document.getElementById(contents) == '') // for all ID's check if ellement with ID=content exists and is not empty
		{
			document.getElementById(contents).style.fontSize = inc + "px";
		}
		else if(contents == 'paragraph' && document.getElementsByTagName('p')) // check if a cookie paragraph is set and at this page a parapragh exists
		{
			var p = document.getElementsByTagName('p');
			for(i=0;i<p.length;i++)
			{
				p[i].style.fontSize = inc + "px";
			}
		}
	}
	else // cookieFontSize is not set
	{
		for (var i=0; i<contents.length; i++) // for each content ID in array
		{
			var content = contents[i];			
			if (document.getElementById(content) && !document.getElementById(content) == '') // check if ellement with ID=content exists and is not empty
			{
				var specific_size = 0; // check if content is a specific font size
				var z;
				for (z=0; z<specific_sizes.length; z++)
				{
					if(content == specific_sizes[z])
					{
						specific_size = 1;
						break;
					}
				}
				if (specific_size == 1) //set specific font size
				{
					if(inc==0)
					{
						j = z+2;
						size = specific_sizes[j];
					}
					else
					{
						var fontsize = parseInt(document.getElementById(content).style.fontSize.replace("px", ""));
						minsize = z+1;
						minsize = specific_sizes[minsize];
						maxsize = z+3;
						maxsize = specific_sizes[maxsize];
						if (fontsize <= minsize) //check if font size is not too small
						{
							if(inc==-1){/*no action*/}
							else
							{
								size = fontsize + inc;
							}		
						}
						if (fontsize >= maxsize) //check if font size is not too large
						{
							if(inc==1){/*no action*/}
							else 
							{
								size = fontsize + inc;
							}
						}			
						if (fontsize != maxsize && fontsize != minsize)
						{
							size = fontsize + inc;
						}
					}
					if(size)
					{
						document.getElementById(content).style.fontSize = size + "px";
						createCookie(content,size,365);
					}
				}
				else //set default font size
				{
					if(inc==0)
					{
						size = default_size;
					}
					else
					{
						var fontsize = parseInt(document.getElementById(content).style.fontSize.replace("px", ""));
						if (fontsize <= default_min_size) //check if font size is not too large
						{
							if(inc==-1){/*no action*/}
							else
							{
								size = fontsize + inc;
							}		
						}
						if (fontsize >= default_max_size) //check if font size is not too small
						{
							if(inc==1){/*no action*/}
							else 
							{
								size = fontsize + inc;
							}
						}
						if (fontsize != default_max_size && fontsize != default_min_size) //fontsize is not too large or too small
						{
							size = fontsize + inc;
						}
					}
					if(size)
					{
						document.getElementById(content).style.fontSize = size + "px";
						createCookie(content,size,365);
					}
				}
			}
		}
		if (document.getElementsByTagName('p')) //set paragraph font size
		{
			var p = document.getElementsByTagName('p');
			for(i=0;i<p.length;i++)
			{
				if(inc==0)
				{
					size = default_size + 'px';
					p[i].style.fontSize = size;
				}
				else
				{
					if(p[i].style.fontSize)
					{
						var fontsize = parseInt(p[i].style.fontSize.replace("px",""));
						
						if (fontsize <= default_min_size)
						{
							if(inc==-1){/*no action*/}
							else 
							{
								size = fontsize + inc;
							}		
						}
						if (fontsize >= default_max_size)
						{
							if(inc==1){/*no action*/}
							else 
							{
								size = fontsize + inc;
							}
						}			
						if (fontsize != default_max_size && fontsize != default_min_size)
						{
							size = fontsize + inc;
						}
					}
					if(size)
					{
						p[i].style.fontSize = size + "px";
					}
					createCookie('paragraph',size,365);
				}
			}
		}
	}
}

// Function to read the fontsize cookies and set the right font size while loading the web site
// This function should be called into the function init()
function fontsizeCookie(contents)
{
	var contents = new Array("titel","description");
	for (var i=0; i<contents.length; i++) // for each content ID in array
	{
		var content = contents[i];
		var cookieFontSize = readCookie(content);
		if(cookieFontSize)
		{
			changeFontSize(cookieFontSize,content);
		}
	}
	
	var cookieFontSize = readCookie('paragraph');
	if(cookieFontSize)
	{
		changeFontSize(cookieFontSize,'paragraph');
	}
}


// Function to create a Print Window to print a page
// This function can be called like this: <a href="#" onclick="javascript:CreatePrintWindow();">
function CreatePrintWindow()
{
    var wPrint = window.open('', 'wPrint', 'toolbar=0; status=0; width=800;height=800; scrollbars=yes');
    if (wPrint)
    {
		wPrint.document.write('<html><head>');
		wPrint.document.write('<title>Steigerkaart</title>');

		wPrint.document.write('<link rel="stylesheet" type="text/css" href="/Style%20Library/aeb.css">');
		wPrint.document.write('</head><body>');

		// Example how to print the title of the page in this window:
		if (!document.getElementById('titel') == '')
		{
			wPrint.document.write('<div class="TitleField_print"><br/>');
			var Title = document.getElementById('TitleField');
			wPrint.document.write(document.title);
			wPrint.document.write('</div>');
		}
		// end of Example to print the title of the page in this window
		
		// Example how to print all content in a DIV with ID="stiegerkaart":
		wPrint.document.write(document.getElementById('steigerkaart').innerHTML);
		// end of Example to print the title of the page in this window
		
        wPrint.document.write('</body></html>');
        
		wPrint.document.location.reload(); //reload document.location
		wPrint.focus(); // set the focus the print window
		wPrint.setTimeout('print()', 1500); //call the function print() to display the print dialog
    }
}

// Function to preload images
// This function solves the Image Flickering in IE6
// The function should be called within the init() function

// This function can also be called in a page lay-outs with
// this code: MM_preloadImages('/Style%20Library/Images/image1.jpg','/Style%20Library/Images/image2.jpg')
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 to create a cookie
// The function can be called like: createCookie("fontsize","11",365);
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// Function to read a cookie
// The function can be called like: readCookie("fontsize");
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// Function to delete a cookie
// The function can be called like: eraseCookie("fontsize");
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


// Function to get a parameter from the url in the adress bar
// This function can be called like: getURLParam("company");
// For example: http://www.ettu.nl/pages/default.aspx?company=ettu
function getURLParam(strParamName)
{
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 )
	{
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
		{
			if(aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
			{
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
		return unescape(strReturn);
	}
}

// Function to fills the height of the web site to 100% independant of the screen resolution
// This function should be called in the init()
function SetBodyHeight()
{
	// Variables to get the height and width of the content area in the Browser
	var ContentAreaWidth = 0;
	var ContentAreaHeight = 0;
	
	// Variable with the height of the web site
	var PageHeight = document.getElementById('canvas').offsetHeight;
	
	//Height of MSO_ContentTable
	var MSO_ContentTable = document.getElementById('MSO_ContentTable').offsetHeight;

	//--Get the height and width of the content area in the Browser--//
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		ContentAreaWidth = window.innerWidth,
		ContentAreaHeight = window.innerHeight
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		ContentAreaWidth = document.documentElement.clientWidth,
		ContentAreaHeight = document.documentElement.clientHeight
	}
	// older versions of IE
	else
	{
		ContentAreaWidth = document.getElementsByTagName('body')[0].clientWidth,
		ContentAreaHeight = document.getElementsByTagName('body')[0].clientHeight
	}
	// end of Get window height

	if(PageHeight < ContentAreaHeight)
	{
		var extrasize = ContentHeight-PageHeight;
		document.getElementById('MSO_ContentTable').style.height = MSO_ContentTable + extrasize + 'px';
	}
	else {/*do nothing*/}
	
	if(document.getElementById('MSOTlPn_MainTD')) // Fix the height of page when editing a web part
	{
		document.getElementById('MSOTlPn_MainTD').style.height = 500 + "px";
	}
}

// This function fills a field in a SharePoint Form with a value
// This function can be called like this: getTagFromIdentifierAndTitle("input","TextField","Referrer");
// Above example sets the field 'referrer' with the document.refferer

// tagName – The name of the tag rendered in the form’s HTML 
// identifier – The string associated with the SharePoint type of the relevant field 
// title – The value of the relevant HTML tag’s “title” attribute, which also matches the field’s display name

// More information: http://mysite/personal/m_molegraaf/Blog/Lists/Posts/ViewPost.aspx?ID=32
// More information: http://mysite/personal/m_molegraaf/Blog/Lists/Posts/ViewPost.aspx?ID=33
function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
	var len = identifier.length;
	var tags = document.getElementsByTagName(tagName);
	for (var i=0; i < tags.length; i++)
	{
		var tempString = tags[i].id;
		if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
		{
			tags[i].value = document.referrer;
		}
	}
}

// This function creates on-the-fly rounded corners for any HTML DIV element.
// The function can be used like this:
// 1. include the javaScript curvycorners.js into your masterpage;
// 2. include the function CreateRoundCorners() into the function init() to load automatically on each page;
// 3. Additional settings can be found in the function below.

// -The new 'validTags' setting is optional and allows you to specify other HTML elements that curvyCorners
// can attempt to round.
// -The value is comma separated list of html elements in lowercase:
// for exmaple: validTags: ["div", "form"]
// -The above example would enable curvyCorners on FORM elements.

// Usage:
// -newCornersObj = new curvyCorners(settingsObj, classNameStr);
// -newCornersObj = new curvyCorners(settingsObj, divObj1[, divObj2[, divObj3[, . . . [, divObjN]]]]);

// More information: http://www.curvycorners.net/index.php
function CreateRoundCorners()
{
      settings = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }
      var myBoxObject = new curvyCorners(settings, "myBox"); //classname of the DIV is 'myBox'
      myBoxObject.applyCornersToAll();
}

//ExpandNavigation
function openSubNavigation(id) 
{
	var myheadersub = document.getElementById('headersub'+id);	
	
	//alert(myheadersub.id);
	
	for(var k=1; k < 5; k++) 
	{
		if( document.getElementById('headersub'+k).style.display == "block")
		{
			if( k != id )
			{
				document.getElementById('headersub'+k).style.display = "none";
			}
		}
	}
	//myheadersub.style.display = "block";
	$('#' + myheadersub.id).slideToggle("slow");
}

function closeSubNavigation(id) 
{
	var myheadersub = document.getElementById('headersub'+id);	

	if( myheadersub.style.display == "block")
	{
		//myheadersub.style.display = "none";
		$('#' + myheadersub.id).slideToggle("slow");
	} 
	else {}
}

//Navigation FlyOut//
function rebuildNavigation()
{
	var myMenuItems = $("td[id*='zz1_TopNavigationMenu']");
	var myMenuItemId = '';
	var subHeaderId = 0;
	
	for(var j=0; j < myMenuItems.length; j++) 
	{
		subHeaderId += 1;
		myMenuItemId = myMenuItems[j];
		//set url
		myMenuItemId.getElementsByTagName('a')[0].href = '#';
		//set onmouseover
		myMenuItemId.onmouseenter = new Function('window.tim = setTimeout(\'openSubNavigation(' + subHeaderId + ')\',50)');
		myMenuItemId.onmouseleave = new Function('clearTimeout(window.tim)');
	}
}

//DataView //
//Portfolio Flyout//
function hover(id)
{
	var tmp = document.getElementsByTagName('div');
	var ThisId = '';
	var divId = '';	
	var divName = '';
	
	for(var i = 0;i <= tmp.length; i++)
	{	
		if($(tmp[i]).hasClass("PortfolioItem"))
		{
			ThisId = tmp[i].id;
			divId = ThisId.substring(13);
			divName = 'PortfolioDetails' + divId;
			if(document.getElementById(divName).style.display == "block")
			{				
				if(divId != id)
				{					
					$('#' + divName).slideToggle("slow");					
				}
			}			
		}		
	}		
	$("#PortfolioDetails" + id).slideToggle("slow");	
}

//On Hover kleur mbt Portfolio Items//
function hoverTR(id)
{
	document.getElementById('PortfolioTr' + id).style.backgroundColor = "#cedbf8";
}

function unHoverTR(id)
{
	document.getElementById('PortfolioTr' + id).style.backgroundColor = "#ffffff";
}

