// changed function to use id's for pages with more than one form - mattd

/*function setDateFromPopUp(aVar, aYear, aMon, aDay)
{
    setSelectedVal(eval('opener.document.forms[0].year_' + aVar), aYear);
    setSelectedVal(eval('opener.document.forms[0].month_' + aVar), aMon);
    setSelectedVal(eval('opener.document.forms[0].day_' + aVar), aDay);
    window.close();
    return false;
}*/


function setDateFromPopUp(aVar, aYear, aMon, aDay)
{
    setSelectedVal(eval('opener.document.getElementById(\'year' + aVar + '\')'), aYear);
    setSelectedVal(eval('opener.document.getElementById(\'month' + aVar + '\')'), aMon);
    setSelectedVal(eval('opener.document.getElementById(\'day' + aVar + '\')'), aDay);
    window.close();
    return false;
}

function setSelectedVal(aElement, aVal)
{
    for (x = 0; x < aElement.options.length; x++)
    {
        if (aElement.options[x].value == aVal)
        {
            aElement.options[x].selected = true;
            return;
        }
    }
}

function getSelectedVal(aElement)
{
    for (x = 0; x < aElement.options.length; x++)
    {
        if (aElement.options[x].selected == true)
        {
            return aElement.options[x].value;
        }
    }
    return false;
}

function popUpCalender(aVar, aYear, aMon)
{
    if ( getSelectedVal(eval('document.getElementById(\'year' + aVar + '\')')) )
    {
        aYear = getSelectedVal(eval('document.getElementById(\'year' + aVar + '\')'));
    }
    if ( getSelectedVal(eval('document.getElementById(\'month' + aVar + '\')')) )
    {
        aMon = getSelectedVal(eval('document.getElementById(\'month' + aVar + '\')'));
    }
    rest='toolbar=no,location=no,directories=no,status=no,menubar=0,scrollbars=no,resizable=no,width=300,height=180';
    newWindow=window.open('/_js/calendar/beekeeper_cal.php?var=' + aVar + '&year=' + aYear + '&month=' + aMon, 'calender_popup', rest);
    newWindow.focus();
    return false;
}

// changed function to use id's for pages with more than one form - mattd

/*function popUpCalender(aVar, aYear, aMon)
{
    if ( getSelectedVal(eval('document.forms[0].year_' + aVar)) )
    {
        aYear = getSelectedVal(eval('document.forms[0].year_' + aVar));
    }
    if ( getSelectedVal(eval('document.forms[0].year_' + aVar)) )
    {
        aMon = getSelectedVal(eval('document.forms[0].month_' + aVar));
    }
    rest='toolbar=no,location=no,directories=no,status=no,menubar=0,scrollbars=no,resizable=no,width=300,height=180';
    newWindow=window.open('/_js/calendar/beekeeper_cal.php?var=' + aVar + '&year=' + aYear + '&month=' + aMon, 'calender_popup', rest);
    newWindow.focus();
    return false;
}*/

function popupHelp(aFilename)
{
    rest='toolbar=no,location=no,directories=no,status=no,menubar=0,scrollbars=yes,resizable=yes,width=350,height=300';
    helpWin=window.open(aFilename,'helpwin_new', rest);
    helpWin.focus();
    return false;
}

function openWindow(aUrl) {
	return BKOpenWin(aUrl, 400, 350);
}

function BKOpenWin(aUrl, aWidth, aHeight) {
    rest='toolbar=no,location=no,directories=no,status=no,menubar=0,scrollbars=yes,resizable=yes,width=' + aWidth + ',height=' + aHeight;
    beeWin=window.open(aUrl,'beekeeper_new', rest);
    beeWin.focus();
    return false;
}

function linkinsert () {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    var my_link = prompt('Enter URL:', 'http://');
    if (my_link != null)
        document.selection.createRange().text = '<a href="' + my_link + '">' + str + '</a>';

}

function buttoninsert () {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    var my_link = prompt('Enter URL:', 'http://');
    if (my_link != null)
        document.selection.createRange().text = '<a href="' + my_link + '" class="specialbu" >' + str + '</a>';

}

function updateIfEmpty(src_id, dst_id) {
	
	src_el = document.getElementById(src_id);
	dst_el = document.getElementById(dst_id);
	
	if (!dst_el.value)
	{
		dst_el.value = src_el.value;
	}
}	

