if ((window.navigator.userAgent.indexOf("Firefox") != -1) || (window.navigator.userAgent.indexOf("MSIE") != -1) || (window.navigator.userAgent.indexOf("SV1") != -1)) {
	var aw = screen.availWidth;
	var ah = screen.availHeight;
}

function fileBrowserCallBack(field_name, url, type, win) {
	blehwindow = win;
	openWin('filebrowser','../../../../../tools/fman/filebrowser.php?type=' + type + '&field_name=' + field_name,600,500,0,1);
}

function urlConvertCallBack(url, node, on_save) {
	return url;
}

function fillImage(field_name,url) {
	blehwindow.document.forms[0].elements[field_name].value = url;
}

function openWin(winName, urlLoc, w, h, showStatus, isViewer) {
	l = (aw - w)/2;
	t = (ah - h)/2;
	features  = "toolbar=no";      // yes|no 
	features += ",location=no";    // yes|no 
	features += ",directories=no"; // yes|no 
	features += ",status=" + (showStatus?"yes":"no");  // yes|no 
	features += ",menubar=no";     // yes|no 
	features += ",scrollbars=" + (isViewer?"yes":"no");   // auto|yes|no 
	features += ",resizable=" + (isViewer?"yes":"no");   // yes|no 
	features += ",dependent";      // close the parent, close the popup, omit if you want otherwise 
	features += ",height=" + h;
	features += ",width=" + w;
	features += ",left=" + l;
	features += ",top=" + t;
	winName = winName.replace(/[^a-z]/gi,"_");
	return window.open(urlLoc,winName,features);
}

function confirmSubmit(vMessage) {
	if (!vMessage) vMessage = "This action will remove this record permanently.";
	return confirm("WARNING!\n\n" + vMessage + "\n\nDo you wish to continue?");
}

function getLabels(FormName, FieldName, LabelName, FieldSet) {
	var str_labels = "";
	if ( !document.forms[FormName] || !LabelName ) return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if ( !objCheckBoxes ) return;
	var countCheckBoxes = objCheckBoxes.length;
	for ( var i = 0; i < countCheckBoxes; i++ ) {
		if ( objCheckBoxes[i].checked == 1 ) {
			if ( str_labels ) str_labels = str_labels + ", ";
			str_labels = str_labels + document.getElementById(LabelName+i).innerHTML;
		}
	}
	if ( str_labels ) document.forms[FormName].elements[FieldSet].value = str_labels;
}

function Choose(id, id2, img, img2) {
	if ( id == "src" || id == "href" ) {
		window.opener.fillImage(id,img);
	}
	else {
		window.opener.$(id).value = img;
		if (id2 != "") {
			window.opener.$(id2).value = img2;
		}
	}
	window.close();
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function findPosX(obj) {
	var curleft = 0;
	if ( obj.offsetParent ) {
		while(1) {
			curleft += obj.offsetLeft;
			if( !obj.offsetParent )
				break;
			obj = obj.offsetParent;
		}
	}
	else if ( obj.x ) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if ( obj.offsetParent ) {
		while(1) {
			curtop += obj.offsetTop;
			if ( !obj.offsetParent )
				break;
			obj = obj.offsetParent;
		}
	}
	else if ( obj.y ) {
		curtop += obj.y;
	}
	return curtop;
}

function clear_balloon(objBalloon) {
	if ( objBalloon ) {
		if ( objBalloon.style.left != '-1000px' ) {
			$(objBalloon).hide('slow', function() {
				objBalloon.style.left = '0px'; //we reset the balloon to the top left corner
				objBalloon.style.top = '0px';
				objBalloon.style.left = '-1000px' //then we move it offstage, ready for the next time we need it
				$(objBalloon).show(); //we show the balloon again so that we can get its dimensions the next time it's needed
			}); //we remove the balloon with flair
		}
	}
}

function set_balloon(objTarget,objBalloon) {
	elemX = findPosX(objTarget);
	elemY = findPosY(objTarget);
	elemW = objTarget.offsetWidth;
	elemH = objTarget.offsetHeight;
	divW = objBalloon.offsetWidth;
	divH = objBalloon.offsetHeight;
	divLeft = ((elemX + elemW) - divW)  + 'px';
	divTop = ((elemY - divH) + 10)  + 'px';
	$(objBalloon).hide(); //we hide the balloon that is waiting off stage so we can bring it in with flair
	objBalloon.style.left = divLeft;
	objBalloon.style.top = divTop;
	objBalloon.style.zIndex = 1000;
	$(objBalloon).show("slow");
	alert(objTarget);
		
	objTarget.focus();
	if ( window.event ) window.event.cancelBubble = true; //Stop the onClick bubble up in IE
	document.onclick = function() { clear_balloon(objBalloon); };
}

function event_create() {
	vName = document.getElementById("event_name").value;
	if ( !vName ) {
		if ( document.getElementById("error_balloon") ) {
			document.getElementById("error_balloon_content").innerHTML = "You must provide a name for this event.";
			set_balloon(document.getElementById("event_name"),document.getElementById("error_balloon"));
		}
	}
	else {
		event_create_ajax(escape(vName));
	}
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if ( !document.forms[FormName] ) return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if ( !objCheckBoxes ) return;
	var countCheckBoxes = objCheckBoxes.length;
	if ( !countCheckBoxes )
		objCheckBoxes.checked = CheckValue;
	else
		for ( var i = 0; i < countCheckBoxes; i++ ) // set the check value for all check boxes
			objCheckBoxes[i].checked = CheckValue;
}

function drop_menu(FormName, FieldName) {
	if ( document.forms[FormName].elements[FieldName].options[document.forms[FormName].elements[FieldName].selectedIndex].value != "none" ) {
		location = document.forms[FormName].elements[FieldName].options[document.forms[FormName].elements[FieldName].selectedIndex].value
	}
}

