/**
 * @author fernando
 */
function FWidget(num, title, content, add_to_id){
   var fwidget_num=num;
   var parent=document.getElementById(add_to_id);
	
   window_parent_node=parent;
   
   parent.innerHTML=parent.innerHTML+
    '<div id="fwidget_'+fwidget_num+'" class="fwidget_class" onmouseout="change_back(\'fwidget_'+fwidget_num+'\',0);" onmouseover="change_back(\'fwidget_'+fwidget_num+'\',1);" onmousedown="moveWindows_move(\'fwidget_'+fwidget_num+'\');" onmouseup="moveWindows_leave(\'fwidget_'+fwidget_num+'\');">'+
      '<div id="fwidget_'+fwidget_num+'_title" class="fwidget_title">'+
      '<div class="fwidget_title_text">'+title+'</div>'+
      '<span class="fwidget_actions"><a href="javascript:closeWidget('+fwidget_num+')"><img src="images/close.png" border="0" alt="Cerrar" /></a> '+
      '  </span> '+
      '</div> '+
      ' <div id="fwidget_'+fwidget_num+'_content" class="fwidget_content">'+
          content +
      '</div>'+
     '</div>';
	 
  this.setDimension=function setDimension(w,h){	
     fwidget_object=document.getElementById('fwidget_'+fwidget_num);
	 
	 fwidget_object.style.width=w+"px";
	 fwidget_object.style.height=h+"px";
  }
  
  this.setPosition=function setPosition(x,y){
  	fwidget_object=document.getElementById('fwidget_'+fwidget_num);
	
	var obj=sizeWindows();
	
	if(x<0){
		fwidget_object.style.left = ((obj.width + x) - fwidget_object.style.width.split("p")[0])+"px";
	} else {
		fwidget_object.style.left = x + "px";
	}
	
	if(y<0){
		fwidget_object.style.top = ((obj.height + y) - fwidget_object.style.height.split("p")[0]) + "px";
	} else {
		fwidget_object.style.top = y + "px";
	}    
  }
  
  this.closeWidget=function closeWidget(){
	   fwidget_object=document.getElementById('fwidget_'+fwidget_num);	 
	   
       fwidget_object.style.visibility= "hidden";
	   window_parent_node.removeChild(fwidget_object);
	 }
  
  //-------------------------------------------Funciones complementarias
	  function getChildElementByName(Node, Name){
   	    for( var x = 0; x < Node.childNodes.length; x++ ) {
	        if(Node.childNodes[x].name==Name){
				return Node.childNodes[x];
			}
        }
   }
    	
   function sizeWindows(){
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ){
			//Non-IE
			myWidth = window.innerWidth;
  		  	myHeight = window.innerHeight;
		} 
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
			//IE 6+ in 'standards compliant mode'
 		  	myWidth = document.documentElement.clientWidth;
 		   	myHeight = document.documentElement.clientHeight;
		} 
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
			//IE 4 compatible
  		  	myWidth = document.body.clientWidth;
  		  	myHeight = document.body.clientHeight;
		}
		var obj = new Object();
		obj.width = myWidth;
		obj.height = myHeight;
		return obj;
	}
   
    function CenterPosition() {
	  var obj=sizeWindows();
	  
	  x=obj.width / 2;
	  y=obj.height / 2;
	  return [x,y];
   }

}