function sendxml(urlstr,xmlstr)
{
	var xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP"); //创建MS的XMLHTTP组件；
	xmlHTTP.Open("post",urlstr,false); //采用Post提交方式；
	xmlHTTP.SetRequestHeader("content-Type","application/x-www-form-urlencoded");
	xmlHTTP.Send(xmlstr);
	//alert(xmlHTTP.responseText)
	var i=xmlHTTP.responseText.indexOf("<aaa>");
	var j=xmlHTTP.responseText.indexOf("</aaa>");
	var info=xmlHTTP.responseText.substring(i+5,j);
	return info;
}

function goPage(f,url)
{
	var pageAll = f.pageAll.value;
	var pageNo = f.pageNo.value;
	//alert("pageAll----------" + pageAll)
	//alert("pageNo----------" + pageNo)
	if (isNaN(parseInt(pageNo))) 
	{
		f.pageNo.value = "";
		f.pageNo.focus();
		return false;
	}
	else if (pageNo<1 || parseInt(pageNo)>parseInt(pageAll) || pageNo.indexOf(".")>-1) 
	{
		f.pageNo.value = "";
		f.pageNo.focus();
		return false;
	}
	else
	{
		f.action = url;
		f.submit();
	}
}

function movePage(f,url,pageno)
{
	f.pageNo.value = pageno;
	f.action = url;
	f.target = "_self";
	f.submit();
}

function chkNull(o)
{
	var str = o.value;
	if (str==null || str.length==0)
	{
		alert(o.id + "不能为空！");
		o.focus();
		return false;
	}
	return true;
}

function isCharsInBag(s,bag)
{
    var i;
    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i=0;i<s.length;i++)
	{
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c)==-1) return false;
    }
    return true;
}

var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
function chkCard(o)
{
	var sId = o.value;
	var len = sId.length;
	var iSum = 0;
	var info = "";
	var judge = 0;
	/*
    if (isEmpty(str))
	{
        alert("身份证不能为空！");
		o.focus();
		return false;
    }
	*/
	if (len==0)
	{
		return true;
	}
	else
	{
		//alert(len)
		if ((!isNaN(sId) && len==15) || (!isNaN(sId) && len==18))
		{}
		else
		{
			if (len==18 && sId.substring(sId.length-1,sId.length)=="X")
			{
				judge = 1;
			}
			else
			{
				alert("身份证号必须是15位或者18位的数字型！");
				o.focus();
				return false;
			}
		}
		sId = sId.replace(/x$/i,"a");
		//alert(sId.length)
		if (aCity[parseInt(sId.substr(0,2))]==null)
		{
			alert("身份证号所在地区不正确！");
			o.focus();
			return false;
		}
		if (len==18)
		{
			sBirthday = sId.substr(6,4)+"-" + Number(sId.substr(10,2)) + "-" + Number(sId.substr(12,2));
		}
		else
		{
			sBirthday = "19" + sId.substr(6,2) + "-" + Number(sId.substr(8,2)) + "-" + Number(sId.substr(10,2));
		}
		var d = new Date(sBirthday.replace(/-/g,"/"));
		//alert(sBirthday)
		//alert((d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate()))
		
		if (sBirthday!=(d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate()))
		{
			alert("身份证号出生日期不正确！");
			o.focus();
			return false;
		}
		
		if (len==18)
		{
			if (judge==1)
			{
			}
			else
			{
				for (var i=17;i>=0;i--)
				{
					iSum += (Math.pow(2,i)%11) * parseInt(sId.charAt(17-i),11);
				}
				if (iSum%11!=1)
				{
					alert("身份证号有错误！");
					o.focus();
					return false;
				}
			}
		}
	}
	//alert(aCity[parseInt(sId.substr(0,2))] + "," + sBirthday + "," + (sId.substr(13,1)%2?"男":"女"));
	return true;
}

function getBirthday(sId)
{
	var len = sId.length;
	if (len==0)
	{
		return "";
	}
	else if (len==15)
	{
		return "19" + sId.substr(6,2) + "-" + sId.substr(8,2) + "-" + sId.substr(10,2);
	}
	else if (len==18)
	{
		return sId.substr(6,4)+"-" + sId.substr(10,2) + "-" + sId.substr(12,2);
	}
}

function getSex(sId)
{
	var len = sId.length;
	if (len==0)
	{
		return "";
	}
	else if (len==15)
	{
		return sId.substr(14,1)%2?"男":"女"
	}
	else if (len==18)
	{
		return sId.substr(16,1)%2?"男":"女"
	}
}

function getHomePlace(sId)
{
	return aCity[parseInt(sId.substr(0,2))]; 
}

function chkQuotes(o)
{
	var str = o.value;
	if (str.length==0)
	{
		return true;
	}
	if (str.indexOf("'")>-1)
	{
		alert(o.id + "中不能包含单引号！");
		o.focus();
		return false;
	}
	else if (str.indexOf("\"")>-1)
	{
		alert(o.id + "中不能包含双引号！");
		o.focus();
		return false;
	}
	return true;
}

function chkEmail(o)
{
	var str = o.value;
	if (str.length==0)
	{
		return true;
	}
	if (str.indexOf("@")<=-1)
	{
		alert("请正确填写EMAIL地址！");
		o.focus();
		return false;
	}
	return true;
}

function chkNaN(o)
{
	var str = o.value;
	if (str.length==0)
	{
		return true;
	}
	else if (isNaN(str))
	{
		alert(o.id + "必须是数字型！");
		o.focus();
		return false;
	}
	return true;
}

