/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2008 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 170 2008-12-04 19:03:12Z emartin24 $
 *
 */

 
$(document).ready(function() {
$('#loginModal a.lgnModal').click(function(e) {
         e.preventDefault();
        // load the contact form using ajax
        $("#msg").html("<font color='red'>loading...</font>");
        $.get("login.htm", function(data) {
            // create a modal dialog with the data
            $(data).modal({
                position: ["15%"],
                overlayId: 'contact-overlay',
                containerId: 'contact-container',
                closeClass: 'closeclass',
                onOpen: contact.open 
                
                 
                
                 
            });
        });
    });

   
});

var contact = {
    message: null,

    open: function(dialog) {
        // add padding to the buttons in firefox/mozilla
        $("#msg").html("");
        if ($.browser.mozilla) {
            $('#contact-container .contact-button').css({
                'padding-bottom': '2px'
            });
        }
        // input field font size
        if ($.browser.safari) {
            $('#contact-container .contact-input').css({
                'font-size': '.9em'
            });
        }

        // dynamically determine height
        var h = 280;
        if ($('#contact-subject').length) {
            h += 26;
        }
        if ($('#contact-cc').length) {
            h += 22;
        }

        var title = $('#contact-container .contact-title').html();

        dialog.overlay.fadeIn(200, function() {
            dialog.container.fadeIn(200, function() {
                dialog.data.fadeIn(200, function() {
                    $('#contact-container .contact-content').animate({
                        height: h
                    }, function() {
                        $('#contact-container .contact-title').html(title);


                    });
                });
            });
        });

        $('#contact-container>#denglu,#denglu,#denglu2').click(function() {

            var username = $("#username").val();
            var pwd = $("#pwd").val();

            var identcode = $('#identcode').val();
           
            var str = "username=" + escape(username) + "&pwd=" + escape(pwd) + "&icode=" + identcode;
 
            // start
            $.ajax({ type: "get",
                url: "ajax/login_proc.aspx?" + str + "&timeStamp=" + new Date().getTime(),
                beforeSend: function(XMLHttpRequest) {//ShowLoading();
                   $("#denglumsg").html("正在处理，稍候...");
                },
                success: function(data, textStatus) {

                    var status = data.split("######")[0];
                    if (status == "icode") {

                        alert("验证码错误！");
                        // window.location.href = ('http://mail.' + houzui);
                    }
                    if (status == "userok") {
                        alert("登陆成功！");
                        window.location.href = ('default.aspx');
                    }
                    else {
                        alert("用户名或密码错误！");
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    //HideLoading();
                  $("#denglumsg").html("");
                },
                error: function() { //alert("服务器处理错误！")
                }
            });

            //end

        });
    }
};
