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 selectall2(a) 
{ 
   var a = document.getElementsByName("idn"); 
   for (var i=0; i<a.length; i++) 
      if (a[i].type == "checkbox") a[i].checked =!a[i].checked; 
} 



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 todelpinpai()
{   
   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=pinpai_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("确定要删除吗？删除将不能恢复！")){
           location="?action=del&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 DoTags(addTags){
	document.addproduct.p_tags.value=addTags+document.addproduct.p_tags.value;
	document.addproduct.p_tags.focus();

}
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 = "Swant_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\"> <font color=\"red\">"+errMsg+"</font>";
    obj.focus(); 
}


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 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 trim(str) //去空格
{
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

function toUpdateGradeIco()  
{   
	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=updateGradeIco&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() 
{   
	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=updatePrice&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];}
	}
}

function resizeEditor(name,size) {   
	var newheight = parseInt(document.getElementById(name +"___Frame").style.height, 10) + size;   
	if(newheight >= 150) {   
		document.getElementById(name +"___Frame").style.height = newheight + 'px';   
	}   
}  