/*
* zj.news
* version : 3.0
1.设置首页
设为首页
2.收藏站点
添加收藏
3.获取cookie
zj.getcookie("sessionid");
4.添加cookie
zj.setcookie("memberid","xxx");
5.删除cookie
zj.deletecookie("memberid");
6.设置默认提交按钮
jquery(".main").keypress(function(){zj.enter(event, '.cont .loginbtn'); } );
7.将指定名称的标签组设置为选项卡样式:鼠标事件
tabover("ul_one","div_one","current");
标签组必须是ul -->li, 内容组必须是div -->div
8.将指定名称的标签组设置为选项卡样式:点击事件
tabclick("cont_one","div_one","current");
标签组必须是ul -->li, 内容组必须是div -->div
9.获取查询字符串值
zj.getquery('id',0) 0为未取到数据时的默认值
10.获取指定url的查询字符串值
zj.getquery2(top.document.location.search,'id')
11.在当前地址后添加查询字符串,如果已存在该查询字符串则替换
zj.addquery('id',10)
12.在指定地址后添加查询字符串,如果已存在该查询字符串则替换
zj.addquery2("/demo/detail.aspx?node=test&id=5",'id',10)
13. 页面中图片超过宽度自动等比缩小
zj.fiximagesize(".text", 600);
14.增加栏目点击数
zj.addnodehits
15.栏目浏览权限检查
checknodeperm
16.增加内容点击数
addcontenthits
17.增加内容点击数评分
addcontentscore
method:(0:按ip,1:按用户)
18.获取当前会员信息(未登录显示登录版块)
loadlogin(elem)
19.登录
login(txtname, txtpwd, chkremeber, hanlder)
txtname,用户名输入框id
txtpwd,密码输入框id
chkremeber,记住我复选框
hanlder,登录成功处理函数
20.
21.请求退出
zj.logout
22.检查会员名是否已存在0:用户名或email不可用,1可用,其他:错误消息
validmembername(username)
23.检查会员邮箱是否存在 0:用户名或email不可用,1可用,其他:错误消息
validemail(email)
24.检查验证码
checkverifycode(input)
25.更换验证码
changecode(elem)
26.兑换礼品
dogifttran(giftid)
27.会员k中心搜索内容
dosearch(itemname)
28.删除确认提示
confirmdelete()
29.获取选中项
getselectkeys()
30.前台搜索,跳到search.aspx
gosearch(input);
*
*/
var contentx_url = apppath + "app_service/contentx.ashx";
var member_url = apppath + "app_service/member.ashx"; //会员登录ajax页
var member_panel_url = "user_ajax.aspx"; //会员登录面板加载页
var gift_tran_url = apppath + "app_service/gift.ashx"; //礼品兑换提交页
var login_url = apppath + "login.aspx"; //会员默认页地址
var node_url = apppath + "app_service/node.ashx"; //栏目点击计数ajax页
var verfiycode_url = apppath + "app_service/validatecode.aspx";
var search_url = "search.aspx";
string.prototype.trim = function () { return (this.replace(/^\s+|\s+$/g, "")); }
string.prototype.ltrim = function () { return (this.replace(/^\s*/, "")); }
string.prototype.rtrim = function () { return (this.replace(/\s*$/, "")); }
var zj = new object();
////////////////////util/////////////////////////
zj.sethome = function (obj) {
var url = document.location.protocol + "//" + document.location.hostname;
try {
obj.style.behavior = 'url(#default#homepage)';
obj.sethomepage(url);
}
catch (e) {
if (window.netscape) {
try {
netscape.security.privilegemanager.enableprivilege("universalxpconnect");
}
catch (e) {
alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
}
var prefs = components.classes['@mozilla.org/preferences-service;1'].getservice(components.interfaces.nsiprefbranch);
prefs.setcharpref('browser.startup.homepage', vrl);
} else {
alert("您的浏览器不支持,请按照下面步骤操作:1.打开浏览器设置。2.点击设置首页。3.输入:" + url + "点击确定。");
}
}
};
zj.addfavorite = function (url, title) {
if (url == null) url = document.location.href;
if (title == null) title = document.title;
try {
window.external.addfavorite(url, title);
}
catch (e) {
try {
window.sidebar.addpanel(title, url, "");
}
catch (e) {
alert("加入收藏失败,请使用ctrl+d进行添加");
}
}
};
zj.getcookie = function (name) {
var cookie_start = document.cookie.indexof(name);
var cookie_end = document.cookie.indexof(";", cookie_start);
if (cookie_start == -1) {
return "";
} else {
var length = cookie_end > cookie_start ? cookie_end : document.cookie.length;
var val = document.cookie.substring(cookie_start + name.length + 1, length);
return unescape(val);
}
};
zj.setcookie = function (cookiename, cookievalue, seconds, path, domain, secure) {
var expires = new date();
expires.settime(expires.gettime() + seconds);
document.cookie = escape(cookiename) + '=' + escape(cookievalue)
+ (expires ? '; expires=' + expires.togmtstring() : '')
+ (path ? '; path=' + path : '/')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
zj.deletecookie = function (name) {
var date = new date();
date.settime(date.gettime() - 10000);
document.cookie = name + "=a; expires=" + date.togmtstring();
};
zj.enter = function (event, linkopentype) {
if (event.keycode == 13 && !(event.srcelement && (event.srcelement.tagname.tolowercase() == "textarea"))) {
var defaultbutton = jquery(linkopentype);
if (defaultbutton && typeof (defaultbutton.click) != "undefined") {
defaultbutton.click();
event.cancelbubble = true;
if (event.stoppropagation)
event.stoppropagation();
return false;
}
}
return true;
};
zj.tabover = function (tabname, divname, hovercss) {
jquery("[name='" + tabname + "'] li").hover(function () {
jquery("[name='" + divname + "'] > div").hide();
jquery("[name='" + tabname + "'] li").removeclass(hovercss);
alert(jquery("[name='" + divname + "'] > div").eq(jquery(this).index()).html());
jquery("[name='" + divname + "'] > div").eq(jquery(this).index()).show();
}, function () {
});
};
zj.tabclick = function (tabname, divname, hovercss) {
jquery("[name='" + tabname + "'] li").click(function () {
jquery("[name='" + divname + "'] > div").hide();
jquery("[name='" + tabname + "'] li").removeclass(hovercss);
jquery(this).addclass(hovercss);
jquery("[name='" + divname + "'] > div").eq(jquery(this).index()).show();
});
};
zj.getquery = function (name, defaultvalue) {
var vstr = defaultvalue;
var search = document.location.search.tolowercase();
search = search.substring(1, search.length);
var arr = search.split("&");
for (i = 0; i < arr.length; i++) {
var temp = arr[i].split("=");
if (temp[0] == name) {
vstr = temp[1];
break;
}
}
return vstr;
};
zj.getquery2 = function (search, name) {
var vstr = "";
search = search.tolowercase();
search = search.substring(1, search.length);
var arr = search.split("&");
for (i = 0; i < arr.length; i++) {
var temp = arr[i].split("=");
if (temp[0] == name) {
vstr = temp[1];
break;
}
}
return vstr;
};
zj.addquery = function (name, value) {
var path = document.location.pathname;
var search = document.location.search.tolowercase();
search = search.substring(1, search.length);
var newsearch = "?";
var arr = search.split("&");
for (i = 0; i < arr.length; i++) {
if (arr[i] == "") continue;
var temp = arr[i].split("=");
if (temp[0] == name) continue;
newsearch += arr[i] + "&";
}
newsearch += name + "=" + value;
return path + newsearch;
};
zj.addquery2 = function (url, name, value) {
var arr = url.split('?');
if (arr.length == 1) return url + "?" + name + "=" + value;
var path = arr[0];
var search = arr[1];
var newsearch = "?";
var arr1 = search.split("&");
for (i = 0; i < arr1.length; i++) {
var temp = arr1[i].split("=");
if (temp[0] == name) continue;
newsearch += arr1[i] + "&";
}
newsearch += name + "=" + value;
return path + newsearch;
};
zj.removequery = function (name) {
var vstr = "";
var search = document.location.search.tolowercase();
search = search.substring(1, search.length);
var arr = search.split("&");
for (i = 0; i < arr.length; i++) {
var temp = arr[i].split("=");
if (temp[0] != "" && temp[0] != name) {
vstr += "&" + temp;
}
}
if (vstr.length > 1) {
vstr = "?" + vstr.substring(1);
}
return document.location.pathname + vstr;
};
zj.getdomain = function () {
var url = document.location.protocol + "//" + document.location.host;
return url;
};
zj.validtip = function (tipcss) {
jquery(tipcss).each(function () {
//var inputid = jquery(this).attr("controltovalidate");
var inputid = jquery(this).attr("id");
inputid = eval(inputid).controltovalidate;
var offset = jquery("#" + inputid).offset();
var l = offset.left;
var t = offset.top;
var w = jquery("#" + inputid).width();
jquery(this).css({ left: l + w, top: t });
});
};
zj.validtipv = function (tipcss) {
jquery(tipcss).each(function () {
//var inputid = jquery(this).attr("controltovalidate");
var inputid = jquery(this).attr("id");
inputid = eval(inputid).controltovalidate;
var offset = jquery("#" + inputid).offset();
var l = offset.left;
var t = offset.top;
var h = jquery("#" + inputid).height();
jquery(this).css({ left: l, top: t + h });
});
};
zj.fiximagesize = function (filter, w, h) {
if (filter == null) return;
if (w == null) w = 700;
if (h == null) h = 2000;
jquery(filter).find("img").bind("load", function () {
var img = jquery(this).get(0);
var heightwidth = img.offsetheight / img.offsetwidth;
var widthheight = img.offsetwidth / img.offsetheight;
if (img.offsetheight > 1)
if (img.readystate != "complete") {
return false; //确保图片完全加载
}
if (img.offsetwidth > w) {
img.width = w;
img.height = w * heightwidth;
}
if (img.offsetheight > h) {
img.height = h;
img.width = h * widthheight;
}
});
};
/////////////////////cms////////////////////////
zj.checkperm = function () {
if (currentnode != "" && currentid != "") {
var res = jquery.ajax({
type: "post",
datatype: "json",
async: false,
url: node_url,
data: { action: "canview", node: currentnode, id: currentid }
}).responsetext;
eval("res=" + res);
if (res.code == 1) {
return true;
} else {
alert("你所在的会员组无权查看该栏目");
document.location.href = member_default_url;
return false;
}
} else {
alert("缺少参数:currentnode,currentid");
return false;
}
};
zj.addhits = function () {
if (currentnode != "" && currentid != "") {
jquery.post(contentx_url, { action: "hits", node: currentnode, id: currentid });
}
};
zj.addscore = function (id, score, method) {
if (id == null || score == "") {
alert("缺少参数id,score");
return;
}
jquery.ajax({
type: "post",
datatype: "json",
url: contentx_url,
data: { action: "score", score: score, id: id, method: method },
success: function (res) {
if (res.code == 1) {
alert("投票成功");
document.location.reload();
} else if (res.code == 2) {
alert("已经评价过");
} else {
alert(res.msg);
}
}
});
};
zj.loadlogin = function (elem) {
var path = member_panel_url + "?" + math.random();
if (language == 'zh-cn') {
path = apppath + path;
} else {
path = apppath + language + "/" + path;
}
jquery(elem).load(path);
};
zj.login = function (txtname, txtpwd,txtverify, chkremeber, jump) {
var name = jquery(txtname).val();
var pwd = jquery(txtpwd).val();
var min = 0;
if (name == "" || pwd == "") {
alert("请输入用户名和密码");
return;
}
if (txtverify != "") {
var code = jquery(txtverify).val();
if (code == "") {
alert("请输入验证码");
return;
}
if (!zj.verifycode(code)) {
alert("验证码错,请重新输入");
return;
}
}
if (chkremeber != "") {
if (jquery(chkremeber).attr("checked") == "true")
{
min = 24 * 60 * 10;
}
}
jquery.ajax({
type: "post",
datatype: "json",
url: member_url,
data: { action: "login", username: name, password: pwd, expire: min },
error: function (req, status, error) { alert(error.message); },
success: function (res) {
if (res.code == 1) {
if (jump == "") {
document.location.reload();
}
else{
document.location.href = jump;
}
} else {
alert(res.msg);
}
}
});
};
zj.logout = function () {
jquery.ajax({
type: "post",
datatype: "json",
url: member_url,
data: { action: "logout" },
error: function (req, status, error) {
alert(error.message);
},
success: function (res) {
if (res.code == 1) {
document.location.reload();
} else {
alert(res.msg);
}
}
});
};
zj.validname = function (username) {
if (username == "") return false;
var res = jquery.ajax({
type: "post",
async: false,
datatype: "json",
url: member_url,
data: { action: "validname", name: username }
}).responsetext;
eval("res=" + res);
if (res.code == 1) {
return true;
} else if (res.code == 0) {
return false;
} else {
alert(res.msg);
return false;
}
};
zj.validemail = function (email) {
if (email == "") return false;
var res = jquery.ajax({
type: "post",
datatype: "json",
async: false,
url: member_url,
data: { action: "validemail", email: email }
}).responsetext;
eval("res=" + res);
if (res.code == 1) {
return true;
} else if (res.code == 0) {
return false;
} else {
alert(res.msg);
return false;
}
};
zj.validcard = function (code) {
if (code == "") return false;
var res = jquery.ajax({
type: "post",
async: false,
datatype: "json",
url: member_url,
data: { action: "validcard", card: code }
}).responsetext;
eval("res=" + res);
if (res.code == 1) {
return true;
} else {
alert(res.msg);
return false;
}
};
zj.verifycode = function (code) {
var u = verfiycode_url + "?action=verify&code=" + code;
var res = jquery.ajax({ url: u, async: false, cache: false }).responsetext;
if (res == "1") return true;
return false;
};
zj.changecode = function (elem) {
jquery(elem).attr("src", verfiycode_url + "?action=create&r=" + math.random());
};
zj.setverifycode = function () {
$(".verifycode").attr("src", verfiycode_url + "?action=create&r=" + math.random());
$(".verifycode").click(function () { zj.changecode(this); });
$(".verifylink").click(function () { zj.changecode($(this).prev()); });
}
zj.dogifttran = function (giftid) {
if (giftid == null) { giftid = getquery("id"); }
if (giftid == "") { alert("缺少参数giftid"); return; }
jquery.ajax({
type: "post",
url: gift_tran_url,
datatype: "json",
data: { action: "buygift", "giftid": giftid },
success: function (res) {
if (res.code == 1) {
alert("兑换成功,请等待管理员处理!");
} else {
alert(res.msg);
}
},
error: function (req, status, error) {
alert("报歉,出现错误:" + error + ",请稍候再试!");
}
});
};
zj.dosearch = function (itemname) {
var title = $("search_title").val();
if (title == "") {
alert("请输入" + itemname);
return;
}
var url = zj.removequery("k");
url += url.indexof('?') > 0 ? "&" : "?";
document.location.href = url + "k=" + title;
};
zj.gosearch = function (inputid) {
var title = $(inputid).val();
if (title == "") return;
var url = search_url;
if (language == "zh-cn") {
url = apppath + search_url;
} else {
url = apppath + language + "/" + search_url;
}
document.location.href = url + "k=" + title;
};
zj.confirmdelete = function () {
var ids = getselectkeys();
if (ids == "") {
alert('请钩选要删除的信息');
return false;
}
if (!confirm("确认要删除所有选中的信息及其相关信息吗?")) {
return false;
}
return true;
};
zj.getselectkeys = function () {
var keys = '';
jquery("input[name=selectkeys]").filter(":checked").each(
function (item) {
keys += this.value + ",";
}
);
return keys;
};
zj.setcurrent = function (curstyle) {
try {
if (channelnode == "") channelnode = "zh-cn";
$("#" + channelnode).addclass(curstyle);
} catch (e) { }
};