
function selectall(a)
{
   var a = document.getElementsByTagName("input");
   for (var i=0; i<a.length; i++)
      if (a[i].type == "checkbox") a[i].checked =!a[i].checked;
}
function tomove()
{
   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var page = document.getElementById("page").value;
   var param = "";
   for (i=0;i<chkArr.length;i++)
   if (chkArr[i].checked)
   param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要转移分类的条目！");
   }else{
       var url="Admin_product_list.asp?action=movecategory&id="+param+"&page="+page;
       window.open(url, 'movecategory', 'width=300,height=240,resizable=0,scrollbars=1,status=no,toolbar=no,location=no,menu=no');
   }
}
function tosale()
{
   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var vtype = document.getElementById("vtype").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var Lang = document.getElementById("Lang").value;
   var param = "";
   for (i=0;i<chkArr.length;i++)
   if (chkArr[i].checked)
   param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要上架的条目！");
   }else{
       location="Admin_product_list.asp?action=changestate&state=0&id="+param+"&zhuangtai="+zhuangtai+"&vtype="+vtype+"&sort_id="+sort_id+"&Lang="+Lang+"&page="+page;
   }
}
function tocancelsale()
{
   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var vtype = document.getElementById("vtype").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var Lang = document.getElementById("Lang").value;
   var param = "";
   for (i=0;i<chkArr.length;i++)
   if (chkArr[i].checked)
   param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要下架的条目！");
   }else{
       location="Admin_product_list.asp?action=changestate&state=1&id="+param+"&zhuangtai="+zhuangtai+"&vtype="+vtype+"&sort_id="+sort_id+"&Lang="+Lang+"&page="+page;
   }
}
function torecom()
{
   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var vtype = document.getElementById("vtype").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var Lang = document.getElementById("Lang").value;
   var param = "";
   for (i=0;i<chkArr.length;i++)
   if (chkArr[i].checked)
   param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要推荐的条目！");
   }else{
       location="Admin_product_list.asp?action=pstj&stj=0&id="+param+"&zhuangtai="+zhuangtai+"&vtype="+vtype+"&sort_id="+sort_id+"&Lang="+Lang+"&page="+page;
   }
}
function tocancelrecom()
{
   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var page = document.getElementById("page").value;
   var zhuangtai = document.getElementById("zhuangtai").value;
   var vtype = document.getElementById("vtype").value;
   var sort_id = document.getElementById("js_sort_id").value;
   var Lang = document.getElementById("Lang").value;
   var param = "";
   for (i=0;i<chkArr.length;i++)
   if (chkArr[i].checked)
   param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要取消推荐的条目！");
   }else{
       location="Admin_product_list.asp?action=pstj&stj=1&id="+param+"&zhuangtai="+zhuangtai+"&vtype="+vtype+"&sort_id="+sort_id+"&Lang="+Lang+"&page="+page;
   }
}
function deletedeaultpage()
{
   if(window.confirm("确定要删除吗？")){
       location="tohtml/_html_default.asp?do=delete";
   }else return;
}
function todelsources()
{
   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var page = document.getElementById("page").value;
   var param = "";
   for (i=0;i<chkArr.length;i++)
   if (chkArr[i].checked)
   param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要删除的条目！");
   }else{
       if(window.confirm("确定要删除吗？删除将不能恢复！")){
           location="?action=sources_del&id="+param+"&page="+page;
       }else return;
   }
}
function todel()
{

   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var page = document.getElementById("page").value;
   var Lang = document.getElementById("Lang").value;
   var l_type = document.getElementById("l_type").value;
   var keyword = document.getElementById("keyword").value;
   var sort_id = document.getElementById("sort_id").value;
   var param = "";
   for (i=0;i<chkArr.length;i++)
     if (chkArr[i].checked)
     param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要删除的条目！");
   }else{
       if(window.confirm("如果您删除是父分类，其子类也会删除。\r确定要删除吗？删除将不能恢复！")){
           location="?action=dete&id="+param+"&keyword="+escape(keyword)+"&l_type="+escape(l_type)+"&Lang="+Lang+"&sort_id="+escape(sort_id)+"&page="+page;
       }else return;
   }
}
function ConfirmDel()
{
  if(confirm("确定要删除吗？删除将不能恢复！"))
    return true;
  else
    return false;
}
function u_Size(num,objname)
{
	var obj=document.getElementById(objname)
	if (parseInt(obj.rows)+num>=3) {
		obj.rows = parseInt(obj.rows) + num;
	}
	if (num>0)
	{
		obj.width="90%";
	}
}
function runscript(n){
	txtRun=n;window.open("../public/templates_view.asp","templates_view")
}
function DoTags(addTags){
	document.addproduct.p_tags.value=addTags+document.addproduct.p_tags.value;
	document.addproduct.p_tags.focus();

}
var n=1;
 function switchSysBar(){
	if (n==1){
	    n=2
 		document.all("frmTitle").style.display="none";
		document.getElementById("arrow").src="images/Btn_open.gif";
		document.getElementById("arrow").alt="伸展";
	}
	else{
		n=1;
		document.all("frmTitle").style.display="";
		document.getElementById("arrow").src="images/Btn_close.gif";
		document.getElementById("arrow").alt="收缩";
	}
}
function cleanDefault(id) {
		document.getElementById(id).value = "";
		document.getElementById(id).style.color="#000000";
}

