
String.prototype.trim = function()
{
	return this.replace(/^\s*|\s*$/gi,"");
}

String.prototype.isNumeric = function()
{
	return /^[-]?(\d+|\d+\.\d+)$/gi.test(this);
}

String.prototype.isInt = function()
{
	var v_len = this.length;
		var digitChars = "0123456789";
		var i;
		for (i = 0; i < v_len; i++){
		if (digitChars.indexOf(str.charAt(i)) == -1)
			return false;
		}
		return true;
}

String.prototype.isCn = function()
{
	return /^[\u4e00-\u9fa5]+$/gi.test(this);
}

String.prototype.isEn = function()
{
	return /^[A-Za-z]+$/gi.test(this);
}

String.prototype.isEmail = function()
{
	return  /^([-_A-Za-z0-9\.]+)@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/gi.test(this);
}

String.prototype.isMobile = function()
{
	if ( this.length != 11 )   return false;   // 11 digits
		
		if ( this.search(/13[0-9]\d{8}/gi) == -1 && this.search(/15[8-9]\d{8}/gi) == -1) // not china mobile
			return false;
			
		return true;
}

String.prototype.isIDNumber = function()
{
		var mLen    = this.length;

		if ( mLen != 15 && mLen != 18 )   return false;

		if ( mLen == 15 && this.search(/\d{15}/gi) == -1 ) //not 15 digits
			return false;
			
		if ( mLen == 18 && this.search(/\d{17}[0-9,x,X]/gi) == -1 ) //not 17 digits + 1 digits or X
			return false;
			
		return true;
}

String.prototype.isUrl = function()
{
	return /^(http|ftp|https)\:\/\/\w+/gi.test(this);
}

String.prototype.getByteLength = function()
{
	return this.replace(/[^\x00-\xff]/g, "**").length;
}

String.prototype.isDate = function()
{
   	var mDate   = this.TrimStr(sDate);
		var mLen    = mDate.length;

		if ( mLen < 8 || mLen > 10 )   return false;

		mDate = mDate.replace(/(\/)/g, "-");
		if ( mDate.search(/\d{4}-\d{1,2}-\d{1,2}/gi) == -1 ) return false;
		var arrDate = mDate.split('-');
		var mYear   = parseInt(arrDate[0],10);
		var mMonth  = parseInt(arrDate[1],10) - 1;  
		var mDay    = parseInt(arrDate[2],10);

		if (mYear<1900 || mYear>3000) return false;

		var objDate = new Date(mYear,mMonth,mDay);
		if(objDate.getFullYear() != mYear || objDate.getMonth() != mMonth || objDate.getDate() != mDay )
			return false;

		return true;
  }
  
Array.prototype.exists = function( item )
{
	for( var i = 0 ; i < this.length ; i++ )
	{
		if( item == this[i] )
		{
			return true;
		}
	}
	return false;
}

Array.prototype.remove = function( item )
{
	for( var i = 0 ; i < this.length ; i++ )
	{
		if( item == this[i] )
		{
			break;
		}
	}
	if( i == this.length )
	{
		return;
	}
	for( var j = i ; j < this.length - 1 ; j++ )
	{
		this[ j ] = this[ j + 1 ];
	}
	this.length--;
} 
  
function winopen(url)
{
	var name='',parameter = [];
	var width,height,resizable,scrollbars;
	if( arguments[1] != null )	//name
	{
		name = arguments[1];
	}
	if( arguments[2] != null )	//width
	{
		parameter[parameter.length] = "width=" + arguments[2];
	}
	if( arguments[3] != null )			//height
	{
		parameter[parameter.length] = "height=" + arguments[3];
	}
	if( arguments[4] != null )			//resizable
	{
		parameter[parameter.length] = "resizable=" + (arguments[4] ? "yes" : "no");
	}
	if( arguments[5] != null )			//scrollbars
	{
		parameter[parameter.length] = "scrollbars=" + (arguments[5] ? "yes" : "no");
	}
	return window.open(url,name,parameter.join(","));
}

function chkEmpty(str,msg)
{
	if(str.trim()=="") 
	{
		alert(msg);
		return false;	
	}
		return true;
}

function chkObjEmpty(obj,msg)
{
	if(chkEmpty($v(obj),msg) == false)
	{
		$(obj).focus(); 
		return false;	
	}
	else
		return true;
		
}

function chkLength(str,maxLen,msg)
{
	if(str.length > maxLen) 
	{
		alert(msg);
		return false;	
	}
		return true;
}

function chkObjLenght(obj,maxLen,msg)
{
	if(chkEmpty($v(obj),maxLen,msg) == false)
	{
		$(obj).focus(); 
		return false;	
	}
	else
		return true;
		
}

function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(element);
  }
  return results.length < 2 ? results[0] : results;
}
function $v(obj) {
	if($(obj))
		return $(obj).value.toString();
	else
		return "";
	}



function CenterWin(ow, oh, strURL, strWinName) {
	try {
	var win = window.open(strURL, strWinName, "left="+((parseInt(screen.Width)-ow)/2)+",top="+((parseInt(screen.Height)-oh)/2)+",width="+ow+",height="+oh+",resizable=yes,scrollbars=1");
	if (win && win.window && win.window.document) {
		win.focus();
	}
	}
	catch(e){}
}

function DisplayOther(pObject,pOther,pValue){
	if (pObject.value == pValue){
		pOther.style.display = ""
	}
	else{
		pOther.style.display = "none"
	}
}
function CHKDisplayOther(pObject,pOther){
	if (pObject.checked){
		pOther.style.display = ""
	}
	else{
		pOther.style.display = "none"
	}
}
