window.name = 'windowAlbertHeijn';

if (document.tags) {
    // Fontsize fix for Netscape 4/MacOS9:
    if (navigator && navigator.platform && navigator.appName && 
                    navigator.platform.toLowerCase().indexOf('mac') >= 0 &&
                    navigator.appName.toLowerCase().indexOf('netscape') >= 0) {
            document.tags.TD.fontSize = '11px';
    }
    // Fontsize fix for Netscape 4/Win:
    if (navigator && navigator.platform && navigator.appName && 
                    navigator.platform.toLowerCase().indexOf('win') >= 0 &&
                    navigator.appName.toLowerCase().indexOf('netscape') >= 0) {
            document.tags.TD.fontSize = '70%';
    }
}

// Fontsize fix for MSIE/MacOS9:
function mac_msie_fix()
{
	if (document.getElementById && navigator.appName && navigator.userAgent
		&& navigator.appName.indexOf("Microsoft Internet Explorer") == 0
		&& navigator.userAgent.indexOf("Mac") > 0)
	{
		var set = document.all.tags('TD');
		for (var i = 0; set.length && i < set.length; i++) {
			if (set(i).className != 'mitem') 
				set(i).style.fontSize = '0.69em';
		}
	}
}

// Linker listitems hilighten 
function hi(obj) 
{
	obj.previousClassName=obj.className;
	obj.className = "llistitem_hi";
}

function lo(obj) 
{
	obj.className = obj.previousClassName;
}

// default print button event handler:
function printPage() {
	if (navigator.userAgent.indexOf("Mac") >= 0) {
		alert('De print knop werkt niet op de Mac.' + 
			'\nMaak gebruik van de optie Print in uw menubalk.');
	} else if (navigator.userAgent.indexOf("MSIE 4") >= 0) {
		printIE4();
	} else if (window.print){
		window.print();
	}
}

// IE4 only printing with the SHDOCVW control:
function printIE4() {
	var OLECMDID_PRINT = 6;
	var OLECMDEXECOPT_DONTPROMPTUSER = 2;
	var OLECMDEXECOPT_PROMPTUSER = 1;
	var browsertext = '<OBJECT ID="WebBrowser1" WIDTH="0" HEIGHT="0" CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', browsertext);
	var obj = document.getElementById('WebBrowser1');
	if (obj) {
		if (confirm('Klik op OK om de pagina af te drukken')) {
			// the confirm is a workaround to get it working!
			oldHandler = window.onerror;
			window.onerror = printIE4reset;
			obj.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER);
			obj.outerHTML = '';
			window.onerror = oldHandler;
		}
	}
}

function printIE4reset()
{
	var obj = document.getElementById('WebBrowser1'); 
	if (obj) obj.outerHTML = ''; 
	window.onerror=oldHandler;
	return true;
}

// Flash detect INI

// these are the user defined globals

var requiredVersion = 3;
var useRedirect = false; 			
var flashPage = "movie.html"
var noFlashPage = "noflash.html"
var upgradePage = "upgrade.html"

// system globals
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var maxVersion = 6;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;

//
//
// Javascript support for the Vacature component
//

//
// Submit the form from javascript, 
//
// Arguments are consecutive name value pairs
// for easy notation: CreateSearch('Company', 'albert', 'Functie', 'knakker')
//
function CreateSearch()
{
	if (!document.frmAutoZoek) return
	if (arguments.length < 2) return
	if (arguments.length % 2 == 1) {
		window.status = 'CreateSearch: Fout, ongelijk aantal naam waarde paren'
		return
	}
	var aMessages = new Array()
	var frmElement
	var value;
	for (var i = 0; i < arguments.length;  i += 2) {
		frmElement = eval('document.frmAutoZoek.' + arguments[i])
		value = arguments[i + 1]
		if (frmElement) {
			frmElement.value = value
		} else {
			aMessages[aMessages.length] = arguments[i]
		}
	}
	if (aMessages.length != 0) {
		window.status = 'CreateSearch: Deze velden bestaan niet: ' 
				+ aMessages.join(", ")
		return
	}
	document.frmAutoZoek.submit()
}

//
// Returns true if the form is valid and can be submit
// In case of any errors, this functions creates appropriate error dialogs, 
// and returns false. 
// 
function isValidJobSearch()
{
	if (!document.frmZoek && !document.frmZoek.Postcode) 
		return
	var elm = document.frmZoek.Postcode
	// Trim trailing spaces:
	if (elm.value.length != 0) {
		for (var i = elm.value.length; i != 0; i--) {
			if (elm.value.charAt(i-1) == '\ ' ||
					elm.value.charAt(i-1) == '\t') {
				elm.value = elm.value.substring(0,i-1) 
				// TODO -- inefficient loop
			} else {
				break
			}
		}
	}
	// Works without the two letters.
	// Matches exactly as specified in AH Werk design:
	rePostcodeLenient = /^[0-9]{4}$/i 
	rePostcodeBetter  = /^[0-9]{4}[ 	][A-Z,a-z][A-Z,a-z]$/i 
	rePostcodeBest = /^[0-9]{4}[A-Z,a-z][A-Z,a-z]$/i 
	if (elm.value.length == 0 ||
			!(elm.value.match(rePostcodeBest)
			|| elm.value.match(rePostcodeBetter)
			|| elm.value.match(rePostcodeLenient))) {
		alert('Sorry, je hebt geen geldige postcode ingevuld. \
\nProbeer het nog eens.')
		elm.focus()
		return false
	}
	return true
}

//
// Wrapper for <a href="javascript:goJobSearch()">zoek</a> hyperlinks
//
function goJobSearch()
{
	if (isValidJobSearch()) {
		document.frmZoek.submit();
	}
}

function printImageNotFound(strDocid) {
	var docloc = new String(document.location.href)
	docloc = docloc.replace(/[:\.\/&?=\"\']/g, '_')
	document.write('<img src="http://nl.sitestat.com/ahold/ah/s?website.error.imagenietgevonden.' + strDocid + '_' + docloc + '" align="top" width="0" height="0" border="0">')
}

/* global.js */
