// Crew Scheduler js utilities

//070524 open a screen in separate window, using std win size
var wins;
function navigateTo(sURL,sName,sFeatures) {
	// if screen size is < spec, use screen max
	var wid = screen.width - 28;	// 28,80 are padding values for a 1024x768 screen 
	var ht = screen.height - 80;	
	// if screen is large enough, use spec size
	if (wid >= 996) wid = 996;
	if (ht >= 688) ht = 688;	
	if (sFeatures == null || sFeatures == '') 
		sFeatures = 'width=' + wid + ',height=' + ht + ',resizable=yes,scrollbars=yes,status=yes,left=0,top=0';					
	if (wins == null)
		wins = new Array();
	if ((wins[sName] == null) || (wins[sName].closed))
		wins[sName] = window.open(sURL,sName,sFeatures);
	wins[sName].focus();
}


// open a child screen; put timestamp in url to avoid caching:
var winChild = null;
function openChildScreen(url) {
	url = url + '&tstamp=' + new Date().getTime();
	winChild = window.open(url,'winChild','width=996,height=688,resizable=yes,scrollbars=yes,status=yes');
	winChild.focus();
}

// handle the wait screen, usually StatusWindow.aspx;
var winWait = null;
function openWaitScreen(url) {
	winWait = window.open(url,'winWait','width=450,height=50,resizable=no,scrollbars=no,status=no');
	winWait.focus();
}
function closeWaitScreen() {
    if(winWait) {
        winWait.close();
    }
}

// trap the button event fired by [Enter] key on textbox; force postback on btnName.Click()
function postbackOnEnterKey(btnName) {
	if (event.keyCode == 13) {
		// cancel the default submit
		event.returnValue = false;
		event.cancel = true;
		// postback via button click
	    if(btnName == null || btnName == 'undefined') {
            btnName = 'btnRefresh'; // default 
        }
		__doPostBack(btnName,'Click'); 		
		return false; 	
	}
}

// trim leading/trailing whitespace
function trim(s) { return s.replace(/^\s+/,'').replace(/\s+$/,''); }  

// Open date picker dialog; ctrlName is control in calling window where date gets sent.
// If reloadFunction is given, the js function by that name is run on the calling window.
function openDatePicker(ctrlName,reloadFunction) {
	window.open('dlgPickDate.aspx?control=' + ctrlName + '&reload=' + reloadFunction,'dlgPickDate','width=150,height=210,resizable=yes');
    // note: don't use window.showmodaldialog(); the dialog uses window.opener, which is null for modals.
	return false;
}

