﻿
// 返回字符串 Unicode 长度
String.prototype.ulen = function(){return this.replace(/[^\x00-\xff]/g,"aa").length;};

// 将 GET 参数转换为 JSON 对象
String.prototype.paramsToJson = function() {
  
    var paraJ = '';
    var paraArr = this.split('&');
    for (var i = 0; i < paraArr.length; i++) {
      var paraSubArr = paraArr[i].split('=');
      paraJ += "'" + paraSubArr[0] + "':";
      paraJ += "'" + paraSubArr[1] + "', "
    }
    paraJ = '{' + paraJ.substring(0, paraJ.length - 2) + '}';
   
    return eval('(' + paraJ + ')');
};

// 判断字符串是否为手机号
String.prototype.isMobile = function() {
     var re=/^(130|131|133|135|135|137|138|139|159|158|153)(\d){8}$/; 
     if(!re.test(this)) {
       return false;
     }
     else {
       return true;
     } 
};

// 判断字符串是否为电话
String.prototype.isPhone = function() {
     var re=/^[\d\-\(\)]+$/; 
     if(!re.test(this)) {
       return false;
     }
     else {
       return true;
     } 
};

// 判断字符串是否为电邮地址
String.prototype.isEmail = function() {
     var re=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
     if(!re.test(this)) {
       return false;
     }
     else {
       return true;
     } 
};

// 判断字符串是否可以转换为日期
String.prototype.isDate = function() {
    var _s = this;
    var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
    if (reg.test(_s)) {
        return true;
    }
    else {
        return false;
    }
};

// 判断字符串是否为邮编
String.prototype.isZipCode = function() {
     var re=/^\d{3,6}$/;
     if(!re.test(this)) {
       return false;
     }
     else {
       return true;
     } 
};

// 截取
String.prototype.trim = function() {
    var _s = this;
    _s = _s.replace(/^\s*(.*?)[\s\n]*$/g, "$1");
    return _s;
};

// 返回字符串是否可转化为日期
String.prototype.isDate = function() {
    var _s = this;
    var reg = /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
    if (reg.test(_s)) {
        return true;
    }
    else {
        return false;
    }
};

// 数组移除元素并改变长度
Array.prototype.remove = function(dx) {
  if (isNaN(dx) || dx>this.length) {
    return false;
  }
  for (var i=0,n=0; i<this.length; i++)
  {
　  if(this[i] != this[dx])
　　{
　　  this[n++] = this[i];
　　}
　}
  this.length -= 1;
}

Math.rand = function(l, u) {
  return Math.floor((Math.random() * (u-l+1))+l);
};



/// ---------------------------------------------------------------------------------------------
/// 原型结束了..
/// ---------------------------------------------------------------------------------------------
/// ---------------------------------------------------------------------------------------------




// 限定文本框的最大长度
var checkLen = function(obj, maxLen) {
    var len=obj.value.replace(/[^\x00-\xff]/g,'oo').length; 
    var llen=maxLen-len; 
     if(len>maxLen) 
        {   var i=0; 
            for(var z=0;z<len;z++) 
            { 
                if(obj.value.charCodeAt(z)>255) 
                { 
                    i=i+2; 
                }else 
                { 
                    i=i+1; 
                } 
                if(i>=maxLen) 
                {  obj.value=obj.value.slice(0,(z + 1)); 
                    break; 
                } 
           } 
        } 
    if(llen<0)llen=0 
    if(len<maxLen)len=maxLen 
    //Wdocument.getElementById('msg').innerHTML='已输入字符数量：'+len+' 剩余数量:'+llen 
};

// 获取标签中的内容
var getTagValue = function(sContent, sTagName) {
    var sTagValue = "";
    var sTemp;
    if (sContent != null && sTagName != null)
    {
        sTemp = "<" + sTagName + ">";
        var nPosBegin = sContent.indexOf(sTemp);
        if (nPosBegin >= 0)
        {
            sTemp  = "</" + sTagName + ">";
            var nPosEnd = sContent.indexOf(sTemp);
            if (nPosEnd >= 0)
            {
                sTagValue = sContent.substring(nPosBegin + sTagName.length + 2,nPosEnd);
            }
        }
    }
    return sTagValue;
}

// 获取URL参数
var QueryString = function() { 
    var name,value,i; 
    var str=location.href; 
    var num=str.indexOf("?") 
    str=str.substr(num+1); 
    var arrtmp=str.split("&"); 
    for(i=0;i < arrtmp.length;i++){ 
        num=arrtmp[i].indexOf("="); 
        if(num>0){ 
            name=arrtmp[i].substring(0,num); 
            value=arrtmp[i].substr(num+1); 
            this[name]=value; 
        } 
    } 
};

// 对话框包装1
var alert1 = function(s) {
  $.prompt(s, { buttons:{确定:false}, prefix:'cleanblue' });
};

// 对话框包装2
var alert2 = function(s, func1, func2) {
  $.prompt(s, { buttons:{确定:true,取消:false}, submit:func1, callback:func2, prefix:'cleanblue' });
};


// cookie support begin ---------------------------------------------

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		  return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

function SetCookie(name, value)
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function getCookieValTransparent(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return document.cookie.substring(offset, endstr);
}

function GetCookieTransparent(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		  return getCookieValTransparent (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

function SetCookieTransparent(name, value)
{
	var argv = SetCookieTransparent.arguments;
	var argc = SetCookieTransparent.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + value +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function DelCookie(name)
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

function JustShowContent(d) {
	if(d.length < 1) { return; }
	//alert(2);
	var dd = document.getElementById(d);
	var availHeight; 
    var availWidth; 
  
    if(typeof(window.innerWidth) == 'number'){ 
        availHeight = window.innerHeight; 
        availWidth = window.innerWidth; 
    }else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){ 
        availHeight = document.documentElement.clientHeight; 
        availWidth = document.documentElement.clientWidth; 
    }else if(document.body && (document.body.clientWidth || document.body.clientHeight)){ 
        availHeight = document.body.clientHeight; 
        availWidth = document.body.clientWidth; 
    } 
  
    var indicatorWidth = 50; 
    var indicatorHeight = 50; 
    var left = (availWidth/2) - (indicatorWidth/2) - 250; 
    var top = (availHeight/2) - (indicatorHeight/2); 
   
    dd.style.border="1px solid gray"; 
    dd.style.background="white"; 
    dd.style.position="absolute"; 
    dd.style.zIndex="999"; 
    dd.style.top=top+"px"; 
    dd.style.left=left+"px"; 
    dd.style.display="block"; 

}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}

function ShowLocationDiv(X, Y, div)
{
	var tempX = 0;
	var tempY = 0;
    tempX = X + document.body.scrollLeft;
    tempY = Y + document.body.scrollTop;
    var divLocation = document.getElementById(div);
    divLocation.style.background="white"; 
	divLocation.style.position='absolute';
	divLocation.style.top=tempY + 200 + "px";
	divLocation.style.left=tempX + 400 + "px";
	divLocation.style.display='block';
	return false;
}
// cookie support end ---------------------------------------------

