// Example:

function gotocar(ID)
{
 	//打开购物车页面
	NewWindow=window.open("mycar.asp?act=add&id="+ID,"ahep_bookcar","width=700,height=500,resizable=no,status=no;menubar=no,toolbar=no,scrollbars=yes");
	NewWindow.moveTo(150,100);
	NewWindow.focus();
}
// writeCookie("myCookie", "my name");
//name,购物车名称 value1物品ID, value2物品数量, value3物品单价, value4物品名称
//onClick="writeCookie('ahep_bookcar',物品ID,数量,单价,'名称')"
function writeCookie(name, value1, value2, value3, value4)
{
	var NewWindow;
	var car_str=readCookie(name);
	var kkk=car_str.indexOf(","+value1+"_");
	if (kkk == -1)
 	{document.cookie = name + "=" + readCookie(name) + "," + value1 + "_" + value2 + "_" + value3 + "_" + trimSpaces(value4);}
	else
	{alert("该物品已经存在于您的购物车中。");}

	document.location.href="mycar.asp";
}
// Example:

// alert( readCookie("myCookie") );
//name购物车名称
function readCookie(name)

{

  var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = document.cookie.substring(offset, end)

    }

  }

  return cookieValue;

}

function stringToInteger (inputString)

{

  return parseInt(inputString);

}

function isNotaNumber (inputString)

{

  return isNaN(inputString);

}

//删除图书  name=购物车名字 , value物品对应cookie
function UpdateCookie(name, value)

{

  var vvv="";
  vvv=readCookie(name);
  vvv=vvv.replace(','+value,"");
  document.cookie = name + "=" + vvv;
  document.location.href="mycar.asp";

}

function ModifyCookie(name, valuex, value1, value2, value3, value4)

{

  var vvv="";
  vvv=readCookie(name);
  vvv=vvv.replace(','+valuex,"");
  //alert(vvv);
  document.cookie = name + "=" + vvv + "," + value1 + "_" + value2 + "_" + value3 + "_" + value4;

}

//去除头部和尾部空格   
function trim(jia) {    
    return jia.replace(/(^\s*)|(\s*$)/g, "");    
}   
//去除头部空格     
function ltrim(jia) {   
    return jia.replace(/(^\s*)/g, "");   
}    
//去除尾部空格   
function rtrim(jia) {    
    return jia.replace(/(\s*$)/g, "");    
}   
//去除头尾和中间空格,制表符   
function trimSpaces(Str){       
        var ResultStr = "";       
        Temp=Str.split(/\s/);        
        for(i = 0; i < Temp.length; i++)       
            ResultStr +=Temp[i];       
        return ResultStr;       
}