yzms/show/js/func.js

600 lines
17 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function $(id)
{
return document.getElementById(id);
}
var $G = {
gIsIE: ((navigator.userAgent.toLowerCase().indexOf('msie') != -1) ? true : false),
gIsIE6: ((navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) ? true : false),
$: function(id)
{
return document.getElementById(id);
},
rm: function(id)
{
if(this.$(id))
this.$(id).parentNode.removeChild(this.$(id));
},
cover: function(color, alpha, magin)
{
if(typeof(color) == 'undefined') color = '#666666';
if(typeof(alpha) == 'undefined') alpha = 40;
if(typeof(magin) == 'undefined') magin = 0;
var alpha2 = alpha / 100;
if(!this.$("cover_div_dasda")) {
var div = document.createElement('div');
div.id = 'cover_div_dasda';
div.style.position = 'absolute';
var height = document.documentElement.clientHeight;
if(height == 0) height = document.body.clientHeight;
var sheight = document.documentElement.scrollHeight;
if(sheight == 0) sheight = document.body.scrollHeight;
var width = document.documentElement.clientWidth;
if(width == 0) width = document.body.clientWidth;
var swidth = document.documentElement.scrollWidth;
if(swidth == 0) swidth = document.body.scrollWidth;
if(sheight > height) height = sheight + magin;
if(swidth > width) width = swidth;
div.style.width = width + 'px';
div.style.height = height + 'px';
div.style.backgroundColor = color;
div.style.left = '0px';
div.style.top = '0px';
div.style.zIndex = '5';
div.style.filter = 'alpha(opacity=' + alpha + ')';
div.style.opacity = alpha2;
document.body.appendChild(div);
}
},
uncover: function()
{
this.rm("cover_div_dasda");
},
show_div: function(id, width, height)
{
this.cover();
var cwidth = document.documentElement.clientWidth;
var ctop = document.documentElement.scrollTop;
if(cwidth == 0) cwidth = document.body.clientWidth;
if(ctop == 0) ctop = document.body.scrollTop;
var cheight = document.documentElement.clientHeight;
if(cheight == 0) cheight = document.body.clientHeight;
var left = parseInt((cwidth-width)/2);
var top = parseInt((cheight-height)/2) + ctop - 20;
this.$(id).style.left = left + 'px';
this.$(id).style.top = top + 'px';
this.$(id).style.display = 'block';
this.scroll(function(){
var ctop = document.documentElement.scrollTop;
if(ctop == 0) ctop = document.body.scrollTop;
var top = parseInt((cheight-height)/2) + ctop - 20;
document.getElementById(id).style.top = top + 'px';
});
},
hide_div: function(id, p)
{
if(p !== false) this.uncover();
this.$(id).style.display = 'none';
},
/*cookie*/
getCookie: function(sName)
{
var cookie = "" + document.cookie;
var start = cookie.indexOf(sName);
if (cookie == "" || start == -1)
return "";
var end = cookie.indexOf(';',start);
if (end == -1)
end = cookie.length;
if(start+sName.length + 1>end) return "";
return decodeURIComponent(this.trim(cookie.substring(start+sName.length + 1,end)));
},
delCookie: function(sName)
{
var expdate = new Date();
expdate.setFullYear(expdate.getFullYear() - 1);
document.cookie = sName + "=;path=/;expires="+expdate.toGMTString()+";domain=.fsecity.com";
},
setCookie: function(sName, value ,t)
{
var expdate = new Date();
if(t == 0) {
document.cookie = sName + "=" + encodeURIComponent(value) + ";path=/;domain=.fsecity.com";
return ;
}
if(typeof(t) == "undefined")
expdate.setFullYear(expdate.getFullYear() + 1);
else
expdate.setTime(expdate.getTime() + 1000 * t);
document.cookie = sName + "=" + encodeURIComponent(value) + ";path=/;expires="+expdate.toGMTString()+";domain=.fsecity.com";
},
trim: function(str)
{
if(str == null || typeof(str) == "undefined") return "";
for(var i = 0 ; i<str.length && (str.charAt(i)==" " || str.charAt(i)==" ") ; i++) ;
for(var j =str.length; j>0 && (str.charAt(j-1)==" " || str.charAt(j-1)==" ") ; j--) ;
if(i>j) return "";
return str.substring(i,j);
},
str_replace: function(str, s, r)
{
var regex = new RegExp(s, "g");
return str.replace(regex, r);
},
set_len: function(str, len, r)
{
if(typeof(r) == 'undefined') r = '...';
if(str.length > len) str = str.substr(0, len - 1) + r;
return str;
},
ajax: function(url, data, func, type, method)
{
var xmlhttp = false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
var param = "rtime=" + new Date().getTime();
for(key in data) {
param += "&" + key + "=" + encodeURIComponent(data[key]);
}
if(method == 'POST') {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Length",param.length);
xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded;");
xmlhttp.send(param);
} else {
url = (url.indexOf("?") == -1)?url + "?" + param:url + "&" + param;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4) {
if(type == 'json') {
try{
var rs = eval('(' + xmlhttp.responseText + ')');
} catch (e){
var rs = xmlhttp.responseText;
}
func(rs);
}
else func(xmlhttp.responseText);
}
};
},
getJSON: function(url, func)
{
var jsonp = "jsonp" + (Math.random() + "").replace(".", "");
url = url.replace("$$", jsonp);
window[jsonp] = function(o) {
func(o);
}
var s = document.createElement('script');
s.src = url;
document.getElementsByTagName("head").item(0).appendChild(s);
},
request: function(url, func)
{
var t = new Date().getTime();
if(url.indexOf("?") == -1) url += "?rt=" + t;
else url += "&rt=" + t;
var s = document.createElement("script");
s.src = url;
document.documentElement.appendChild(s);
if(this.gIsIE) {
s.onreadystatechange = function() {
if(s.readyState == "loaded") {
if(func) func();
}
}
} else {
s.onload = function() {
if(func) func();
}
}
},
getValue: function(id)
{
var obj = document.getElementsByName(id);
if(obj.length == 0 || obj[0].getAttribute("id") == id) obj = document.getElementById(id);
else obj = obj[0];
var nodeName = obj.nodeName.toLowerCase();
if(nodeName == "select" || nodeName == "textarea") return this.trim(obj.value);
var type = obj.getAttribute("type");
if(type == "radio") {
obj = document.getElementsByName(id);
for(var i = 0; i < obj.length; i++)
if(obj[i].checked)
return obj[i].value;
return "";
} else if(type == "checkbox") {
obj = document.getElementsByName(id);
var arr = new Array();
for(var i = 0; i < obj.length; i++)
if(obj[i].checked)
arr.push(obj[i].value);
return arr;
} else {
return this.trim(obj.value);
}
},
setValue: function(id, value)
{
if(typeof(value) == "undefined") value = "";
var obj = document.getElementsByName(id);
if(obj.length == 0) obj = document.getElementById(id);
else obj = obj[0];
var nodeName = obj.nodeName.toLowerCase();
if(nodeName == "select") {
if(this.trim(value) != '') obj.value = this.trim(value);
else obj.options.selectedIndex = 0;
return ;
}
var type = obj.getAttribute("type");
if(type == "radio") {
obj = document.getElementsByName(id);
for(var i = 0; i < obj.length; i++) {
obj[i].checked = false;
if(obj[i].value == value)
obj[i].checked = true;
}
} else if(type == "checkbox") {
obj = document.getElementsByName(id);
for(var i = 0; i < obj.length; i++) {
if(value === 1) { obj[i].checked = true; continue; }
obj[i].checked = false;
for(var j = 0; j < value.length; j++) {
if(value[j] == obj[i].value)
obj[i].checked = true;
}
}
} else {
obj.value = this.trim(value);
}
},
show: function(id, type)
{
if(typeof(type) == "undefined") type = 'block';
document.getElementById(id).style.display = type;
},
hide: function(id)
{
document.getElementById(id).style.display = "none";
},
disable: function(id)
{
document.getElementById(id).disabled = true;
},
enable: function(id)
{
document.getElementById(id).disabled = false;
},
pageHTML: function(page, pagecount, url, N)
{
var html = "";
if(page != 1) {
html += '<a href="' + url.replace("%s", (page - 1)) + '" class="nostyle"><img src="http://pic.hjsm.tom.com/hj_site/huodong/gaoxiao/images/fy_s.gif" align="absmiddle" /></a>';
} else {
html += '<a class="nostyle"><img src="http://pic.hjsm.tom.com/hj_site/huodong/gaoxiao/images/fy_s.gif" align="absmiddle" /></a>';
}
var n = parseInt((N - 1) / 2);
var pos1 = page - n;
var pos2 = page + n;
if(N % 2 == 0) pos2++;
if(pos1 <= 0) {
pos2 += Math.abs(pos1) + 1;
pos1 = 1;
}
if(pos2 > pagecount) {
pos1 -= (pos2 - pagecount);
}
for(var i = pos1; i <= pos2; i++) {
if(i >= 1 && i <= pagecount) {
if(page == i) {
html += '<a class="cur">' + i + '</a>';
} else {
html += '<a href="' + url.replace("%s", i) + '">' + i + '</a>';
}
}
}
if(page != pagecount && pagecount != 0) {
html += '<a href="' + url.replace("%s", (page + 1)) + '" class="nostyle"><img src="http://pic.hjsm.tom.com/hj_site/huodong/gaoxiao/images/fy_x.gif" align="absmiddle" /></a>';
} else {
html += '<a class="nostyle"><img src="http://pic.hjsm.tom.com/hj_site/huodong/gaoxiao/images/fy_x.gif" align="absmiddle" /></a>';
}
return html;
},
str_width: function(str)
{
var sum=0;
str = str.replace(/\&nbsp\;/gi, " ");
for(var i=0;i<=str.length-1;i++)
{
if(str.charCodeAt(i)>=0 && str.charCodeAt(i)<128)
sum += 1;
else
sum += 2;
}
return sum;
},
setWidth: function(str, len)
{
if(len <= 0) return "";
var p = 0;
while(str_width(str) >= len) {
p = 1;
str = str.substr(0, str.length - 1);
}
if(p == 1) str += "..";
return str;
},
write_flash: function(src,width,height,id)
{
var str = "";
if(typeof(id) == "undefined") id = "";
if(typeof(transparent) == "undefined") transparent = true;
str += '<object style="width:' + width + 'px" id="' + id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="flash/swflash.cab#version=9,0,28,0 width="'+width+'" height="'+height+'">';
str += '<param name="movie" value="' + src + '" />';
str += '<param name="quality" value="high" />';
if(transparent) str += '<param name="wmode" value="transparent" />';
str += '<embed name="'+id+'" src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"';
if(transparent) str += ' wmode="transparent" ';
str += '></embed></object>';
document.write(str);
},
json_encode: function(input)
{
if (typeof(input) == 'undefined' || input == null) return 'null' ;
switch (input.constructor) {
case String: return '"' + this.addslashes(input) + '"';
case Number: return input.toString();
case Boolean: return input.toString();
case Array :
var buf = [];
for (i in input)
buf.push(this.json_encode(input[i]));
return '[' + buf.join(', ') + ']';
case Object:
var buf = [];
for (k in input)
buf.push('"' + k + '" : ' + this.json_encode(input[k]));
return '{' + buf.join(', ') + '} ';
default:
return 'null';
}
},
addslashes: function(str)
{
str = str.replace(/\\/g, "\\\\");
str = str.replace(/\//g, "\\/");
str = str.replace(/"/g, "\\\"");
str = str.replace(/\r\n/g, "\\r\\n");
str = str.replace(/\n/g, "\\r\\n");
return str;
},
get_flash: function(id)
{
if(this.gIsIE)
return window[id];
else
return document[id];
},
Enter: function(e,str)
{
e=e||event;
if(e.keyCode==13)
{
eval(str);
return false;
}
},
check_date: function(date)
{
var reg = /^(\d){4}-(\d){2}-(\d){2}$/;
if(!date.match(reg)) {
return false;
}
var arr = date.split("-");
if(arr[0].length != 4) return false;
if(Number(arr[1]) > 12 || Number(arr[1]) <= 0) return false;
if(Number(arr[2]) > 31 || Number(arr[2]) <= 0) return false;
return true;
},
check_time: function(time)
{
var reg = /^(\d){4}-(\d){2}-(\d){2} (\d){2}:(\d){2}:(\d){2}$/;
if(!time.match(reg)) {
return false;
}
var arr1 = time.split(" ");
var arr2 = arr1[0].split("-");
var arr3 = arr1[1].split(":");
if(Number(arr2[1]) > 12 || Number(arr2[1]) <= 0) return false;
if(Number(arr2[2]) > 31 || Number(arr2[2]) <= 0) return false;
if(Number(arr3[0]) >= 24 || Number(arr3[0]) < 0) return false;
if(Number(arr3[1]) >= 60 || Number(arr3[1]) < 0) return false;
if(Number(arr3[2]) >= 60 || Number(arr3[2]) < 0) return false;
return true;
},
check_int: function(str, fu)
{
if(str == '0') return true;
if(fu) var reg = /^(\-)?[1-9][0-9]*$/;
else var reg = /^[1-9][0-9]*$/;
if(!str.match(reg)) {
return false;
}
return true;
},
check_number: function(str)
{
if(str == '0') return true;
var reg = /^[1-9][0-9]*(\.\d+)?$/;
if(str.match(reg)) {
return true;
}
return false;
},
scroll: function(func)
{
if(this.gIsIE) window.attachEvent("onscroll", func);
else window.addEventListener("scroll", func, false);
},
load: function(func)
{
if(this.gIsIE) window.attachEvent("onload", func);
else window.addEventListener("load", func, false);
},
dateToStr: function(date, type)
{
if(!date) return "";
var y = date.getFullYear()+"";
var m = (date.getMonth()+1)+""; if(m.length == 1) m = "0" + m;
var d = date.getDate()+""; if(d.length == 1) d = "0" + d;
var h = date.getHours()+""; if(h.length == 1) h = "0" + h;
var i = date.getMinutes()+""; if(i.length == 1) i = "0" + i;
var s = date.getSeconds()+""; if(s.length == 1) s = "0" + s;
if(!type) {
return y + "-" + m + "-" + d + " " + h + ":" +i + ":" +s;
} else {
return y + "-" + m + "-" + d;
}
},
getStrTime:function(str)
{
str = str.replace(/ /g, "-");
str = str.replace(/:/g, "-");
var a = str.split("-");
if(a.length == 3) {
if(a[0].length != 4) return false;
if(a[1].length == 1) a[1] = "0" + a[1];
if(a[1].length != 2) return false;
if(a[2].length == 1) a[2] = "0" + a[2];
if(a[2].length != 2) return false;
var s1 = a[0] + "/" + a[1] + "/" + a[2];
var s2 = a[0] + "-" + a[1] + "-" + a[2];
var date = new Date(Date.parse(s1));
var y = date.getFullYear()+""; if(y.length != 4) return false;
var m = (date.getMonth()+1)+""; if(m.length == 1) m = "0" + m;
var d = date.getDate()+""; if(d.length == 1) d = "0" + d;
var s = y + "-" + m + "-" + d;
if(s == s2) return date;
else return false;
} else if(a.length == 6) {
if(a[0].length != 4) return false;
if(a[1].length == 1) a[1] = "0" + a[1];
if(a[1].length != 2) return false;
if(a[2].length == 1) a[2] = "0" + a[2];
if(a[2].length != 2) return false;
if(a[3].length == 1) a[3] = "0" + a[3];
if(a[3].length != 2) return false;
if(a[4].length == 1) a[4] = "0" + a[4];
if(a[4].length != 2) return false;
if(a[5].length == 1) a[5] = "0" + a[5];
if(a[5].length != 2) return false;
var s1 = a[0] + "/" + a[1] + "/" + a[2] + " " + a[3] + ":" +a[4] + ":" +a[5];
var s2 = a[0] + "-" + a[1] + "-" + a[2] + " " + a[3] + ":" +a[4] + ":" +a[5];
var date = new Date(Date.parse(s1));
var y = date.getFullYear()+""; if(y.length != 4) return false;
var m = (date.getMonth()+1)+""; if(m.length == 1) m = "0" + m;
var d = date.getDate()+""; if(d.length == 1) d = "0" + d;
var h = date.getHours()+""; if(h.length == 1) h = "0" + h;
var i = date.getMinutes()+""; if(i.length == 1) i = "0" + i;
var s = date.getSeconds()+""; if(s.length == 1) s = "0" + s;
var s3 = y + "-" + m + "-" + d + " " + h + ":" + i + ":" + s;
if(s2 == s3) return date;
else return false;
}
return false;
},
getTimeStr: function ()
{
var date = new Date();
var y = date.getFullYear()+""; if(y.length != 4) return false;
var m = (date.getMonth()+1)+""; if(m.length == 1) m = "0" + m;
var d = date.getDate()+""; if(d.length == 1) d = "0" + d;
var h = date.getHours()+""; if(h.length == 1) h = "0" + h;
var i = date.getMinutes()+""; if(i.length == 1) i = "0" + i;
var s = date.getSeconds()+""; if(s.length == 1) s = "0" + s;
return y + "-" + m + "-" + d + " " + h + ":" + i + ":" + s;
},
add_p: function (name, v)
{
var href = location.href;
var idx = href.indexOf("?"+name+"=");
if(idx == -1) idx = href.indexOf("&"+name+"=");
if(idx != -1) {
var idx2 = href.indexOf("&", idx+1);
if(idx2 == -1) {
href = href.substr(0, idx);
} else {
href = href.substr(0, idx) + href.substr(idx2);
}
}
if(href.indexOf("?") == -1) href = href.replace("&", "?");
if(href.substr(href.length-1) == "?") href = href.substr(0, href.length-1);
if(v != '') {
if(href.indexOf("?") == -1) href+="?"+name+"="+v;
else href+="&"+name+"="+v;
}
location.href = href;
},
httpPost: function(URL, PARAMS, target) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.target = target;
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
};