/**
  * 	toJs
  *
  * 	converts a php data item into js object
  * 	(c) dr dot slump at cyteknt dot com
  *
  * @param arbitrary $var
  * 	php variable
  * @param boolean $recursed
  * 	recursive call flag
  *
  * @return string
  * 	js code
  */
 function toJs($var, $recursed = FALSE)
 {
     if (is_null($var) || is_resource($var)) {
         return 'null';
     }
     $js = '';
     if (is_object($var) || EasyContactFormsUtils::isAssocArray($var)) {
         $props = (array) $var;
         foreach ($props as $k => $v) {
             if (is_int($k)) {
                 $k = "idx_{$k}";
             }
             $js .= $k . ':' . EasyContactFormsUtils::toJs($v, TRUE) . ',';
         }
         if (count($props)) {
             $js = substr($js, 0, strlen($js) - 1);
         }
         $js = '{' . $js . '}';
         if (!$recursed) {
             $js = "({$js})";
         }
     } elseif (is_array($var)) {
         foreach ($var as $v) {
             $js .= EasyContactFormsUtils::toJs($v, TRUE) . ",";
         }
         if (count($var)) {
             $js = substr($js, 0, strlen($js) - 1);
         }
         $js = "[{$js}]";
     } elseif (is_string($var)) {
         $dq = chr(34);
         $var = str_replace(array(chr(34), chr(10), chr(13)), array(chr(92) . $dq, chr(92) . chr(10)), stripslashes($var));
         $js = $recursed ? $dq . $var . $dq : "(new String({$dq}{$var}{$dq}))";
     } elseif (is_bool($var)) {
         $var = $var ? 'TRUE' : 'FALSE';
         $js = $recursed ? $var : "(new Boolean({$var}))";
     } else {
         $js = $recursed ? $var : "(new Number({$var}))";
     }
     return $js;
 }