/*
 * $Id: common.js 1165 2008-03-16 15:49:02Z storance $
 *
 * Copyright 2006 Steven Torance
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 *
 *		http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function confirmDelete(element, name) {
	var conf = confirm('Are you sure you want to delete the selected ' + name +'?');
		
	if (conf)
		element.href += '&confirm=yes';
	return conf;
}

function confirmUnlink(element, name1, name2) {
    var conf = confirm('Are you sure you want to unlink the selected ' + name1 +' from the ' + name2 + '?');
		
	if (conf)
		element.href += '&confirm=yes';
	return conf;
    
}

function addOption(selectElement, text, value, position) {
    if (position == undefined) {
        position = -1;
    }
    
    var insertBeforeElement = null;
    if (position >= 0 && position < selectElement.options.length) {
        insertBeforeElement = selectElement.options[position];
    } else {
        position = -1;
    }
    
    var optionElement = document.createElement('option');
    optionElement.text = text;
    optionElement.value = value;
    
    try {
         // standards compliant; doesn't work in IE
        selectElement.add(optionElement, insertBeforeElement);
    } catch(ex) {
        if (position == -1) {
            selectElement.add(optionElement); // IE only
        } else {
            selectElement.add(optionElement, position);
        } 
    }
    
    return optionElement;
}