function checkNoDate(theField,s){
	var pattern = new RegExp("[0-3][0-9]-0|1[0-9]-19|20[0-9]{2}");
	return true;
}

function checkDate(theField,s){
	// Regular expression used to check if date is in correct format
	var pattern = new RegExp("[0-3][0-9]/0|1[0-9]/19|20[0-9]{2}");
	if (theField.value.match(pattern)) {
		var date_array = theField.value.split('/');
		var day = date_array[0];
		// Attention! Javascript consider months in the range 0 - 11
		var month = date_array[1] - 1;
		var year = date_array[2];
		// This instruction will create a date object
		source_date = new Date(year,month,day);
		if((year != source_date.getFullYear()) || (month != source_date.getMonth()) || (day != source_date.getDate()))
		return warnWrong(theField, s, 'Invalid date format (dd/mm/yyyy)');
		}
	else return warnWrong(theField, s, 'Invalid date format (dd/mm/yyyy)');
	return true;
}

function closeWindow(){
	var prKey = window.event.keyCode;
	if ((prKey == 27) || (prKey == 8))
		window.close();
	return true;
}

function checkCaller(){
	if (!window.opener){
		window.onerror = null;
    window.alert ('This page is supposed to be called from another program ...');
    return;
	}
}

function openWindow(title,show,id){
   window.open("popup.asp?show=" + show + "&id=" + id,
	 	title,"toolbar=no,menubar=no,location=no,scrollbars=1,directories=no,resizeable=no,width=720,height=500,left=100,top=100");
}

function calcPayment(){
var discount = 0;
var readOnly = document.getElementById("readOnly").value;
//Calculate the price as the sum of participation and accommodation
	var earlyText = document.getElementById("early").value;
/*
	var hotelValue  = document.getElementById("hotel").value;
	var hotDep = 150;
	if (hotelValue.replace('&#8364;','€')=="0_0_€0") hotDep = 0;
	var H_price = parseInt(hotDep);
*/
	var H_price = 0;
	var A_price = 0;
	var C_price = 0;
	early = new Array();
	early[1] = 670;
	early[2] = 0;
	early[3] = 0;
	early[4] = 0;
	late = new Array();
	late[1] = 750;
	late[2] = 0;
	late[3] = 0;
	late[4] = 0;
	//Count accompanying persons and add for their participation in Reception and Dinner
	/*
	var accomp = 2;
	if (isEmpty(trimAll(document.getElementById("accFirst").value))) accomp = accomp - 1;
	if (isEmpty(trimAll(document.getElementById("accSecond").value))) accomp = accomp - 1;
	A_price = accomp * 80;
	*/
	//	No extra fee for accompanying persons joining Icebreaker reception and Social dinner	
	//	if (document.getElementById("accWelcome").checked ) A_price = A_price + accomp * 20;
	//	if (document.getElementById("accDinner").checked ) A_price = A_price + accomp * 90;
	//Conference fee
	var typ = parseInt(document.getElementById("regType").value);
	if (earlyText == 'Yes')
		C_price = early[typ];
	else C_price = late[typ];
	// Short courses A and B - all pay
	if ((document.getElementById("accWelcome").checked)) C_price = C_price + 300; // Short course A
	if ((document.getElementById("accCityHall").checked)) C_price = C_price + 200; // Short course B
	// Meet and greet - organisers don't pay
	// Now free for all
	// if ((document.getElementById("iceBreaker").checked) && (typ !== 4)) C_price = C_price + 40; // Meet and greet
	// Excursions - organisers don't pay
	if ((document.getElementById("accDinner").checked) && (typ !== 4)) C_price = C_price + 60; // Excursion by bus
	if ((document.getElementById("dinner").checked) && (typ !== 4)) C_price = C_price + 35; // Excursion by boat
	//Company stand - all pay
	if ((document.getElementById("cityHall").checked)) C_price = C_price + 600; // Company stand
	
	var price = H_price + A_price + C_price;
	//Exchange rate April 19 at XE.COM using converter calculator
	var priceDKK = parseInt(price * 7.44252);
	/*
	document.getElementById("H_price").innerHTML = 'Hotel booking, calculated deposit = EUR ' + H_price;
	document.getElementById("A_price").innerHTML = 'Accompanying persons, calculated fee = EUR ' + A_price;
	*/
	document.getElementById("C_price").innerHTML = 'Conference registration, calculated fee = EUR ' + C_price;
/*
	document.getElementById("sub3").innerHTML = H_price;
	document.getElementById("sub2").innerHTML = A_price;
	document.getElementById("sub1").innerHTML = C_price;
*/
	document.getElementById("totalPrice").innerHTML = price;
	document.getElementById("totalPriceDKK").innerHTML = 'DKK ' + priceDKK;
	document.getElementById("totalDanishPrice").innerHTML = 'DKK ' + priceDKK;
/*
	document.getElementById("cur1").innerHTML = 'EUR';
	document.getElementById("cur2").innerHTML = 'EUR';
	document.getElementById("cur3").innerHTML = 'EUR';
*/
	document.getElementById("cur4").innerHTML = 'EUR';
	document.getElementById("grandTotal").value = 'EUR ' + price;
	return true;
}

