﻿/*----------------------------------------------------------------------------\
|                This script is created by William Tam Yuen Hei               |
|                          (http://tambot.no-ip.com)                          |
|-----------------------------------------------------------------------------|
|                Copyright (c) by 1997 - 2011 TamBot.com Workshop             |
|-----------------------------------------------------------------------------|
| The scripts and the whole design of this website is my painstaking effort   |
| and they are JUST available on Shabuzen Restaurant Taipei.                  |
| Consequently, if you have NO authorization, it is NOT allowed to use on     |
| other website.                                                              |
|-----------------------------------------------------------------------------|
| Created 2011-09-01 |                  All rights reserved                   |
\----------------------------------------------------------------------------*/

function init_contactus() {
  document.getElementById("goomap").src = "http://maps.google.com/maps/api/staticmap?size=240x250&markers=icon:http://chart.apis.google.com/chart%3Fchst%3Dd_map_pin_icon%26chld%3Dcafe%257C996600|" + encodeURI(document.getElementById("address").innerHTML) + "&sensor=false";
  var frmvalidator  = new Validator("enquiryform");
  if (!isIE) {
    frmvalidator.EnableOnPageErrorDisplay();
    frmvalidator.EnableMsgsTogether();
  }
    frmvalidator.setAddnlValidationFunction(enquiry_form_submit);

    frmvalidator.addValidation("strName","req","請填上您的姓名");
    frmvalidator.addValidation("strTel","num", "這裡只能輸入數字");
    frmvalidator.addValidation("strEmail","req", "請提供您的電郵地址");
    frmvalidator.addValidation("strEmail","email", "請輸入正確的電郵地址");
    frmvalidator.addValidation("strComment","req", "請填寫您的意見或問題");
    frmvalidator.addValidation("captchab","req", "請輸入認證碼");
}

function findway() {
  goolnk = "http://maps.google.com.tw/maps?saddr=";
  goolnk += encodeURI(document.getElementById("findway").value);
  goolnk += "&daddr=" + encodeURI(document.getElementById("address").innerHTML);
  window.open(goolnk);
}

function findway_tooltip() {
  if (document.getElementById("findway").value.length>0) toolTip("滑鼠點兩下清空輸入框");
}

function map_tooltip() {
  toolTip("按這裡開啟Google地圖");
}

function clearfindway() {
  document.getElementById("findway").value = "";
}

function openmap() {
  goolnk = "http://maps.google.com.tw/maps?q=";
  goolnk += encodeURI(document.getElementById("address").innerHTML);
  window.open(goolnk);
}

function openemail(t) {
  location.href="mailto:"+t.innerHTML;
}

function enquiry_form_submit() {
  if (!document.getElementById("male").checked&&!document.getElementById("female").checked) {
    sfm_show_error_msg("請選擇 \"先生\" 或 \"小姐\"",enquiryform.strName);
    return false;
  } else {
    if (cookieEnabled) {
    setcookie("CustomerName",document.enquiryform.strName.value, 30);
    var t = (document.getElementById("male").checked) ? 1 : 0;
    setcookie("CustomerTitle",t, 7);
    setcookie("CustomerPhone",document.enquiryform.strTel.value, 30);
    setcookie("CustomerEmail",document.enquiryform.strEmail.value, 30);
    setcookie("Comment",document.enquiryform.strComment.value, 1);
    }
    return true;
  }
}

function enquiry_form_reset() {
  document.enquiryform.strName.value = "";
  document.enquiryform.strTel.value = "";
  document.enquiryform.strEmail.value = "";
  document.enquiryform.strComment.value = "";
  document.enquiryform.captcha_code.value = "";
}

function setcookie(c_name,value,expiredays) {
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 ;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return ""
}

function deleteCookie(cookie_name) {
  var cookie_date = new Date();
  cookie_date.setTime(cookie_date.getTime()-1);
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

/************* Home Page functions *****************/

function cntbkformdish() {
  var msg = "";
  if (cookieEnabled) {
    var cusselcookie = getCookie("CustomerDishselect");
    var cnt = 1;
    if (cusselcookie) {
      for (i=0;i<cusselcookie.length;i++) {
        if (cusselcookie.charAt(i)==".") cnt++;
      }
      msg = "您有<span style='color:blue;font-weight:bold;'> "+cnt+" </span>樣料理在點菜單上";
    }
  }
  return msg;
}

function loadsubpage(page, exe) {
  fadeChangeDiv("cover_main", "mainpage");
  jah(page, "mainframe_content", exe);
}

function menu_init() {
  new Accordian('basic-accordian',3,'header_highlight');
}

function fb_init() {
  document.getElementById("fb_iframe").src = document.getElementById("fb_link").value;
}
