﻿/*
功能：创建遮罩背景
作者：LY
*/
function createLoad(bodyId,headId)
{
   var sourceBody = $(bodyId)
   var sourceHead = $(headId)
   var position = getPosition(sourceHead) ;

   var maskObj = document.createElement("div");
   maskObj.setAttribute('id','BackDiv');
   maskObj.style.position = "absolute";

   maskObj.style.top = position.y+"px";
   maskObj.style.left = position.x+"px";
   maskObj.style.background = "#777";
   maskObj.style.filter = "Alpha(opacity=30);";
   maskObj.style.opacity = 75/100;
   maskObj.style.MozOpacity = 75/100;
   maskObj.style.opacity = "0.3";
   maskObj.style.width = sourceBody.offsetWidth+"px" ;
   maskObj.style.height = sourceHead.offsetHeight+sourceBody.offsetHeight+30+"px";
   maskObj.style.zIndex = "9999";

   document.body.appendChild(maskObj);
}

/*
功能：得到绝对位置
作者：LY
*/
function getPosition(el)
{
     for (var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
     return {x:lx,y:ly}
}


/*
功能：判断字符串是否为数字
作者：LY
*/

function checkRate(input)
{
     var re =/^[0-9]*[1-9][0-9]*$/;   //
     if (!re.test(input))
     {
        alert("请输入正整数");
        return false;
     }
     else
     {
        return true;
     }
}



//绑定下拉框
function setSelectvalue(sel,value)
{

    var selgoodtype = document.getElementById(sel);
    var leng = selgoodtype.options.length;
    for (i=0;i<leng;i++)
    {
        if (selgoodtype.options[i].text == value)
        {
            selgoodtype.options[i].selected = true;
            break;
        }
    }
}




function setSelectNum(sel,value)
{

    var selgoodtype = document.getElementById(sel);
    var leng = selgoodtype.options.length;
    for (i=0;i<leng;i++)
    {
        if (selgoodtype.options[i].value == value)
        {
            selgoodtype.options[i].selected = true;
            break;
        }
    }
}



function getSelectNum(sel)
{
    var selgoodtype = document.getElementById(sel);
    var leng = selgoodtype.options.length;
    for (i=0;i<leng;i++)
    {
        if (selgoodtype.options[i].selected == true )
        {
            return selgoodtype.options[i].innerText
        }
    }

    return null;
}

//绑定checkbox
function setValueToCheckbox(obj,value)
{
    var arrValue = value.split("_");//1|2|3|4|5|6|7
    var v = document.getElementsByName(obj);

    for(var i = 0; i<arrValue.length;i++)
    {
        for(var h = 0;h<v.length;h++)
        {
            if(arrValue[i] == v[h].value)
            {
                v[h].checked = true;
            }
        }
    }
}


//取得单选
function GetRadioValue(value,type)
{
   var radios = document.getElementsByName(value);

   for(var i=0;i< radios.length;i++)
   {

     if(radios[i].checked)
     {
        if(type == "value")
        return radios[i].value;
        if(type == "text")
        return radios[i].getAttribute("text");

     }
   }
   return null;
}


//清空单选
function ClearRadioBoxType(value)
{
   var radios = document.getElementsByName(value);
   for(var i=0;i< radios.length;i++)
   {
     if(radios[i].checked)
     {
        return radios[i].checked = false ;

     }
   }
}







//获得周起止
function GetDays(d1)
{
    var weeknow=parseDate(d1).getDay();
    if (weeknow==0)
    weeknow=7;
    var daydiff = (-1) * (weeknow-1);
    var dayadd = 7-weeknow;
    var p1=ChangeDateToString(new Date(parseDate(d1).getTime()+(1000*60*60*24*daydiff)));

    var p2=ChangeDateToString(new Date(parseDate(d1).getTime()+(1000*60*60*24*dayadd)));

    var weeks= GetWeek(d1);
    var lblzhou=document.getElementById("lblzhou");
    lblzhou.innerText=p1+"(一)－－"+p2+"(日)";
    document.getElementById("lblweekCount").innerText=weeks;
    document.getElementById('1Close_Date').value=d1;
    document.getElementById('weeks').value=document.getElementById("FullYear").value+weeks;
}


function GetWeekSpanStr(value)
{

    var weeknow=parseDate(value).getDay();

    if (weeknow==0) weeknow=7;

    var daysub = (-1) * (weeknow-1);
    var dayadd = 7-weeknow;

    var from=ChangeDateToString(new Date(parseDate(value).getTime()+(1000*60*60*24*daysub)));
    var to=ChangeDateToString(new Date(parseDate(value).getTime()+(1000*60*60*24*dayadd)));


    return from+"(一)－－"+to+"(日)";
}



//获得第几周
function GetWeek(d)
{
    var d1=parseDate(d);
    var year = d1.getFullYear();
    document.getElementById("FullYear").value=year;
    var month = d1.getMonth();

    var date = d1.getDate();
    var daysInYear = Math.ceil((d1-new   Date(year,0,0))/86400000);
    var getday=new   Date(year,0,1).getDay()-1;
    var weekInYear = Math.ceil((daysInYear+getday)/7);
    return weekInYear;
}


//将字符串转化为日期类型
function parseDate(str){
         var converted = Date.parse(str);
        var myDate = new Date(converted);
        if (isNaN(myDate))
        {
            var arys= str.split('-');
            myDate = new Date(arys[0],--arys[1],arys[2]);
        }
        return myDate;
}

//日期转换成字符串 月.日
function ChangeDateToString(DateIn)
{
    var Year=0;
    var Month=0;
    var Day=0;
    var CurrentDate="";

    //初始化时间
    Year      = DateIn.getYear();
    Month     = DateIn.getMonth()+1;
    Day       = DateIn.getDate();

   // CurrentDate = Year + "-";
    if (Month >= 10 )
    {
        CurrentDate = CurrentDate + Month + ".";
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Month + ".";
    }
    if (Day >= 10 )
    {
        CurrentDate = CurrentDate + Day ;
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Day ;
    }
    return CurrentDate;
}

//日期转换成字符串 年-月-日
function ChangeDateToString2(DateIn)
{
    var Year=0;
    var Month=0;
    var Day=0;

    var CurrentDate="";

    //初始化时间
    Year      = DateIn.getFullYear();
    Month     = DateIn.getMonth()+1;
    Day       = DateIn.getDate();

    CurrentDate = Year + "-";
    if (Month >= 10 )
    {
        CurrentDate = CurrentDate + Month + "-";
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Month + "-";
    }
    if (Day >= 10 )
    {
        CurrentDate = CurrentDate + Day ;
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Day ;
    }

    return CurrentDate;
}

//运价对比标准改变
function flag(obj)
{


  $("txtflag").value = obj;

  if($("str"+obj).className == "on-down")
  {

      mainTable.sortElement = 2;
  }
  else
  {
     mainTable.sortElement = 1;
  }

  $("idFilterbtn").click();
}

//日期改变
function getdateWeek()
{
    var a = document.getElementById('1Close_Date').value
    GetDays(a);
    var weeks=document.getElementById("lblweekCount").innerText;

    var search = "";
    var sea = "";
    var flag = "";
    var weekstemp = "";
    var strdatetime = "";
    var boxtype = "";
    sea = document.getElementById("sea").value;
    flag = document.getElementById('txtflag').value;
    weekstemp = document.getElementById("FullYear").value+weeks;
    strdatetime = replaceDate(document.getElementById('1Close_Date').value);
    boxtype = document.getElementById("selBoxType").value;
}

//箱型选择改变
function ChangeBoxType()
{
    var type=document.getElementById("selBoxType").value;
    document.getElementById("txtBoxType").value=type;

    if(type != "Other")
        ClearRadioBoxType("rdbBoxType")
}


//replace 日期
function replaceDate(obj)
{
    if(obj.length >0)
    {
        while(obj.indexOf('-') >-1)
            obj = obj.replace('-','')
    }
    return obj;
}

//重写innerText方法
function isIE(){ //ie?
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1)
    return true;
   else
    return false;
}

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText",
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    }
   );
   HTMLElement.prototype.__defineSetter__(     "innerText",
    function(sText){
     this.textContent=sText;
    }
   );
}


