/* $Id : common.js 4865 2007-01-31 14:04:10Z paulgao $ */

/* *
 * 添加商品到购物车
 */
function addTocart(goodsId, is_real)
{
  var number       = 0;
  var context      = "";
  var formBuy      = document.forms['CS_FORMBUY'];

  // 检查是否有商品规格
  if (formBuy)
  {
    if (formBuy.elements['number'])
    {
      number = formBuy.elements['number'].value;
    }
    if (formBuy.elements['context'])
    {
      context = formBuy.elements['context'].value;
    }
  }

  Ajax.call('/service/flow.aspx?act=add_to_cart', 'number='+ number +'&context='+ context +'&is_real='+ is_real +'&goods_id=' + goodsId, addToCartResponse, 'POST', 'JSON');
}





/* *
* 添加商品到购物车
*/
//function addToEmail(goodsId, is_real) {
//    var number = 0;
//    var context = "";
//    var formBuy = document.forms['CS_FORMBUY'];

//    // 检查是否有商品规格
//    if (formBuy) {
//        if (formBuy.elements['number']) {
//            number = formBuy.elements['number'].value;
//        }
//        if (formBuy.elements['context']) {
//            context = formBuy.elements['context'].value;
//        }
//    }

//    Ajax.call('/service/flow.aspx?act=add_to_Email', 'number=' + number + '&context=' + context + '&is_real=' + is_real + '&goods_id=' + goodsId, addToCartResponse, 'POST', 'JSON');
//}









/**
 * 获得选定的商品属性
 */
function getSelectedAttributes(formBuy)
{
  var spec_arr = new Array();
  var j = 0;

  for (i = 0; i < formBuy.elements.length; i ++ )
  {
    var prefix = formBuy.elements[i].name.substr(0, 5);

    if (prefix == 'spec_' && (
      (formBuy.elements[i].type == 'radio' && formBuy.elements[i].checked) ||
      formBuy.elements[i].tagName == 'SELECT'))
    {
      spec_arr[j] = formBuy.elements[i].value;
      j++ ;
    }
  }

  return spec_arr;
}

/* *
 * 处理添加商品到购物车的反馈信息
 */
function addToCartResponse(result)
{
    var cartInfo = document.getElementById('ECS_CARTINFO');

    if (cartInfo)
    {
      cartInfo.innerHTML = result.content;
    }

          get_order_count();
          
    switch(result.error)
      {
        case 0 :
          if (confirm(result.message)) location.href = '/service/flow.aspx';
          break;
        case 1 :
          if (!confirm(result.message)) location.href = '/service/flow.aspx';
          break;
        case 2 :
          location.href = '/service/flow.aspx';
          break;
        case 3 :
          break;
        case 10:
          alert(result.message);
          break;
      }
      

}

/* *
 * 修改购买数量
 */
function update_number(id,val)
{
    if (!Utils.isNumber(val))
    {
        alert("必须为数字");
        return;
    }
    
    var res = Ajax.call('/service/flow.aspx', "act=update_number&id="+ id +"&val="+ val +"", null, "POST", "JSON", false);

    if (res.error == 1)
    {
        window.location.reload();
    }
}

/* *
 * 移除购物车
 */
function remove_cart(id)
{
    if (confirm("您确定要移除本条记录吗"))
    {
        var res = Ajax.call('/service/flow.aspx', "act=remove&id="+ id +"", null, "POST", "JSON", false);

        if (res.error == 0)
        {
            window.location.reload();
        }
    }
    
    return;
}

/* *
 * 添加商品到收藏夹
 */
function collect(goodsId)
{
  Ajax.call('user.php?act=collect', 'id=' + goodsId, collectResponse, 'GET', 'JSON');
}

/* *
 * 处理收藏商品的反馈信息
 */
function collectResponse(result)
{
  alert(result.message);
}

/* *
 *  返回属性列表
 */
function getAttr(cat_id)
{
  var tbodies = document.getElementsByTagName('tbody');
  for (i = 0; i < tbodies.length; i ++ )
  {
    if (tbodies[i].id.substr(0, 10) == 'goods_type')tbodies[i].style.display = 'none';
  }

  var type_body = 'goods_type_' + cat_id;
  try
  {
    document.getElementById(type_body).style.display = '';
  }
  catch (e)
  {
  }
}

