/* verify a link with a javascript dialog */
function verifyClick( message ) {
	if( typeof( message ) == 'string' ) {
		return confirm( message );
	} 

	return confirm( "Are you sure you want to delete this item?" );
}


/* create a popup with the provided link, window, width and height */
function sizedPopup( linkname, windowname, ww, wh ) {
	var href;

	if( !window.focus ) return true;

	if( typeof( linkname ) == 'string' ) { href = linkname; }
	else { href = linkname.href; }

	window.open( href, windowname, 'width='+ ww +', height= '+ wh +' ,scrollbars=no, resizable=no');

	return false;
}
function sizedPopupscroll( linkname, windowname, ww, wh ) {
        var href;

        if( !window.focus ) return true;

        if( typeof( linkname ) == 'string' ) { href = linkname; }
        else { href = linkname.href; }

        window.open( href, windowname, 'width='+ ww +', height= '+ wh +' ,scrollbars=yes, resizable=yes');

        return false;
}


/* image rollover code */
function changeImage( imageName, newImage ) {
	document.getElementById( imageName ).src = newImage;
}

/* use css/dhtml to display or hide page elements */
function toggleElement( divId ) {
        if( document.getElementById( divId ) ) {
		if( document.getElementById( divId ).style.display == 'none' ) {
			showElement( divId );
		} else {
			hideElement( divId );
		}
	}
}
function showElement( divId ) {
        if( document.getElementById( divId ) ) {
                document.getElementById( divId ).style.display = 'block';
		return true;
        }
        return false;
}
function hideElement( divId ) {
        if( document.getElementById( divId ) ) {
                document.getElementById( divId ).style.display = 'none';
		return true;
        }
        return false;
}

function updateSelectList( key, selected, selectObj, selectArray ) {
	//alert( '('+key+')('+selected+')('+selectObj+')('+selectArray+')' );
	// remove all children
	while ( selectObj.hasChildNodes() ) { selectObj.removeChild ( selectObj.firstChild ); }

	// create new children
	catArray = selectArray[key];

	for( optionVal in catArray ) {
		newOption = document.createElement( 'OPTION' );
		newOption.setAttribute( 'value', optionVal );
		newOption.appendChild( document.createTextNode( catArray[ optionVal ] ) );
		if( catArray[ optionVal ] == selected ) { newOption.defaultSelected = true; }
		else { newOption.defaultSelected = false; }
		selectObj.appendChild( newOption );
	}
	//alert( selectObj );
	//alert( document.FilterWidget.CategoryId.options );
}

function getMousePosition( e ) {
	var posX = 0;
	var posY = 0;

	if( !e ) var e = window.event;
	if( e.pageX || e.pageY ) {
		posX = e.pageX;
		posY = e.pageY;
	} else if( e.clientX || e.clientY ) {
		posX = e.clientX + document.body.scrollLeft;
		posY = e.clientY + document.body.scrollTop;
	}
	return [ posX, posY ];
}

function getMouseX( e ) {
	var mouse = getMousePosition( e );
	return mouse[0];
}

function getMouseY( e ) {
	var mouse = getMousePosition( e );
	return mouse[1];
}

function displayDialog( id, event ) {
	var box = document.getElementById( id );	
	var parent = document.getElementById( id ).parentNode;
	var mouseX = getMouseX( event );
	var mouseY = getMouseY( event );
	boxX = mouseX + 5;
	boxY = mouseY;
	box.style.left = boxX + "px";
	box.style.top = boxY + "px";
	box.style.display = 'block';
}
