﻿
//function:replace space by null
String.prototype.Trim = function()
{
	var regEx = /\s*/g;
	return this.replace(regEx,''); 
}
//------------------------------------------------------	
//function:replace html mark by null
String.prototype.HtmlEncodeNew = function () {
	return this
		.replace(/&/g, "&amp;")
		.replace(/^[ ]/, '&nbsp;')
		.replace(/"/g, "&quot;")
		.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;");
}
String.prototype.endcodeDot = function ()
{
	return this
		.replace(/&/g, "%26")
		.replace(/\+/g, "%2b");//only this row has semicolon(;)
}
//function：only number is requested
//use this function：Then on input attribute with onkeyup="numonly(this);" and onBlur="numonly(this);"
function numonly(n){ 
n.value=n.value.replace(/\D/g,'') 
} 
//function：get value after ie address's '?'
//use this function：show.htm?id=2 get 'id' value use QueryString("id")
function QueryString(qs)
{
	s = location.href;
	var SharpIndex=s.indexOf("#");
	if (SharpIndex!=-1) {
		s=s.substring(0,SharpIndex);
	}
	s = s.replace("?","?&").split("&");
	re = "";
	for(i=1;i<s.length;i++)
	{
		if(s[i].indexOf(qs+"=")==0)
		{
			re = s[i].replace(qs+"=","");
		}
	}
	return re;
}
//Begin
//function: pop-up window 
//url:popup windows' url 
//nu_width:popup windows'width
//nu_height:popup windows'height
var newWindow = null;
function openwin(url,stoolbar)
{
	if (! newWindow || newWindow.closed)
		newWindow = window.open(url,"",stoolbar);
	else
		newWindow = window.open(url,"",stoolbar);
		newWindow.focus();
}
function openurl(url,nu_width,nu_height)
{
	var nu_left=(window.screen.width-nu_width)/2-5;
	var nu_top=(window.screen.height-nu_height)/2-40;
	openwin(url,"toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,top="+nu_top+",left="+nu_left+",width=" + nu_width + ",height=" + nu_height);
}
//End
//function to get file's suffixal name
//example: var newimgpath=imgpath.GetExtensionName();
String.prototype.GetExtensionName = function()
{
	var regEx = /^.*\/[^\/]*(\.[^\.\?]*).*$/;
	return this.replace(regEx,'$1');
}

//Begin pagination 
function JudgeNumOnly(obj) 
{ 
	obj.value=obj.value.replace(/\D/g,'');
}
function JudgeGoPage(p_txtNumName, p_PageCount)
{ 
	var m_ret = true;
	var m_toPage = document.getElementById(p_txtNumName);
	if ( m_toPage.value == '' ) 
	{ 
		alert('抱歉，转到的页数不能为空，请重新输入!');
		m_toPage.focus(); 
		m_ret = false;
	} 
	else if( parseInt(m_toPage.value)<1 || parseInt(m_toPage.value)>p_PageCount ) 
	{ 
		alert('抱歉，只能输入1至'+p_PageCount+'的整数，请重新输入！');
		m_toPage.focus();
		m_ret = false;
	}
	return m_ret;
}
//function to get all selected values
function GetSetChecked()
{
    var list = document.documentElement.getElementsByTagName("input"); 
    var strid="";
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox"&& list[i].checked)
        {
        if(list[i].name=="chk"){
            if(strid=="")
                strid=list[i].value;
            else
                strid+=","+list[i].value;
                }
        }
    } 
    return strid;   
}

///function to select all checkboxs in this page
function SelChecked()
{
    var cboxAll=$("cboxAll");
    var list = document.documentElement.getElementsByTagName("input");
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox")
        {
            if(list[i].name=="chk"){
            list[i].checked =true;
            }
        }
    }
}
///function to SELECT INVERT 
function RevChecked()
{
    var cboxAll=$("cboxAll");
    var list = document.documentElement.getElementsByTagName("input");
    for(i=0;i<list.length;i++)
    {  
        if(list[i].type == "checkbox")
        {
             if(list[i].name=="chk"){
            list[i].checked =!list[i].checked;
             }
        }
    }
}

//Check file's dat is image
 function CheckImg(fileName){
        var exName =  fileName.substr(fileName.lastIndexOf(".")+1).toLowerCase();
        if(exName!="jpg"){
            if(exName!="gif"){
                if(exName!="jpeg"){
                    return false;
                }
            }
        }
        return true;
    }
