function BodyOnLoad(){
	var cell
	var calendar

	cell = document.getElementById('KR5039')
	if(cell != null){
		cell.style.visibility = "hidden";
	}

	calendar = document.getElementById('KR5276')
	if(calendar != null){
		calendar.onclick = function(){show_office_calendar(null, null, null, null, 'YYMMDD')};
		calendar.style.cursor = 'pointer';
	}

	calendar = document.getElementById('KR5278')
	if(calendar != null){
		calendar.onclick=function(){show_office_calendar(null, null, null, null, 'YYMMDD')};
		calendar.style.cursor = 'pointer';
	}

	for(var i = 0, l = document.getElementsByTagName('input').length; i < l; i++) {
		if(document.getElementsByTagName('input').item(i).type == 'text') {
			document.getElementsByTagName('input').item(i).setAttribute('autocomplete', 'off');
		};
	};

}

function selectDay(cellInfo){
	var cell

	cell = document.getElementById('KR5039')
	if(cell != null){
		cell.value = cellInfo;
		__doPostBack('KR5038', '');
	}
}

function stopEnterKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

document.onkeyfunction BodyOnLoad(){
	var cell;
	var calendar;
	var input;
	var orderSeek;
	var timeCodeSeek;
	
	hideElement('KR5039'); //Selected cell
	hideElement('KR27011');
	hideElement('KR27012');
	hideElement('KR27014');
	hideElement('KR27015');

	calendar = document.getElementById('KR5276');
	if(calendar != null){
		calendar.onclick = function(){show_office_calendar(null, null, null, null, 'YYMMDD')};
		calendar.style.cursor = 'pointer';
	}

	calendar = document.getElementById('KR5278');
	if(calendar != null){
		calendar.onclick=function(){show_office_calendar(null, null, null, null, 'YYMMDD')};
		calendar.style.cursor = 'pointer';
	}

	orderSeek = document.getElementById('I5165')
	if(orderSeek != null){
		orderSeek.onclick = setOrderValue;
	}
	else{
		orderSeek = document.getElementById('I5234')
		if(orderSeek != null){
			orderSeek.onclick = setOrderValue;
		}
	}

	timeCodeSeek = document.getElementById('I5166')
	if(timeCodeSeek != null){
		timeCodeSeek.onclick = setTimeCodeValue;
	}
	else{
		timeCodeSeek = document.getElementById('I5236')
		if(timeCodeSeek != null){
			timeCodeSeek.onclick = setTimeCodeValue;
		}
	}

	for(var i = 0, l = document.getElementsByTagName('input').length; i < l; i++) {
		input = document.getElementsByTagName('input').item(i);
		if(input.type == 'text') {
			if(input.id != 'KR5039' || input.id != 'KR27011' || input.id != 'KR27012' || input.id != 'KR27014' || input.id != 'KR27015'){
				input.onfocus = checkIfChanged;
			}
			//Tar bort autocomplete, vet inte om det funkar till 100%???
			input.autocomplete = 'off';
			//Ändrar till mörkare färg i disablade inputs.
//			if(input.disabled == true){
//				input.disabled = false;
//				input.style.className = 'testklass';
//				input.disabled = true;
//				input.color = '#456ABC';
//			}
		}
	}
}

function hideElement(elementId){
	element = document.getElementById(elementId);
	if(element != null){
		element.style.visibility = "hidden";
	}
}

function selectDay(cellInfo){
	var cell

	cell = document.getElementById('KR5039')
	if(cell != null){
		cell.value = cellInfo;
		__doPostBack('KR5038', '');
	}
}

function setOrderValue(){
	var ordernr = document.getElementById('KR27011');
	var ordernrNow = document.getElementById('KR28');
	if(ordernrNow == null){
		ordernrNow = document.getElementById('KR5233');
	}
	if(ordernr != null){
		ordernr.value = ordernrNow.value;
		document.getElementById('KR27012').value = true;
	}
}

function setTimeCodeValue(){
	var timeCode = document.getElementById('KR27014');
	var timeCodeNow = document.getElementById('KR5134');
	if(timeCodeNow == null){
		timeCodeNow = document.getElementById('KR5032');
	}
	if(timeCode != null){
		timeCode.value = timeCodeNow.value;
		document.getElementById('KR27015').value = true;
	}
}

function checkIfChanged(){
	checkIfOrderChanged();
	checkIfTimeCodeChanged();
}

function checkIfOrderChanged(){
	var ordernr = document.getElementById('KR28');
	if(ordernr  == null){
		ordernr = document.getElementById('KR5023');
	}
	if(ordernr != null){
		if(document.getElementById('KR27012').value == 'true' && document.getElementById('KR27011').value != ordernr.value){
			document.getElementById('KR27012').value = 'false';
			document.getElementById('KR27010').click();
		}
	}
}

function checkIfTimeCodeChanged(){
	var timeCode = document.getElementById('KR5134');
	if(timeCode == null){
		timeCode = document.getElementById('KR5032');
	}
	if(timeCode != null){
		if(document.getElementById('KR27015').value == 'true' && document.getElementById('KR27014').value != timeCode.value){
			document.getElementById('KR27015').value = 'false';
			document.getElementById('KR27016').click();
		}
	}
}

function stopEnterKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

document.onkeypress = stopEnterKey;press = stopEnterKey;
