<?php

class CrmClientScript extends CClientScript
{
	/**
	 * Registers a CSS file
	 * @param string $url URL of the CSS file
	 * @param string $media media that the CSS file should be applied to. If empty, it means all media types.
	 * @return static the CClientScript object itself (to support method chaining, available since version 1.1.5).
	 */
	public function registerCssFile($url,$media='')
	{
		$url .= '?asset_version='. VERSAO . '-' . ASSETS_BUILD;
        if(ASSETS_FORCE_REFRESH) {
          $url .= '-' . date('YmdHis');
        }
        
		return parent::registerCssFile($url,$media);
	}

	/**
	 * Registers a piece of CSS code.
	 * @param string $id ID that uniquely identifies this piece of CSS code
	 * @param string $css the CSS code
	 * @param string $media media that the CSS code should be applied to. If empty, it means all media types.
	 * @return static the CClientScript object itself (to support method chaining, available since version 1.1.5).
	 */
	public function registerCss($id,$css,$media='')
	{
		if(!ASSETS_FORCE_REFRESH)
			$css = CssMin::minify($css);
		return parent::registerCss($id,$css,$media);
	}

	/**
	 * Registers a javascript file.
	 * @param string $url URL of the javascript file
	 * @param integer $position the position of the JavaScript code. Valid values include the following:
	 * <ul>
	 * <li>CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.</li>
	 * <li>CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.</li>
	 * <li>CClientScript::POS_END : the script is inserted at the end of the body section.</li>
	 * </ul>
	 * @param array $htmlOptions additional HTML attributes
	 * @return static the CClientScript object itself (to support method chaining, available since version 1.1.5).
	 */
	public function registerScriptFile($url,$position=null,array $htmlOptions=array())
	{
		$url .= '?'. VERSAO . '-' . ASSETS_BUILD;
        if(ASSETS_FORCE_REFRESH) {
          $url .= '-' . date('YmdHis');
        }
        
		return parent::registerScriptFile($url,$position,$htmlOptions);
	}

	/**
	 * Registers a piece of javascript code.
	 * @param string $id ID that uniquely identifies this piece of JavaScript code
	 * @param string $script the javascript code
	 * @param integer $position the position of the JavaScript code. Valid values include the following:
	 * <ul>
	 * <li>CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.</li>
	 * <li>CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.</li>
	 * <li>CClientScript::POS_END : the script is inserted at the end of the body section.</li>
	 * <li>CClientScript::POS_LOAD : the script is inserted in the window.onload() function.</li>
	 * <li>CClientScript::POS_READY : the script is inserted in the jQuery's ready function.</li>
	 * </ul>
	 * @param array $htmlOptions additional HTML attributes
	 * Note: HTML attributes are not allowed for script positions "CClientScript::POS_LOAD" and "CClientScript::POS_READY".
	 * @return static the CClientScript object itself (to support method chaining, available since version 1.1.5).
	 */
	public function registerScript($id,$script,$position=null,array $htmlOptions=array())
	{
		if(!ASSETS_FORCE_REFRESH)
			$script = JSMin::minify($script);
		return parent::registerScript($id,$script,$position,$htmlOptions);
	}
}
