/* 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;
}

/* image rollover code */
function changeImage( imageName, newImage ) {
	if( document.getElementById(imageName) ) {
		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 == 'block' ) {
			hideElement( divId );
		} else {
			showElement( 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 - parent.offsetLeft + 15;
	boxY = mouseY - parent.offsetTop;
	box.style.left = boxX + "px";
	box.style.top = boxY + "px";
	box.style.display = 'block';
}

//change the opacity for different browsers
function changeOpacity(id, opacity) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function blendImage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

	//make image transparent
	changeOpacity(imageid,0);

	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpacity('"+ imageid + "',"+ i +")",(timer * speed));
		timer++;
	}
}