function toWeek(obj){

	  if(obj)
	  {

	　obj = obj.replace("1","周一")
	　obj = obj.replace("2","周二")
	　obj = obj.replace("3","周三")
	　obj = obj.replace("4","周四")
	　obj = obj.replace("5","周五")
	　obj = obj.replace("6","周六")
	　obj = obj.replace("7","周日")
	　}
	　else
	　{
	　  obj = '';
	　}
	  return obj;
}

function getEtd()
{
    var tfa=document.getElementsByName("cbxEtd");
    var result = [];

    for(var i = 0 ; i<tfa.length ; i++ )
    {
       if(tfa[i].checked == true)
       {
          result.push(tfa[i].value);
       }
    }

    return result.join(',');

}

/*
功能：二级数据模板类
作者：LY
*/

var Template = Class.create();

Template.prototype = {

   initialize:function(e){

      var othis = this;
      this.renderTo = e;

      this.head = '<thead><tr><td width="25"><div class="pos"><div class="arrow"></div></div></td><td width="5">&nbsp;</td>'
                 +'<td width="50">箱型</td>'
                 +'<td width="90"> 有效时间</td>'
                 +'<td width="70"> 付款方式</td>'
                 +'<td width="70"> 箱量限制</td>'
                 +'<td width="120">20\'限重&nbsp;&nbsp;&nbsp;&nbsp;40\'限重</td>'
                 +'<td width="60">提单要求</td>'
                 +'<td width="200">20\'&nbsp;&nbsp;40\'&nbsp;&nbsp;40HQ&nbsp;&nbsp;45\'</td>'
                 +'<td width="150">公司名称</td>'
                 +'<td width="90">操作</td>'
                 +'</tr><thead>';

      this.rows = {};


      this.rows.templ = '<tr>'
                +'<td><div class="mo-pr-check"><input type="checkbox" name="cbxFreightChild{masterID}" style="display:none"  id="cbxChild_{masterID}" value="{masterID}"  onclick="clickcompareBox(\'cbxFreightChild{masterID}\',this,\'{masterID}\');" /></div></td>'
                +'<td><p class="{FreightType}"></p></td>'
                +'<td>{BoxType}</td>'
                +'<td>{enddate}</td>'
                +'<td>{PayWay}</td>'
                +'<td>{BoxCount}</td>'
                +'<td>{weight}</td>'
                +'<td>{TakeStandard}</td>'
                +'<td class="mo-price">'
                +'<span class="{minFlag20}">{Type20}</span>|'
                +'<span class="{minFlag40}">{Type40}</span>|'
                +'<span class="{minFlag40HQ}">{Type40HQ}</span>|'
                +'<span class="{minFlag45}">{Type45}</span>'
                +'</td>'
                +'<td><span class="{isjct}">{GoodCents}</span><a href="{domain_name}" onmousedown="return jctransClick(this,\'40100-12\');"  {open} ><span class="fc-orange">{compname}</span></a></td>'
                +'<td><a href="http://shipping.jctrans.com/FreightShow/details-{masterID}.html" target=_blank class="btn-xx" onmousedown="return jctransClick(this,\'40100-13\');" ><img src="http://style.jctrans.com/pub/img_bg.gif" alt="" /></a><span id="spanwlt_{masterID}"></span></td>'
                +'</tr>';
      this.root = {};

      this.root.templ = '<table width="900" border="0" cellspacing="5" cellpadding="0" class="fr-data-dp" align="center">'
                      +'<tr><td class="fr-data-dp-t">'

                      +'<table border="0" align="center" cellpadding="0" cellspacing="5">'
                      +'<tr>'
                      +'<td width="80" class="title"><span>航线信息</td>'
                      +'<td class="content">承运人：<span class="fc-orange">{FeedCabin}</span>'
                      +'&nbsp;&nbsp;|&nbsp;&nbsp;航线名称：<span class="fc-orange"> {SeaLineEngName} </span>'
                      +'&nbsp;&nbsp;|&nbsp;&nbsp;总航程：<span class="fc-orange">{TotalVoyage}</span>'
                      +'&nbsp;&nbsp;&nbsp;&nbsp;{1}</td>'
                      +'</tr>'
                      +'</table>'
                      +'<table border="0" cellspacing="0" cellpadding="0" class="fr-data-dp-c">'
                      +'<tr>'
                      +'{2}{3}{4}'
                      +'</tr>'
                      +'</table>'
                      +'</td></tr></table>';




      this.request = new AjaxRequest('AjaxGetQuerySubListData.rails',
          {method:'post',parameters:'',contentType:'application/x-www-form-urlencoded'}) ;

      this.request.callback = function(jsondata)
      {

         var o = Function("return "+jsondata+";")();

         var rowsHtml = [];

         var idList = [];

         Each(o.tables[0].rows,function(p){

           othis.renderFliter(p);

           var formatData = String.format(othis.rows.templ,p);
           rowsHtml.push(formatData);

           idList.push("cbxChild_"+p.masterID);


           var innerAjax = new AjaxRequest("GetWltShow.rails?gid="+p.wlt+"&mid="+p.masterID+"&compname="+encodeURIComponent(p.compname),
                    {method:'post',parameters:'',contentType:'application/x-www-form-urlencoded'}) ;

           innerAjax.callback = function(script)
           {
                eval(script);
           }

           innerAjax.request("GetWltShow.rails?gid="+p.wlt+"&mid="+p.masterID+"&compname="+ encodeURIComponent(p.compname),{});




         });


         var footRow = o.tables[1].rows[0];

         var  partOne = "";
         var  partTwo = "";
         var  partThree = "";

         var  week = footRow.SeaSchedule||footRow.InnerLineSchedule;


         if(footRow.ExportLoadPort && footRow.ExportLoadPort != "")
         {
           partOne =  '<td width="100">'+footRow.ExportLoadPort+'</td>'
                     +'<td width="100"><div class="jt"><p>内支线（驳船）</p>ETD:'+week+'</div></td>';
         }


         partTwo =   '<td width="100">'+footRow.SeaStartPortName+'</td>'
                    +'<td width="100"><div class="jt"><p>{0}</p>{1}</div></td>'
                    +'<td width="100">'+footRow.SeaEndPortName+'</td>'

         if(footRow.TransferPortName && footRow.TransferPortName != "" )
         {
            partTwo = String.format(partTwo,footRow.TransferPortName,"中转");
         }
         else
         {
            partTwo = String.format(partTwo,"&nbsp;","&nbsp;");
         }



         if(footRow.ImportLoadPort && footRow.ImportLoadPort != "")
         {
           partThree = '<td width="100" ><div class="jt"><p>转运/陆运</p>ETD:'+week+'</div></td>'
                      +'<td width="100">GAUNZHOU</td>'
         }

         var shipUrl = "#";


         //未定义航线
         if(typeof footRow.SeaLineEngName == "undefined" || footRow.SeaLineEngName =="")
         {

            footRow.SeaLineEngName = "电询";


            footRow.TotalVoyage = footRow.TotalVoyage == 0? "电询":footRow.TotalVoyage;

            shipUrl = "";

         }
         else
         {
            footRow.TotalVoyage = footRow.TotalVoyage +'天';
            shipUrl= '<a  href="http://shipping.jctrans.com/OceanSchedules/SailingDates-'
                   +footRow.FeedCabin+'-'+footRow.courseCode+'-1-'+footRow.SeaStartPortNameID+','+footRow.SeaStartPortName+'-'
                   +footRow.SeaEndPortNameID+','+footRow.SeaEndPortName+'-,请输入承运人-.html" target="_blank" onmousedown="return jctransClick(this,\'40100-15\');" >查看船期表</a>';
         }


         var footHtml = String.format(othis.root.templ,footRow,shipUrl,partOne,partTwo,partThree);

         if(typeof othis.renderTo == "string")
         {
            othis.renderTo = $(othis.renderTo)
         }

         othis.renderTo.innerHTML = '<table  border="0" cellpadding="0" cellspacing="0" class="mo-pr-list">'
                             +othis.head
                             +"<tbody>"+rowsHtml.join("")
                             + '<tr><td colspan="11">'
                             + footHtml
                             +'</td></tr></tbody>'
                             +"</table>";


//         othis.renderTo.setAttribute('innerHTML', '<table  border="0" cellpadding="0" cellspacing="0" class="mo-pr-list">'
//                             +othis.head
//                             +"<tbody>"+rowsHtml.join("")
//                             + '<tr><td colspan="11">'
//                             + footHtml
//                             +'</td></tr></tbody>'
//                             +"</table>");
//

         othis.renderTo.className = "data-block";


         insert(idList,othis.parentTo.rowNumber);


         for(i=0;i<idList.length;i++)
         {
            if(idList[i] == "cbxChild_"+othis.parentTo.masterID)
            {

               $(idList[i]).checked = true;

               addOfferId(idList[i],othis.parentTo.masterID);

               //changecheckStat($(idList[i])) ;
            }
         }

      }





   },

   renderFliter:function(p)
   {

      p.open = 'target=_blank';

      var temp = p.weight.split('|');
      p.weight = temp[0]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+temp[1];

      if(p.domain_name == "")
      {
         p.domain_name = "javascript:void(0);";
         p.open = '';
      }
      else
      {
         p.domain_name = "http://"+ p.domain_name;
      }

      if(p.isjct == '0')
      {
         p.GoodCents = '';
      }


      p.Type20 = p.Type20 == ""?"--":parseInt(p.Type20);
      p.Type40= p.Type40 == ""?"--":parseInt(p.Type40);
      p.Type40HQ= p.Type40HQ == ""?"--":parseInt(p.Type40HQ);
      p.Type45 = p.Type45 == ""?"--":parseInt(p.Type45);


      p.minFlag20 = p.minFlag20 == 0 ? "":"fc-orange";
      p.minFlag40 = p.minFlag40 == 0 ? "":"fc-orange";
      p.minFlag40HQ = p.minFlag40HQ == 0 ? "":"fc-orange";
      p.minFlag45 = p.minFlag45 == 0 ? "":"fc-orange";

      if(p.GoodCents == 0)
      {
         p.GoodCents = "";
      }

      //【我的优势】链接
    /*p.AdvantageUrl="#";
      var shopurl="";
      if (p.domain_name.indexOf("http://shop.jctrans.com/")>=0)
      {
        p.AdvantageUrl="http://shop.jctrans.com/Advantage/Index/"+p.domain_name.replace("http://shop.jctrans.com/","").replace(".html","")+"/-/1.html";
      }
      else //ccp
      {
        p.AdvantageUrl=p.domain_name+"/Advantage/Index/-/1.html";
      }*/

    //  p.FreightType = p.FreightType == 0?"icon-allin":"icon-jing";

      p.isjct = p.isjct == 100? "credit-num":"credit-num-none";
      if(p.BoxType == "LCL")
      {
         p.weight = "--/--";
      }
   },

   renderTo:""


}

