var GRMobj;
GRMobj=function(){};

GRMobj.prototype={

	isIE: function() { 
		return (navigator.appName == "Microsoft Internet Explorer"); 
	},

	request: function(argu){
		var url=location.search;
		urlstr=url.substring(1).split("&");
		var arguValue="";

		for(i=0;i<urlstr.length;i++){
			if(urlstr[i].indexOf(argu+"=")!=-1){
				subCell=urlstr[i].split("=");
				arguValue=subCell[1];
			}
		}
		return unescape(arguValue)
	},
	
	createTag: function(obj,tagname,option){
		var _obj=document.createElement(tagname);
		for(i in option){ _obj[i]=option[i] };
		obj.appendChild(_obj)
	},

	//.........................................GRM Cookie manage
	_getCookieVal: function(offset){
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1) endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	},

	setCookie: function(name,value){
		/*if(document.cookie) document.cookie=name+"="+value;
		else {
			alert("Error: No cookie support in your Browers!");
			return false;
		}*/
		document.cookie=name+"="+value;
	},
	
	getCookie: function(name){
		if(name == "path" || name == "expires" || name == "domain" || name == "version") name = "badCookieName";

		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 this._getCookieVal (j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break; 
		}
		return null;
	},

	imgpop: function(imgpath){
		var isIE=this.isIE();
		if(!isIE) openwin=window.open(imgpath,'imagePOP','');
		else{
			openwin=window.open ('','imagePOP','width=100,height=100,top=0,left=0,scrollbars=no');
			with(openwin.document){
				writeln('<html><head>');
				writeln('<title>Image Gallery</title>');
				writeln('</head>');
				writeln('<body style="margin:0;">') ;
				writeln('<a href="javascript:window.close()" onfocus="this.blur()">');
				writeln('<img src="'+imgpath+'" border="0" alt="Loading......" onload="javascript:window.resizeTo(this.width+10,this.height+28);this.alt=\'Click to Close\'" /></a>');
				writeln('</body>');
				writeln('</html>');
				close();
			}
		}
		openwin.focus();
	 },

	open: function(url,name,width,height){//need prototype.js framework

		var bodyWidth	=document.documentElement.clientWidth;
		var bodyHeight	=document.documentElement.clientHeight;
		var defaultCSS	=""+
			"width:"+width+"px; height:"+height+"px; position:absolute;"+
			"left:"+(bodyWidth-width)/2+"px;"+
			"top:"+(bodyHeight-height)/2+"px;"

		var divOption	={id:name};
		this.createTag(document.body,"div",divOption);
		$(name).style.cssText=defaultCSS;

		var pars='rdn='+Math.random();
		var myAjax = new Ajax.Updater(
			name, url,
			{method:"get", parameters:pars}
		);
	}
}

var GRM=new GRMobj()

/**********************GRM STRING EXPEND**************************/

var pattern_DB=/[^\x00-\xff]/g;					//双字节字符
var pattern_CN=/^[\u4e00-\u9fa5]/g;			//中文字符
var pattern_NB=/^\d+$/g;						//数字
var pattern_FN=/^\d+\.\d+$/g;					//浮点数
var pattern_EM=/^\w(\w*\.*)*@(\w+\.)+\w{2,4}$/	//EMAIL
var pattern_UL=/^(http|https|ftp):\/\/.*/		//URL
var pattern_EP=/(^\s*)|(\s*$)/g					//去除首尾空字符
var pattern_DT=/^(?:([0-9]{4}(-|\.|#)(?:(?:0?[1,3-9]|1[0-2])(-|\.|#)(?:29|30)|((?:0?[13578]|1[02])(-|\.|#)31)))|([0-9]{4}(-|\.|#)(?:0?[1-9]|1[0-2])(-|\.|#)(?:0?[1-9]|1\d|2[0-8]))|(((?:(\d\d(?:0[48]|[2468][048]|[13579][26]))|(?:0[48]00|[2468][048]00|[13579][26]00))(-|\.|#)0?2(-|\.|#)29)))$/

String.prototype.isEmpty=function(){
	return (this=="");
}
String.prototype.isCNText=function(){
	return pattern_CN.test(this);
}
String.prototype.isInt=function(){
	return pattern_NB.test(this);
}
String.prototype.isFloat=function(){
	return pattern_FN.test(this);
}
String.prototype.isEmail=function(){
	return pattern_EM.test(this);
}
String.prototype.isURL=function(){
	return pattern_UL.test(this);
}
String.prototype.isDate=function(){//(yyyy.mm.dd || yyyy-mm-dd || yyyy#mm#dd)
	return pattern_DT.test(this);
}
String.prototype.isIDCard=function(){
	/*var Errors=new Array(
		"验证通过!",
		"身份证号码位数不对!",
		"身份证号码出生日期超出范围或含有非法字符!",
		"身份证号码校验错误!",
		"身份证地区非法!"
	);*/
	var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};

	var idcard=this;
	var Y,JYM;
	var S,M,yearNo;
	var idcard_array = new Array();
	idcard_array = idcard.split("");
	//地区检验
	if(area[parseInt(idcard.substr(0,2))]==null) return 4;
	//身份号码位数及格式检验
	switch(idcard.length){
		case 15:
			yearNo=parseInt(idcard.substr(6,2))+1900;
			if ((yearNo+"").isLeapYear()){
				ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试生日期的合法性
			} 
			else {
				ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
			}
			if(ereg.test(idcard)) return true;
			else return 2;
		break;

		case 18:
			//18位身份号码检测
			//出生日期的合法性检查 
			yearNo=idcard.substr(6,4);
			if (yearNo.isLeapYear()){
				ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式
			} 
			else {
				ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式
				}
			if(ereg.test(idcard)){//测试出生日期的合法性
				//计算校验位
				S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
				+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
				+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
				+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
				+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
				+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
				+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
				+ parseInt(idcard_array[7]) * 1 
				+ parseInt(idcard_array[8]) * 6
				+ parseInt(idcard_array[9]) * 3 ;
				Y = S % 11;
				M = "F";
				JYM = "10X98765432";
				M = JYM.substr(Y,1);//判断校验位
				if(M == idcard_array[17]) return true; //检测ID的校验位
				else return 3;
			}
			else return 2;
		break;

		default:
			return 1;
		break;
	}
}
String.prototype.isLeapYear=function(){
	var curYear;
	if(this.isInt()) {
		curYear=this;
		switch(curYear.length){
			case 2:
				curYear=curYear-0+1900;
				if(curYear % 4 ==0 || (curYear % 100 ==0 && curYear % 4 ==0)) return true;
				else return false;
			break;

			case 4:
				if(curYear % 4 ==0 || (curYear % 100 ==0 && curYear % 4 ==0)) return true;
				else return false;
			break;

			default:
				return false;
			break;
		}
	}
	else return false;
}
String.prototype.lenB=function(){
	len=this.replace(pattern_DB,"aa").length;
	return len;
}
String.prototype.trim=function(){
	return this.replace(pattern_EP,"");
}
String.prototype.cutStr=function(strNo,postFix){
	var cutFix	=(postFix) ? postFix : "...";
	var strLen	=this.length;
	var tempLen	=0;
	var totle	=strNo;
	var tempStr	="";

	if (strLen<totle/2) tempStr=this;
	else{
		for(i=0;i<strLen;i++){
			tempChr=this.charCodeAt(i);
			tempLen+=1;
			if(tempLen>totle){
				tempStr+=cutFix;
				break;
			}
			if (tempChr<0 || tempChr>255) tempLen++;
			tempStr+=this.charAt(i);
		}
	}
	return tempStr;
}