/* *
 * 截取小数位数
 */
function advFormatNumber(value, num) // 四舍五入
{
  var a_str = formatNumber(value, num);
  var a_int = parseFloat(a_str);
  if (value.toString().length > a_str.length)
  {
    var b_str = value.toString().substring(a_str.length, a_str.length + 1);
    var b_int = parseFloat(b_str);
    if (b_int < 5)
    {
      return a_str;
    }
    else
    {
      var bonus_str, bonus_int;
      if (num == 0)
      {
        bonus_int = 1;
      }
      else
      {
        bonus_str = "0."
        for (var i = 1; i < num; i ++ )
        bonus_str += "0";
        bonus_str += "1";
        bonus_int = parseFloat(bonus_str);
      }
      a_str = formatNumber(a_int + bonus_int, num)
    }
  }
  return a_str;
}

function formatNumber(value, num) // 直接去尾
{
  var a, b, c, i;
  a = value.toString();
  b = a.indexOf('.');
  c = a.length;
  if (num == 0)
  {
    if (b != - 1)
    {
      a = a.substring(0, b);
    }
  }
  else
  {
    if (b == - 1)
    {
      a = a + ".";
      for (i = 1; i <= num; i ++ )
      {
        a = a + "0";
      }
    }
    else
    {
      a = a.substring(0, b + num + 1);
      for (i = c; i <= b + num; i ++ )
      {
        a = a + "0";
      }
    }
  }
  return a;
}

/* *
 * 当支付方式改变时出发该事件
 * @param       pay_id      支付方式的id
 * return       void
 */
function changePayment(pay_id)
{
  // 计算订单费用
  calculateOrderFee();
}

function getCoordinate(obj)
{
  var pos =
  {
    "x" : 0, "y" : 0
  }

  pos.x = document.body.offsetLeft;
  pos.y = document.body.offsetTop;

  do
  {
    pos.x += obj.offsetLeft;
    pos.y += obj.offsetTop;

    obj = obj.offsetParent;
  }
  while (obj.tagName.toUpperCase() != 'BODY')

  return pos;
}

function showCatalog(obj)
{
  var pos = getCoordinate(obj);
  var div = document.getElementById('ECS_CATALOG');

  if (div && div.style.display != 'block')
  {
    div.style.display = 'block';
    div.style.left = pos.x + "px";
    div.style.top = (pos.y + obj.offsetHeight - 1) + "px";
  }
}

function hideCatalog(obj)
{
  var div = document.getElementById('ECS_CATALOG');

  if (div && div.style.display != 'none') div.style.display = "none";
}

function sendHashMail()
{
  Ajax.call('user.php?act=send_hash_mail', '', sendHashMailResponse, 'GET', 'JSON')
}

function sendHashMailResponse(result)
{
  alert(result.message);
}

function display_mode(str)
{
    document.getElementById('display').value = str;
    setTimeout(doSubmit, 0);
    function doSubmit() {document.forms['listform'].submit();}
}


/* 修复IE6以下版本PNG图片Alpha */
function fixpng()
{
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])

  if ((version >= 5.5) && (document.body.filters))
  {
     for(var i=0; i<document.images.length; i++)
     {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
           var imgID = (img.id) ? "id='" + img.id + "' " : ""
           var imgClass = (img.className) ? "class='" + img.className + "' " : ""
           var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
           var imgStyle = "display:inline-block;" + img.style.cssText
           if (img.align == "left") imgStyle = "float:left;" + imgStyle
           if (img.align == "right") imgStyle = "float:right;" + imgStyle
           if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
           var strNewHTML = "<span " + imgID + imgClass + imgTitle
           + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
           + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
           + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
           img.outerHTML = strNewHTML
           i = i-1
        }
     }
  }
}

function hash(string, length)
{
  var length = length ? length : 32;
  var start = 0;
  var i = 0;
  var result = '';
  filllen = length - string.length % length;
  for(i = 0; i < filllen; i++)
  {
    string += "0";
  }
  while(start < string.length)
  {
    result = stringxor(result, string.substr(start, length));
    start += length;
  }
  return result;
}