/*
功能：运价数据表类
作者：LY
*/
var AjaxTable = Class.create();

AjaxTable.prototype = {


   initialize:function(o,h){

       oThis = this;
       this.sortElement = 0;
       this.Rows = [];
       this.body = $(o);
       this.head = $(h);



       Each(this.body.rows,function(r){
          if(r.id && r.id.indexOf("con_")!= -1)
          {
             var parent = oThis.Rows[oThis.Rows.length-1];
             parent.rowCustomChilds = r;

          }
          else
          {

             oThis.Rows.push(r);
          }

       });




       this.request = new AjaxRequest('AjaxGetQueryListData.rails',
          {method:'post',parameters:'',contentType:'application/x-www-form-urlencoded'}) ;

       this.request.callback = function(jsondata)
       {

         var o = Function("return "+jsondata+";")();

         if(o.error)
         {

            document.body.removeChild($('BackDiv'));

            $("idFirstOrSecond").value="查看批发价";
            alert("只有采购通（CPF）权限的会员可查看批发价及认证庄家公司名录！\n详情咨询：021-63251008！");
            return
         }

         var pageCount = parseInt(o.other.split(",")[0]);
         var rowsCount = parseInt(o.other.split(",")[1]);
         var currentPageNmb = parseInt(o.other.split(",")[2]);


         tool.pageCount=pageCount;

         if(oThis.request.params.boxType == "LCL")
         {

           oThis.head.rows[1].cells[0].innerHTML =
           '<a href="javascript:flag(1)" id="str1" >M<sup>3</sup><span></span></a>';
           oThis.head.rows[1].cells[1].innerHTML =
           '<a href="javascript:flag(2)" id="str2">T<span></span></a>'
           oThis.head.rows[1].cells[2].innerHTML = '<a  id="str3"></a>';
           oThis.head.rows[1].cells[3].innerHTML = '<a  id="str4"></a>';
           if(oThis.request.params.flag < 3)
           {

              if(oThis.request.params.sort == 2)
              {
                  oThis.head.rows[1].cells[oThis.request.params.flag-1].getElementsByTagName('a')[0].className = "on-up";

              }
              else
              {
                  oThis.head.rows[1].cells[oThis.request.params.flag-1].getElementsByTagName('a')[0].className = "on-down";

              }
           }
         }
         else
         {
           oThis.head.rows[1].cells[0].innerHTML =  '<a href="javascript:flag(1)" id="str1" >20\'<span></span></a>';
           oThis.head.rows[1].cells[1].innerHTML =  '<a href="javascript:flag(2)" id="str2">40\'<span></span></a>'
           oThis.head.rows[1].cells[2].innerHTML =  '<a href="javascript:flag(3)" id="str3">40HQ<span></span></a>';
           oThis.head.rows[1].cells[3].innerHTML =  '<a href="javascript:flag(4)" id="str4">45\'<span></span></a>';
           if(oThis.request.params.sort == 2)
           {
                oThis.head.rows[1].cells[oThis.request.params.flag-1].getElementsByTagName('a')[0].className = "on-up";

           }
           else
           {
               oThis.head.rows[1].cells[oThis.request.params.flag-1].getElementsByTagName('a')[0].className = "on-down";

           }
         }



         if(pageCount < currentPageNmb)
         {
            currentPageNmb = pageCount;

         }

         tool.refrush(currentPageNmb);


         $("weekCountId").innerHTML = GetWeek($('1Close_Date').value);
         $("weekSpanId").innerHTML = GetWeekSpanStr($('1Close_Date').value);
         $("idTeam").innerText = rowsCount;

         $("freightTypeId").innerText = GetRadioValue("rdbBoxType","text") || getSelectNum("selBoxType");

         for(i=0; i<oThis.Rows.length; i++)
         {
             if(i < o.tables[0].rows.length)
             {


             oThis.Rows[i].className = "";

             var r = o.tables[0].rows[i];


             var check = oThis.Rows[i].cells[0].getElementsByTagName('input')[0];

             check.name = "cbxFreight"+r.masterID;
             check.id = "cbxParent_"+r.masterID;
             check.value = r.masterID;
             check.checked = false;
             check.readOnly = true;
             check.disabled = true;


             //float.js
             //add(check.id);

             oThis.Rows[i].id = 'tr'+r.masterID;

             oThis.Rows[i].cells[1].innerHTML = '<span>'+r.ArriveWay+'</span>';
             oThis.Rows[i].cells[2].innerHTML = '<span>'+r.FeedCabin+'</span>';
             oThis.Rows[i].cells[3].innerHTML = toWeek(r.SeaSchedule||r.InnerLineSchedule)
             oThis.Rows[i].cells[4].innerHTML = r.TotalVoyage == 0? "电询":r.TotalVoyage;
             oThis.Rows[i].cells[5].innerHTML = r.BoxType;



             if(r.coursecode == '' && r.CourseName=='')
             {
                 oThis.Rows[i].cells[6].innerHTML = '<span>电询</span>';
             }
             else
             {
                 if(r.coursecode != '')
                     oThis.Rows[i].cells[6].innerHTML = '<span>'+'('+r.coursecode+')'+r.CourseName+'</span>';
                 else
                     oThis.Rows[i].cells[6].innerHTML = '<span>'+r.CourseName+'</span>';

             }

             oThis.Rows[i].cells[7].innerHTML = '<span>--</span>';



             if(r.Type20 && r.Type20 != "")
            oThis.Rows[i].cells[7].innerHTML = '<span>'+parseInt(r.Type20)+'</span>';

            if(oThis.request.params.flag == 1)
            {
               oThis.Rows[i].cells[7].className = 'price-lowest';
            }
            else
            {
               oThis.Rows[i].cells[7].className = 'price';
            }


             oThis.Rows[i].cells[8].innerHTML = '<span>--</span>';

             if(r.Type40 && r.Type40 != "")
             oThis.Rows[i].cells[8].innerHTML = '<span>'+parseInt(r.Type40)+'</span>';

             if(oThis.request.params.flag == 2)
             {
               oThis.Rows[i].cells[8].className = 'price-lowest';
             }
             else
             {
               oThis.Rows[i].cells[8].className = 'price';
             }

             if(r.BoxType == "LCL")
             {
                 oThis.Rows[i].cells[9].innerHTML = '';
                 oThis.Rows[i].cells[10].innerHTML = '';

             }
             else
             {
                 oThis.Rows[i].cells[9].innerHTML = '<span>--</span>';

                 if(r.Type40HQ && r.Type40HQ != "")
                 oThis.Rows[i].cells[9].innerHTML = '<span>'+parseInt(r.Type40HQ)+'</span>';

                 if(oThis.request.params.flag == 3)
                 {
                   oThis.Rows[i].cells[9].className = 'price-lowest';
                 }
                 else
                 {
                    oThis.Rows[i].cells[9].className = 'price';
                 }


                 oThis.Rows[i].cells[10].innerHTML = '<span>--</span>';

                 if(r.Type45 && r.Type45 != "")
                 oThis.Rows[i].cells[10].innerHTML = '<span>'+parseInt(r.Type45)+'</span>';

                 if(oThis.request.params.flag == 4)
                 {
                   oThis.Rows[i].cells[10].className = 'price-lowest';
                 }
                 else
                 {
                   oThis.Rows[i].cells[10].className = 'price';
                 }

             }



             oThis.Rows[i].cells[0].getElementsByTagName('input')[0].value = r.masterID
             //<a>

             var searchButton = oThis.Rows[i].cells[0].getElementsByTagName('a')[0];

             searchButton.id=r.masterID;


             searchButton.customData =
             {effectWeek:oThis.request.params.effectWeek,level:oThis.request.params.level,rowIndex:i};

             searchButton.onclick
             = function(){

                     if(this.id&&this.id != '')
                     {
                         value = "con_"+this.id;



                         if (this.className=="")
                         {

                            this.className = "yc";
                             var customChilds = oThis.Rows[this.customData.rowIndex].rowCustomChilds;


                             //firefox3 customChilds.getElementsByTagName('div')[0].innerHTML == "" 为 false
                             //customChilds.getElementsByTagName('div')[0].innerHTML.length 为 15


                             if(customChilds.id != value||customChilds.getElementsByTagName('div')[0].innerHTML == "")
                             {

                                 customChilds.id = value;

                                 subTable.renderTo = customChilds.getElementsByTagName('div')[0];                

                                 subTable.parentTo =  oThis.Rows[this.customData.rowIndex];
                                 subTable.parentTo.masterID = this.id;

                                 var lineIndex = 0;

                                 for(i=0;i<this.customData.rowIndex;i++)
                                 {
                                    var rowsBody = oThis.Rows[i].rowCustomChilds.getElementsByTagName('tbody');
                                    if(rowsBody.length > 0)
                                    {

                                       lineIndex += (rowsBody[0].rows.length-1);
                                    }

                                    lineIndex++;

                                 }


                                 subTable.parentTo.rowNumber = lineIndex+1;

                                 var param = 'id='+this.id+'&effectWeek='+this.customData.effectWeek+'&level='+this.customData.level;

                                 subTable.request.request('AjaxGetQuerySubListData.rails',param);

                             }
                             else
                             {

                                customChilds.getElementsByTagName('div')[0].className = "data-block";
                               // changecheckStat(currentCheckedBox);

                             }

                              oThis.Rows[this.customData.rowIndex].className= "data-open";

                          }
                          else
                          {

                              this.className = "";
                              $(value).getElementsByTagName('div')[0].className = "data-dis";
                              oThis.Rows[this.customData.rowIndex].className= "";
                              //$('tishiDiv').style.display="none";
                          }
                      }



                 }; //onclick function end

                 if(r.masterID && r.masterID != '')
                 {
                    searchButton.className="";
                    searchButton.innerHTML="";
                    searchButton.href="javascript:void(0)";
                    searchButton.target="";
                 }
                 else
                 {
                    //没发布过运价的，显示商务通 whr 2009-10-14
                   searchButton.className = "no1";
                   var h2 = "&p=" + encodeURI(location.href);
                   var h3 = "&r=" + encodeURI(location.href);
                   searchButton.innerHTML="<img src='http://company.shipping.jctrans.com/Content/images/swt2.gif' border='0' style='cursor: pointer;' align='absbottom' />";
                   searchButton.href="http://swt.jctrans.com/LR/Chatpre.aspx?id=LHF61175281"+h2+h3;
                   searchButton.target="_blank";
                 }

              }//if end
              else
              {

                 oThis.Rows[i].className = "data-dis";
                 oThis.Rows[i].rowCustomChilds.id = "con_";


              }



              oThis.Rows[i].rowCustomChilds.getElementsByTagName('div')[0].className = "data-dis";
              oThis.Rows[i].rowCustomChilds.getElementsByTagName('div')[0].innerHTML = "";

         }


        mainTable.sortElement = 0;
        document.body.removeChild($('BackDiv'));

       } //callend



   }




}

