//define the special word Array 
function specialWordArray()
{
	var specailword = new Array();
	specailword[0]="'";
	specailword[1]='"';
	specailword[2]="<";
	specailword[3]=">";
	specailword[4]="/";
	specailword[5]="\\";
	return specailword;
}


//check whether  somestring include the special world defined in the function of specialWordArray()
function ifspecialword(str)
{
	var varray = specialWordArray();
	var vlen = varray.length;
	var i = 0, sflag = 0;
	for(i=0; i<vlen; i++)
	{
		if( str.indexOf( varray[i] ) >= 0 )
		{
			sflag ++;
			break;
		}
	}
	if(sflag>0)
		return true;
	else
		return false;
}


//check whether  sequential space
function ifspace(str)
{
	var vlen = str.length;
	var i = 0, flag = 0;
	for(i=0; i<vlen; i++)
	{
		if( str.substring(i, i+1) == " " )
			flag ++;
	}
	if(flag == vlen)
		return true;
	else
		return false;
}


//check whether somestring include Chinese
function ifchinese(str)
{
	if( escape(str).indexOf("%u") != -1 )
		return true;
	else
		return false;
}


//check whether somestring is valid numeric
function ifnumeric(str)
{
	var vlen = str.length;
	var i = 0, sflag = 0;
	for(i=0; i<vlen; i++)
	{
		if( str.substring(i, i+1)<'0' || str.substring(i, i+1)>'9' || (vlen>1 && i==0 && str.substring(i, i+1)=='0') )
		{
			sflag ++;
			break;
		}
	}
	if(sflag>0)
		return false;
	else
		return true;
}


//check whether somestring is valid float
function iffloat(str)
{
	var vlen = str.length;
	var i = 0, sflag = 0, pflag = 0;
	for(i=0; i<vlen; i++)
	{
		if( str.substring(i, i+1)!="." && (str.substring(i, i+1)<'0' || str.substring(i, i+1)>'9') )
		{
			sflag ++;
			break;
		}
		if ( str.substring(i, i+1) =="." )
			pflag++;
	}
	if(sflag>0 || pflag>1)
		return false;
	else
		return true;
}



//********************************************
//check whether the user logininfo is valid
//used in the common program /include/left.inc
function checklogin(formname)
{
	var form = eval(formname)
	var vusr = form.username.value;
	var vpwd = form.userpwd.value;
	
	if(vusr == "")
	{
		alert("请填写会员账号！");
		form.username.focus();
		return false;
	}
	if(vpwd == "")
	{
		alert("请填写登录密码！");
		form.userpwd.focus();
		return false;
	}
	/*
	if( ifspecialword(vusr) || ifspecialword(vpwd) )
	{
		alert("请填写有效的会员账号或密码！");
		return false;
	}
	*/
}


//********************************************
//change “city” options when “province” changes
function ChangeOption(selectname1, selectname2, showtitle)
{
	var fvalue = eval('document.aa.'+ selectname1).value;
	var telemt = eval('document.aa.'+ selectname2);
	var hidval = document.aa.hidpcity.value;
	var i=0, j=0, tempary=null, vlen = 0, thisp = "";
	for (i=telemt.options.length-1; i>=0; i--) 
		telemt.options[i]=null;
	telemt.options[0] = new Option(showtitle, "");	
	if (fvalue != "")
	{
		tempary = fvalue.split(":");
		pvalue = tempary[0];
		tempary = null;
		tempary = hidval.split(";");
		for(i=0; i<tempary.length; i++)
		{
			Intempary = tempary[i].split(",");
			thisp = Intempary[0];
			if( thisp == pvalue )
			{
				j++;
				telemt.options[j] = new Option(Intempary[2], Intempary[2]);
			}
			Intempary = null;
			thisp = ""
		}		
	}
}


//********************************************
//prepage, nextpage, firstpage, endpage
function jumppage(x, formname, pagename)
{
	eval('document.'+ formname +'.'+ pagename).value = x;
	eval('document.'+ formname).submit();
}


//********************************************
//弹出窗口
function popwin(url, title, width, height)
{
	window.open(url, title, "width="+width+", height="+height+", directories=no, toolbar=no, resizable=yes, menubar=no, scrollbars=yes");
}



//********************************************
//查询结果（单选）返回父页面
function changeParent(fromForm, fromshowname, fromhidname, toForm, toshowname, tohidname)
{
	
	var i = 0, tmpi = 0, checki = 0, vcount = 0, errflag=0;
	var tmpid = "", tmpvalue = "";
	var formleng = eval(fromForm).elements.length;
	for(i=0; i<formleng; i++)
	{
		if ( eval(fromForm).elements[i].name == fromshowname )
		{
			vcount++;
			if( eval(fromForm).elements[i].checked == false )
				tmpi++;
			else
			{
				checki = vcount - 1;
				tmpid = eval(fromForm).elements[i].value;
			}
		}
	}
	if(tmpi == vcount)
		errflag = 1;
	if (vcount > 0 && errflag > 0)
	{
		alert("请选择信息提交！");
		return false;
	}
	else
	{
		
		if (vcount == 1)
			tmpvalue = eval(fromForm +"."+ fromhidname).value;
		else
			tmpvalue = eval(fromForm +"."+ fromhidname +"["+ checki +"].value");
		
		eval( "window.opener."+ toForm +"."+ tohidname ).value = tmpid;
		eval( "window.opener."+ toForm +"."+ toshowname ).value = tmpvalue;
		
		window.close();
		return true;
	}
}


//********************************************
//后台管理中全选功能
function checkoption(fromForm, toForm, toElemt)
{
	var i=0; vcounts = 0;
	var vfleng = eval(toForm).elements.length;
	for(i=0; i<vfleng; i++)
	{
		if (eval(toForm).elements[i].name == toElemt)
		{
			vcounts++;
			if(eval(fromForm).checkall.checked == true)
				eval(toForm).elements[i].checked = true;
			else if(eval(fromForm).checkall.checked == false)
				eval(toForm).elements[i].checked = false;
		}
	}
}



//********************************************
//后台管理中更改状态（会员状态，货物状态，空车状态）提交前，（复选）组合参数传给隐含变量
function getHiddenPara(fromForm, fromElemt, toForm, toElemt, optElemt, URLAddr)
{
	var i=0; vcounts = 0, errflag = 0;
	var symb = "", tmp = "";
	var vfleng = eval(fromForm).elements.length;
	
	for(i=0; i<vfleng; i++)
	{
		if (eval(fromForm).elements[i].name == fromElemt)
		{
			vcounts++;
			if(eval(fromForm).elements[i].checked == false)
				errflag++;
			else
			{
				tmp = tmp + symb + eval(fromForm).elements[i].value;
				symb = ",";
			}
		}
	}
	
	if ( errflag == vcounts )
	{
		alert("请选择要更改状态的信息！");
		return false;
	}
	else
	{
		
		eval(toForm +"."+ toElemt).value = tmp;
		//eval(toForm).action = URLAddr;
		//eval(toForm).submit();
		
		theurl = URLAddr + "?adminopt="+ eval(toForm +"."+ optElemt).value +"&hidelemt="+ tmp;
		
		window.open (theurl, "updateElementStatus", "width=210, height=260, directories=no, toolbar=no, resizsable=no, menubar=no, scrollbars=yes");
	}
	
}
