<?php

/**
 *
 * @author Peter Csubak (chuby)
 * @copyright Peter Csubak (chuby)
 */
class PDiv extends PComponent{

	/** @CProperty */
	protected $content;
	/** @CProperty */
	protected $style;
	
	public static $evtOnClick = 1;
	public static $evtOnMouseOver = 2;
	public static $evtOnMouseOut = 3;
	public static $evtOnDoubleClick = 4;
	
	public function __construct($content = "", $id = "", $cssclass = "", $style = "", $evtslock = ""){
		$this->content = $content;
		$this->id = $id;
		$this->cssclazz = $cssclass;
		$this->style = $style;
		$this->eventsLock = $evtslock;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setContent($content){
		$this->content = $content;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getContent(){
		return $this->content;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setStyle($style){
		$this->style = $style;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getStyle(){
		return $this->style;
	}
	
	public function render(){
		$res = "<div";
		
		if ($this->id != ""){
			$res .= " id=\"".$this->id."\"";
		}
		
		if ($this->cssclazz != ""){
			$res .= " class=\"".$this->cssclazz."\"";
		}
		
		if ($this->style != ""){
			$res .= " style=\"".$this->style."\"";
		}
		
		if (is_array($this->activeEvents)){
			foreach ($this->activeEvents as $evtTypes){
				if ($evtTypes == self::$evtOnClick){   //TYPE			SENDEDFROM			BINDEDTO				LOCK
					$res .= " onclick=\"sendAjaxEvent('AjaxOnClick', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnDoubleClick){
					$res .= " ondblclick=\"sendAjaxEvent('AjaxOnDoubleClick', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnMouseOut){
					$res .= " onmouseout=\"sendAjaxEvent('AjaxOnMouseOut', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnMouseOver){
					$res .= " onmouseover=\"sendAjaxEvent('AjaxOnMouseOver', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
			}
		}
		
		if (is_object($this->content) && ($this->content instanceof PComponent)){
			$res .= ">".$this->content->render()."</div>";
		}elseif(is_array($this->content)){
			$res .= ">";
			foreach ($this->content as $cont){
				if ($cont instanceof PComponent){
					$res .= $cont->render();
				}else{
					$res .= $cont;
				}
			}
			$res .= "</div>";
		}else{
			$res .= ">".$this->content."</div>";
		}
		
		return $res;
	}
	
}
?>