//open window
function openwindow(url,width,height,windowobj)
{
	var returnstr=showmodaldialog(url,windowobj,'dialogwidth:'+width+'pt;dialogheight:'+height+'pt;status:no;help:no;scroll:no;');
	return returnstr;
}
//open modal window
function openwindowandsetvalue(url,width,height,windowobj,setobj)
{
	var returnstr=showmodaldialog(url,windowobj,'dialogwidth:'+width+'pt;dialogheight:'+height+'pt;status:no;help:no;scroll:no;');
	if (returnstr!='007007007007') setobj.value=returnstr;
	return returnstr;
}
//open editer window
function openediterwindow(url,windowname,width,height)
{
	window.open(url,windowname,'toolbar=0,location=0,maximize=1,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,top=50,left=50,width='+width+',height='+height);
}
//send data to server
function senddatatoserver(url)
{
	var http = new activexobject("microsoft.xmlhttp");
	var returnvalue=http.open("post", url, false);
	http.send("");
	return http.responsetext;
}
//button mouseover event
function btnmouseover(obj)
{
	if (event.type!='mouseout')
	{
		obj.classname='btnmouseover';
		if (obj.tagname=='img') window.status=obj.alt;
		else window.status=obj.title;
	}
	else
	{
		window.status=top.loginstr;
		obj.classname='';
	}
}
// 去空格
// trim() , ltrim() , rtrim()