var mainTable = new AjaxTable('idfreightbody','idfreighthead');
var subTable = new Template();

/*
功能：异步提交运价数据请求事件
作者：LY
*/


$("idFilterbtn").onclick = $("idFirstOrSecond").onclick= function()
{

  var params = {};
  params.level = 0;
  if(this.id == "idFirstOrSecond")
  {


      if(this.value == "查看批发价")
      {
          params.level = 1;
          this.value = "查看市场价";

          SetCookie("jcloc","1",1000*60,"/",".jctrans.com");
      }
      else
      {
          params.level = 0;
          this.value = "查看批发价";

          SetCookie("jcloc","2",1000*60,"/",".jctrans.com");
      }
  }

  params.startPortID =  $("Yjstartport1").value;
  params.endPortID =$("Yjendport1").value;

  params.feedCabinID= $("ddlFeedCabin").value;
  if(params.feedCabinID == "全部")
  params.feedCabinID ="";

  params.etd = getEtd();
  if(params.etd == "")
  {
     params.etd = "1,2,3,4,5,6,7";
  }


  params.boxType = GetRadioValue("rdbBoxType","value") || $("selBoxType").value;

  params.effectWeek = $("FullYear").value+$("lblweekCount").innerText;
  if(params.effectWeek == "")
  {
    params.effectWeek = GetWeek(new Date());
  }

  params.flag = $('txtflag').value;
  params.currentPage = tool.currentPage;
  params.pageSize = 15;

  params.sort = mainTable.sortElement;

  /*
  if(window.location.search)
  {
     var p = Function("return {"+window.location.search.replace("?","").replace("&",",").replace("=",":")+"};")();
     if(p.flag)
     params.flag = p.flag;
     if(p.currentPage)
     params.currentPage = p.currentPage;

  }*/
  mainTable.request.params = params;
  var pr = Object.jsonToString(params);

  createLoad('idfreightbody','idfreighthead');

  mainTable.request.request('AjaxGetQueryListData.rails',pr);

}




