var defaultEmptyOK=true;
function All(objectName) 
{
	var whichIt = event.srcElement;
	while	(whichIt.tagName.indexOf("FORM") ==	-1)	
	{	whichIt	=	whichIt.parentElement;
		if (whichIt	== null) { return	true;	}
	}
 
	var length = whichIt.elements.length 
		
	var tocheck = whichIt.SelAll.checked 
	for (var i=0; i<length; i++) 
	{ 
		if (whichIt.elements[i].name.indexOf(objectName) != -1) 
		whichIt.elements[i].checked = tocheck 
			
	} 
	return; 
} 

function SetAll(objectName) 
{
	var whichIt = event.srcElement;
	while	(whichIt.tagName.indexOf("FORM") ==	-1)	
	{	whichIt	=	whichIt.parentElement;
		if (whichIt	== null) { return	true;	}
	}

	if (1 == whichIt.SelAll.checked) 
	{ 
		whichIt.SelAll.checked = 0 
	} 
	else 
	{ 
		whichIt.SelAll.checked = 1 
	} 
	All(objectName) 
	return; 
}



function boxChecked(box){
	var choosed=false;
	if (typeof(box)=="undefined"){
		return false;
	}
	if (typeof(box.length)=="undefined"){
		if (box.checked){
			choosed=true;
		}
	}else{
		for (var i=0;i<box.length;i++) {
			if (box[i].checked) {
				choosed=true;
				break;
			}
		}
	}
	return choosed;
}



function isInputEmail(texto) {

	var tvalue = trim1(texto.value); // email
	texto.value = tvalue;

	if (tvalue == "") { // email值为空时,返回true
		return true;
	}
	
	if (getSubStrTotal(tvalue, "@") == 1
		&& getSubStrTotal(tvalue, ".") >= 1 
		&& getSubStrTotal(tvalue, "@.") != 1 
		&& getSubStrTotal(tvalue, ".@") != 1) {
		return true;
	}
	else {
		alert("E-mail address invalid, please try again.");
		texto.focus();
		return false;
	}
}



function getSubStrTotal(inputString, subString) {
	var total = 0;
	if (trim1(inputString) == "") {
		return 0;
	} 

	while (inputString.indexOf(subString) != -1) {
		inputString = inputString.replace(subString, "");
		total += 1;
	}
	return total;
}



function trimLeft1(str) {
	var rtnStr = "";
	for (var i = 0; i < str.length; i++){
	if (str.charAt(i) != " "){
	rtnStr = str.substr(i);
	break;
	}
	}
	return rtnStr;
}

/*
 * 去除字符串右边的空格
 * @str 待处理字符串
 * @return 去除右边空格的字符串
 */
function trimRight1(str) {
	var rtnStr = "";
	for (var i = str.length - 1; i >= 0; i--){
	if (str.charAt(i) != " "){
	rtnStr = str.substring(0, i + 1);
	break;
	}
	}
	return rtnStr;
}

/*
 * 去除字符串左右边的空格
 * @str 待处理字符串
 * @return 去除左右边空格的字符串
 */
function trim1(str) {
	str = trimLeft1(str);
	str = trimRight1(str);
	return str;
}


function OpenBrWindow(mypage, myname, w, h, scroll){
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'resizable=yes,height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+'';
	window.open(mypage, myname, winprops);
}




//add by super.wang begin

var whitespace = " \t\n\r";


function isInteger (s) {
    var i;
    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }

    return true;
}


function isDigit (c) {   
    return ((c >= "0") && (c <= "9"))
}


function isEmpty(s) {
    if ((s == null) || ((stripInitialEndingWhitespace(s)).length == 0)) {
        return true
    }
    else
        return false
}


function charInString (c, s) {   
    for (i = 0; i < s.length; i++) {   
        if (s.charAt(i) == c) return true;
    }
    return false
}


function stripInitialWhitespace (s) {   
    var i = 0;
    s +=""; // convert numbet to string
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;

    return s.substring(i, s.length);
}

function stripEndingWhitespace (s) {
    var i = s.length;

    while ((i > 0) && charInString (s.charAt(i-1), whitespace))
       i--;

    return s.substring(0,i);
}

function stripInitialEndingWhitespace (s) {
    var returnString = stripInitialWhitespace (s);
    returnString = stripEndingWhitespace (returnString);
    return returnString
}

//add by super.wang end