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 ; i0 && (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 += ''; } else { html += ''; } 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 += '' + i + ''; } else { html += '' + i + ''; } } } if(page != pagecount && pagecount != 0) { html += ''; } else { html += ''; } return html; }, str_width: function(str) { var sum=0; str = str.replace(/\ \;/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 += ''; str += ''; str += ''; if(transparent) str += ''; str += ' 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; } };