function checkPaper(theForm) {
	if  ((checkString(theForm.pTitle,"Paper title"))
		&& (checkString(theForm.pAuthor,"Principal author"))
		&& (checkString(theForm.pPresenter,"Paper presented by"))
		&& (checkCombo(theForm.country,"Presenter country"))
		&& (checkEmail(theForm.pEmail,"Presenter E-mail address"))
		&& (checkWordPdf(theForm.fileName,"File name"))
	)
		return true;
	else return false;
}

function checkAbstract(theForm) {
	if  ((checkString(theForm.aTitle,"Abstract title"))
		&& (checkString(theForm.aAuthor,"Principal author"))
		&& (checkRadio(theForm.presentation,"Prefered presentation"))
		&& (checkWordPdf(theForm.fileName,"File name"))
	)
		return true;
	else return false;
}

function checkUpload(theForm) {
	if  (checkWordPdf(theForm.fileName,"File name"))
		return true;
	else return false;
}

function checkRegistration(theForm) {
	if (document.getElementById("totalPrice").innerHTML == '0')
		return true;
	else {
		if (checkRadio(theForm.payment,"your payment method"))
			return true;
		else return false;
	}
}

function checkMail(theForm) {
	if ((checkString(theForm.subject,"A subject for your mail"))
	&& 	(checkString(theForm.body,"Your mail message"))
	)
		return true;
	else return false;
}

function checkLogin() {
	if ((checkEmail(document.all["logusr"],"User name ")))
		return true;
	else return false;
}

function askConfirm(qst)
{
	return confirm(qst)
}

function setAmount00(theField){
	document.getElementById("Amount").value = theField.value + '00';
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
		}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
}

function checkArea(theField,msgFld,len) {
	if (document.getElementById(msgFld) != null){
		var characters = theField.value
		var msg = characters.length + "/" + len
		if (characters.length < len)
			document.getElementById(msgFld).innerHTML = "[" + msg + "]"
		else {
			if (characters.length > len) {
				alert("This field can only hold " + len + " characters. Any excess characters are discarded.");
				theField.value = characters.substring(0,len);
				characters = theField.value
				msg = characters.length + "/" + len
			}
			document.getElementById(msgFld).innerHTML = "<span class=red>[" + msg + "]</span>"
		}
	}
} 

function checkRadio(theField,what){
var sRadio = -1;
    for (var i=0;i<theField.length;i++){
      if (theField[i].checked){
        sRadio = theField[i].value;
        break;
      }
    }
	if (sRadio == -1) {
		alert("Please indicate " + what);
		return false;
	}
	else {
		return true;
	}
}

function checkCopy(theForm) {
	if  (checkString(theForm.title,"New menu entry"))
		return true;
	else return false;
}

function startTimeout(loginStatus){
	if (loginStatus > 0){
		oneSecond = window.setTimeout("timeoutCheck();",1000);
	}
}

function timeoutCheck() {
	elapsedTime = elapsedTime + 1;
	if (elapsedTime > minusFive) {
		alert('Your session will timeout in 5 minutes. Please save your work or refresh the screen to stay logged in.');
	}
	else {
		oneSecond = window.setTimeout("timeoutCheck();",1000);
	}
}