function chkSpec(o)
{
	var str = o.value;
	if (str.length==0)
	{
		return true;
	}
	if (str.indexOf(">")>-1)
	{
		alert(o.id + "中不能包含 > 这个字符！");
		o.focus();
		return false;
	}
	else if (str.indexOf("<")>-1)
	{
		alert(o.id + "中不能包含 < 这个字符！");
		o.focus();
		return false;
	}
	return true;
}

function chkComma(o)
{
	var str = o.value;
	if (str.length==0)
	{
		return true;
	}
	if (str.indexOf(",")>-1)
	{
		alert(o.id + "中不能包含半角的逗号！");
		o.focus();
		return false;
	}
	return true;
}

function chkColumn(o)
{
	if (chkSpec(o) && chkQuotes(o) && chkComma(o))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function insertSubjectID(o,id)
{
	o.movefirst();
	o.fields("SUBJECTID")=id;
	o.movefirst();
}

function insertServerDate(o,f)
{
	o.movefirst();
	o.fields("DOCPUBLISHDATE")=f.date.value;
	o.movefirst();
}

function insertDisplay(o,f)
{
	o.movefirst();
	o.fields("DISPLAY")=0;
	o.movefirst();
}


function insertContentDate(o,str)
{
	o.movefirst();
	o.fields("DOCDESC")=str;
	o.movefirst();
}

function insertPublisherID(o,str)
{
	o.movefirst();
	o.fields("LINEPUBLISHERID")=str;
	o.movefirst();
}

function insertPublishDate(o,str)
{
	o.movefirst();
	o.fields("LINEPUBLISHDATE")=str;
	o.movefirst();
}

function insertRemark(o,str)
{
	o.movefirst();
	o.fields("REMARK")=str;
	o.movefirst();
}

function insertPicPath(o,str)
{
	o.movefirst();
	o.fields("PICPATH")=str;
	o.movefirst();
}

function changeStartDate(o)
{
	var tempDate = o.fields("LINESTARTDATE").value;
	tempDate = tempDate.substring(tempDate,tempDate.indexOf(" "));
	o.movefirst();
	o.fields("LINESTARTDATE")=tempDate;
	o.movefirst();
}

function cmdSearch(f)
{
	var compName = f.comp_name.value;
	//alert(compName);
	var strURL="hidden/membercount.jsp?companyName=" + compName;
	var a1=sendxml(strURL,"");
	//alert(a1);
	if (a1=="0")
	{
		alert("查找单位不存在！");
	}
	else if (a1=="2")
	{
		alert("符合条件的单位超过200家，请增加查询条件限制！");
	}
	else if (a1=="1")
	{
		var sRet=window.showModalDialog("hidden/memberlist.jsp?companyName="+compName,"","status:no;scroll:yes;dialogHeight:500px;dialogWidth:300px;dialogTop:20;dialogLeft:300px") 
		if (sRet!=",")
		{
			f.comp_name.value=sRet.substring(0,sRet.indexOf(","))
			f.comp_code.value=sRet.substring(sRet.indexOf(",")+1)
		}
	}
	else
	{
		alert(a1);
	}
}

function addWholeSaleLineXml(nodeName)
{
	var curNode = WHOLESALELINE.documentElement;
	var newNode = WHOLESALELINE.createElement(nodeName)
	curNode.lastChild.appendChild(newNode);
	//alert(WHOLESALELINE.xml);
}

function insertText(o)
{
	o.movefirst();
	o.fields("LINECONTENT")=document.all.lineContent.value;
	o.fields("LINEJOURNEY")=document.all.lineJourney.value;
	o.movefirst();
}

function insertVoteDate(o,str)
{
	o.movefirst();
	o.fields("VOTE_DATE")=str
	o.movefirst();
}

function insertVoteState(o)
{
	o.movefirst();
	o.fields("STATE")=1
	o.movefirst();
}

function insertVote(o)
{
	var temp;
	o.movefirst();
	temp = o.fields("VOTE1").value;
	if (temp.length!=0)
	{
		o.fields("VOTE1")=temp + "-0"
	}
	temp = o.fields("VOTE2").value;
	if (temp.length!=0)
	{
		o.fields("VOTE2")=temp + "-0"
	}
	temp = o.fields("VOTE3").value;
	if (temp.length!=0)
	{
		o.fields("VOTE3")=temp + "-0"
	}
	temp = o.fields("VOTE4").value;
	if (temp.length!=0)
	{
		o.fields("VOTE4")=temp + "-0"
	}
	temp = o.fields("VOTE5").value;
	if (temp.length!=0)
	{
		o.fields("VOTE5")=temp + "-0"
	}
	o.movefirst();
}

function deleteRecord(i,o,o1)
{
	try
	{
		if(o.recordcount>i)
			o.absoluteposition=i;
		else 
			o.absoluteposition=o.recordcount;
		if (o.recordcount==1)
		{
			for (r=0;r<o.fields.count;r++)
			{
				o.fields(r)="";
			}
		}
		else
		{
			o.Delete();
			if(o.recordcount>1)
			{
				for(r=0;r<o.recordcount;r++)
					o1[r].id=r+1;
			}
		}
	}
	catch(e){}
}

function addRecord(o,o1)
{
	try
	{
		o.addNew();
		if(o1!=null)
		{
			if(o.recordcount!=1)
			{
				for(r=0;r<o.recordcount;r++)
				{
					o1[r].id=r+1;
				}
			}
		}
		return true;
	}
	catch(e)
	{
		return false;
	}
}
