﻿// JScript 文件
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
function getObject(objectId)
{
    if(document.getElementById && document.getElementById(objectId))
	return document.getElementById(objectId);
}
$(document).ready(function(){
    if($("input#sendWords").length!=0){
        $("input#sendWords").click(function(){
            saveMessage();
        });
        
    }
});

function saveMessage()
        {
            if($("#textfield3").val()==""){
                alert("请输入您的姓名！");
                return ;
            }
            if($("#textfield5").val()==""){
                alert("留言的具体内容不能为空！");
                return ;
            }
            if($("#textfield7").val()==""){
                alert("留言的标题不能为空！");
                return ;
            }
            if($("#textfield6").val().toLowerCase()!= $.cookie("CheckCode").toLowerCase()){
                alert("验证码不正确！");
                return ;
            }
            
            $.ajax({
                 url: "/saveMessage.aspx",
                 type:"POST",
                 cache: false,
                 data:{"ToCompany":$("#companyid").val(),"name":$("#textfield3").val(),"company":$("#textfield2").val(),"email":$("#textfield").val(),"phone":$("#textfield4").val(),"title":$("#textfield7").val(),"content":$("#textfield5").val()},
                 contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                 dataType:"json",
                 processData:true,
                 success: function (data){
                     if(data.result=="success")
                     {
                        alert("恭喜您，您的留言已经成功被保存！");
                        $("input#sendWords").unbind("click").click(function(){
                            alert("您已经成功提交留言，不能再次提交！");
                        });
                        
                     }else{
                        alert("您还有没有登录，请登录后再试！");
                     }
		       }
		       
        });
} 
       

