
function translateEvent(ev){
	
	console.dir(ev);

	
	if (!ev) {var ev = window.event;}

	var myEvent = Object();
	myEvent.type = ev.type;
	myEvent.ctrlKey = ev.ctrlKey;
	myEvent.keyCode = ev.keyCode;
	myEvent.which = ev.which;
	myEvent.altKey = ev.altKey;
	myEvent.shiftKey = ev.shiftKey;
	myEvent.target = ev.srcElement;

	if(is_ie){
		myEvent.button = ev.button;
		myEvent.clientX = ev.clientX;
		myEvent.clientY = ev.clientY;
		myEvent.target = ev.srcElement;
	}else if(is_nav){
		if(ev.button==0){myEvent.button = 1;}else
		if(ev.button==1){myEvent.button = 4;}else
		if(ev.button==2){myEvent.button = ev.button;}else
		{myEvent.button = 0;}
		myEvent.clientX = ev.clientX;
		myEvent.clientY = ev.clientY;
		myEvent.target = ev.target;
	}else{
		if(ev.button==0){myEvent.button = 1;}else
		if(ev.button==1){myEvent.button = 4;}else
		if(ev.button==2){myEvent.button = ev.button;}else
		{myEvent.button = 0;}
		myEvent.clientX = ev.clientX;
		myEvent.clientY = ev.clientY;
		myEvent.target = ev.target;
	}

	if(typeof(client)!="undefined" && typeof(client[0])!="undefined"&&typeof(client[0])!="unknown"&&client[0].minCorner!=null&&client[0].minCorner!=null){
		myEvent.geoX = getGeoCoordX(myEvent.clientX-client[0].offsetX, client[0].minCorner.x, client[0].maxCorner.x, client[0].width);
		myEvent.geoY = getGeoCoordY(myEvent.clientY-client[0].offsetY, client[0].minCorner.y, client[0].maxCorner.y, client[0].height);
	}
/*
		var msg = "";
		for (var i in ev){
			//myEvent[i] = ev[i];
			msg+=i + " = " + ev[i] + "\n";
		}
		alert(msg);
		*/

	return myEvent;
}


function getTextTranslation(key){
	if(typeof(ART_DICT)!="undefined"){
		if(typeof(ART_DICT[key])=="string"){
			return ART_DICT[key];
		}else{
			return "Requested translation does not exist.";
		}
	}else{
		return "Dictionary is not defined.";
	}
}

function gTT(key){
	return getTextTranslation(key);
}


function errorMsg(text){
	alert(text);
}


function notImplemented(){
	//alert("Selected function is currently under development. For more information see http://artegis.cz.");
  alert("Tato funkce není momentálně k dispozici...");
}

function logout(){
	var url = window.location.href;
	var parts = url.split("#");
	var parts = parts[0].split("?");

	url = parts[0]+"?logout=1";
	window.location.href = url;

	/*
	var lastChar = getLastChar(url);
	if(lastChar=="#"||lastChar=="?"){url = url.substring(0,url.length-1);}
	lastChar = getLastChar(url);
	if(lastChar=="#"||lastChar=="?"){url = url.substring(0,url.length-1);}
	url+="?logout=1";
	window.location.href = url;
	*/
}

function getLastChar(str){
	return str.substring(str.length-1,str.length);
}
function isEmail(value) {
	alert(value);
	invalidChars = " /:,;";
	if (value=="") return false;
	
	for (i=0; i<invalidChars.length;i++) {
	   badChar = invalidChars.charAt(i);
	   if (value.indexOf(badChar,0) != -1) return false;
	}
	
	atPos = value.indexOf("@", 1);
	if (atPos == -1) return false;
	if (value.indexOf("@", atPos + 1) != -1) return false;
	
	periodPos = value.indexOf(".", atPos);
	if (periodPos == -1) return false;
	
	if (periodPos+3 > value.length) return false;

	return true;
}




function sizeOf(array)
{
	var count = 0;

	for (var i in array)
	{
		++count;
	}

	return count;
}

function chooseSelectedItem(selBoxId,selectedItem){
	var selBox = document.getElementById(selBoxId);
	for(var i in selBox.options){
		if(selBox.options[i]!=null){
			if(selBox.options[i].value == selectedItem){
				selBox.options.selectedIndex = i;
			}
		}
	}
}

function getOptionBoxSelectedValue(optBoxId){
	var optBox = document.getElementById(optBoxId);
	return optBox.options[optBox.selectedIndex].value;
}