function stringxor(s1, s2)
{
  var s = '';
  var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  var max = Math.max(s1.length, s2.length);
  for(var i=0; i<max; i++) 
  {
    var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
    s += hash.charAt(k % 52);
  }
  return s;
}

var evalscripts = new Array();
function evalscript(s)
{
  if(s.indexOf('<script') == -1) return s;
  var p = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/ig;
  var arr = new Array();
  while(arr = p.exec(s)) appendscript(arr[1], '', arr[2], arr[3]);
  return s;
}

function $$(id)
{
    return document.getElementById(id);
}

function appendscript(src, text, reload, charset) 
{
  var id = hash(src + text);
  if(!reload && in_array(id, evalscripts)) return;
  if(reload && $$(id))
  {
    $$(id).parentNode.removeChild($$(id));
  }
  evalscripts.push(id);
  var scriptNode = document.createElement("script");
  scriptNode.type = "text/javascript";
  scriptNode.id = id;
  //scriptNode.charset = charset;
  try 
  {
    if(src) 
    {
      scriptNode.src = src;
    }
    else if(text)
    {
      scriptNode.text = text;
    }
    $$('append_parent').appendChild(scriptNode);
  } 
  catch(e)
  {}
}

function in_array(needle, haystack)
{
  if(typeof needle == 'string' || typeof needle == 'number')
  {
    for(var i in haystack)
    {
      if(haystack[i] == needle)
      {
        return true;
      }
    }
  }
  return false;
}

var pmwinposition = new Array();

var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
function pmwin(action, param)
{
  var objs = document.getElementsByTagName("OBJECT");
  if(action == 'open')
  {
    for(i = 0;i < objs.length; i ++)
    {
      if(objs[i].style.visibility != 'hidden')
      {
        objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
        objs[i].style.visibility = 'hidden';
      }
    }
    var clientWidth = document.body.clientWidth;
    var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
    var pmwidth = 800;
    var pmheight = clientHeight * 0.9;
    if(!$$('pmlayer'))
    {
      div = document.createElement('div');div.id = 'pmlayer';
      div.style.width = pmwidth + 'px';
      div.style.height = pmheight + 'px';
      div.style.left = ((clientWidth - pmwidth) / 2) + 'px';
      div.style.position = 'absolute';
      div.style.zIndex = '999';
      $$('append_parent').appendChild(div);
      $$('pmlayer').innerHTML = '<div style="width: 800px; background: #666666; margin: 5px auto; text-align: left">' +
        '<div style="width: 800px; height: ' + pmheight + 'px; padding: 1px; background: #FFFFFF; border: 1px solid #7597B8; position: relative; left: -6px; top: -3px">' +
        '<div onmousedown="pmwindrag(event, 1)" onmousemove="pmwindrag(event, 2)" onmouseup="pmwindrag(event, 3)" style="cursor: move; position: relative; left: 0px; top: 0px; width: 800px; height: 30px; margin-bottom: -30px;"></div>' +
        '<a href="###" onclick="pmwin(\'close\')"><img style="position: absolute; right: 20px; top: 15px" src="images/close.gif" title="关闭" /></a>' +
        '<iframe id="pmframe" name="pmframe" style="width:' + pmwidth + 'px;height:100%" allowTransparency="true" frameborder="0"></iframe></div></div>';
    }
    $$('pmlayer').style.display = '';
    $$('pmlayer').style.top = ((clientHeight - pmheight) / 2 + scrollTop) + 'px';
    if(!param)
    {
        pmframe.location = 'pm.php';
    }
    else
    {
        pmframe.location = 'pm.php?' + param;
    }
  }
  else if(action == 'close')
  {
    for(i = 0;i < objs.length; i ++)
    {
      if(objs[i].attributes['oldvisibility'])
      {
        objs[i].style.visibility = objs[i].attributes['oldvisibility'].nodeValue;
        objs[i].removeAttribute('oldvisibility');
      }
    }
    hiddenobj = new Array();
    $$('pmlayer').style.display = 'none';
  }
}

