<?php

//CONSIDER not using this rendered when you need direct access to array data, i.e. for data grids (this rendered is intended for HTML render to JSON)
//will not encode arrays
//echo 'Debug';
require_once 'library/jQuery/jQuery.php';
$debugString = '';

if( isset($this->jsonIdsToRender) && is_array($this->jsonIdsToRender) )
{
	foreach( $this->jsonIdsToRender as $key => $value )
	{
		//allow this method to also clear id content
		if($value == false || $value == null || strlen($value) < 1)
		{
			jQuery('#' . $key)->html( false );
		}
		else
		{
			jQuery('#' . $key)->html( iconv("UTF-8", "UTF-8//TRANSLIT", $this->render(utf8_encode($value))) );
		}
		unset($this->jsonIdsToRender[$key]);
	}
}		

if( isset($this->jsonIdsToAppend) && is_array($this->jsonIdsToAppend) )
{
	foreach( $this->jsonIdsToAppend as $key => $value )
	{
		//allow this method to also clear id content
		if($value == false || $value == null || strlen($value) < 1)
		{
			jQuery('#' . $key)->append( false );
		}
		else
		{

			//jQuery('#' . $key)->append( $this->render($value) );
			jQuery('#' . $key)->append( iconv("UTF-8", "UTF-8//TRANSLIT", $this->render(utf8_encode($value))) );

		}
		unset($this->jsonIdsToAppend[$key]);
	}
}		

if( !isset($this->errors) )
{
	jQuery('#errors')->html( false );
}
elseif( is_array($this->errors) )
{	
	jQuery('#errors')->html( implode('<br />', $this->errors) );
}
else
{	
	jQuery('#errors')->html( $this->errors );
}

if( !isset($this->notices) )
{	
	jQuery('#notices')->html( false );    
}
elseif( is_array($this->notices) )
{	
	jQuery('#notices')->html( implode('<br />', $this->notices) );
}
else
{	
	jQuery('#notices')->html( $this->notices );
}	

if( !isset($this->debug) )
{	
	jQuery('#debug')->html( false );    
}
elseif( is_array($this->debug) )
{	
	jQuery('#debug')->html( dump($this->debug, '', true) );
}
else
{	
	jQuery('#debug')->html( $this->debug );
}	

if( !isset(jQuery::$jQuery) )
{
	jQuery::$jQuery = new jQuery(); //should only be needed for empty requests
}
echo Zend_Json::encode(jQuery::$jQuery->response);