function checkWindowStatus(period,gc_maxlifetime){
	if(typeof(opener)=="object"&&opener!=null){
		var milisecLimit = gc_maxlifetime*1000;
		var date = new Date();
		var dif = date.getTime() - ART_LAST_WINDOW_UPDATE.getTime();
		//alert(dif + " > " + milisecLimit);
		var warningLimit = 60000;
		if(dif>(milisecLimit-warningLimit)&&dif<(milisecLimit-warningLimit+period+period)){
			alert("Již delší dobu je aplikace neaktivní. V případě další nečinosti bude vaše přihlášení za "+parseInt(warningLimit/1000)+" vteřin z bezpečnostních důvodů zrušeno.");
		}
		if(dif>milisecLimit){
			alert("Aplikace bude z bezpečnostních důvodů automaticky uzavřena.");
			opener.location.reload();
			self.close();
		}else{
			//alert("NOT CLOSING");
			setTimeout("checkWindowStatus("+period+","+gc_maxlifetime+")",period);
		}
	}else{
		alert("This window is unable to manage itself automatically. Please turn off this function.");
	}
}


function array_copy(arr){
 	var copy = new Array();
  	for (var i in arr) {
  		copy[i] = arr[i];
  	}
  	return copy;
}

function array_removeAt(arr,index){
	var i = 0;
	while(i<arr.length){
		if(i == index){
			arr.splice(i,1);
			break;
		}else{
			i++;
		}
	}
	return arr;
}


function array_switch(arr,first,second){
		//alert("first "+first+"    second " + second);
		if(first==second){return arr;}
		var firstId = false;
		var secondId = false;
		for(var i in arr){
			if(i==first){firstId=i;}
			if(i==second){secondId=i;}
		}
		if(firstId===false){alert("Unable to find FIRST index in provided pair of indexes");return false;}
		if(secondId===false){alert("Unable to find SECOND index in provided pair of indexes");return false;}

		var f = arr[firstId];
		var s = arr[secondId];
		arr[firstId]=s;
		arr[secondId]=f;
		return arr;
}



function sizeof(associative_array){
	var count = 0;
	for (var i in associative_array) {count++;  };
	return count;
}

function mergeArrays(arr1,arr2){
  var retArr = new Array();
  for(var elem in arr1){
    if(isNaN(elem)){
      retArr[elem] = arr1[elem];
    }
  }
  for(var elem in arr2){
    if(isNaN(elem) ){
      retArr[elem] = arr2[elem];
    }
  }
  return retArr;
}


function dumpArray(arr){
	var txt = "";
	for (var i in arr){
		txt += "["+i+"] => "+  arr[i]+"\n";
	}
	alert(txt);
}

/*
function dumpArray(arr){
	var txt = "";
	for (var i in arr){
		if(typeof arr[i] == "object"){
			txt += dumpArray(arr[i]);
		}else{
			txt += "["+i+"] => "+ typeof arr[i]+"\n";
		}
	}
	alert(txt);
}
*/


/*

Array.prototype.assCon = function(theArray){
  var retArr = new Array();
  for(var elem in this){
    if(isNaN(elem) && elem!="assCon"){
      retArr[elem] = this[elem];
    }
  }
  for(var elem in theArray){
    if(isNaN(elem) && elem!="assCon"){
      retArr[elem] = theArray[elem];
    }
  }
  return retArr;
}
*/



function showMapDetails(){
	var d = "";
	var parts = new Array("spacer","border","image","");
	for(var i in parts){
		var idObj = "artMapWindow_0_"+parts[i];
		if(parts[i]==""){
			idObj = "artMapWindow_0";
		}
		var el = document.getElementById(idObj);
		d+= "===== "+parts[i]+" ======\n";
		d+= " top = "+el.style.top+"\n";
		d+= " left = "+el.style.left+"\n";
		d+= " width = "+el.style.width+"\n";
		d+= " height = "+el.style.height+"\n";
		d+= " zIndex = "+el.style.zIndex+"\n";
	}
	alert(d);
}



function showToolTipText(x,y,text){
	var div = document.getElementById("art_tooltiptext");
	if(div==null){
		div = document.createElement("div");
		div.id = "art_tooltiptext";
		div.style.zIndex = 9999999;
		div.style.position ="absolute";
	}
	div.innerHTML = text;
	div.style.left = x+20 + "px";
	div.style.top = y+20 + "px";
	document.body.appendChild(div);
}

function hideToolTipText(){
	var tt = document.getElementById('art_tooltiptext');
	if(tt!=null){
		document.body.removeChild(tt);
	}
}




