// <SCRIPT>
<!-- //
// 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 ) ))  
					// 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 = 'skal indeholde en gyldig email-adresse';
			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 strMsgIsNum = '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 strMsgIsNum = '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.type == "checkbox" || objField.type == "radio" || objField[1].type == "checkbox" || objField[1].type == "radio")
					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 ) || ((objField.type == "checkbox" || objField.type == "radio") && objField.checked == false)) { // 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
						if (valField != '' + parseFloat(valField)) 
							strErrors += '- ' + strFieldAlertText + ' (' + strMsgIsNum + ')\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 fncGetRadioValue(aryName){
		var aryFields;
		var objValue = '';
		aryFields = fncFindObj(aryName);
		if (aryFields) {
			if (aryFields.checked) // Mark if only one radiobutton exists i.e. there is no array (possible in dynamic arrays)
				objValue = aryFields.value;
			else
				for (n = 0; n < aryFields.length; n++)
					if (aryFields[n].checked)
						objValue = aryFields[n].value;
			return objValue;
		}
	}


// SEARCH FOR A TERM IN A TARGET STRING AND REPLACE IT
	// replace(targetString,oldTerm,newTerm,caseSensitive,wordOrSubstring) 
	// where caseSenstive is a boolean value and wordOrSubstring is a boolean
	// value and true means whole words, false means substrings

	function replace(target,oldTerm,newTerm,caseSens,wordOnly) {

		var work = target;
		var ind = 0;
		var next = 0;

		if (!caseSens) {
			oldTerm = oldTerm.toLowerCase();
			work = target.toLowerCase();
		}

		while ((ind = work.indexOf(oldTerm,next)) >= 0) {
			if (wordOnly) {
				var before = ind - 1;
				var after = ind + oldTerm.length; 
				if (!(space(work.charAt(before)) && space(work.charAt(after)))) {
					next = ind + oldTerm.length; 
					continue;
				}
			}
			target = target.substring(0,ind) + newTerm + 
			target.substring(ind+oldTerm.length,target.length); 
			work = work.substring(0,ind) + newTerm + 
			work.substring(ind+oldTerm.length,work.length); 
			next = ind + newTerm.length;
			if (next >= work.length) { break; } 
		}

		return target;
	}

	function space( chrChar ) {
		if ( ' ' == chrChar || 'x-' == chrChar || '.' == chrChar || ',' == chrChar )
			return true;
		else
			return false;
	}


// COOKIE FUNCTIONS

	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
		return (cookiePosInArray != -1);
	}

	function clearCookie(cookieName){
		var a=new Date();
		document.cookie = cookieName + "=; path=/; expires=" + a.toGMTString();
		document.location = "/";
	}
	
	function returnCookie(cookieName) {
		var cookieArray = document.cookie.split('; ');
		for(var i=0;i<cookieArray.length;i++){
			if(cookieArray[i].split('=')[0]==cookieName)
				return cookieArray[i].split('=')[1];
		}
	}

// --></SCRIPT>
