/*
 * ...
 * <br>Project:			KOK Kontaktdatenbank
 * <br>Format:			Tab width 4
 * 
 * @author Gabriele Janecke & Thomas Hoernke
 * @copyright Copyright (c) 2009, h3:: PartG, Berlin
 * @version 0.21	31.05.2009, gj & tom
 * @package 
 */


	

function getSafeFormId() { return document.getElementById('safeFormId').value; }


function jumpTo(jumper) {
	window.location.hash = '#'+jumper;
}

// Google Maps View
var winGMaps = null;
function gmapsView() {
	if (winGMaps == null || winGMaps.closed == true) {
		winGMaps = window.open("","winGMaps","width=1000,height=660,left=20,top=20,dependent=yes,hotkeys=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
	}
	winGMaps.focus();
	return true;
}

// Preview
var winPreview = null;
function openPreview(textId) {
	if (winPreview == null || winPreview.closed == true) {
		winPreview = window.open("","winPreview","width=815,height=400,left=20,top=20,dependent=yes,hotkeys=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
	}
	winPreview.focus();
	
	document.previewForm.ptext.value = document.getElementById(textId).value;
	document.previewForm.submit();
	return true;
}

// Text Format Help Page
var winHelp = null;
function openHelp(width, height) {
	if (winHelp == null || winHelp.closed == true) {
		winHelp = window.open("","winHelp","width="+width+",height="+height+",left=20,top=20,dependent=yes,hotkeys=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
		winHelp.resizeTo(width, height);
	}
	else {
		winHelp.resizeTo(width, height);
	}
	winHelp.focus();
	return true;
}

// For the PDF/Document Popup
var winPdf = null;
function pdfView() {
	if (winPdf == null || winPdf.closed == true) {
		winPdf = window.open("","winPdf","width=640,height=720,left=20,top=20,dependent=no,hotkeys=yes,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=no");
	}
	winPdf.focus();
}

// 
function checkMaxLength(caller, max) {
	text = caller.value;
	if (text.length > max) {
		text = text.substring(0, max);
		alert('Sie haben die erlaubte Textlänge von '+max+' Zeichen erreicht!');
	}
	caller.value.value = text;
}


function showHintField(caller, reference) {
	var hintDgl = document.getElementById('hint');
	if (hintDgl.style.display == 'block') return;
	var safeFormId = getSafeFormId();

	var posX = caller.offsetLeft - 113;
	var posY = caller.offsetTop + 15;
	var parent = caller.offsetParent;
	while (parent) {
		posX += parent.offsetLeft;
		posY += parent.offsetTop;
		parent = parent.offsetParent;
	}
	hintDgl.style.left = posX + 'px';
	hintDgl.style.top  = posY + 'px';
	hintDgl.style.display = 'block';
	$.ajax({ 
		type: "POST", 
		url: ajaxUrl, 
		data: "safeFormId="+safeFormId+"&"+"key=getHelptext&"+"val="+reference, 
		success: function(data, textStatus) { if (textStatus == 'success') $(hintDgl).append(data); }
	});
}
function closeHintField() {
	var hintDgl = document.getElementById('hint');
	hintDgl.style.display = 'none';
	var $disKids = $(hintDgl).children().filter(":not([id='closeX'])");
	$disKids.remove();
}