function SetSubmittedDate(strGroupName){
	var elmDay = document.forms[0].elements['fmDay_' + strGroupName]
	var elmMonth = document.forms[0].elements['fmMonth_' + strGroupName]
	var elmYear = document.forms[0].elements['fmYear_' + strGroupName]
	var strMonth = elmMonth[elmMonth.selectedIndex].value
	var strYear = elmYear[elmYear.selectedIndex].value
	var strDay;
	
	if(elmDay.type == 'select-one' ){
		strDay = elmDay[elmDay.selectedIndex].value
	}
	else{
		strDay = elmDay.value;
	}
	var testDate = new Date(strYear,strMonth-1,strDay)
	//alert(testDate)
	if(testDate.getMonth() != strMonth-1){
		alert('Not a valid date')
	}
	else{
		//document.forms[0].elements['fmDate_' + strGroupName].value = strMonth + '/' + strDay + '/' + strYear
		document.forms[0].elements['fmDate_' + strGroupName].value = strDay + '-' + strMonth + '-' + strYear
	}
}

function OpenHelpWindow(strPosition){
	var RosterHelpWin = window.open('/RosterV2/RosterV2Help.html#Help' + strPosition, 'RosterHelpWin','height=300,width=300,scrollbars=yes');
	RosterHelpWin.focus();
}

function resizeIframe(strId){
//alert(document.body.offsetHeight)
	if(document.all){
		window.parent.document.getElementById(strId).style.height = document.body.scrollHeight + 0 + 'px'
	}
	else{
		
		window.parent.document.getElementById(strId).style.height = document.body.offsetHeight + 10 + 'px'
	}
}

function testDates(strFieldFrom, strFieldTo, strMessage){
	var strDatFrom = document.forms[0].fmDate_fmDateFrom.value;
	var strDatTo = document.forms[0].fmDate_fmDateTo.value;
	
	if(parseDateString(strFieldFrom).valueOf() > parseDateString(strFieldTo).valueOf()){
		alert(strMessage);
		return false;
	}
	else{
		return true;
	}
				
}
	
function parseDateString(strField){
	
	var strDat = document.forms[0].elements[strField].value;
	var strYear = strDat.substring(strDat.lastIndexOf('-')+1);
	var strDay = strDat.substring(0, strDat.indexOf('-'));
	var strMonth = strDat.substring(strDat.indexOf('-') + 1, strDat.lastIndexOf('-'))
	var datDate = new Date(strYear, strMonth-1, strDay);
	return datDate;
}



//----------------------------------------------------------------------------------//
//----------------------   form validation Start  ---------------------------------//

function validateForm(frmForm,objTest){
	
	try{
			
			
			objTest.alert = ""
			
			for(i=0;i<objTest.content.length;i++){
				var objFormElement = ''
				objFormElement = document.forms[frmForm.name].elements[objTest.content[i].fieldName]

				//alert(objFormElement.name)
				

				strValue = ''
				strValue =objFormElement.value

				
				
				if(objFormElement.type != 'select-one' && objFormElement.type != 'select-multiple'){
					if(strValue != null){
						strValue = _TrimSpaces(strValue)
					}
					else{
						strValue = ""
					}
				}
				//alert(strValue)
				switch(objTest.content[i].type){
					case 1:
						objTest.isNumeric(strValue)
					break;
					case 2:
						objTest.isEmpty(strValue)
					break;
					case 3:
						objTest.maxStringLength(objTest.content[i].param,strValue)
					break;
					case 4:
						objTest.minStringLength(objTest.content[i].param,strValue)
					break;
					case 5:
						objTest.IsOptionSelected(objFormElement)
					break;
					case 6:
						objTest.IsNotThisValue(objTest.content[i].param,strValue)
					break;
					case 7:
						objTest.isInMask(objTest.content[i].param,strValue)
					break;
					case 8:
						objTest.isEmail(strValue)
					break;
					case 9:
						objtest.IsTorDate(strValue)
					break;
				}
			}
			for(i=0;i<objTest.content.length;i++){
				if(objTest.content[i].valid == false){
					objTest.alert += objTest.content[i].alert + '\n' 
				}
			}

			var isFormValid = new Boolean(true);

			for(i=0;i<objTest.content.length;i++){
				if(objTest.content[i].valid == false){
					isFormValid = false;
					selectInputField(objTest,frmForm);
					break;
				}
				else{
					isFormValid = true;
				}
			}

			if(isFormValid == false){
				alert(objTest.alert)
				return false;
			}
			else{
				//alert("hurra")
				return true
				//return false;
			}

		// private Functions start
			function _TrimSpaces(strStr){
				var testStr = strStr
				while(testStr.charCodeAt(0) == 32){
					testStr = testStr.substr(1,testStr.length)
				}
				while(testStr.charCodeAt(testStr.length-1) == 32){
					testStr = testStr.substr(0,testStr.length-1)
				}
				return testStr
			}
			function selectInputField(objTest,frmForm){
				for(i=0;i<objTest.content.length;i++){
					if(objTest.content[i].valid == false && objTest.content[i].SelectAfterTest == 1){
						document.forms[frmForm.name].elements[objTest.content[i].fieldName].focus()
						if(document.forms[frmForm.name].elements[objTest.content[i].fieldName].type != 'select-one' && document.forms[frmForm.name].elements[objTest.content[i].fieldName].type != 'select-multiple'){
							document.forms[frmForm.name].elements[objTest.content[i].fieldName].select();
						}
						break;
					}
				}
			}
		// private Functions end

	}catch(err){
		alert(err.description)
		return false
	}
}