var pmwindragstart = new Array();
function pmwindrag(e, op)
{
  if(op == 1)
  {
    pmwindragstart = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
    pmwindragstart[2] = parseInt($$('pmlayer').style.left);
    pmwindragstart[3] = parseInt($$('pmlayer').style.top);
    doane(e);
  }
  else if(op == 2 && pmwindragstart[0])
  {
    var pmwindragnow = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
    $$('pmlayer').style.left = (pmwindragstart[2] + pmwindragnow[0] - pmwindragstart[0]) + 'px';
    $$('pmlayer').style.top = (pmwindragstart[3] + pmwindragnow[1] - pmwindragstart[1]) + 'px';
    doane(e);
  }
  else if(op == 3)
  {
    pmwindragstart = [];
    doane(e);
  }
}

function doane(event)
{
  e = event ? event : window.event;
  if(is_ie)
  {
    e.returnValue = false;
    e.cancelBubble = true;
  } 
  else if(e)
  {
    e.stopPropagation();
    e.preventDefault();
  }
}

//控制DIV显示隐藏
function Display(obj,targetobj,downclass,upclass)
{
    this.obj = obj;
    this.Targetobj = document.getElementById(targetobj);
    this.DownClass = downclass;
    this.UpClass = upclass;
}

Display.prototype._switch = function()
{
    this.Targetobj.style.display = this.Targetobj.style.display == "" ? "none" : "";
    this.obj.className = this.obj.className == this.DownClass ? this.UpClass : this.DownClass;
}

//计算购买价格
function get_count_price(old_weight,obj,price)
{
    var weight = obj.value;
    
    if (!Utils.isNumber(weight))
    {
        alert('预订数量必须为数字');
        obj.value = old_weight;
        return;
    }
    
    if (weight < old_weight )
    {
        alert('预订数量不能小于'+old_weight);
        obj.value = old_weight;
        return;
    }
    $$('count_price').innerText = advFormatNumber(weight * price,2);
}

function font(obj,size)
{
    document.getElementById(obj).style.fontSize = size + 'px';
}

//复制到剪切板
var content;
content="";
content="我发现一篇好文章，文章标题为：[prodname]， 赶紧去看看，网址是：";
content+=location.href;
function SendToMyFriend(ProdName)
{	
    content=content.replace("[prodname]",ProdName);
    window.clipboardData.setData("Text",  content);
    alert("已经把信息拷贝到粘贴板里面，请把内容通过即时通讯工具发送给你的好朋友广而告之。");
}

function copy(con)
{	
    window.clipboardData.setData("Text",  con);
    alert("已复制");
}

function article_tab(tab,len,obj)
{
    $$('article_tab_more').href = obj.href;
    
    for (var i=1;i<=len;i++)
    {
        if (i == tab)
        {
            $$('article_tab_'+tab).className= "current_nav";
            $$('article_tab_content_'+tab).style.display = "";
        }
        else
        {
            $$('article_tab_'+i).className= "";
            $$('article_tab_content_'+i).style.display = "none";
        }
    }
}

