<?php

//取得jquery路徑，$mode="google"、"xoops"、"default","link","none"
if(!function_exists('get_jquery')){
  function get_jquery($ui=false,$mode=""){
/*
    if(defined("_JQUERY_LOADED")){
      return;
    }
    define("_JQUERY_LOADED",true);
*/
    switch($mode){

      case "none":
      $jquery_path="";
      break;
      /*
      case "link":
        $jquery_path="<script type='text/javascript' src='".XOOPS_URL."/modules/tadtools/jquery/jquery.js'></script>";
        if($ui){
          $jquery_path.="
          <link href='".XOOPS_URL."/modules/tadtools/jquery/themes/base/jquery.ui.all.css' rel='stylesheet' type='text/css'/>
          <script src='".XOOPS_URL."/modules/tadtools/jquery/ui/jquery-ui.js'></script>";
        }
      break;
      */
      
      case "google":
      default:
        $google_api_key=get_google_api_key();
  
        $jquery_ui="";
        if($ui){
          $jquery_ui="google.load('jqueryui', '1.8.6');";
          //$jquery_ui="<script src='".XOOPS_URL."/modules/tadtools/jquery/ui/jquery-ui.js'></script>";
        }
        $jquery_path="
        <script type='text/javascript' src='http://www.google.com/jsapi?key={$google_api_key}'></script>
        
        <script type='text/javascript'>
        	google.load('jquery', '1.4.4');
        	$jquery_ui
        </script>
        
        <link href='".XOOPS_URL."/modules/tadtools/jquery/themes/base/jquery.ui.all.css' rel='stylesheet' type='text/css'/>";
      break;
      /*
      default:
        $jquery_path="
        <script type='text/javascript' src='".XOOPS_URL."/modules/tadtools/jquery/chk_jquery.js'></script>
        <script type='text/javascript'>importJS('".XOOPS_URL."/modules/tadtools/jquery/jquery.js', 'jQuery');</script>";
        if($ui){
          $jquery_path.="
          <link href='".XOOPS_URL."/modules/tadtools/jquery/themes/base/jquery.ui.all.css' rel='stylesheet' type='text/css'/>
          <script src='".XOOPS_URL."/modules/tadtools/jquery/ui/jquery-ui.js'></script>";
        }
      break;
      */
    }

    return $jquery_path;
  }
}


//取得API Key
if(!function_exists('get_google_api_key')){
  function get_google_api_key(){
    $modhandler = &xoops_gethandler('module');
    $xoopsModule = &$modhandler->getByDirname("tadtools");
    if(is_object($xoopsModule)){
      $config_handler =& xoops_gethandler('config');
      $xoopsModuleConfig =& $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));
      return $xoopsModuleConfig['google_api_key'];
    }
    return;
  }
}

?>