/*
功能：全选
作者：LY
*/

function checkAll(obj)
{
    if(obj.checked == true)
    {
        for(var i=0;i<document.getElementsByName("cbxFreight").length;i++)
        {
            document.getElementsByName("cbxFreight")[i].checked = true;
        }
    }
    else
    {
        for(var i=0;i<document.getElementsByName("cbxFreight").length;i++)
        {
            document.getElementsByName("cbxFreight")[i].checked = false;
        }
    }
}



/*
功能：分页类
作者：LY
*/
var pageTool = Class.create();

pageTool.prototype = {


   pageCount:1,
   displagLength:5,
   currentPage:1,
   node:[],

   initialize:function(render,pCount,dLength){

       this.UI = $(render);

       if(pCount)
       this.pageCount = pCount;

       if(dLength)
       this.displagLength = dLength;

   },

   preOnclick:function()
   {
      var oThis = this;
      return function()
      {
         var rowth = 0
         if(oThis.currentPage > 4)
         rowth = parseInt((oThis.currentPage-1)/4);


         if(oThis.currentPage > 1 && oThis.currentPage <= oThis.pageCount)
         {
            oThis.node[oThis.currentPage-4*rowth-1].className = "";
            oThis.currentPage--;

         }
         else
         {
            oThis.currentPage = 1;
         }

         rowth = parseInt((oThis.currentPage-1)/4);
         //oThis.node[oThis.currentPage-4*rowth-1].className = "on";

         //oThis.roll();
         $("idFilterbtn").click();
      }
   },

   nextOnclick:function()
   {
      var oThis = this;
      return function()
      {
         var rowth = 0
         if(oThis.currentPage > 4)
         rowth = parseInt((oThis.currentPage-1)/4);

         if(oThis.currentPage < oThis.pageCount)
         {
             oThis.node[oThis.currentPage-4*rowth-1].className = "";
             oThis.currentPage++;
         }
         else
         {
             oThis.currentPage = oThis.pageCount;
         }
         rowth = parseInt((oThis.currentPage-1)/4);
         //oThis.node[oThis.currentPage-4*rowth-1].className = "on";

         //oThis.roll();
         $("idFilterbtn").click();


      }

   },

   pageOnclick:function()
   {
      var oThis = this;
      return function()
      {
         var rowth = 0
         if(oThis.currentPage > 4)
          rowth = parseInt((oThis.currentPage-1)/4);

         oThis.node[oThis.currentPage-4*rowth-1].className = "";

         oThis.currentPage = parseInt(this.innerText);
         rowth = parseInt((oThis.currentPage-1)/4);

         //oThis.node[oThis.currentPage-4*rowth-1].className = "on";


         //oThis.roll();
         $("idFilterbtn").click();


      }

   },

   refrush:function(nmb)
   {


       this.currentPage = nmb;

       var rowth = 0

       if(nmb > 4)
       rowth = parseInt((nmb-1)/4);




       for(var n = 0; n < this.displagLength ; n++)
       {
          if(n+rowth*4+1 < this.pageCount+1)
          {
             this.node[n].innerText = n+1+rowth*4;
             this.node[n].onclick = this.pageOnclick();
             this.node[n].className = "data-block";
          }
          else
          {
             this.node[n].innerText = "";
             this.node[n].onclick = function(){};
             this.node[n].className = "data-dis";
          }
       }

       this.node[this.currentPage-4*rowth-1].className = "on";


   },

   roll:function()
   {



      if(this.currentPage%(this.displagLength-1) == 1 )
      {

          if(this.currentPage == parseInt(this.node[0].innerText))
          {
              if(parseInt(this.node[0].innerText) > 1 )
              {

                  for(i=this.displagLength-1,j=0 ; i >= 0 ; i--,j++)
                  {
                     this.node[i].innerText = this.currentPage - j;
                  }
              }
          }
          else
          {
              for(i=0 ; i<this.displagLength ; i++)
              {
                   if(this.currentPage+ i <= this.pageCount)
                   {
                      this.node[i].innerText = this.currentPage + i;
                   }
                   else
                   {
                      this.node[i].innerText = "";
                   }
               }
          }
     }



   },



   renderTo:function()
   {

       var box = document.createElement('ul');

       var pre = document.createElement('li');
       pre.className = "prev";

       var tmp = document.createElement('a');

       tmp.innerText = "前一页";
       tmp.onclick = this.preOnclick();

       pre.appendChild(tmp);
       box.appendChild(pre);

       //var count = this.pageCount < this.displagLength ? this.pageCount : this.displagLength;



       for(var n = 0; n < this.displagLength ; n++)
       {
          var nmb = document.createElement('li');
          var tmp = document.createElement('a');

          if(n < this.pageCount)
          {
             tmp.innerText = n+1;
             tmp.onclick = this.pageOnclick();
          }


          this.node.push(tmp);

          nmb.appendChild(tmp);
          box.appendChild(nmb);
       }


       var next = document.createElement('li');
       next.className = "next";
       var tmp = document.createElement('a');
       tmp.innerText = "后一页";
       tmp.onclick = this.nextOnclick();
       next.appendChild(tmp);
       box.appendChild(next);

       this.UI.appendChild(box);



   }


}


