// charset=utf-8
// $Id: PinboardPageAdder.js 465 2008-02-04 07:55:19Z hebing $
// $HeadURL: svn://svnserver/mcmplugins/Pinboard_ProductsDb/trunk/mcm-5.5/scripts/PinboardPageAdder.js $
// +----------------------------------------------------------------------+
// | mcm board-Plugin                                                     |
// | version 1.0                                                          |
// | for mcm v5.5                                                         |
// | (c) 2002-2007 monsun media (http://www.monsun-media.com)             |
// +----------------------------------------------------------------------+


/**
* mcmPinboardPageAdder 
*
* @author	dierker <dierker@monsun-media.com>
* @author	jansen <jansen@monsun-media.com>
*/
var mcmPinboardPageAdder = {
	/**
	* add the page to the pinboard
	*
	* @param	Event	evt
	* @param	int		page_id
	* @param	Object	optionsAry
	* @return	void
	*/
	addPage : function(evt,page_id,query_string,optionsAry){
		
		var x = mcm.getPageX(evt);
		var y = mcm.getPageY(evt);
		var xmlReq = mcm.createXmlHttpRequest();
		xmlReq.onreadystatechange = function(){
			if( xmlReq.readyState==4 ){
				if( xmlReq.status==200 ){
					var message = xmlReq.responseText;
					mcmPinboardPageAdder.showConfirmationMessage(x,y,message);
				}
			}
		}
		var servletUrl = 'plugins/Pinboard/servlet.php?action=addPage&'+'page_id='+page_id+'&query_string='+query_string;
		xmlReq.open('GET',servletUrl,true);
		xmlReq.send(null);
		mcm.cancelEvent(evt);
	}
	,
	/**
	* show a confirmation message
	* @param	int		x
	* @param	int		y
	* @return	void
	*/
	showConfirmationMessage : function(x,y,message){

		var d;
		d = document.getElementById('PinboardConfirmationBox');
		if( d==null ){
			var d = document.createElement('div');
			d.setAttribute('id','PinboardConfirmationBox');
			d.style.visibility = 'hidden';
			document.body.appendChild(d);
		};
		d.innerHTML = message;
		d.style.left = parseInt(x)-parseInt(d.offsetWidth)+'px';
		d.style.top  = parseInt(y)+'px';
		d.style.visibility = 'visible';
		setTimeout(mcmPinboardPageAdder.hideConfirmationMessage,2000);
	}
	,
	hideConfirmationMessage : function(){
		var d = document.getElementById('PinboardConfirmationBox');
		d.style.visibility = 'hidden';
	}
}
