function sfHover() 
{
	var sfEls,
		nav;
		
	if ((nav = document.getElementById("nav")) != null)
	{
		if ((sfEls = nav.getElementsByTagName("li")) != null)
		{
			for (var i = 0; i < sfEls.length; i++) 
			{
				sfEls[i].onmouseover = function() 
				{
					this._className = this.className;
					this.className += " sfhover";
				}
				sfEls[i].onmouseout = function() 
				{
					this.className = this._className;
				}
			}
		}
	}
}
	
function DownloadDocument(documentID, whitelabel)
{
	window.location.href = applicationPath + whitelabel + "/whitepaper/download/" + documentID;
}
	
function OnChangeLanguage(language)
{
	var expr,
		url,
		m;
	
	url = window.location.href;
	expr = /(.)(lang=\w+)/i;
	if ((m = url.match(expr)) == null)
		url += (window.location.search.length == 0 ? "?" : "&") + "lang=" + language;
	else
		url = url.replace(expr, m[1] + "lang=" + language);

	window.location.href = url;
}

function OnSetFontSize(size)
{
	var expr,
		url,
		m;
	
	url = window.location.href;
	expr = /(.)(fontsize=\w+)/i;
	if ((m = url.match(expr)) == null)
		url += (window.location.search.length == 0 ? "?" : "&") + "fontsize=" + size;
	else
		url = url.replace(expr, m[1] + "fontsize=" + size);

	window.location.href = url;
}

function ShowInfo()
{
	if (document.getElementById('info_text').className != 'info_text_closed')
		document.getElementById('info_text').className = 'info_text_closed';
	else
		document.getElementById('info_text').className = 'info_text_open';
}	

function Login()
{
	SetReload(true);
	Submit(99, "login");
}

function Logoff()
{
	var returnUrl,
		url;
	returnUrl = sVRoot + "/";
	// If a returnURL is available, return to the page from which we called the Logoff function
	if ((url = document.getElementById("returnurl")) != null)
		returnUrl = url.value;
	SetRedirect(true);
	AddSubmitParameter("returnurl", returnUrl);
	Submit(99, "logoff");
}

function ShowLogin() 
{
	var div;
	if ((div = document.getElementById('login')) != null) {
		if (div.style.display == 'block')
			div.style.display = 'none';
		else
			div.style.display = 'block';
	}
}

function TellAFriend()
{
	window.open('TellAFriend.aspx?url=' + window.location.href,"","dialog=yes, width=500, height=360, scrollbars=no, status=no");			
}

function ToggleInterests(checked) {
    var sfEls,
		interests;

    if (checked) {
        if ((interests = document.getElementById("interests")) != null) {
            if ((sfEls = interests.getElementsByTagName("input")) != null) {
                for (var i = 0; i < sfEls.length; i++) {
                    if (sfEls[i].type == "checkbox")
                        sfEls[i].checked = false;
                    else
                        sfEls[i].value = false;
                }
            }
        }
    }
}

function ToggleOptin(checked) {
    var optin;

    if (checked) {
        if ((optin = getElementByAlias("_optinmarqit")) != null) {
            optin.checked = false;
            document.getElementById('hidden_' + optin.id).value = true;
        }
    }
}

function QuickLogin(e) {
	var event = window.event;

	if (event.keyCode == 13) {
		Login();
	}
}

function QuickSiteSearch(e) {
		var event = window.event;

		if (event.keyCode == 13) {
				SiteSearch(document.getElementById('1010'),	document.getElementById('1111'));
				event.returnValue = false;
		}
}

function SiteSearch() {
	var conditionElement,
		condition,
		element,
		type;

	if ((element = getElementByAlias("searchtype")) != null) {
		type = element.value;
		
		condition = "";
		if ((conditionElement = getElementByAlias("condition")) != null)
			condition = conditionElement.value;

		window.location.href = applicationPath + "sitesearch.aspx?condition=" + condition + "&searchtype=" + type;
	}
}

function Register() {
	window.location.href = applicationPath + "register.aspx?returnurl=" + getElementByName("returnurl").value;
}

function IntPhoneNumberValidator(id, s) {
	var stripped,
			valid,
			e,
			c;

	c = GetValue('businessaddress.country');
	if (typeof (c) == "undefined" || c == "")
		c = "NL";

	valid = false;
	if ((e = getElementByID(id)) != null) {
		stripped = e.value.replace(/[\(\.\-\ ]/g, '');
		valid = UpdateMessage(e, s, stripped.length == 0 || (isNaN(parseInt(stripped)) == false &&
					c == "BE" ? stripped.length >= 8 && stripped.length <= 10 : stripped.length == 9),
				true);
	}
	else
		alert("IntPhoneNumberValidator: element with id '{0}' not found".replace("{0}", id));

	return valid;
}

