/*
 * init javascript by CCI IT GROEP
 * http://www.cci-itgroep.nl/
 * Copyright (c) 2009 CCI IT GROEP
 */

/*== HideEmptyImages ==*/
function HideEmptyImages()
{	
	/*var regex_1 = new RegExp("(shownoimg)\.gif$");
	
	for (var i=0; i < document.images.length; i++)
	{
		if (regex_1.test(document.images[i].src))
		{
			document.images[i].style.display = "none";
		}
	}*/
	
	$("img.afb_").each(function()
	{
		if ($(this).attr("src").match(/(spacer)\.gif$/))
		{
			$(this).css("display","none");
		}
	});
}
/*== ==*/

/*== displayDate ==*/
/**
  * displayDate display's the current date of today formatted in the element with the className date in the element with the ID hlLeft
  */
function displayDate(elementExpressionToPutDateIn)
{
	var monthNames = [];
	monthNames[0] = "januari";
	monthNames[1] = "februari";
	monthNames[2] = "maart";
	monthNames[3] = "april";
	monthNames[4] = "mei";
	monthNames[5] = "juni";
	monthNames[6] = "juli";
	monthNames[7] = "augustus";
	monthNames[8] = "september";
	monthNames[9] = "oktober";
	monthNames[10] = "november";
	monthNames[11] = "december";
	
	var date = new Date();
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var m = date.getMonth();
	//var month = (m < 10) ? '0' + m : m;
	var month = monthNames[m];
	
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	
	var dateFormatted = day + " " + month + " " + year;
	
	$(elementExpressionToPutDateIn).html(dateFormatted);
}

/*== Cookielogin ==*/
var cUserNameCookie = "WEALOGIN"; 
function SaveCookieOnLogin()
{
	oForm = window.document.forms['frmCustomSecurearea'];
	if (!oForm) 
		return;	
	if (oForm.elements['fldOnthouden'].checked)
		SaveInCookie(cUserNameCookie, oForm.elements['username'].value, oForm.elements['password'].value);
	else
		ClearCookie(cUserNameCookie);
	//oForm.submit(); //vervolgactie...
}
function ReadCookieOnLoad()
{
	oForm = window.document.forms['frmCustomSecurearea'];
	if (!oForm) 
		return;
	//controleer of er een cookie is
	var sCookieValue = ReadFromCookie(cUserNameCookie);

	if (!sCookieValue)
		return;
	//er is een cookie: vul gebruikersnaam en password in, en zet checkbox op checked
	var sItems = sCookieValue.split('~');
	if (sItems[0])
		oForm.elements['username'].value = sItems[0];
	if (sItems[1])
		oForm.elements['password'].value = sItems[1];
	if (sItems[0] && sItems[1])
	{
		oForm.elements['fldOnthouden'].checked = 1;
//		window.document.getElementById('submitLogin').focus(); // werkt dit op browser varianten?
		SaveInCookie(cUserNameCookie, oForm.elements['username'].value, oForm.elements['password'].value);
	}
}
function SaveInCookie(sCookieName, sUserName, sPassword)
{
	var sCookieValue;
	sCookieValue = sUserName + '~' + sPassword;
	document.cookie = sCookieName + '=' + escape(sCookieValue) + ';expires=Fri, 25 Dec 2037 23:59:59 GMT';
}
function ClearCookie(sCookieName)
{
	document.cookie = sCookieName + '=;';
}
function ReadFromCookie(sCookieName)
{
	var start = document.cookie.indexOf(sCookieName + '=');
	if (start == -1 ) return;
	start += sCookieName.length + 1;
	var end = document.cookie.indexOf(';', start);
	if (end == -1)
	{
		end = document.cookie.length;
	}
	var sCookieValue = document.cookie.substring(start, end);
	sCookieValue = unescape(sCookieValue);
	return sCookieValue;
}

/*== ==*/



/*== ==*/

/*== Body onload (jQuery) ==*/
$(document).ready(function()
{
	HideEmptyImages();
	displayDate("#hlLeft .date");
	ReadCookieOnLoad();
});
/*== ==*/


/*== Body onload ==
window.onload = function(e)
{
	HideEmptyImages();
}
/*== ==*/