/*申请加盟表单提交 */
function join_apply(obj)
{
    var msg = "";
    var send = true;

    if (obj.company.value == "")
    {
        msg += "公司名称不能为空\r";
        send = false;
    }
    
    if (obj.name.value == "")
    {
        msg += "联系人姓名不能为空\r";
        send = false;
    }
    
    if (obj.tel.value == "")
    {
        msg += "联系人电话不能为空\r";
        send = false;
    }
    else
    {
        if (!Utils.isTel(obj.tel.value))
        {
            msg += "联系电话格式错误\r";
            send = false;
        }
    }
    
    if (obj.mobile.value == "")
    {
        msg += "手机号码不能为空\r";
        send = false;
    }
    else
    {
        if (!Utils.isMobile(obj.mobile.value))
        {
            msg += "手机号码格式错误\r";
            send = false;
        }
    }
    
    if (obj.email.value == "")
    {
        msg += "电子邮箱不能为空\r";
        send = false;
    }
    else
    {
        if (!Utils.isEmail(obj.email.value))
        {
            msg += "电子邮箱格式错误\r";
            send = false;
        }
    }
    
    if (obj.fax.value == "")
    {
        msg += "传真号码不能为空\r";
        send = false;
    }
    
    if (obj.province.value == "")
    {
        msg += "所在省份不能为空\r";
        send = false;
    }
    
    if (obj.city.value == "")
    {
        msg += "所在城市不能为空\r";
        send = false;
    }
    
    if (obj.address.value == "")
    {
        msg += "详细地址不能为空\r";
        send = false;
    }
    
    if (obj.postzip.value == "")
    {
        msg += "邮编不能为空\r";
        send = false;
    }
    
    if (obj.hangye.value == "")
    {
        msg += "所属行业不能为空\r";
        send = false;
    }
    
    if (!send)
    {
        alert(msg);
        return false;
    }
    
    var para = "&company="+obj.company.value;
    para += "&name="+obj.name.value;
    para += "&sex="+obj.sex.value;
    para += "&tel="+obj.tel.value;
    para += "&mobile="+obj.mobile.value;
    para += "&email="+obj.email.value;
    para += "&fax="+obj.fax.value;
    para += "&qq="+obj.qq.value;
    para += "&province="+obj.province.value;
    para += "&city="+obj.city.value;
    para += "&address="+obj.address.value;
    para += "&postzip="+obj.postzip.value;
    para += "&hangye="+obj.hangye.value;
    para += "&content="+obj.content.value;
        
    Ajax.call('/tools/ajax.aspx', "act=join_apply"+para, null, "POST", "JSON", false);
    
    alert("信息已经成功递交，我们会尽快与你取得联系");
    
    obj.reset();
    
    return false;
}

/*集团采购验证 */
function group_buy_validator(obj)
{
    var msg = "";
    var send = true;
    
    if (obj.contact_name.value == "")
    {
        msg += "联系人不能为空\r\n";
        send = false;
    }
    
    if (obj.tel.value == "")
    {
        msg += "联系电话不能为空\r\n";
        send = false;
    }
    
    if (!send)
    {
        alert(msg);
        return false;
    }
    
    return send;
}

/*订单查询验证信息 */
function check_find_order(obj)
{
    if (obj.order_sn.value == "")
    {
        alert("订单号不能为空");
        return false;
    }
    
    if (obj.order_sn.value.length != 12 || Utils.isInt(obj.order_sn.value) != true)
    {
        alert("您输入的订单号格式不正确，仔细查看下是否为12位数字？");
        return false;
    }
}

function getPosition() {
    var top    = document.documentElement.scrollTop;
    var left   = document.documentElement.scrollLeft;
    var height = document.documentElement.clientHeight;
    var width  = document.documentElement.clientWidth;
    
    return {top:top,left:left,height:height,width:width};
}

function QuickPostion(objID) {
    
    var obj = document.getElementById(objID);
    if (obj) {
        window.onscroll = function() {
            var Position = getPosition();
            obj.style.top = (Position.top) + 60 + "px";
            obj.style.right = "1px";
        };

        if (document.getCookie("kefutype") == "0") {
            document.getElementById("bodd").style.display = "";
            document.getElementById("kefubtn").style.display = "none";
        } else if (document.getCookie("kefutype") == "1") {
            document.getElementById("bodd").style.display = "none";
            document.getElementById("kefubtn").style.display = "";
        } else {
            document.getElementById("bodd").style.display = "";
            document.getElementById("kefubtn").style.display = "none";
        } 
    }
}

