/*********************************************************************
* These are commonly used scripts                                    *
*********************************************************************/

function openWindow(file,window) {
	msgWindow=open(file,window,'scrollbars=yes,resizable=yes,width=450');
}

function newWindow(file,window) {
msgWindow=open(file,window,'scrollbars=yes,resizable=yes,width=450');
}

function openFullWindow(file,window) {
	msgWindow=open(file,window,'scrollbars=yes,resizable=yes,width=750');
}

/**********************************************************
* Open small window for help information                 *
**********************************************************/
function OpenHelpWindow(href, wnd) {
    var width='600';
    var height='450';
	ourIndex = window.open(href, wnd, "resizable=no,scrollbars=yes,width="+width+",height="+height+" ");
	ourIndex.focus();
}

/**********************************************************
* Prepare and send request for a specific type of action
**********************************************************/
function sendAction(frm, action) {
    if(action == '') {
       frm.fuseaction.value = 'CAL.HOME';
       }
    else {
        frm.fuseaction.value = action;
    }
	frm.submit(); 		
}

/**********************************************************
* Set paging information and send form                    *
* this routine uses form so that the search criteria is   *
* saved as you page through                               *
**********************************************************/
function setMonth(frm, new_month, new_year) {
    frm.selMonth.value = new_month;
	frm.selYear.value = new_year;
    frm.submit(); 		
}

/**********************************************************
* send action after a confirmation 
**********************************************************/
function sendConfirm(frm, action, msg) {
   msgConfirm = 'Are you sure you want to ' + msg + '\n Click OK to continue or CANCEL to return.'; 
   if (confirm(msgConfirm)) {
		frm.fuseaction.value = action;
		frm.submit();
		}
}

/**********************************************************
* Set paging information and send form                    *
* this routine uses form so that the search criteria is   *
* saved as you page through                               *
**********************************************************/
function setPaging(frm, new_start) {
    frm.list_start.value = new_start;
    frm.submit(); 		
}

/**********************************************************
 * General routine for setting the specified option in the
 * specified selection list item as the selected option.
 **********************************************************/
function setSelList(itemName, valToSelect) {
    var i;
    var item = document.forms[0].elements[itemName];

    for(i = 0; i < item.options.length; i++) {
        if(item.options[i].value == valToSelect) {
            item.options[i].selected = true; 
            break;
        }
    }
}

/**********************************************************
 * Routines for validing new calendar entries 
 **********************************************************/
 /**********************************************************
 * Check that user entered all required fields before displaying
 * New Posting Confirmation page.
 **********************************************************/
function submitPosting(frm, cal, type) {
    if(frm.EventTypeId.options[frm.EventTypeId.selectedIndex].value == '') {
       alert('Please select an event type.');
       frm.EventTypeId.focus();
    }
    else if(frm.MultiCommunity.options[frm.MultiCommunity.selectedIndex].value == '') {
        alert('Please select at least one community.');
        frm.MultiCommunity.focus();
    }
    else if(frm.EventTitle.value == '') {
        alert('Please enter a title for the event.');
        frm.EventTitle.focus();
    }
    else if(frm.EventDateStart.value == '') {
        alert('Please enter a start date for the event.');
        frm.EventDateStart.focus();
    }
    else {
        frm.submit();
    }
}

/**********************************************************
 * Prepare and send request to update database
 **********************************************************/
function processPosting(frm, cal, type) {
    if(type == "edit") {
        frm.UserRequest.value = "ProcessEditPosting";
    }
    else {
        frm.UserRequest.value = "ProcessNewPosting";
    }
    setDate(frm, cal);
    frm.submit();
}