var i = 1;
function searchselect () {
	if (i % 2 == 0) {
		hiddenmenu();
	} else {
		showmenu();
	}
	i=i+1;
}
function choose(items) {
	switch (items) {
		case 1:
			document.getElementById("searchall").value="请输入商品名称搜索";
			document.all.SearchType.value="Admin_product_list.asp?product_name=";
			document.all.SearchTitle.value="商品管理";
			break;
		case 2:
			document.getElementById("searchall").value="请输入订单编号搜索";
			document.all.SearchType.value="Admin_orders.asp?s_order_number=";
			document.all.SearchTitle.value="订单管理";
			break;
		case 3:
			document.getElementById("searchall").value="请输入会员名称搜索";
			document.all.SearchType.value="admin_user.asp?userid=";
			document.all.SearchTitle.value="注册会员管理";
			break;
	}
	hiddenmenu();
	i = i+1;
}
function showmenu() {
		document.getElementById("searchmenu").style.display="block";
}
function hiddenmenu() {
		document.getElementById("searchmenu").style.display="none";
}
function Indexsearch() {
		right.location.href=''+document.all.SearchType.value+document.all.SearchName.value+'';
		top.document.getElementById('topTitle').innerHTML=''+document.all.SearchTitle.value+'';
}

function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
   }
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
var s="";
for(i=0;i<=document.all("get_product").length-1;i++)
{
	//var s=s+document.addNEWS.get_product.options(i).value+",";  // 原程序
	var s=s+document.getElementById("get_product").options[i].value+","; //WL 改动 2008-1-10
}
//document.addNEWS.n_product.value=s;  // 原程序
document.getElementById("n_product").value = s;  //WL 改动 2008-1-10
//document.addNEWS.get_n_product.focus();
}

var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function callsearch() {
  var s_keywords = document.getElementById("s_keywords").value;
  var s_sort_id = document.getElementById("s_sort_id").value;
  var url = "admin_news.asp?action=search&s_keywords=" + escape(s_keywords) +"&s_sort_id=" + s_sort_id;
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);
}

function updatePage() {
  if (xmlHttp.readyState < 4) {
	document.getElementById("test1").innerHTML="<select multiple size='10' name='list1' style='width:340px;'><option>loading...</option></select>";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	document.getElementById("test1").innerHTML=response;
  }
}

function Trim(str){
   if(str.charAt(0) == " "){
   str = str.slice(1);
   str = Trim(str);
}
return str;
}

function isDigit(pObj,errMsg){
   var obj = eval(pObj);
   var patrn=/^[0-9]{1,20}$/;
   if (!patrn.exec(pObj.value))
   {
      alert(errMsg);
      obj.focus();
      return false;
   }
   return true
}