function writeIm(textS,siteNm){
    if (textS.split('|').length > 0) {
        var textCrumbs = textS.split(',');
        if (textCrumbs.length == 0) return;
        if (!siteNm) siteNm = "Oran";
        var rowStr = "<div style='position:absolute;right:1px;width:100px;top:60px;z-index:1000;' id='divOranIm'><div id=\"kefubtn\" style=\"text-align:right;cursor:hand;display:none\" ><img alt='打开客服菜单' src=\"/images/im.gif\" onclick=\"setkefu(1)\"></div><div id=\"bodd\"><div class='ImHeader' onclick='setkefu(0)' style=\"cursor:hand\" title='隐藏客服菜单'><a href='javascript:void(0);' onclick='setkefu(0)'></a></div><div class=\"ImBorder\"><table class='ImTable' border='0' cellspacing='0' cellpadding='0' width='96'>";
        var online = [0];
        var isType = "QQ";
        var imgPath;
        var classIm;
        var thisIm;
        var idCrumbs;
        var menber;
        var menber;
        var tt;

        for (var i = 0; i < textCrumbs.length; ++i) {

            classIm = textCrumbs[i].split('||');
            if (classIm[0]) {
                rowStr += "<tr><td class='ImGroup'><h5>" + classIm[0] + "</h5></td></tr>";
            }
            idCrumbs = classIm[1].split('|');
            for (var j = 0; j < idCrumbs.length; ++j) {
                rowStr += "<tr><td align='center'><div class='ImRow" + (j % 2) + "'><a target='_self' class='im' href='";




                thisim = idCrumbs[j].split('$');

                tt = thisim[0];
                tt = tt.replace(")", "").split('(');
                isType = tt[1];

                menber = tt[0];
                if (isType == "qq") {
                    imgPath = "/images/qq.jpg";
                    rowStr += "tencent://message/?menu=yes&site=&uin=" + menber;
                }
                if (isType == "msn") {
                    imgPath = "/images/msn.jpg";
                    rowStr += "msnim:chat?contact=" + menber;
                }
                if (isType == "wangwang") {
                    imgPath = "/images/WANGWANG.gif";
                    rowStr += "http://amos.im.alisoft.com/msg.aw?v=2&site=cntaobao&s=1&charset=utf-8&uid=" + menber;
                }




                rowStr += "'><img src='" + imgPath + "' alt='" + isType + "' style='border:none' align='absmiddle'/> " + thisim[1] + "</a></div></td></tr>";
            }
        }


        rowStr += "</table><div style='text-align:center; border-top:1px #ccc dotted; padding-top:6px; width:88%; margin-left:6px;'><a href='/member/'><img src='/images/k_15.jpg' /></a></div></div><div class='ImFooter'></div></div></div>";
        //document.write(rowStr);
        document.getElementById("siteim").innerHTML = rowStr;
    }
}

function setkefu(valtype) {

    if(valtype==0){
        document.getElementById("bodd").style.display="none";
        document.getElementById("kefubtn").style.display="";
        document.setCookie("kefutype",1);
    }else{
        document.getElementById("bodd").style.display="";
        document.getElementById("kefubtn").style.display="none";
        document.setCookie("kefutype",0);
    }
}

//取得父窗口浏览器可见区高度
function getClientHeight()
{
    var clientHeight=0;
    if(parent.document.body.clientHeight&&parent.document.documentElement.clientHeight)
    {
        var clientHeight = (parent.document.body.clientHeight<parent.document.documentElement.clientHeight)?parent.document.body.clientHeight:parent.document.documentElement.clientHeight;        
    }
    else
    {
        var clientHeight = (parent.document.body.clientHeight>parent.document.documentElement.clientHeight)?parent.document.body.clientHeight:parent.document.documentElement.clientHeight;    
    }
    return clientHeight;
}

function getPos(o)
{
    var t = o.offsetTop;
    var l = o.offsetLeft;
    while(o = o.offsetParent)
    {
        t += o.offsetTop;
        l += o.offsetLeft;
    }
    var pos = {top:t,left:l};
    return pos;
}

function pop()
{
    if (navigator.userAgent.indexOf("MSIE") != -1)
    {
        this.classname = "ie_pop_style";
        this.iframe_class = "ie_pop_iframe_style";
    }
    else
    {
        this.classname = "firefox_pop_style";
        this.iframe_class = "firefox_iframe_style";
    }
}

pop.prototype.show = function()
{
    var _pop = parent.document.createElement("div");
	_pop.id = "sys_pop";
	_pop.style.width = "100%";
	_pop.style.height = ""+ getClientHeight() +"px";
	_pop.className = this.classname;
	
	var _frame = parent.document.createElement("iframe");
	_frame.frameBorder = "0";
	_frame.src = "http://www.163.com";
	_frame.className = this.iframe_class;

	parent.document.body.appendChild(_pop);
	parent.document.body.appendChild(_frame);
}

window.onload = function()
{
    //new pop().show();
    
}

