var $ie = window.navigator.userAgent.toLowerCase().indexOf('msie') >= 0,
$saf = window.navigator.userAgent.toLowerCase().indexOf('safari') >= 0,
$opr = window.navigator.userAgent.toLowerCase().indexOf('opera') >= 0,
$fox = window.navigator.userAgent.toLowerCase().indexOf('gecko') >= 0;
/**
* selected(un) all checkbox
* @param {Object} iptName checkbox name;
* @param {Object} isCheck is selected;
*/
function checkAll (iptName, isCheck) {
var ipts = document.getElementsByName(iptName);
for (var i = 0; i < ipts.length; i ++)
ipts[i].checked = isCheck ? true : false;
}
/**
* string to object
* @param {Object} d string
* @return object;
*/
function toObject (d) {
try {
return (new Function("return " + d))();
}
catch (e) {
return {};
}
}
/**
* get element absolute x and y, for body client;
* @param {Object} e : element
* @return Array [x, y];
*/
function getOffset(e) {
if (!e)
return [0, 0];
var x = e.offsetLeft, y = e.offsetTop;
while (e = e.offsetParent)
x += e.offsetLeft, y += e.offsetTop;
return [x, y];
}
/**
* lock background
*/
function __Lock () {
var bgLayer = document.getElementById('xLock_bgLayer');
if (!bgLayer) {
bgLayer = document.createElement('div');
bgLayer.setAttribute('id', 'xLock_bgLayer');
bgLayer.style.position = 'absolute';
bgLayer.style.left = '0px';
bgLayer.style.top = '0px';
bgLayer.style.backgroundColor = '#222';
bgLayer.style.zIndex = '10';
bgLayer.style.opacity = '0.35';
bgLayer.style.filter = 'alpha(opacity=35)';
bgLayer.style.zoom = '1';
bgLayer.style.width = '100%';
bgLayer.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight, getVHeight()) + 'px';
document.body.appendChild(bgLayer);
}
bgLayer.style.display = 'block';
var sels = document.getElementsByTagName('select');
for (var i = 0; i < sels.length; i ++)
sels[i].style.visibility = 'hidden';
}
/**
* unlock background
*/
function __unLock () {
document.getElementById('xLock_bgLayer').style.display = 'none';
var sels = document.getElementsByTagName('select');
for (var i = 0; i < sels.length; i ++)
sels[i].style.visibility = 'visible';
}
/**
* get body client height.
*/
function getVHeight () {
var height = self.innerHeight, mode = document.compatMode;
if((mode || $ie) && !$opr)
height = (mode == 'CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight);
return height;
}
/**
* get body client width.
*/
function getVWidth () {
var width = self.innerWidth, mode = document.compatMode;
if((mode || $ie) && !$opr)
width = (mode == 'CSS1Compat' ? document.documentElement.clientWidth : document.body.clientWidth);
return width;
}
/**
* send post request.
* @param {Object} url : request url.
* @param {Object} callback : call back method.
*/
function doPost (url, callback) {
if (!url) {
(callback && callback());
return;
}
if (typeof url == 'object') {
(callback && callback.call(url));
return;
}
var ajax;
if(window.ActiveXObject) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
ajax = new ActiveXObject("msxml2.XMLHTTP");
}
}
else if(window.XMLHttpRequest) ajax = new XMLHttpRequest();
ajax.onreadystatechange = function () {
if(ajax.readyState == 4)
callback && callback(ajax.responseText, ajax.status);
}
ajax.open('post', url.substring(0, url.indexOf('?') == -1 ? url.length : url.indexOf('?')), true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(getRequestBody(url));
function getRequestBody(url){
var parems = '';
if (url.indexOf('?') != -1)
parems = url.substring(url.indexOf('?') + 1);
var tArr = parems.split('&');
for (var i = 0;i < tArr.length; i ++) {
var tStrs = tArr[i].split('=');
for (var j = 0; j < tStrs.length; j ++) {
tStrs[j] = encodeURIComponent(tStrs[j]);
}
tArr[i] = tStrs.join('=');
}
parems = tArr.join('&');
return parems;
}
}
/**
* show message dialog
* @param {Object | elementId} dlg : dialog element
* @param {Object | elementId} draw : show message element
* @param {String} msg : message
*/
function showMessageDialog (dlg, draw, msg) {
if (dlg) {
__Lock();
if (typeof dlg == 'string')
dlg = document.getElementById(dlg);
dlg.style.display = '';
if (draw) {
if (typeof draw == 'string')
draw = document.getElementById(draw);
draw.innerHTML = msg;
}
dlg.style.top = (getVHeight() - dlg.offsetHeight) / 2 + 'px';
dlg.style.left = (getVWidth() - dlg.offsetWidth) / 2 + 'px';
}
}
/**
* hide message dialog
* @param {Object | elementId} dlg : dialog element
* @param {Object | elementId} draw : show message element
*/
function hideMessageDialog (dlg, draw) {
if (dlg) {
__unLock();
if (typeof dlg == 'string')
dlg = document.getElementById(dlg);
dlg.style.display = 'none';
if (draw) {
if (typeof draw == 'string')
draw = document.getElementById(draw);
draw.innerHTML = '';
}
}
}
/**
* show message
* @param {Object | String} id : element | elementId;
* @param {String} msg : message;
* @param {function} callback : call back function,
* return false and void, timer end.
* return true, timer continue;
*/
function showMessage(id, msg, callback){
if (id) {
if (typeof id == 'string')
id = document.getElementById(id);
if (msg) {
(function () {
var _$_i, _$_timer = setInterval (function () {
if (typeof msg == 'function')
id.innerHTML = '<div><span>' + msg(_$_i ++) + '</span></div>';
if (!callback || !callback(id.getElementsByTagName('span')[0]))
clearInterval(_$_timer), hideMessage(id);
}, 1000);
setTimeout (function () {
id.innerHTML = '<div><span>' + (typeof msg == 'function' ? msg(_$_i ++) : msg) + '</span></div>';
}, 100);
})();
}
}
}
/**
* hide message
* @param {Object} id : element | elementId;
*/
function hideMessage (id) {
if (id) {
id = typeof id == 'string' ? document.getElementById(id) : id;
id.innerHTML = '';
id.display = 'none';
}
}
/**
* trim
*/
String.prototype.trim = function () {
return this.replace(/^\s*|\s*$/g, '');
}
/**
* html code
*/
String.prototype.toHtmlCode = function () {
var tStr = this;
tStr = tStr.replace(/</g, '<');
tStr = tStr.replace(/>/g, '>');
tStr = tStr.replace(/\"/g, '"');
tStr = tStr.replace(/\'/g, '´');
return tStr;
}
/**
* correctly handle PNG transparency in Win IE 5.5 & 6.
*/
function correctPNG() {
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters))
{
for(var j=0; j<document.images.length; j++)
{
var img = document.images[j]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ "\"width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
j = j-1
}
}
}
}
($ie && window.attachEvent("onload", correctPNG));
/**
* fade effect.
* @param {Object} e: html element.
* @param {Number} v: fade value(0 - 1)
*/
function fadeTo (e, v) {
if (v > 1)
v = v / 100;
e.style.opacity = v;
e.style.filter = 'alpha(opacity=' + parseInt(v * 100, 10) + ')';
}
/**
* YYYY-MM-DD HH-mm-ss to date.
* @param {string} time (YYYY-MM-DD)
* @return {number} time
*/
function parseDate (str) {
str = str.replace(/,|\s|\.|-|:/g, '|%|').split('|%|');
return new Date(parseInt(str[0], 10), parseInt(str[1], 10) - 1, parseInt(str[2], 10), parseInt(str[3], 10),
parseInt(str[4], 10), parseInt(str[5], 10)).getTime();
}
/**
* distance date.
* @param {Object} s
* @param {Object} e
* return {Object} y: year, M: mouth, d: day, h: hours, m: minutes, s: seconds;
*/
function distanceDate (start, end) {
var date = end > start ? end - start : start - end,
s = 1000, m = 60 * s, h = 60 * m, d = 24 * h, M = d * 30, y = 12 * M;
var y1 = parseInt(date / y, 10), M1 = parseInt((date = date - y1 * y) / M, 10),
d1 = parseInt((date = date - M1 * M) / d, 10), h1 = parseInt((date = date - d1 * d) / h, 10),
m1 = parseInt((date = date - h1 * h) / m, 10), s1 = parseInt((date = date - m1 * m) / s, 10);
return {'y': y1, 'M': M1, 'd': d1, 'h': h1, 'm': m1, 's': s1};
}
/**
* combination
*
*/
function showDiv(data)
{
__Lock();
var ss= document.getElementById(data);
ss.style.left = parseInt((getVWidth() - ss.offsetWidth) /2, 10)-100;
ss.style.top = parseInt((getVHeight() - ss.offsetHeight) /2, 10)-50;
ss.style.display = "block";
}
function hideDiv(data)
{
__unLock();
document.getElementById(data).style.display = "none";
}
/**
* input name and number if names.value >number now false
*/
function ValidateLength(names,numbers){
var elem = document.getElementById('names');
if(elem.value.length>numbers){
return false;
}else{
return true;
}
}
/**
* validate nullAndBank
*/
function checkNullAndBank(data){
if(data==null||data==""){
return false;
}
else{
return true;
}
}
Smilar Posts of js example
-
Hibernate primary key strategy-sequence
Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation coul ...
-
hibernate call stored procedure
hibernate call stored procedure
-
hibernate using c3p0 connection pooling
Private http://www.lifevv.com/tenyo/doc/20070605102040991.html c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuratio ...
-
Hibernate configuration parameters hibernate.hbm2ddl.auto
Hibernate in the configuration file: Parameter Description: validate load hibernate, the authentication to create a database table structure create each load hibern ...
-
Build flex + spring + blazeds + hibernate application
Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the ...
-
Hibernate connection pool configuration
Hibernate connection pool configuration oracle.jdbc.driver.OracleDriver jdbc: oracle: thin: @ 10.203.14.132:1521: remotedb
-
hibernate generic generic DAO
hibernate generic generic DAO
-
Struts2 + hibernate + spring problem user log in
dao layer services layer action jsp user name: Password:
-
Hibernate secondary cache
Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml ...
-
Hibernate's lazy strategy
hibernate Lazy strategy can be used in: tag, it can be true / false Tags can values true / false type of necessary tools to enhance can tag values true / false / extra can be single-ended cor ...