function isEmpty(pObj,errMsg){
   var obj = eval(pObj);
   if( obj == null || Trim(obj.value) == ""){
   if (errMsg == null || errMsg =="")
      alert("输入为空!");
   else
      alert(errMsg);
      obj.focus();
      return false;
   }
   return true;
}

function Empty(pObj){
   var obj = eval(pObj);
   if( obj == null || Trim(obj.value) == ""){
      return true;
   }else{}
   return false;
}
function ShowinnerHTML(pObj,iobj,errMsg){
   iobj.innerHTML = "<img src=\"images/error.gif\" align=\"absmiddle\"> <font color=\"red\">"+errMsg+"</font>";
   pObj.focus();
}

function CheckEmpty(pObj){
   var obj = document.getElementById(pObj);
   var iobj = document.getElementById("mes_"+ pObj);
   if( obj == null || Trim(obj.value) == ""){
      return true;
   }else{iobj.innerHTML = "";obj.style.backgroundColor="";}
   return false;
}

function ShowMessage(pObj,errMsg){
	var obj = document.getElementById(pObj);
	var iobj = document.getElementById("mes_"+ pObj);
	obj.style.backgroundColor="#f5f5f5";
    iobj.innerHTML = "<img src=\"images/error.gif\" align=\"absmiddle\"> <font color=\"red\">"+errMsg+"</font>";
    obj.focus();
}

 /****** START WangLei 2008-1-10 添加************************/
function ajaxSub(t,url,t2)
{
	if (url.indexOf("?")==-1)
		url = url + '?t000='+Math.random()
	else
		url = url + '&t000='+Math.random()
	xmlHttp.open("GET", url, true);
	switch (t) {
		case 0 :
			xmlHttp.onreadystatechange = updatePageUnite
			break;
		case 1 :
			xmlHttp.onreadystatechange = getUniteProduct;
			break;
		case 2 :
			xmlHttp.onreadystatechange = setarea2;
			break;
		default :
			//alert('3');
			break;
	}
	xmlHttp.send(null);
}
function updatePageUnite() {
  if (xmlHttp.readyState < 4) {
	test1.innerHTML="<select multiple size='10' id='temp_product' name='temp_product' style='width:300px;'><option>loading...</option></select>";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	test1.innerHTML=response;
  }
}

function getUniteProduct()
{
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	var tArr = response.split('||||');
		//alert(xmlHttp.responseText);
	for (i = 0; i < tArr.length; i++) {
	   var sArr = tArr[i].split('||');
		if (sArr.length > 6)
		{
			addUniteRows(sArr[1],sArr[2],sArr[3],sArr[4],"",sArr[5]);
		}
	}
	//sumWeight();
  }
}
function getUniteProduct_re(str)
{
	var tArr = str.split('||||');
	for (i = 0; i < tArr.length; i++)
	{
	   var sArr = tArr[i].split('||');
		if (sArr.length > 4)
		{
			addUniteRows(sArr[0],sArr[1],sArr[2],sArr[3],sArr[4],sArr[5]);
		}
	}
	sumWeight();
}


function sumSPrice() //计算市场价和,计算重量和
{
	var t = 0;
	var tWeight = 0;
	var uPNum = document.getElementsByName("uPNum");
	var uSprice = document.getElementsByName("uSprice");
	var pWeight = document.getElementsByName("pWeight");
	for(i=0;i<uPNum.length;i++)
	{
		if (uPNum[i].value!="" && uSprice[i].value!="")
		{
			t = t + Number(uPNum[i].value)*Number(uSprice[i].value);
		}
		if (uPNum[i].value!="" && pWeight[i].value!="")
		{
			tWeight = tWeight + Number(uPNum[i].value)*Number(pWeight[i].value);
		}
	}
	document.getElementById("sprice").value = t;
	document.getElementById("p_weight").value = tWeight;
}