/*
显示文件上传窗口
obj 点击显示窗口的对象
upload_type 文件上传类型，有file,photo,video
target_obj 目标接收返回地址的对象
save_folder 文件保存路径
*/
function upload(obj,upload_type,target_obj,save_folder)
{
    var pos = getPos(obj);
    
    if (document.getElementById('pop_upload'))
        pop_close();
        
    var pop = document.createElement("div");
    pop.id = "pop_upload";
    pop.className = "pop";
    pop.style.top = pos.top;
    pop.style.left = pos.left;
    
    document.body.appendChild(pop);
    
    var close = document.createElement("a");
    close.innerText = "×";
    close.title = "关闭";
    close.href = "javascript:pop_close('pop_upload');";
    pop.appendChild(close);
    
    var iframe = document.createElement("iframe");
    iframe.src = "/tools/upload.aspx?t="+ escape(upload_type) +"&target_obj="+ escape(target_obj) +"&save_folder="+ escape(save_folder) +"";
    iframe.width = "100%";
    iframe.height = "60";
    iframe.frameBorder = "0";
    
    document.getElementById(pop.id).appendChild(iframe);
    
    iframe.src = iframe.src;

}

function pop_close(_pop)
{
    var obj = document.getElementById(_pop);
    
    document.body.removeChild(obj);
}

/*上传商品图 */
function up_goods_photo(clcik_obj,upload_type,target_obj,obj,tow_obj)
{
    var val = obj.options[obj.selectedIndex].name;
    
    if (val == "")
    {
        alert("请先选择商品所属分类");
        return false;
    }
    
    if (tow_obj.value == "")
    {
        alert("请先输入商品货号");
        return false;
    }
    
    var res = Ajax.call('/tools/ajax.aspx', "act=get_pingying&val="+ val +"", null, "POST", "JSON", false);
    
    upload(clcik_obj,upload_type,target_obj,res.message+'|'+ tow_obj.value + '|')
}

function sys_photo_list(obj,target_obj)
{
    var pos = getPos(obj);
    
    if (document.getElementById('pop_photo'))
        pop_close();
        
    var pop = document.createElement("div");
    pop.id = "pop_photo";
    pop.className = "pop";
    pop.style.top = pos.top;
    pop.style.left = pos.left;
    
    document.body.appendChild(pop);
    
    var close = document.createElement("a");
    close.innerText = "×";
    close.title = "关闭";
    close.href = "javascript:pop_close('pop_photo');";
    pop.appendChild(close);
    
    var iframe = document.createElement("iframe");
    iframe.src = "/tools/sys_photo.aspx?target_obj="+target_obj;
    iframe.width = "100%";
    iframe.height = "200";
    iframe.frameBorder = "0";
    
    document.getElementById(pop.id).appendChild(iframe);
    
    iframe.src = iframe.src;
}

function countdown(endtime, today, showid)
{
	today = new Date();
	target_time=new Date(endtime);
	timeold=(target_time.getTime()-today.getTime()); 
	sectimeold=timeold/1000;
	secondsold=Math.floor(sectimeold); 
	msPerDay=24*60*60*1000;
	e_daysold=timeold/msPerDay;
	daysold=Math.floor(e_daysold); 
	e_hrsold=(e_daysold-daysold)*24; 
	hrsold=Math.floor(e_hrsold); 
	e_minsold=(e_hrsold-hrsold)*60; 
	minsold=Math.floor(e_minsold); 
	e_seconds=(e_minsold-minsold)*60;
	seconds=Math.floor(e_seconds); 
	e_millisecond=(e_seconds-seconds)*1000;
	millisecond=Math.floor(e_millisecond);
    millisecond10=Math.floor(millisecond/10);

/*
	s = 'timeold: '+ timeold + '<br>';
	s+= 'sectimeold:' + sectimeold + '<br>';
	s+= 'secondsold:' + secondsold + '<br>';
	s+= 'msPerDay:' + msPerDay + '<br>';
	s+= 'e_daysold:' + e_daysold + '<br>';
	s+= 'daysold:' + daysold + '<br>';
	s+= 'e_hrsold:' + e_hrsold + '<br>';
	s+= 'hrsold:' + hrsold + '<br>';
	s+= 'e_minsold:' + e_minsold + '<br>';
	s+= 'minsold:' + minsold + '<br>';
	s+= 'e_seconds:' + e_seconds + '<br>';
	s+= 'seconds:' + seconds + '<br>';
	s+= 'e_millisecond:' + e_millisecond + '<br>';
	s+= 'millisecond:' + millisecond + '<br>';
	s+= 'millisecond10:' + millisecond10;
    document.write(s);
*/

	the_element = document.getElementById(showid);
	the_element.innerHTML=""+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"/*+millisecond10/*+"毫秒"*/ ; 

	//today.setSeconds(today.getSeconds() + 0.01);
	window.setTimeout("countdown('" + endtime + "', today ,'"+ showid +"')", 100); 
} 

