function $(id) {
	return document.getElementById(id);
}

Array.prototype.push = function(value) {
	this[this.length] = value;
	return this.length;
}
function in_array(needle, haystack) {
	if(typeof needle == 'string') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
					return true;
			}
		}
	}
	return false;
}
function SelectAll(obj) {
	//遍历全部input
	var chkother= document.getElementsByTagName("input");
	
	for (var i = 0; i < chkother.length; i++){		
		if( chkother[i].type=='checkbox' && chkother[i].name == 'checkOne')
	  {
			chkother[i].checked = obj.checked;
	  }
	}
}
function checkSelAll(obj) {
	if (!obj.checked)
	{
		$('checkAll').checked = false;
	}
	else
	{
		var checkAll = true;
		var chkother= document.getElementsByTagName("input");
		var selids = "";
		for (var i = 0; i < chkother.length; i++){		
			if( chkother[i].type=='checkbox' && chkother[i].name == 'checkOne' && !chkother[i].checked)
		  {
				checkAll = false;
				break;
		  }
		}
		if (checkAll)
		{
			$('checkAll').checked = true;
		}
		else
		{
			$('checkAll').checked = false;
		}
	}
}
function getAllSelectedCheckValue()
{
	var chkother= document.getElementsByTagName("input");
	var selids = "";
	for (var i = 0; i < chkother.length; i++){		
		if( chkother[i].type=='checkbox' && chkother[i].name == 'checkOne' && chkother[i].checked)
	  {
			selids += "," + chkother[i].value;
	  }
	}
	if (selids != "")
	{
		selids = selids.substr(1);
	}
	
	return selids;
}

function checkExistOnline()
{
	var chkother= document.getElementsByTagName("input");
	var exist = false;
	for (var i = 0; i < chkother.length; i++){		
		if( chkother[i].type=='checkbox' && chkother[i].name == 'checkOne' && chkother[i].checked)
	  {
			if (chkother[i+1].name == 'checkstatus' && chkother[i+1].value == '1')
			{
				exist = true;
				break;
			}
	  }
	}
	return exist;
}
function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

function mb_strlen(str) {
	var len = 0;
	for(var i = 0; i < str.length; i++) {
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
	}
	return len;
}

function strlen(str) {
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}

function trim(str) {
	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}
function changedisplay(obj, display) {
	if(display == 'auto') {
		obj.style.display = obj.style.display == '' ? 'none' : '';
	} else {
		obj.style.display = display;
	}
	return false;
}
function doane(event) {
	e = event ? event : window.event;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}
var evalscripts = new Array();
function evalscript(s) {
	if(s.indexOf('<script') == -1) return s;
	var p = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/ig;
	var arr = new Array();
	while(arr = p.exec(s)) {
		appendscript(arr[1], '', arr[2], arr[3]);
	}
	s = s.replace(p, '');
	p = /<script(.*?)>([^\x00]+?)<\/script>/ig;
	while(arr = p.exec(s)) {
		appendscript('', arr[2], arr[1].indexOf('reload=') != -1);
	}
	return s;
}

function appendscript(src, text, reload, charset) {
	var id = hash(src + text);
	if(!reload && in_array(id, evalscripts)) return;
	if(reload && $(id)) {
		$(id).parentNode.removeChild($(id));
	}

	evalscripts.push(id);
	var scriptNode = document.createElement("script");
	scriptNode.type = "text/javascript";
	scriptNode.id = id;
	scriptNode.charset = charset;
	try {
		if(src) {
			scriptNode.src = src;
		} else if(text){
			scriptNode.text = text;
		}
		$('append_parent').appendChild(scriptNode);
	} catch(e) {}
}

function stripscript(s) {
	return s.replace(/<script.*?>.*?<\/script>/ig, '');
}


function showloading(display, waiting) {
	var display = display ? display : 'block';
	var waiting = waiting ? waiting : 'Loading...';
	$('ajaxwaitid').innerHTML = waiting;
	$('ajaxwaitid').style.display = display;
}

function searchSubmit()
{
    if (event.keyCode == 13)
    {
        event.returnValue=false;
        event.cancel = true;
        advsearch();
    }
}