function doSubmit() {
	document.forms[0].submit();
}

function redirect(page) {
	window.location.href = page;
}

//Setup for htmlArea Editor
_editor_url = "/inc/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }

function checkUserInfo(theForm) {
	if ((checkString(theForm.firstName,"First name"))
	&& 	(checkString(theForm.lastName,"Last name"))
	&& 	(checkString(theForm.organisation,"Organisation"))
	&& 	(checkCombo(theForm.country,"Country"))
	&& 	(checkEmail(theForm.eMail,"E-mail address")) )
		return true;
	else return false;
}

function checkNewPsw(theForm){
	if ((checkString(theForm.oldPsw,"Old password"))
	&&	(checkStringLength(theForm.newPsw,"New password",8))
	&& 	(checkMatch(theForm.newPsw,theForm.newPswChk)) )
		return true;
	else return false;
}

function checkLogon(theForm) {
//Check required values for creation of new account
	if ((checkEmail(theForm.emailaddress,"E-mail address"))
	&& 	(checkString(theForm.password,"Password")) ) 
		return true;
	else return false;
}

// Generic functions

var whitespace = " \t\n\r";

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

function isInteger (s) {
	var i;
	if (isEmpty(s)) 
		return false;
  for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}

function isEmpty(s) {
	return  ((s == null) || (s.length == 0));
}

function isWhitespace (s) {
	var i;
	if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++) {   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	} 
	return true;
}

function warnEmpty(theField, s){
	theField.focus();
	theField.select();
	alert("Please enter information in the required field <" + s + ">");
	return false;
}

function warnNoSelect(theField, s){
	theField.focus();
	alert("Please make a selection in the required field <" + s + ">");
	return false;
}

function warnWrong(theField, s, msg){
	theField.focus();
	alert("Please enter proper information in the required field <" + s + "> [" + msg + "]");
	return false;
}

function checkInteger (theField, s){   
	if (isInteger(theField.value))
		return true;
	else return warnEmpty(theField, s);
}

function checkString(theField, s) {
	if (isWhitespace(theField.value)) 
		return warnEmpty(theField, s);
	else return true;
}

function checkWordPdf(theField, s) {
	if (isWhitespace(theField.value)) 
		return warnEmpty(theField, s);
	else {
		var x = theField.value;
		var wordFilter = /([a-z0-9_\-]*\.doc)/i;
		var pdfFilter = /([a-z0-9_\-]*\.pdf)/i;
		if ((wordFilter.test(x)) || (pdfFilter.test(x)))
			return true;
		else return warnEmpty (theField, s+"  (Your entry is NOT a valid .DOC or .PDF file)");
	}
}

function checkStringLength(theField, s, len) {
	if (checkString(theField, s, false)) {
		if (theField.value.length > len-1)
			return true;
		else return warnEmpty (theField, s+" (at least "+ len +" characters)");
	}
	else return false;
}

function checkEmail(theField, s)
{
	var x = theField.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return warnEmpty (theField, s+"  (Your entry is NOT a valid E-mail address)");
}

function checkMatch(psw1, psw2) {
	if (psw1.value==psw2.value)
		return true;
	else return warnEmpty (psw1, " New password (the two passwords are not identical)");
}

function checkCombo(theField, s) {
//Do not allow first option, e.g. Please select a country
	if (theField.selectedIndex == 0)
		return warnNoSelect(theField, s);
	else return true;
}

function setFocus(loginStatus) {
// If document contains a form, set focus to first text element within first form
	if (document.forms.length != 0) {
		for (var i=0;i<document.forms[0].elements.length;i++) {
			if ((document.forms[0].elements[i].type == "text") ||
					(document.forms[0].elements[i].type == "password") ) {
				document.forms[0].elements[i].focus();
				document.forms[0].elements[i].select();
				break;
			}
		}
	}
//	document.oncontextmenu=new Function("return false;")
	startTimeout(loginStatus);
}

function emailCrypt(partOne, partTwo, partThree) {
	document.location.href = 'mailto:' + partOne + '@' + partTwo + '.' + partThree;
}

var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';

		var printWin = window.open("","printSpecial","left=150,top=130,scrollbars=1,width=720,height=500");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (gAutoPrint)
			printWin.print();

	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}