function validationBase(){
	this.content = new Array()
	this.add = add;
	this.alert = '';
	this.isNumeric = isNumeric;
	this.isEmpty = isEmpty;
	this.maxStringLength = maxStringLength;
	this.minStringLength = minStringLength;
	this.IsOptionSelected = IsOptionSelected;
	this.IsNotThisValue = IsNotThisValue;
	this.isInMask = isInMask;
	this.isEmail = isEmail;
	this.IsTorDate = IsTorDate;
}

function inputToValidate(strFieldName,intType,strAlert,intSelectAfterTest,strParam){
	this.fieldName = strFieldName;
	this.type = intType || '';
	this.param = strParam || '';
	this.SelectAfterTest = intSelectAfterTest || 0;
	this.alert = strAlert || 'feltet: ' + strFieldName + ' er ikke udfyldt korrekt\n'
	this.valid = false;
}


function add(strFieldName,intType,strAlert,intSelectAfterTest,strParam){
	this.content[this.content.length] = new inputToValidate(strFieldName,intType,strAlert,intSelectAfterTest,strParam)
}

function isNumeric(strValue){
var tmp = new Number(strValue)
	if(!isNaN(strValue) && strValue != ''){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function isEmpty(strValue){
	if(strValue != ''){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function maxStringLength(intLength,strValue){
	//alert(this.content[i].valid);return;
	if(strValue.length <= intLength){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function minStringLength(intLength,strValue){
	//alert(this.content[i].valid);return;
	if(strValue.length >= intLength){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function IsOptionSelected(objField){
	if(objField.selectedIndex != 0){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function isInMask(strMask, strValue){
	var re = new RegExp(strMask)
	if(re.test(strValue)){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function IsNotThisValue(strNotLength,strValue){
	if(strValue != strNotLength){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function isEmail(strValue){
	var re = new RegExp("^[a-zA-Z0-9]+[a-zA-Z0-9-_\.]*\@[a-zA-Z0-9]+[-_\.]?[a-zA-Z0-9]*[\.]{1}[a-zA-Z0-9]{2,4}$","gi")
	if(re.test(strValue)){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}
}

function IsTorDate(strValue){

	if(strValue != '-' || strValue != ''){
		this.content[i].valid = new Boolean(true)
	}
	else{
		this.content[i].valid = new Boolean(false)
	}

}
//----------------------   form validation End   ---------------------------------//
//-------------------------------------------------------------------------------//


function showTime(ConfigDefault)			
		{
		intConfigDefault = parseInt(ConfigDefault)
		 if ( document.frmForm.timer.value.length == 0 )
		        {
		                var date = new Date();
		                document.frmForm.timer.value = date.getTime();
		        }
		  var timeNow = parseInt( document.frmForm.timer.value );
		  timeEnd = new Date( timeNow + 60*60000 );
		  var timeRemainingString = "";
		  var timeNow = new Date();
		  var time = Math.floor( (timeEnd.getTime() - timeNow.getTime()) / 1000.0 );
						
		  timeOut = 0;

		  if (time == 1800)
		  { 
				time = time - 1;
		        alert("\tFor security reasons you have to save/complete each page within 60 minutes\n\n\tTIP: if you cannot finish within this time, just input temporary text and change it after saving.\n\n\tYou have 30 minutes left.");
		  }
		  if (time == 300)
		  { 
				time = time - 1;
		        alert("You have to save now, not to loose your data.\n\nYou have 5 minutes left.");			     
		  }

		    hours   = Math.floor( time /3600) % 24;
		    minutes = Math.floor( time  / 60) % 60;
		    seconds = (time%60);

		    if (minutes < 10) minutes = "0" + minutes;
		    if (seconds < 10) seconds = "0" + seconds;

		    timeRemainingString = minutes + ":" + seconds;
		    timeOut = 1000;
		        document.frmForm.clock.value = timeRemainingString;
		        timerID = setTimeout("showTime(60)",1000);
		        timerRunning = true;
		}