function sumWeight() //计算重量和
{
	var t = 0;
	var pWeight = document.getElementsByName("pWeight");

	for(i=0;i<pWeight.length;i++)
	{
		if (pWeight[i].value!="")
		{
			t = t + Number(pWeight[i].value);
		}
	}
	document.getElementById("p_weight").value = t;
}

function addUniteRows(v0,v1,v2,v3,v4,v5)
{
	//创建td节点
	var td0= document.createElement("td");
	var td1= document.createElement("td");
	var td2= document.createElement("td");
	var td3= document.createElement("td");
	td3.setAttribute("align","");
	var td4= document.createElement("td");
	td4.setAttribute("align","");

	td0.innerHTML = v1+'<INPUT TYPE="hidden" NAME="uBianhao" value="'+v1+'"> <INPUT TYPE="hidden" id="uPid" NAME="uPid" value="'+v0+'"><INPUT TYPE="hidden" NAME="pWeight" id="pWeight" value="'+v5+'">';
	td1.innerHTML = v2+'<INPUT TYPE="hidden" NAME="uProduct_name" value="'+v2+'">';
	td2.innerHTML = v3+'<INPUT TYPE="hidden" NAME="uSprice" value="'+v3+'">';
	td3.innerHTML = '<input type=text name=uPNum size=2 value="'+v4+'" maxlength=3 class=form onkeyup=value=value.replace(\/[^\\d]\/g,\'\');  onblur=sumSPrice();>';
	td4.innerHTML = '<A onclick="return delUniteRows(event);" style="cursor:pointer;">删除</a>';

	//创建tr节点
	var trNode = document.createElement("tr");
	trNode.appendChild(td0);
	trNode.appendChild(td1);
	trNode.appendChild(td2);
	trNode.appendChild(td3);
	trNode.appendChild(td4);

	//创建tbody节点，必须使用tbody，不然无法使用dom方式添家行，只能用insertRow
	var trBody = document.createElement("tbody");
	trBody.appendChild(trNode);
	document.getElementById("tableUP").appendChild(trBody);
}
function getEvent()
{
    if(document.all)   return window.event;
    func=getEvent.caller;
    while(func!=null){
        var arg0=func.arguments[0];
        if(arg0)
        {
          if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
          {
          return arg0;
          }
        }
        func=func.caller;
    }
    return null;
}
function delUniteRows(event)
{
    var Evt = getEvent();
    var srcElements = Evt.srcElement == undefined ? Evt.target : Evt.srcElement
    var i = srcElements.parentNode.parentNode.rowIndex;
    document.getElementById("tableUP").deleteRow(i);
	sumSPrice();
	sumWeight();
}
//function delUniteRows(event)
//{
//	if(event == null)
//	{
//		event = window.event; // For IE
//	}
//	var eventObj = event.srcElement? event.srcElement : event.target;
//	var tbodyNode = eventObj.parentNode.parentNode.parentNode;
//	var trNode = eventObj.parentNode.parentNode
//	var rowIndex = trNode.rowIndex;
//	var objTable = document.getElementById("tableUP");
//
//	objTable.removeChild(tbodyNode);
//	sumSPrice();
//	return false;
//	//sumWeight();
//}
function getSubmitUniteStr() // 获取提交时绑定商品字符串值
{
	var uPidArr = document.getElementsByName("uPid");
	var uBianhao = document.getElementsByName("uBianhao");
	var uProduct_name = document.getElementsByName("uProduct_name");
	var uSprice = document.getElementsByName("uSprice");
	var uPNum = document.getElementsByName("uPNum");
	var pWeight = document.getElementsByName("pWeight");

	if (uPidArr.length < 2)
	{
		alert("捆绑促销您至少要选择两种商品.");
		return false;
	}
	for(i=0;i<uPNum.length;i++)
	{
		if (uPNum[i].value=="")
		{
			alert("请输入正确的产品捆绑数量");
			return false;
			break;
		}
	}
	var tArray = new Array();
	for(i=0;i<uPidArr.length;i++)
	{
		tArray.push(uPidArr[i].value + "||" +uBianhao[i].value + "||" + uProduct_name[i].value + "||" + uSprice[i].value + "||" + uPNum[i].value + "||" + pWeight[i].value);
	}
	document.getElementById("productUniteStr").value=tArray.join("||||");
	return true;
}
function trim(str) //去空格
{
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function toUpdateGradeIco()  // WangLei 更新记录排序  2008-3-10
{
	var i = 0,icoStr="";
	var grade_ico = document.all.grade_ico;
	for (var i=0; i<grade_ico.length; i++)
	{
		icoStr+=grade_ico[i].value+",";
	}
	if (icoStr.length == 0 )
	{
		alert("暂无内容可更新！");
		return;
	}else{
		//alert(icoStr);
		location.href="?action=updtGradeIco&icoStr="+icoStr;
	}
}

 /****配送地区*/
function setarea2() {
  if (xmlHttp.readyState < 4) {
	//test1.innerHTML="loading...";
  }
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	area2_div_id.innerHTML=response;
  }
}
/**批量删除*/
function todels(urlstr)
{
   var i = 0;
   var chkArr = document.getElementsByTagName("input");
   var param = "";
   for (i=0;i<chkArr.length;i++)
   if (chkArr[i].checked) param+=chkArr[i].value +",";
   if (param.length == 0)
   {
       alert("请先选择要删除的条目！");
   }else{
       if(window.confirm("确定要删除吗？删除将不能恢复！")){
		   //alert(urlstr + "&id=" + param);
           location= urlstr + "&id=" + param;
       }else return;
   }
}
/************************************/
function toUpdateDeliverPrice()  // WangLei 更新配送方式价格  2008-6-10
{
	var i = 0,idStr = "",priceStr="",nameStr="",infoStr="";
	var a = document.getElementsByName("e_id");
	var page = document.getElementById("page").value;
	var pPrice = document.getElementsByName("d_price");
	var pName = document.getElementsByName("d_name");
	var pInfo = document.getElementsByName("d_info");
	for (var i=0; i<a.length; i++)
	{
		idStr+=a[i].value +"|||";
	}
	for (var i=0; i<pPrice.length; i++)
	{
		priceStr+=pPrice[i].value+"|||";
	}
	for (var i=0; i<pName.length; i++)
	{
		nameStr+=escape(pName[i].value)+"|||";
	}
	for (var i=0; i<pInfo.length; i++)
	{
		infoStr+=escape(pInfo[i].value)+"|||";
	}
	if (idStr.length == 0)
	{
		alert("暂无内容更新！");
	}else{
		//if (window.confirm("确定要更新记录吗？"))
		//{
			location.href="?action=updtPrice&id="+idStr+"&pPrice="+priceStr+"&pName="+nameStr+"&pInfo="+infoStr+"&page="+page;
		//}else return;
	}
}

function checknum(str){
var strSource ="0123456789.";
var ch;
var i;
var temp;
for (i=0;i<=(str.length-1);i++)
{

    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1)
    {
     return 0;
    }
}
if (strSource.indexOf(ch)==-1)
{
    return 0;
}
else
{
    return 1;
}
}

function SinnerHTML(pObj,iobj,errMsg){
   iobj.innerHTML = "<img src=\"images/succes.gif\" align=\"absmiddle\"> <font color=\"red\">"+errMsg+"</font>";
}

function EinnerHTML(pObj,iobj,errMsg){
   iobj.innerHTML = "<img src=\"images/error.gif\" align=\"absmiddle\"> <font color=\"red\">"+errMsg+"</font>";
   pObj.focus();
}

function tdshow(obj,arr)
{
	var cArr = arr||["#fff","#FAFAFA","#EBEBEB"];
	var trArr=document.getElementById(obj).getElementsByTagName("tr");
	for(var i=0,j=trArr.length;i<j;i++)
	{
		var o=trArr[i];
		o.style.backgroundColor=cArr[i%2];
		o.onmouseover=function(){this.style.backgroundColor=cArr[2];}
		o.onmouseout=function(){this.style.backgroundColor=cArr[this.sectionRowIndex%2];}
	}
}