//  © 2005 segment systemutveckling ab

//---------------------------//
//  GLOBAL VARIABLES  //
//---------------------------//
aResources = new Array();
aResources[0] = "Detta kommer att skriva över alla timmar för denna vecka med timmarna från föregående vecka.\n\nVill du fortsätta?";
aResources[1] = "Raden kommer att plockas bort.\n\nVill du fortsätta?";
aResources[2] = "Projektet kommer att plockas bort.\n\nVill du fortsätta?";
aResources[3] = "Kategorin/Aktiviteten kommer att plockas bort.\n\nVill du fortsätta?";
aResources[4] = "Personen kommer att av-aktiveras.\n\nVill du fortsätta?";
aResources[5] = "Veckorapporten kommer att skickas.\n\nVill du fortsätta?";
aResources[6] = "Raden kunde inte sparas!\n\nVald tidsperiod överlappas av befintlig.";


function validateDate(obj){
	var iCode = event.keyCode;
	
	if(iCode != 8 && iCode != 9 && iCode != 37 && iCode != 39 && iCode != 46){
		// number
		//if((iCode <= 49 | iCode >= 58) && (iCode <= 95 | iCode >= 106)){
		if(isNaN(obj.value.substring(obj.value.length-1, obj.value.length))){
			obj.value = obj.value.substring(0, obj.value.length-1);
			stop();
		}
		
		// auto add dash
		if(obj.value.length == 4 || obj.value.length == 7){
			obj.value += "-";
		}
	}	
}

function stop(){
	window.event.returnValue = false;
	window.event.cancelBubble = true;
}

function openModalWindow(strURL, strData, width, height){
  var aVariables = new Array();
  aVariables[0] = strURL;
  aVariables[1] = strData;
  filterSelects();
  document.getElementById("divFilter").className = "filter";
  document.getElementById("divFilter").style.top = document.body.scrollTop;
  var vReturnValue = window.showModalDialog('/_inc/modal/modalContainer.html' , aVariables, 'dialogHeight: ' + height + 'px; dialogWidth: ' + width + 'px; center: yes; help: no; resizable: no; scroll: no; status: no;');
  if(strURL.indexOf("reportComment") != -1){
  	if(document.location.href.indexOf("index") != -1){
		document.getElementById("frmTimereg").submit();
	}
	else{
		document.getElementById("btnSavePlanning").click();
	}
  }
  else if(strURL.indexOf("export") != -1){
  	document.location = document.location;
  }
else{
  	document.getElementById("frmProject").submit();
  }
}

function displayConfirm(resourceID){
  return confirm(aResources[resourceID]);
}

function openModal(obj, strURL, width, height){
	if(obj.value == -1){
		openModalWindow(strURL, "", width, height);
	}
}


//------------------------------------
// EXTRA
//------------------------------------
var bActive = false;
var currentPos = 0;
var aFacit = new Array(87, 69, 68, 73, 68, 73, 84);
var aTry = new Array();

function activate(){
	bActive = true;
	currentPos = 0;
	aTry = new Array();
}

function deActivate(){
	bActive = false;
	dontDoIT();
}

function eggIT(e){
	if(bActive){
		if(currentPos < aFacit.length){
			aTry[currentPos] = e.keyCode;
		}
		currentPos++;
	}

	if(currentPos == aFacit.length){
		allOK = true;
		for(i = 0; i < aFacit.length; i++){
			if(aFacit[i] != aTry[i]){
				allOK = false;
			}
		}
		if(allOK){
			doIT();
		}
	}
}

function doIT(){
	document.location.href = "http://www.segment.se";
}

function dontDoIT(){
	window.event.returnValue=false;
	window.event.cancelBubble = true;
}
