function toggleVisibility(id) {
	var obj = document.getElementById(id);

	if( obj.style.display == 'none' ) {
		obj.style.display = '';
		return true;
	}
	else {
		obj.style.display = 'none';
		return true;
	}
}

function editSettings(src, user_id) { 
	return '<div id="tag_to_tooltip" style="position: relative; z-index: 10;"><table cellspacing="0" cellpadding="2" width="250"><tr><td align="center" id="help_border_top"><a href="#openclose"><img style="float: left;" src="gfx/osx_exit_button.png"><\/a><span style="margin-left: -12px; font-size: 12.0px; color: #dddddd;">Settings<\/span><\/td><\/tr><tr id="bg_color1"><td align="left" id="underline1" style="color: #dddddd; font-size: 12.0px; height: 65px;"><iframe name="edit_settings" id="edit_settings" height="100%" width="100%" scrolling="no" frameborder="0" margin-height="0" marginwidth="0" src="'+ src +'?diver='+user_id+'&iframe=1"><\/iframe><\/td><\/tr><\/table><\/div><\/span>';
}

//åpner uploader
function customPopup(url, width, height) {

	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 3) - ( height / 2);


	newwindow=window.open(url,'name','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=yes, menubar=no, location=no, screenX='+topX+', screenY='+topY);
	if (window.focus) {newwindow.focus()}
	return false;
}

function popitup(url) {

	var width = 460;
	var height = 350;

	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 3) - ( height / 2);


	newwindow=window.open(url,'name','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=yes, menubar=no, location=no, screenX='+topX+', screenY='+topY);
	if (window.focus) {newwindow.focus()}
	return false;
}

function popupCal(input_id){
	// "endre innhold" har en tilsvarende funksjon i iframen
	var load_date = document.getElementById(input_id).value;
	
	var url = 'includes/calendars/date_time_picker.php?input_id='+input_id+'&load_date='+load_date;
	
	var width = 360;
	var height = 235;

	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 3) - ( height / 2);
	
	newwindow=window.open(url,'cal','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=yes, menubar=no, location=no, screenX='+topX+', screenY='+topY);
	if (window.focus) {newwindow.focus()}
	return false;
	
}



function popUpEditLog(dive_id, dive_reference_id, diver, org) {

	var width = 800;
	var height = 200;

	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 3) - ( height / 2);

	var url = 'admin/dive_logs/includes/complete_edit_log.php?sid='+dive_reference_id+'&diver='+diver+'&org='+org+'&dive_id2='+dive_id;

	newwindow=window.open(url,'name','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=yes, menubar=no, location=no, screenX='+topX+', screenY='+topY);
	if (window.focus) {newwindow.focus()}
	return false;
}



function popUpSaveSearch(url) {
	var width = 350;
	var height = 130;
	
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	
	newwindow=window.open(url,'name','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=yes, menubar=no, location=no, screenX=' + topX + ',screenY=' + topY);
	if (window.focus) {newwindow.focus()}
	return false;
}

function popUpDepthProfile(url, diver_nr) {
	width = window.screen.width-50;
	height = 545;
	
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	
	newwindow=window.open(url,'explore_chart','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=no, menubar=no, location=no, screenX=' + topX + ',screenY=' + topY);
	if (window.focus) {newwindow.focus()}
	return false;
}


function popUpAttachments(url) {
	width = 650;
	height = 200;
	
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 3) - ( height / 2);
	
	newwindow=window.open(url,'name','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=yes, menubar=no, location=no, screenX=' + topX + ',screenY=' + topY);
	if (window.focus) {newwindow.focus()}
	return false;
}

