﻿///<reference path="../ext/vswd-ext_2.2.js">

/*
========================
     Contact Us
@author: HONG,Lane-Chang
@dates:  2009/02/25
@update: 
========================
*/

var PanelCU, WindowCU, objJsonCU;

    Ext.BLANK_IMAGE_URL = 'include/ext/resources/images/default/s.gif';
    Ext.QuickTips.init();

    function ShowCU(el) {
        PanelCU = new Ext.form.FormPanel({
                layout:'form',
                autoScroll: false,
                frame: true,
                bodyStyle: 'border:none;margin:0px auto;padding:10px;',
                labelAlign: 'center',
                labelWidth: 80,
                items: [
                    new Ext.form.TextField({
                        id: 'txtCompany',
                        name: 'txtCompany',
                        labelSeparator: '：',
                        msgTarget: 'side',
                        width: 200,
                        fieldLabel: '公司名稱',
                        maxLength: 20,
                        minLength: 2,
                        allowBlank: false
                    }),
                    new Ext.form.RadioGroup({
                        labelSeparator: '：',
                        width:400,
                        vertical: false,
                        fieldLabel: '服務需求',
                        columns: 2,
                        items: [
                            {
                                name: 'rioService',
                                inputValue: '網站規劃建置',
                                boxLabel: '網站規劃建置',
                                checked: true
                            }, {
                                name: 'rioService',
                                inputValue: '互動式光碟',
                                boxLabel: '互動式光碟'
                            }, {
                                name: 'rioService',
                                inputValue: '影片剪輯',
                                boxLabel: '影片剪輯'
                            }, {
                                name: 'rioService',
                                inputValue: '多媒體簡報',
                                boxLabel: '多媒體簡報'
                            }
                        ]
                    }),
                     new Ext.form.TextField({
                         id: 'txtName',
                         name: 'txtName',
                         labelSeparator: '：',
                         msgTarget: 'side',
                         width: 200,
                         fieldLabel: '您的姓名',
                         maxLength: 15,
                         minLength: 2,
                         allowBlank: false
                     }),
                     new Ext.form.TextField({
                         id: 'txtPhone',
                         name: 'txtPhone',
                         labelSeparator: '：',
                         msgTarget: 'side',
                         width: 200,
                         fieldLabel: '聯絡電話',
                         maxLength: 20,
                         minLength: 2,
                         allowBlank: false
                     }),
                      new Ext.form.TextField({
                          id: 'txtAddress',
                          name: 'txtAddress',
                          labelSeparator: '：',
                          msgTarget: 'side',
                          width: 200,
                          fieldLabel: '聯絡地址',
                          maxLength: 50
                      }),
                      new Ext.form.TextField({
                          id: 'txtEmail',
                          name: 'txtEmail',
                          labelSeparator: '：',
                          msgTarget: 'side',
                          width: 250,
                          vtype: 'email',
                          fieldLabel: '電子郵件',
                          maxLength: 50
                      }),
                      new Ext.form.TextArea({
                          id: 'txtContent',
                          name: 'txtContent',
                          labelSeparator: '：',
                          msgTarget: 'side',
                          width: 400,
                          height: 150,
                          fieldLabel: '需求說明',
                          maxLength: 512
                      })
                ],
                buttons: [
                    {
                        id: 'btn_SUBMIT',
                        name: 'btn_SUBMIT',
                        text: '確定送出',
                        handler: Form_Sumbit
                    }, {
                        id: 'btn_Clear',
                        name: 'btn_Clear',
                        text: '清除重填',
                        handler: function() {
                        fnShowQ_YN('系統訊息', '您確定要清除已填寫的資料嗎?', 'btn_Clear', fnClear);
                        }
                    }
                ]
            });



        //建立 Windows
        WindowCU = new Ext.Window({
            layout: 'fit',
            width: 560,
            height: 460,
            animateTarget: el,
            bodyStyle: 'padding:5px;',
            resizable: false,
            modal: true,
            closeable: true,
            plain: true,
            iconCls: 'icon-mail',
            title: '<span class="Window-Title">聯絡康佳</span>&nbsp;<span class="Window-Title2">Contact us</span>',
            items: [PanelCU]
        });

        //當Windows Close
        WindowCU.on('close', function() {
            PanelCU = null;
            WindowCU = null;
        });

        WindowCU.show();
    }




    //清除資料
    function fnClear(id) {
        if (id == "yes") {
            PanelCU.getForm().reset();
        }
    }



//送出資料
function Form_Sumbit() {
        if (PanelCU.getForm().isValid()) {
            PanelCU.getForm().submit({
                method: 'POST',
                url: 'Handle.aspx?fn=sendmail',
                waitMsg: '資料傳送中，請稍候...',
                waitTitle: '系統訊息',
                reset: true,
                success: function(form, action) {
                    try {
                       objJsonCU = Ext.util.JSON.decode(action.response.responseText);
                        if (objJsonCU.success == true) {
                            fnShowInfo('系統訊息', objJsonCU.msg, '',
                            function() {
                                WindowCU.close();
                                PanelCU = null;
                                WindowCU = null;
                            });
                        }
                        else {
                            fnShowErr(objJsonCU.msg, '', '');
                        }
                    } catch (e) {
                        if (action.response.responseText != '') {
                            fnShowWar('連線發生錯誤，系統忙碌中請稍候再試...');
                        }
                        else {
                            fnShowWar(e);
                        }
                    }
                },
                failure: function(form, action) {
                    try {
                       objJsonCU = Ext.util.JSON.decode(action.response.responseText);
                        fnShowErr(objJsonCU.msg, '', '');
                    }
                    catch (e) {
                        if (action.response.responseText != '') {
                            fnShowWar('連線發生錯誤，系統忙碌中請稍候再試...');
                        }
                        else {
                            fnShowWar(e);
                        }
                    }
                }
            });
        }
}




//跳一個視窗
function Pop_Window(w,h,title,el,url){
	var Pop_tmp = null;
	var fpop = null;
            	
	Pop_tmp = new Ext.Window({
			layout: 'fit',
            width: w,
            height: h,
            animateTarget: el,
            resizable: false,
            modal: true,
            closeable: true,
            plain: true,
            bodyStyle:'padding:2px;',
            title: '<span class="Window-Title2">' + title + '</span>',
           	html:'<iframe src="' + url + '" style="border:none;width:' + (w -22) +'px;height:' + (h-42) + 'px;"/>'
	}).show()
	
	//Pop_tmp.on('close',function(){Pop_tmp = null;});
}



//到某個網址
function ToURL(url){
	parent.location = url;
}