function RemoveWp(str,tag)
{
	var rstr = "";
	for(i=0;i<str.length;i++)
	{
		if((str.charAt(i) != " ") && (str.charAt(i) != ""))
		{
			rstr = rstr + str.charAt(i)
		}
	}
	if(rstr == "")
	{
		cnt = cnt + 1;
		errstr = errstr + cnt + ". " + tag + "不能为空。\n";
		return rstr;
	}
	else
	{
		return rstr;
	}
}

function RemoveWpE(str,tag)
{
	var rstr = "";
	for(i=0;i<str.length;i++)
	{
		if((str.charAt(i) != " ") && (str.charAt(i) != ""))
		{
			rstr = rstr + str.charAt(i)
		}
	}
	if(rstr == "")
	{
		cnt = cnt + 1;
		errstr = errstr + cnt + ". " + tag + " is not Null.\n";
		return rstr;
	}
	else
	{
		return rstr;
	}
}

function trim(str)
{
	var rstr = "";
	for(i=0;i<str.length;i++)
	{
		if((str.charAt(i) != " ") && (str.charAt(i) != ""))
		{
			rstr = rstr + str.charAt(i)
		}
	}
	return rstr;
}

function check(value,tag,contain,nocontain)
{
	var j;
	var k;
	if(contain != "")
	{
		for(j=0;j<contain.length;j++)
		{
			containstr = value.indexOf(contain.charAt(j),0)
			if(containstr < 0)
			{
				cnt = cnt + 1;
				errstr = errstr + cnt + ". " + tag + "中必须含有“" + contain.charAt(j) + "”。\n";
			}
		}
	}

	if(nocontain != "")
	{
		for(k=0;k<nocontain.length;k++)
		{
			nocontainstr = value.indexOf(nocontain.charAt(k),0)
			if(nocontainstr >= 0)
			{
				cnt = cnt + 1;
				errstr = errstr + cnt + ". " + tag + "中不能含有“" + nocontain.charAt(k) + "”。\n";
			}
		}
	}
}

function checknumber(value,tag)
{
	if(isNaN(value))
	{
		cnt = cnt + 1;
		errstr = errstr + cnt + ". " + tag + "必须为数字。\n";
	}
}

function checkemail(value)
{
	emaila = value.indexOf("@",1);
	if(emaila == -1)
	{
		cnt = cnt + 1;
		errstr = errstr + cnt + ". 您的Email格式不正确。\n";
	}
	else
	{
		emailb = value.indexOf(".",emaila + 2)
		if(emailb == -1)
		{
			cnt = cnt + 1;
			errstr = errstr + cnt + ". 您的Email格式不正确。\n";
		}
		else
		{
			if(emailb == value.length - 2)
			{
				cnt = cnt + 1;
				errstr = errstr + cnt + ". 您的Email格式不正确。\n";
			}
		}
	}
}

function checkimage(imagename)
{
	imageExtPosition = imagename.lastIndexOf(".");
	imageExt = imagename.substring(imageExtPosition + 1,imagename.length).toLowerCase();
	if((imageExt != "jpg") && (imageExt != "gif") && (imageExt != "jpeg"))
	{
		cnt = cnt + 1;			
		errstr = errstr + cnt + ". 您要上传的图片的格式不正确，\n    目前只支持Jpeg和Gif格式的图片，\n    最好为Gif格式。\n";
	}
}

function checkfile(imagename)
{
	imageExtPosition = imagename.lastIndexOf(".");
	if(imageExtPosition == -1)
	{
		cnt = cnt + 1;
		errstr = errstr + cnt + ". 您上传的文件格式不正确。\n";
	}
}

function js_callpage(htmlurl,w,h){
var focusok;
var newwin=window.open(htmlurl,"newWin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=2,left=2,width=" + w +",height=" + h );
	if(focusok){
		newwin.location=htmlurl
		newwin.focus();
	}
return false;
}

function checklength(str,tag,maxlength)
{
	curlength = 0;
	for(var i=0;i<str.length;i++)
	{
		if (str.charCodeAt(i)<0||str.charCodeAt(i)>255)
		{
			curlength = curlength + 2;
		}
		else
		{
			curlength = curlength + 1;
		}
	}

	if (curlength > maxlength)
	{
		cnt = cnt + 1;
		errstr = errstr + cnt + ". " + tag + "最多只能输入" + maxlength + "个字符(一个汉字相当于两个字符)。\n";
	}
}

function showsub(sub,value)
{
	for(var i=0;i<sub.length;i++)
	{		
		if(sub[i][0] == value)
		{
			document.write("<option value='" + sub[i][0] + "' selected>" + sub[i][1] + "</option>")
		}
		else
		{
			document.write("<option value='" + sub[i][0] + "'>" + sub[i][1] + "</option>")
		}
	}
}

function showsubmore(rootid,fatherid,sortid,sub)
{	
	for(var i=0;i<sub.length;i++)
	{
		if(sub[i][0] == sortid)
		{
			document.write("<option value='" + sub[i][0] + "' selected>" + sub[i][1] + "</option>");
		}
		else
		{
			if((sub[i][3] == rootid) && (sub[i][2] == fatherid))
			{
				document.write("<option value='" + sub[i][0] + "'>" + sub[i][1] + "</option>");
			}			
		}
	}
}

function writesub(sub,value)
{
	for(var i=0;i<sub.length;i++)
	{		
		if(sub[i][0] == value)
		{
			document.write(sub[i][1]);
			break;
		}
	}
}

function writesubc(sub,value)
{
	for(var i=0;i<sub.length;i++)
	{		
		if(sub[i][0] == value)
		{
			document.write("<font color='" + sub[i][1] + "'>" + sub[i][0] + "</font>");
			break;
		}
	}
}

function mOvr(src,color) {
    if (!src.contains(event.fromElement)) {
	  src.bgColor = color;
	}
}
function mOut(src,color) {
	if (!src.contains(event.toElement)) {
	  src.bgColor = color;
	}
}