function get_order_count()
{
    //检查余额是否够进行本次支付
    //var res = Ajax.call('/service/flow.aspx', "act=get_order_count", null, "POST", "TEXT", false);
    
    //document.getElementById("get_order_count").innerText = res;
}

















var maxWidth = 250;
var maxHeight = 250;
function getPosXY(a, offset) {
    var p = offset ? offset.slice(0) : [0, 0], tn;
    while (a) {
        tn = a.tagName.toUpperCase();
        if (tn == 'IMG') {
            a = a.offsetParent; continue;
        }
        p[0] += a.offsetLeft - (tn == "DIV" && a.scrollLeft ? a.scrollLeft : 0);
        p[1] += a.offsetTop - (tn == "DIV" && a.scrollTop ? a.scrollTop : 0);
        if (tn == "BODY")
            break;
        a = a.offsetParent;
    }
    return p;
}
function checkComplete() {
    if (checkComplete.__img && checkComplete.__img.complete)
        checkComplete.__onload();
}

checkComplete.__onload = function() {
    clearInterval(checkComplete.__timeId);
    var w = checkComplete.__img.width;
    var h = checkComplete.__img.height;
    if (w >= h && w > maxWidth) {
        previewImage.style.width = maxWidth + 'px';
    }
    else if (h >= w && h > maxHeight) {
        previewImage.style.height = maxHeight + 'px';
    }
    else {
        previewImage.style.width = previewImage.style.height = '';
    }
    previewImage.src = checkComplete.__img.src; previewUrl.href = checkComplete.href; checkComplete.__img = null; imgtxt.innerHTML = checkComplete.picAlt;
}

function showPreview(e) {
    hidePreview(e);
    previewFrom = e.target || e.srcElement;
    previewImage.src = loadingImg;
    previewImage.style.width = previewImage.style.height = '';
    previewTimeoutId = setTimeout('_showPreview()', 500);
    checkComplete.__img = null;
}
function hidePreview(e) {
    if (e) {
        var toElement = e.relatedTarget || e.toElement;
        while (toElement) {
            if (toElement.id == 'PreviewBox')
                return;
            toElement = toElement.parentNode;
        }
    }
    try {
        clearInterval(checkComplete.__timeId);
        checkComplete.__img = null;
        previewImage.src = null;
    }
    catch (e) { }
    clearTimeout(previewTimeoutId);
    previewBox.style.display = 'none';
}
function _showPreview() {
    checkComplete.__img = new Image();
    if (previewFrom.tagName.toUpperCase() == 'A')
        previewFrom = previewFrom.getElementsByTagName('img')[0];
    var largeSrc = previewFrom.getAttribute("large-src");
    var picLink = previewFrom.getAttribute("pic-link");
    var picAlt = previewFrom.getAttribute("talt");
    if (!largeSrc)
        return;
    else {
        checkComplete.picAlt = picAlt;
        checkComplete.__img.src = largeSrc;
        checkComplete.href = picLink;
        checkComplete.__timeId = setInterval("checkComplete()", 20);
        var pos = getPosXY(previewFrom, [106, 26]);
        previewBox.style.left = pos[0] + 'px';
        previewBox.style.top = pos[1] + 'px';
        previewBox.style.display = 'block';
    }
}



function addToEmail(val) {
    if (val != false)
        Ajax.call('/service/flow.aspx?act=add_to_Email', 'content=' + val, alert_Msg, 'POST', 'JSON');
}
function alert_Msg(result) {
    alert(result.message);
}
