var alertDialog = null;
var alertX = -1; // centers dialog in window!
var alertY = -1;
var i18N_MyAppAlert = "MyApp Alert"; // can be changed by application

function MyAppAlertSetXY(x, y) {
	// call prior to 'MyAppAlert()'
	alertX = x;
	alertY = y;
	}

function MyAppAlertXY(ev) {
	// call using 'onclick' prior to 'MyAppAlert()'
	var e = jt_fixE(ev);
	MyAppAlertSetXY(e.clientX, e.clientY + document.body.scrollTop);
	return true;
	}

function MyAppAlertInit(title, icon) {
	// 'title' and 'icon' are optional; both may be changed using 'MyAppAlert()'
	var locTitle = i18N_MyAppAlert;
	if (title) locTitle += " - " + title;
	if (alertDialog == null) {
		alertDialog = new jt_AppAlert(icon ? icon : jt_AppAlert.Error);
		alertDialog.setTitle(locTitle);
		}
	else {
		if (title) alertDialog.setTitle(locTitle);
		if (icon) alertDialog.setIcon(icon);
		}
	}

function MyAppAlert(msg, title, icon) {
	// 'title' and 'icon' are optional
	MyAppAlertInit(title, icon);
	alertDialog.setContent(msg);
	alertDialog.moveTo(alertX, alertY);
	alertDialog.show();
	if ((alertX == -1) || (alertY == -1)) alertDialog.moveTo(alertX, alertY);
	}


function centerJtWindows(jt_Dialog_xas, event){
	if (!event) event = window.event; 
	
	var newx, newy;
	
	if(event){	
		newx=event.clientX-jt_Dialog_xas.container.clientWidth/2;
		newy=event.clientY + document.body.scrollTop-jt_Dialog_xas.container.clientHeight/2;
	}
	else{
		newx=(document.body.clientWidth-jt_Dialog_xas.container.clientWidth)/2;
		newy=(document.body.clientHeight-jt_Dialog_xas.container.clientHeight)/2;
	}
	
	var borderGap=5;
	if(newx<0){
		newx=borderGap;
	}
	else if(newx+jt_Dialog_xas.container.clientWidth>document.body.clientWidth || isNaN(newx)){
		newx=document.body.clientWidth-jt_Dialog_xas.container.clientWidth-borderGap;
	}
	if(newy<document.body.scrollTop){
		newy=document.body.scrollTop+borderGap;
	}
	if(newy+jt_Dialog_xas.container.clientHeight>document.body.scrollTop+document.body.clientHeight || isNaN(newy)){
		newy=document.body.scrollTop+document.body.clientHeight-jt_Dialog_xas.container.clientHeight-borderGap;
	}

	// ok, here's the bare minimum requirements:	
	if(isNaN(newx) || newx<0)
		newx=10;
	if(isNaN(newy) || newy<0)
		newy=10;
	
	jt_Dialog_xas.moveTo(newx, newy);
}