var tool = new pageTool('page',15,5);
tool.renderTo();


window.onload = function()
{
   $("idFilterbtn").click();
}

//window.onload();


function deleteInfo(obj)
{
    deleteCookieViews(obj);
    document.getElementById("history").innerHTML = "<dt><a href=\"javascript:deleteInfo('FreightDetails')\">清除 </a>浏览过的运价</dt><dd class=\list-none\" style=\"display:none;\">暂无您浏览过的运价</dd><script>WriteComName('FreightDetails')</script>";
}


function CheckBatchOffer()
{
    if($('OfferParentValue').value == "")
    {
        alert("请至少选择1条信息进行询价！");
    }
    else
    {
        var arrofferid = $('OfferParentValue').value.split(',');
        var parentid = $('txtParentID').value;

        var arrofferid = arrofferid.strip();


        if(arrofferid.toString().indexOf(',') == 0)
        {
            arrofferid = arrofferid.toString().substring(1,arrofferid.toString().length);
        }
        window.open("/AskOfferInput/AskOfferInput.rails?strId="+escape("("+arrofferid+")")+"&strParentId="+escape(parentid));
    }
}

Array.prototype.strip=function(){
if(this.length<2) [this[0]]||[];
var arr=[];
for(var i=0;i<this.length;i++){
    arr.push(this.splice(i--,1));
    for(var j=0;j<this.length;j++){
        if(this[j]==arr[arr.length-1]){
            this.splice(j--,1);
        }
    }
}
return arr;
}
