$(function(){
$.cookie("FAQ_SourceType", "", {path: "/"});
$.cookie("FAQ_ProductsType", "", {path: "/"});
});
/**
* 字符串为javascript转码。
*/
String.prototype.encode = function() {
var o = [/\\/g, /"/g, /'/g, /\//g, /\r/g, /\n/g];
var n = ["\\u005C", "\\u0022", "\\u0027", "\\u002F", "\\u000A", "\\u000D"];
var s = this;
for (var i = 0; i < o.length; i++) {
s = s.replace(o[i], n[i]);
}
return s;
};
/**
* 序列化一个对象(只序列化String,Number,Date,Array,Json对象和有serialize方法的对象,其它的对象都会被序列化成null)
* @memberof Object
* @param obj { Object } 需要序列化的Json、Array对象或其它对象
* @return 序列化后的字符串
* @type String
*/
Object.serialize = function(obj) {
if (obj == null) return null;
if (obj.serialize) return obj.serialize();
var cst = obj.constructor;
switch (cst) {
case String:
return '"' + obj.encode() + '"';
case Number:
return obj + "";
case Date:
return 'new Date(' + obj.getTime() + ')';
case Array:
var ar = [];
for (var i = 0; i < obj.length; i++) ar[i] = Object.serialize(obj[i]);
return '[' + ar.join(',') + ']';
case Object:
var ar = [];
for (var i in obj) {
ar.push('"' + (i + '').encode() + '":' + Object.serialize(obj[i]));
}
return '{' + ar.join(',') + '}';
}
return null;
};
var Comment, CommentUtils, IComment, IReadComment, IWriteComment, ReadComment, WriteComment,WriteFactory, comment, WriteInfo, Singleton, tmp_cache_time = "", tmp_cache_id = "";
var __hasProp = Object.prototype.hasOwnProperty,
__extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
};
/**
* IComment Class
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
IComment = (function() {
function IComment() {}
IComment.prototype.writeComment = function() {};
IComment.prototype.readComment = function() {};
return IComment;
})();
/**
* IWriteComment Class
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
IWriteComment = (function() {
function IWriteComment() {}
IWriteComment.prototype.writeComment = function() {};
return IWriteComment;
})();
/**
* IReadComment Class
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
IReadComment = (function() {
function IReadComment() {}
IReadComment.prototype.readComment = function() {};
return IReadComment;
})();
/**
* Comment Class
*
* This class extends the parent result class: IComment
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
Comment = (function() {
var _conf, _read_comment, _write_comment;
__extends(Comment, IComment);
function Comment() {
Comment.__super__.constructor.apply(this, arguments);
}
_write_comment = "";
_read_comment = "";
Comment.prototype.writeComment = function(write_comment) {
_write_comment = write_comment;
return _write_comment.writeComment();
};
Comment.prototype.readComment = function(read_comment) {
_read_comment = read_comment;
return _read_comment.readComment();
};
return Comment;
})();
/**
* CookieWriteComment Class
*
* This class extends the parent result class: IWriteComment
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
CookieWriteComment = (function() {
var _utils, _makeParser, _database, _comment_info_json;
__extends(CookieWriteComment, IWriteComment);
_utils = "";
function CookieWriteComment(comment_info_json) {
_comment_info_json = comment_info_json;
_utils = new CommentUtils;
}
CookieWriteComment.prototype.writeComment = function() {
if(_comment_info_json.name == '' || _comment_info_json.email == ''){
return ;
}
_utils.setCookie(_comment_info_json.id, _makeParser());
//alert("Cookies write comment!" +' '+ _comment_info_json.id +' ' + _comment_info_json.comment +' '+ _comment_info_json.email +' '+ _comment_info_json.name +' '+ _comment_info_json.sendmail +' '+ _comment_info_json.isweb);
};
_makeParser = function(){
var _tmp_cookie, _append;
_database =
{
id: _comment_info_json.id,
items:[]
};
_append = {name: _comment_info_json.name, time: _comment_info_json.time, email: _comment_info_json.email, comment: _comment_info_json.comment} ;
try{
_tmp_cookie = eval("("+ _utils.getCookie(_comment_info_json.id) +")");
_tmp_cookie.items.push(_append);
_database = _tmp_cookie;
}catch(err){
_database.items.push(_append);
}
return Object.serialize(_database);
};
return CookieWriteComment;
})();
/**
* HtmlWriteComment Class
*
* This class extends the parent result class: IWriteComment
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
HtmlWriteComment = (function() {
var _utils, _comment_info_json;
__extends(HtmlWriteComment, IWriteComment);
_utils = "";
function HtmlWriteComment(comment_info_json) {
_comment_info_json = comment_info_json;
_utils = new CommentUtils;
}
HtmlWriteComment.prototype.writeComment = function() {
if(_comment_info_json.name == '' || _comment_info_json.email == ''){
return ;
}
var t;
t = "";
t += "
\n";
t += "
Q\n";
t += "
"+ _comment_info_json.comment.replace(/[\n|\r]/g, "
") +"
\n"
t += "
Asked by "+ _comment_info_json.name +" ("+ _comment_info_json.time +") \n";
t += "
\n";
t += "
\n";
t += "
\n";
$(".qaMaintitle").after(t);
//alert("Html write comment!" +' '+ _comment_info_json.comment +' '+ _comment_info_json.email +' '+ _comment_info_json.name +' '+ _comment_info_json.sendmail +' '+ _comment_info_json.isweb);
};
return HtmlWriteComment;
})();
/**
* PostWriteComment Class
*
* This class extends the parent result class: IWriteComment
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
PostWriteComment = (function() {
var _utils, _comment_info_json;
__extends(PostWriteComment, IWriteComment);
_utils = "";
function PostWriteComment(comment_info_json) {
_comment_info_json = comment_info_json;
_utils = new CommentUtils;
}
PostWriteComment.prototype.writeComment = function() {
if(_comment_info_json.comment.length < 20){
$("#sendbutton").attr("disabled",false);
alert("The question must be more than 20 characters long");
$("#qloading").removeAttr("style");
$("#qloading").hide();
$("#qloadingbg").remove();
tmp_cache_time = "", tmp_cache_id = "";
return false;
}
writeQAtoQ_static(
$("sendbutton"),
_comment_info_json.name,
_comment_info_json.email,
_comment_info_json.sendmail,
_comment_info_json.isweb,
_comment_info_json.comment,
_comment_info_json.sources_type,
_comment_info_json.product_type,
_comment_info_json.i_doBook,
_comment_info_json.i_PhoneNo,
_comment_info_json.i_TravelDate,
_comment_info_json.i_GroupType,
_comment_info_json.i_Nationality,
_comment_info_json.i_partner
);
return true;
//alert("Post write comment!" +' '+ _comment_info_json.comment +' '+ _comment_info_json.email +' '+ _comment_info_json.name +' '+ _comment_info_json.sendmail +' '+ _comment_info_json.isweb);
};
return PostWriteComment;
})();
/**
* ReadComment Class
*
* This class extends the parent result class: IReadComment
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
ReadComment = (function() {
var _utils;
__extends(ReadComment, IReadComment);
ReadComment.id;
_utils = "";
function ReadComment(id) {
this.id = id;
_utils = new CommentUtils;
}
ReadComment.prototype.readComment = function() {
var _comment_info_json, _sizeof;
//try{
_comment_info_json = eval("("+ _utils.setCookie($.md5(location.pathname)) +")") ;
if(_comment_info_json != undefined){
_sizeof = _comment_info_json.items.length;
for(var i=0; i < _sizeof; i++){
if($("#qupdate").val() > _utils.getNumberDate(_comment_info_json.items[i].time)){
(new HtmlWriteComment({"comment": _comment_info_json.items[i].comment, "email": _comment_info_json.items[i].email, "name": _comment_info_json.items[i].name, "time": _comment_info_json.items[i].time})).writeComment();
}
}
};
//}catch(err){
// return;
//}
};
return ReadComment;
})();
/**
* CommentUtils Class
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
CommentUtils = (function() {
function CommentUtils() {}
CommentUtils.prototype.synchroGet = function() {};
CommentUtils.prototype.setCookie = function(name, value, options) {
return $.cookie(name, value, options);
};
CommentUtils.prototype.getCookie = function(sMainName, sSubName) {
return GetCookie(sMainName, sSubName);
};
CommentUtils.prototype.getDatetime = function() {
var _tmp_date = "";
$.ajaxSetup({async: false});
$.get("/api/sys-date.asp?d=shortdate", "", function(data){_tmp_date=data;}, "text");
$.ajaxSetup({async: true});
return _tmp_date;
};
CommentUtils.prototype.getLngDate = function(o) {
var _tmp_date = "";
$.ajaxSetup({async: false});
$.get("/api/sys-date.asp?d=lngdate", "", function(data){_tmp_date=data;}, "text");
$.ajaxSetup({async: true});
return _tmp_date;
};
CommentUtils.prototype.getNumberDate = function(date) {
var _numer_date, _month, _date, _year, _tmp_datetime, _time;
//_time = new Date();
_numer_date = {"Jan.": "01", "Feb.": "02", "Mar.": "03", "Apr.": "04", "May.": "05", "Jun.": "06", "Jul.": "07", "Aug.": "08", "Sep.": "09", "Oct.": "10", "Nov.": "11", "Dec.": "12"};
//_tmp_datetime = "Oct. 09, 2011";
_tmp_datetime = date;
_tmp_datetime = _tmp_datetime.replace(/\s+/g, "");
_date = _tmp_datetime.match(/[^a-zA-Z\.\,]+/);
_month= _tmp_datetime.match(/[a-zA-Z\.]+/);
_year = _tmp_datetime.match(/[0-9]{4}/);
for(var i in _numer_date){
if(i == _month){
_month = _numer_date[i];
break;
}
}
//_tmp_datetime = _year +''+ _month +''+ _date;
//_tmp_datetime = _tmp_datetime + this.substr("00" + _time.getHours(), -2) +''+ this.substr("00" + _time.getMinutes()) +''+ this.substr("00" + _time.getSeconds());
_tmp_datetime = this.getLngDate();
return _tmp_datetime;
};
CommentUtils.prototype.substr = function(str, start, len) {
var i = 0,
allBMP = true,
es = 0,
el = 0,
se = 0,
ret = '';
str += '';
var end = str.length;
// BEGIN REDUNDANT
this.php_js = this.php_js || {};
this.php_js.ini = this.php_js.ini || {};
// END REDUNDANT
switch ((this.php_js.ini['unicode.semantics'] && this.php_js.ini['unicode.semantics'].local_value.toLowerCase())) {
case 'on':
// Full-blown Unicode including non-Basic-Multilingual-Plane characters
// strlen()
for (i = 0; i < str.length; i++) {
if (/[\uD800-\uDBFF]/.test(str.charAt(i)) && /[\uDC00-\uDFFF]/.test(str.charAt(i + 1))) {
allBMP = false;
break;
}
}
if (!allBMP) {
if (start < 0) {
for (i = end - 1, es = (start += end); i >= es; i--) {
if (/[\uDC00-\uDFFF]/.test(str.charAt(i)) && /[\uD800-\uDBFF]/.test(str.charAt(i - 1))) {
start--;
es--;
}
}
} else {
var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
while ((surrogatePairs.exec(str)) != null) {
var li = surrogatePairs.lastIndex;
if (li - 2 < start) {
start++;
} else {
break;
}
}
}
if (start >= end || start < 0) {
return false;
}
if (len < 0) {
for (i = end - 1, el = (end += len); i >= el; i--) {
if (/[\uDC00-\uDFFF]/.test(str.charAt(i)) && /[\uD800-\uDBFF]/.test(str.charAt(i - 1))) {
end--;
el--;
}
}
if (start > end) {
return false;
}
return str.slice(start, end);
} else {
se = start + len;
for (i = start; i < se; i++) {
ret += str.charAt(i);
if (/[\uD800-\uDBFF]/.test(str.charAt(i)) && /[\uDC00-\uDFFF]/.test(str.charAt(i + 1))) {
se++; // Go one further, since one of the "characters" is part of a surrogate pair
}
}
return ret;
}
break;
}
// Fall-through
case 'off':
// assumes there are no non-BMP characters;
// if there may be such characters, then it is best to turn it on (critical in true XHTML/XML)
default:
if (start < 0) {
start += end;
}
end = typeof len === 'undefined' ? end : (len < 0 ? len + end : len + start);
return start >= str.length || start < 0 || start > end ? !1 : str.slice(start, end);
}
return undefined; // Please Netbeans
};
return CommentUtils;
})();
/**
* WriteFactory Class
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
WriteFactory = (function() {
var _write_info;
function WriteFactory() {
_write_info = new WriteInfo;
}
WriteFactory.prototype.createInstance = function(ationName) {
var extension;
extension = ationName;
switch (extension) {
case "Cookie":
return new CookieWriteComment({"comment": _write_info.comment, "email": _write_info.email, "name": _write_info.name, "id": _write_info.id, "time": _write_info.time});
case "Html":
return new HtmlWriteComment({"comment": _write_info.comment, "email": _write_info.email, "name": _write_info.name, "time": _write_info.time});
case "Post":
return new PostWriteComment({
"comment": _write_info.comment,
"email": _write_info.email,
"name": _write_info.name,
"sendmail": _write_info.sendmail,
"isweb": _write_info.isweb,
"sources_type": _write_info.sources_type,
"product_type": _write_info.product_type,
"i_doBook": _write_info.i_doBook,
"i_PhoneNo": _write_info.i_PhoneNo,
"i_TravelDate": _write_info.i_TravelDate,
"i_GroupType": _write_info.i_GroupType,
"i_Nationality": _write_info.i_Nationality,
"i_partner": _write_info.i_partner
});
}
};
return WriteFactory;
})();
/**
* WriteInfo Class
*
* @package Comment
* @category QA
* @author CH Dev Team
*/
WriteInfo = (function() {
var _utils;
WriteInfo.id;
WriteInfo.time;
WriteInfo.comment;
WriteInfo.email;
WriteInfo.name;
WriteInfo.sendmail;
WriteInfo.isweb;
WriteInfo.qabody;
WriteInfo.sources_type;
WriteInfo.product_type;
WriteInfo.i_doBook;
WriteInfo.i_PhoneNo;
WriteInfo.i_TravelDate;
WriteInfo.i_GroupType;
WriteInfo.i_Nationality;
WriteInfo.i_partner;
function WriteInfo() {
_utils = new CommentUtils;
if(tmp_cache_time == ""){
this.id = $.md5(location.pathname);
this.time = _utils.getDatetime();
tmp_cache_id = this.id;
tmp_cache_time = this.time;
}else{
this.id = tmp_cache_id;
this.time = tmp_cache_time;
}
this.comment = $("#qabody").val();
this.email = $("#qaemail").val();
this.name = $("#qaname").val();
this.sendmail= $("#sendmail").attr("checked");
this.isweb = $("#isweb").attr("checked");
this.sources_type = $("#sources_type").val() || -1;
this.product_type = $("#product_type").val() || -1;
this.i_doBook = $("#i_doBook").attr("checked") || false;
this.i_PhoneNo = $("#i_PhoneNo").val();
this.i_TravelDate = $("#i_TravelDate").val();
this.i_GroupType = $("#i_GroupType").val();
this.i_Nationality = $("#i_Nationality").val();
this.i_partner=$('input[name="partner"]').val();
}
return WriteInfo;
})();
/**
*
* Main
*
*/
comment = new Comment;
function send(){
var _load = (function (){
var _qaBox;
_qaBox= $("#qaBox");
$("#qloading").after("");
$("#qloading").show();
$("#qloading").css({"position": "absolute", "width": _qaBox.outerWidth(), "height": _qaBox.outerHeight(), "z-index": "10000"});
$("#sendbutton").attr("disabled","disabled");
})();
if(!comment.writeComment((new WriteFactory).createInstance("Post"))){
return;
}
comment.writeComment((new WriteFactory).createInstance("Html"));
comment.writeComment((new WriteFactory).createInstance("Cookie"));
}
try{
comment.readComment(new ReadComment());
}catch(err){
//alert(err);
}