string.prototype.trim = function() 
{ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

string.prototype.ltrim = function() 
{ 
return this.replace(/(^\s*)/g, ""); 
} 

string.prototype.rtrim = function() 
{ 
return this.replace(/(\s*$)/g, ""); 
} 

//检测是否为空
function checkinputstr(obj,descriptionstr)
{
	if (obj.value.trim() == '')
	{
		alert(descriptionstr);
		obj.value="";
		obj.focus();
		return false;
	}
	return true;
}
//check number or not and alarm user.
function checknumber(obj,descriptionstr)
{
	if (obj.value!='' && (isnan(obj.value) || obj.value<0))
	{
		alert(descriptionstr+"应填有效数字！");
		obj.value="";
		obj.focus();
		return false;
	}
	return true;
}
//check english str
function checkenglishstr(obj,descriptionstr)
{
	var tempstr=obj.value,i=0,errorstr='',charascii;
	if (tempstr!='')
	{
		for (i=0;i<tempstr.length;i++)
		{
			charascii=tempstr.charcodeat(i);
			if (charascii>=255||charascii<=31)
			{
				errorstr=errorstr+tempstr.charat(i);
			}
			else
			{
				if (!checkclasserrorstr(charascii))
				{
					errorstr=errorstr+tempstr.charat(i);
				}
			}
		}
		if (errorstr!='')
		{
			alert(descriptionstr+'发现非法字符:'+errorstr);
			obj.focus();
			return false;
		}
		if (!(((tempstr.charcodeat(0)>=48)&&(tempstr.charcodeat(0)<=57))||((tempstr.charcodeat(0)>=65)&&(tempstr.charcodeat(0)<=90))||((tempstr.charcodeat(0)>=97)&&(tempstr.charcodeat(0)<=122))))
		{
			alert(descriptionstr+'首字符只能够为数字或者字母');
			obj.focus();
			return false;
		}
	}
	return true;
}
//检测电话号码格式
function checktelstr(obj,descriptionstr){
	var checkok = '0123456789--';
  var checkstr = obj.value;
  var allvalid = true;
  for (i = 0;  i < checkstr.length;  i++)
  {
    ch = checkstr.charat(i);
    for (j = 0;  j < checkok.length;  j++)
      if (ch == checkok.charat(j))
        break;
    if (j == checkok.length)
    {
      allvalid = false;
      break;
    }
  }
  if (!allvalid)
  {
    alert(descriptionstr+' 只能输入数字与 - 字符');
    obj.focus();
    return (false);
  }
  return (true);
}
//邮箱的合法性检查
function checkemailstr(obj,descriptionstr){
  var checkok1 = "@";
  var checkok2 = ".";
  var checkemail = obj.value;
  var contain1 = false;
  var contain2 = false;
  if(checkemail != "")
  {
	  for (i = 0;  i < checkemail.length;  i++)
	  {
	    ch = checkemail.charat(i);
	    if (ch == checkok1)
		{
		    contain1=true;
		    continue;
		}
		else if (ch == checkok2)
		{
		    contain2=true;
			continue;
		}
	  }
	  if (!contain1 || !contain2)
	  {
	        alert(descriptionstr+' 输入格式有误');
	    obj.focus();
	    return (false);
	  }
  }
  return (true);
}

function checkclasserrorstr(charasciicode)
{
	var temparray=new array(34,47,92,42,58,60,62,63,124);
	for (var i=0;i<temparray.length;i++)
	{
		if (charasciicode==temparray[i]) return false;
	}
	return true;
}

//
function choosespecial(special)
{
	var temparray,tempstr;
	temparray=special.split("***");
	if (temparray[0] != '')
	{
		if (document.all.specialid.value.search(temparray[1])==-1)
	
		   {		if (document.all.specialidtext.value=='') 	document.all.specialidtext.value=temparray[0];
					else document.all.specialidtext.value = document.all.specialidtext.value + ',' + temparray[0];
					if (document.all.specialid.value=='') 	document.all.specialid.value=temparray[1];
					else document.all.specialid.value = document.all.specialid.value + ',' + temparray[1];
			}
	}
	if ((temparray[0] == '')&&(temparray[1] == 'clean'))
	{
		document.all.specialid.value = '';
		document.all.specialidtext.value = '';
	}
	return;
}

function dosusite(source)
{
	var temparray,tempstr;
	temparray=source.split("***");
	if (temparray[0] != '')
	{
		if (document.newsform.txtsourcetext.value.indexof(temparray[0])<0)
		{
			if (typeof(temparray[1])=='undefined') tempstr=temparray[0];
			else tempstr='<a href='+temparray[1].replace(/[\"\']/,'')+'>'+temparray[0]+'</a>';
			if (document.newsform.txtsourcetext.value=='') 	document.newsform.txtsourcetext.value=temparray[0];
			else document.newsform.txtsourcetext.value = document.newsform.txtsourcetext.value + ',' + temparray[0];
			if (document.newsform.txtsource.value=='') 	document.newsform.txtsource.value=temparray[0];
			else document.newsform.txtsource.value = document.newsform.txtsource.value + ',' + temparray[0];
		}
	}
	if ((temparray[0] == '')&&(temparray[1] == 'clean'))
	{
		document.newsform.txtsource.value = '';
		document.newsform.txtsourcetext.value = '';
	}
	return;
}

function dokesite(keywords)
{
	if (keywords!='')
	{
		if (document.newsform.keywordtext.value.search(keywords)==-1)
		{
			if (document.newsform.keywords.value=='') document.newsform.keywords.value=keywords;
			else document.newsform.keywords.value=document.newsform.keywords.value+','+keywords;
			if (document.newsform.keywordtext.value=='') document.newsform.keywordtext.value=keywords;
			else document.newsform.keywordtext.value=document.newsform.keywordtext.value+','+keywords;
		}
	}
	if (keywords == 'clean')
	{
		document.newsform.keywords.value = '';
		document.newsform.keywordtext.value = '';
	}
	return;
}

function doauthsite(author)
{
	var temparray,tempstr;
	temparray=author.split("***");
	if (temparray[0] != '')
	{
		if (document.newsform.authortext.value.indexof(temparray[0])<0)
		{
			if (typeof(temparray[1])=='undefined') tempstr=temparray[0];
			else tempstr='<a href='+temparray[1].replace(/[\"\']/,'')+'>'+temparray[0]+'</a>';
			if (document.newsform.authortext.value=='') 	document.newsform.authortext.value=temparray[0];
			else document.newsform.authortext.value = document.newsform.authortext.value + ',' + temparray[0];
			if (document.newsform.author.value=='') 	document.newsform.author.value=temparray[0];
			else document.newsform.author.value = document.newsform.author.value + ',' + temparray[0];
		}
	}
	if ((temparray[0] == '')&&(temparray[1] == 'clean'))
	{
		document.newsform.author.value = '';
		document.newsform.authortext.value = '';
	}
	return;
}

function editsite(editer1)
{
	var temparray,tempstr;
	temparray=editer1.split("***");
	if (temparray[0] != '')
	{
		if (document.newsform.editertext.value.indexof(temparray[0])<0)
		{
			if (typeof(temparray[1])=='undefined') tempstr=temparray[0];
			else tempstr='<a href='+temparray[1].replace(/[\"\']/,'')+'>'+temparray[0]+'</a>';
			if (document.newsform.editertext.value=='') 	document.newsform.editertext.value=temparray[0];
			else document.newsform.editertext.value = document.newsform.editertext.value + ',' + temparray[0];
			if (document.newsform.editer.value=='') 	document.newsform.editer.value=temparray[0];
			else document.newsform.editer.value = document.newsform.editer.value + ',' + temparray[0];
		}
	}
	if ((temparray[0] == '')&&(temparray[1] == 'clean'))
	{
		document.newsform.editer.value = '';
		document.newsform.editertext.value = '';
	}
	return;
}

function choosesystem(downsystem)
{
	if (downsystem != '')
		{	
			if (document.downform.systemtype.value.search(downsystem)==-1)
			{
				if (document.downform.systemtype.value=='') document.downform.systemtype.value=downsystem;
				else document.downform.systemtype.value = document.downform.systemtype.value + '/' + downsystem;
			}
		}
	if (downsystem == 'clean') document.downform.systemtype.value = '';
	return;
}

//分页
function changepageno(no,searchstr)
{
	var locationstr=window.location.href;
	var searchlocation=locationstr.lastindexof(searchstr);
	if (searchlocation!=-1)
	{
		var tempsearchlocation=locationstr.indexof('&',searchlocation);
		if (tempsearchlocation!=-1)
		{
			locationstr=locationstr.slice(0,searchlocation)+searchstr+'='+no+window.location.href.slice(tempsearchlocation);
		}
		else locationstr=locationstr.slice(0,searchlocation)+searchstr+'='+no;
	}
	else
	{
		if (locationstr.lastindexof('?')!=-1) locationstr=locationstr+'&'+searchstr+'='+no;
		else  locationstr=locationstr+'?'+searchstr+'='+no;
	}
	window.location=locationstr;
}

