<!-- //
// ONLOAD

	function fncOnLoad() { 
		// Changes target on external links and media
		// To use this function add this in all body tags: onload="fncOnLoad()"
		if (!(null==document.links) && document.links.length>0) {
			for (i=0;i<document.links.length;i++) {
				if ( document.links[ i ].hostname > '' && 'http:' == document.links[ i ].protocol && (document.links[ i ].pathname.toLowerCase().indexOf('showmedium.asp')>0 || document.links[ i ].pathname.toLowerCase().indexOf('edia(')>0 || document.links[ i ].pathname.toLowerCase().indexOf('.pdf')>0 || (document.links[ i ].hostname.toLowerCase().indexOf(document.location.hostname)==-1 && document.location.hostname.toLowerCase()!='www.kultunaut.dk' && document.links[ i ].hostname.toLowerCase()!='www.kultunaut.dk') ))  
					// Change link target to siteExtern
					document.links[ i ].target = 'siteExtern';
			}
		}
	}

// Global functions

	function getArgs(){	
		var	args = new Object(); 
		var	query =	location.search.substring(1); 
		var	pairs =	query.split("&"); 
		for	(i=0;i<pairs.length;i++){ 
			var pos	= pairs[i].indexOf('='); 
			if (pos	== -1) continue; 
			var argname = pairs[i].substring(0,pos); 
			var value = pairs[i].substring(pos+1); 
			args[argname] = unescape(value); 
		} 
		return args;	
	} 

	var args = getArgs();

	function fncValidateForm(aryArgs, lngLCID)  { //v3.0 browsers
		// This function validates forms
		// The input is an array of arguments with 3 arguments per form field
		// The array must have this syntax: 'Form field name', 'Text to alert in case of error', 'Type of validation'
		// Example: 'companyName', 'Company name', 'R', 'email', 'Email', 'RisEmail'
		// Requires the function fncFindObj()
		// Version 1.0, dec 2000, by Søren Larsen
		var objField; // The form field object matching the given field name
		var strFieldAlertText; // The given text that represent the form field in the alert box
		var strTypeOfValidation; // The given validation string
			// Possible values: 
			// - R - input is required
			// - RisEmail - input is required, must be an email address (one or more characters + @ + 3 or more characters and at least one dot after the first lette after the @)
			// - NisEmail - input is NOT required, but if input is given it must be an email address
			// - RisChecked2:3 - input is required, between 2 and 3 of the checkboxes must checked
			// - NisChecked0:3 - input is not required, no more that 3 of the checkboxes can be checked
			// - RisNum - input is required, must be a number
			// - NisNum - input is NOT required, but if input is given it must be a number
			// - RinRange10:400 - input is required, must be a number in this case in the range 10 to 400
			// - NinRange1:5 - input is NOT required, but if input is given it must be a number in this case in the range 1 to 5
		var i;	// Counter for iterations
		var pAt;	// Pointer for email '@'
		var pDot;	// Pointer for email '.'
		var lngCheckedFields; // Count number of checked checkboxes
		var n; // Counter for array of checkboxes / radio buttons
		var pColon;	// Pointer for ':' in numeric ranges
		var lngMin;	// Minimum value for numeric ranges
		var lngMax;	// Maximum value for numeric ranges
		var strErrors = ''; // Used to build string for alert box

		if (lngLCID == 1030) {
			var strMsgGeneral1 = 'Du mangler at udfylde nogle felter.';
			var strMsgGeneral2 = 'Udfyld venligst:';
			var strMsgGeneral3 = 'og send formularen igen.';
			var strMsgIsEmail = 'adressen er ugyldig. Prøv venligst igen.';
			var strMsgIsChecked1 = ' (du må ikke markere flere end ';
			var strMsgIsChecked2 = ' (du skal markere mindst ';
			var strMsgIsChecked3 = ' (du skal markere ';
			var strMsgIsChecked4 = ' (du skal markere mellem ';
			var strMsgIsChecked5 = ' af checkboksene';
			var strMsgNumeric = 'skal være et tal';
			var strMsgInRange1 = ' (skal være et tal mellem ';
			var strMsgAnd = ' og ';
		}
		else {
			var strMsgGeneral1 = 'You need to specify aditional information.';
			var strMsgGeneral2 = 'Please fill in:';
			var strMsgGeneral3 = 'and submit again.';
			var strMsgIsEmail = 'must contain a valid e-mail address';
			var strMsgIsChecked1 = ' (you must check no more than ';
			var strMsgIsChecked2 = ' (you must check at least ';
			var strMsgIsChecked3 = ' (you must check ';
			var strMsgIsChecked4 = ' (you must check between ';
			var strMsgIsChecked5 = ' of the checkboxes';
			var strMsgNumeric = 'must contain a number';
			var strMsgInRange1 = ' (must contain a number between ';
			var strMsgAnd = ' and ';
		}

		for (i = 0; i < (aryArgs.length - 2); i += 3) { 
			objField = fncFindObj(aryArgs[i]);
			if (objField) { 
				valField = objField.value;
				strFieldAlertText = aryArgs[i+1];
				strTypeOfValidation = aryArgs[i+2]; 

				// save status of array of checkboxes or radio buttons in variable.
				lngCheckedFields = 0
				if (objField.checked) // Mark if only one checkbox exists i.e. there is no array (possible in dynamic arrays)
					lngCheckedFields = 1;
				else
					for (n = 0; n < objField.length; n++)
						if (objField[n].checked)
							lngCheckedFields++;

				if ((valField == '') || (valField == null && lngCheckedFields == 0 )) { // If no input was given
					if (strTypeOfValidation.charAt(0) == 'R') { // and input is required
						strErrors += '- ' + strFieldAlertText + '\n'; //build error string
					}
				}
				else { // Input was given
					if (strTypeOfValidation.indexOf('isEmail') != -1) { 
						pAt = valField.indexOf('@')
						pDot = valField.indexOf('.', pAt)
						if (pAt < 1 || pAt == (valField.length - 3) || pDot < 1|| pDot == (valField.length - 1) )
							strErrors += '- ' + strFieldAlertText + ' (' + strMsgIsEmail + ')\n';
					}
					else if (strTypeOfValidation.indexOf('isChecked') != -1) {
						pColon = strTypeOfValidation.indexOf(':');
						lngMin = strTypeOfValidation.substring( 10, pColon ); 
						lngMax = strTypeOfValidation.substring( pColon + 1 );
						if (lngCheckedFields < lngMin || lngMax < lngCheckedFields) {
							if (lngMin == 0)
								strErrors += '- ' + strFieldAlertText + strMsgIsChecked1 + lngMax + strMsgIsChecked5 + ')\n';
							else if ((lngMax == 9999) && (lngCheckedFields > 9998)) //9999 means unlimited
								strErrors += '- ' + strFieldAlertText + strMsgIsChecked2 + lngMin + strMsgIsChecked5 + ')\n';
							else if (lngMin == lngMax)
								strErrors += '- ' + strFieldAlertText + strMsgIsChecked3 + lngMin + strMsgIsChecked5 + ')\n';
							else
								strErrors += '- ' + strFieldAlertText + strMsgIsChecked4 + lngMin + strMsgAnd + lngMax + strMsgIsChecked5 + ')\n';
						}
					}
					else if (strTypeOfValidation != 'R') { // The rest of the validation types are numeric
						valField = valField.replace(/\ /, "");
						if (valField != '' + parseFloat(valField)) 
							strErrors += '- ' + strFieldAlertText + ' (' + strMsgNumeric + ')\n';
						else { // Value is a number
							if (strTypeOfValidation.indexOf('inRange') != -1) { 
								pColon = strTypeOfValidation.indexOf(':');
								lngMin = strTypeOfValidation.substring( 8, pColon ); 
								lngMax = strTypeOfValidation.substring( pColon + 1 );
								if (lngMin*1 > valField*1 || valField*1 > lngMax*1){
									strErrors += '- ' + strFieldAlertText + strMsgInRange1 + lngMin + strMsgAnd + lngMax + ')\n';
								}
							}
						} 
					} 
				}
			} // Field not found
		} // End of loop
		if (strErrors) {
			alert(strMsgGeneral1 + '\n\n' + strMsgGeneral2 + '\n' + strErrors + '\n' + strMsgGeneral3 + '\n\n');
		}
		document.blnReturnValue = (strErrors == '');
		return (strErrors == '');
	}

	function fncFindObj(strFormFieldName, d) { //v3.0
		var p, i, x;

		if (!d) 
			d = document; 
		if ((p = strFormFieldName.indexOf("?") ) > 0 && parent.frames.length) {
			d = parent.frames[strFormFieldName.substring(p + 1)].document; 
			strFormFieldName = strFormFieldName.substring(0, p);
		}
		if (! (x = d[strFormFieldName]) && d.all) 
			x = d.all[strFormFieldName]; 
		for (i = 0; ! x && i < d.forms.length; i++) 
			x = d.forms[i][strFormFieldName];
		for (i = 0; ! x && d.layers && i < d.layers.length; i++) 
			x = fncFindObj(strFormFieldName,d.layers[i].document); 
		return x;
	}


	function loadFormFromCookies( frmHtmlForm  ) {
		var aryCookieValues = document.cookie.split('; ');
		for (var i=0; i<aryCookieFormFields.length; i++)
			for (var j=0; j<aryCookieValues.length; j++)
				if (aryCookieFormFields[i] == unescape(aryCookieValues[j].split('=')[0]))
					frmHtmlForm[ aryCookieFormFields[i] ].value = unescape(aryCookieValues[j].split('=')[1]);
	}
	
	function saveFormToCookies(frmHtmlForm) {
		for (var i=0; i<aryCookieFormFields.length; i++)
			if (null != frmHtmlForm[ aryCookieFormFields[i] ] && null != frmHtmlForm[ aryCookieFormFields[i] ].value && frmHtmlForm[ aryCookieFormFields[i] ].value > '')
				document.cookie = aryCookieFormFields[i] + '=' + escape(frmHtmlForm[ aryCookieFormFields[i] ].value) + '; expires=Mon, 03-Jan-2011 00:00:00 GMT';
	}

	function cookieExists(cookieName) {
		var allCookies = document.cookie;
		var cookiePosInArray = allCookies.indexOf(cookieName);
			// If the index is found, the cookie exist
		if (cookiePosInArray != -1)
			return true;
		else
			return false;
	}
	

	//Security function - transfers update information through cookies
	//
	function setCookie(name,value,expire){
		document.cookie = name + "=" + value + "; path=/;";
	}
	
	function clearCookies(){
		a=new Date();
		document.cookie = "user=; path=/; expires="+a.toGMTString();
		document.cookie = "userName=; path=/; expires="+a.toGMTString();
		document.cookie = "admin=; path=/; expires="+a.toGMTString();
		document.cookie = "active=; path=/; expires="+a.toGMTString();
		parent.location = strWEBRoot
	}
	
// -->