function addUser(org, title) {
	width = 500;
	height = 220;
	scrolling = 'auto';
	
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	
	var url = 'admin/admintools/includes/add_user.php?org='+org+'&title='+title;
	
	newwindow=window.open(url, 'userinfo', 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
	if (window.focus) {newwindow.focus()}
	return false;
}

//åpner kart
function popitupKart(url) {
	width = 1000;
	height = 700;
	
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	
	newwindow=window.open(url,'map','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=no, menubar=no, location=no,screenX=' + topX + ',screenY=' + topY);
	if (window.focus) {newwindow.focus()}
	return false;
}

function submitFormById(formId){
alert(formId);
	var formObj = document.getElementById(formId);
	formObj.submit();
}

//åpner search kart
function popitupSearchMap(url, row_id, coordinates) {
	width = 1000;
	height = 769;
	scrolling = 1;
	
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	if(coordinates != 0){
		geocode = document.getElementById('var5_'+row_id).innerHTML.split('/')
		url = url + '&geocode='+geocode[0]+','+geocode[1];
	}
	else{
		url = url + '&geocode=64.86381640940925,11.607742309570312';
	}
	newwindow=window.open(url,'google_map','width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
	newwindow.resizeTo(width,height)
	if (window.focus) {newwindow.focus()}
	return false;
}

//åpner dive i popup
function popUpDive(url) {
	width = window.screen.width * 0.70;
	height = window.screen.height * 0.70;
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	newwindow=window.open(url,'show_dive','width=' + width + ',height=' + height + ', status=no, toolbar=no, scrollbars=yes, menubar=no, location=no, screenX=' + topX + ',screenY=' + topY);
		newwindow.resizeTo(width,height)
	if (window.focus) {newwindow.focus()}
	return false;
}

//åpner pdf i popup
function popUpPdf(url) {
	width = 950;
	height = 750;
	var topX = (window.screen.width / 2) - ( width / 2);
	var topY = (window.screen.height / 2) - ( height / 2);
	newwindow=window.open(url,'show_pdf','width=' + width + ',height=' + height + ', status=yes, toolbar=no, scrollbars=auto, menubar=no, location=no, screenX=' + topX + ',screenY=' + topY);
		newwindow.resizeTo(950,750)
	if (window.focus) {newwindow.focus()}
	return false;
}

// brukes i SØK
var lastDiv = "";
function showDiv(divName) {

	//if value of the box is not nothing and an object with that name exists, then change the class
	if (divName && document.getElementById(divName)) {
		document.getElementById(divName).className = "visibleDiv";
		lastDiv = divName;
	}
}

/* tror ikke denne brukes
function buttonHandlingSearch(skjema, input){
	document.skjema.input.disabled=false; 
	document.skjema.input.disabled=true;
	
}
*/

	function showDiv(id_vises) {
		var obj = document.getElementById(id_vises);
				obj.style.display = '';
				return true;
	}
	
	function hideDiv(id_vises) {
		var obj = document.getElementById(id_vises);
			obj.style.display = 'none';
			return true;
	}



// finner klokkeslett (realtime)
function startTime(){
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
document.getElementById('hour').value=h+":"+m;
document.getElementById('hour2').innerHTML=h+":"+m;
t=setTimeout('startTime()',500);
}

function checkTime(i, h)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
if (h<10)
  {
  h="0" + h;
  }
return h;
}


// disabler [enter]. hentes fra body-tag
function checkShortcut() { 
	if(event.keyCode==13) { 
		return false; 
	}
} 


function switchFakeInput(input_id, message){
		
		var fake_input = document.getElementById(input_id+'_span');
		var real_input = document.getElementById(input_id);
	
		if(fake_input.style.display == 'none'){
			// update <input id="input_id">
			document.getElementById('input_id').value=input_id;
			
			// hide real input
			real_input.style.display='none';

			// format text 
			new_value = real_input.value.replace(/,/g, "<br>");
			
			
			if(new_value == ''){
				new_value = 'blank';
			}
			
			// give fake_input the new value and show it
			fake_input.innerHTML = new_value;
			fake_input.style.display='';
			UnTip();
		}
		else{
			// resize the input to fit content
			real_input.size = real_input.value.length;

			// hide fake input
			fake_input.style.display='none';

			// format text 
			new_value = real_input.value.replace(/<br>/g, ",");
			real_input.value = new_value;
			// show real input
			real_input.style.display='';
			real_input.focus();
			real_input.select();
			
			
			// show message (if any)
			if(message != ''){
				Tip(TooltipTxt(message), OFFSETX, -20, OFFSETY, -42, DELAY, 200);
			}
		}
	}

function showSaveMessage(message, milliSec){

	document.getElementById('save_message').style.backgroundColor='#fff1a8';
	document.getElementById('save_message').innerHTML=message;
	opacity('save_message', 0, 100, 500);
	setTimeout("if(document.getElementById('save_message').style.opacity == '1'){opacity('save_message', 100, 0, 1000);}",milliSec);
	setTimeout("document.getElementById('save_message').innerHTML='';",milliSec+1000);
	
}

function loadJavascriptCodeAsText(divId){
	var code = document.getElementById(divId).value;
	
	code = code.replace('<script type="text/javascript">');
	code = code.replace('</script>');
	eval(code);
}

