var debugStr="";
var itemsLength=0;

function debugPrint(runStr)
{
    debugStr=debugStr+runStr+"<br>";
}

function debugShow()
{
    document.write(debugStr);	
}

function ReadUrl(paraName,para)
{
    var str_url,str_pos,str_para;    
    var arr_param=new Array();   
    str_url = window.location.href;    
    str_pos = str_url.indexOf("?");    
    str_para = str_url.substring(str_pos+1);    
    if (str_pos>0){   
     arr_param=str_para.split("&");   
        for(var i=0;i<arr_param.length;i++){   
           var temp_str = new Array();   
           temp_str=arr_param[i].split("=") ;
           
           if( temp_str[0] == paraName)
           {
              cmdSring=para+"=temp_str[1];";
              //alert(cmdSring);
              eval(cmdSring);
           }
        }
     }
}

function GetTmpl(startPot, endPot, num)
{
        if (!num)
                num = '';
	//alert("start="+startPot+"end="+endPot+"num="+num);
        var tmpStr = document.body.innerHTML;
        var splitStr = startPot + num;
        var tmpArr = tmpStr.split(splitStr);
        tmpStr = tmpArr[1];
        splitStr = num + endPot;
        tmpArr = tmpStr.split(splitStr);
        tmpStr = tmpArr[0];
        return tmpStr;
}

function ItemConvStr(srcStr, srcDelim, desDelim)
{
        var tmpStr = new String(srcStr);
        var tmpArray = tmpStr.split(srcDelim);
        var tmp='';
        for(var i=0;i<tmpArray.length;i++)
        {
                if(i == 0)
                        tmp += tmpArray[i];
                else
                        tmp += desDelim+tmpArray[i];
        }

        return tmp;
}

function showPage(preUrl, tailUrl, curPage,totalPage)
{
    document.write("<td><a href=\""+preUrl+"1"+tailUrl+"\">first</a></td>");
    for(var iNum=1; iNum<=totalPage; iNum++)
    {
        if(iNum==curPage)
            document.write("<td><a href=\""+preUrl+iNum+tailUrl+"\"><font color=red>"+iNum+"</font></a></td>");
        else
            document.write("<td><a href=\""+preUrl+iNum+tailUrl+"\">"+iNum+"</a></td>");
    } 
    document.write("<td><a href=\""+preUrl+totalPage+tailUrl+"\">last</a></td>");
    return 1;
}

function getItemsLength()
{
	if(pageContent == "")
	    return 0;
	var tmpArray = pageContent.split('*');
        itemsLength=tmpArray.length;
        return itemsLength;
}

function getItemsInfo(i)
{
	var tmpArray = pageContent.split('*');
	var itemsinfo = tmpArray[i];
	var infoArray= itemsinfo.split('|');
	//if(infoArray.length != 10)
	//	return -1;
	return infoArray;
}



function showContent()
{
  var infoArray=getItemsInfo(0);
  for(var i=0;i<infoArray.length;i++)
  {
      debugPrint(infoArray[i]);
  }
}

function showContentTpl(idx)
{
  var newStr="";
  
  if (!idx)
  {
  	getItemsLength();
  	alert(itemsLength);
  	for(var i=0;i<itemsLength;i++)
  	{
	  var infoArray=getItemsInfo(i);
	  newStr=GetTmpl('<!--itemTD', 'TDitem-->');
	  newStr = ItemConvStr(newStr, "<!--itemTD", " ");
	  newStr = ItemConvStr(newStr, "TDitem-->", " ");
	  newStr = ItemConvStr(newStr, "[itemname]", infoArray[0]);
	  newStr = ItemConvStr(newStr, "[itemprice]", infoArray[1]);
	  document.write(newStr);	
  	}
  }
  else
  {
	  idx=idx-1;
	  newStr=GetTmpl('<!--itemTD', 'TDitem-->');
	  var infoArray=getItemsInfo(idx);
	  newStr = ItemConvStr(newStr, "<!--itemTD", " ");
	  newStr = ItemConvStr(newStr, "TDitem-->", " ");
	  newStr = ItemConvStr(newStr, "[itemname]", infoArray[0]);
	  newStr = ItemConvStr(newStr, "[itemprice]", infoArray[1]);
	  document.write(newStr);
  }
}

function setCookie (name, value) {
  //document.cookie = name + "=" + escape(value) + "; path=/; domain=qq.com";
  document.cookie = name + "=" + value  + "; path=/";
}

function getCookie(name) {
  var search;
  search = name + "="
  offset = document.cookie.indexOf(search) 
  if (offset != -1) {
    offset += search.length ;
    end = document.cookie.indexOf(";", offset) ;
    if (end == -1)
      end = document.cookie.length;
    return unescape(document.cookie.substring(offset, end));
  }
  else
    return "";
}

function deleteCookie(name) {
  document.cookie = name + "= ;expires=Fri, 02-Jan-1970 00:00:00 GMT";
}

function chkLgn(val)
{  
    uId=getCookie("uId");
    if(uId=="" || uId=="0")
    {
        alert("温馨提示: 请先登录");
        return;
    }
    if(val=="saleIcEdit.php")
         window.location = "/indexSaleIcEdit.htm";   
    else if(val=="buyEdit.php")
         window.location = "/indexLgnIn.htm";      
}

function loginOut()
{
    setCookie("uId","0");
    setCookie("uLgnId","0");
    setCookie("key","0");
    setCookie("lgnTime","0");
    setCookie("lgnTimeVerify","0");
    window.location="/index.htm";       

}

function doCheck(el)
{
    var r=new RegExp("^\\s*(\\d+)\\s*$");
    if(r.test(el.value))
    {
        if(RegExp.$1<1||RegExp.$1>totalPage)
        {
           alert("页数超出范围！");
           document.all['pageInput'].select();
           return false;
        }
        return true;
    }
    alert("页索引无效！");
    document.all['pageInput'].select();
    return false;
}

function BuildUrlString(nPage,tailUrl)
{
   tailUrl = (typeof(tailUrl)=="undefined")?"":tailUrl; 
   return preUrl+nPage+tailUrl;
}

function OpenClose(id){
    var xml = new ActiveXObject("Microsoft.XMLDOM");
    xml.async = false;
    xml.load("http://www.ic-cn.com.cn/count.php?id="+id);
    return;
}

var xmlHttp;
function createXMLHttpRequest(){
    if(window.ActiveXObject){
          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
    else if(window.XMLHttpRequest){
          xmlHttp = new XMLHttpRequest();
      }
}

function startRequest(){
      createXMLHttpRequest();
    try{
          xmlHttp.onreadystatechange = handleStateChange;
          xmlHttp.open("GET", "http://www.ic-cn.com.cn/adpage.htm", true);
          xmlHttp.send(null);    
      }catch(exception){
          //alert("您要访问的资源不存在!");
      }
}

function handleStateChange(){    
    if(xmlHttp.readyState == 4){        
        if (xmlHttp.status == 200 || xmlHttp.status == 0){
              // 显示返回结果
              document.write(xmlHttp.responseText);
          }
      }
}

