
function submitform () {

  document._xclick.invoice.value=geninvoiceno();
  document._xclick.submit();
}

function geninvoiceno () {

  var currentTime = new Date();

  var year = currentTime.getFullYear();
  var month = currentTime.getMonth()+1;
  var date = currentTime.getDate();
  var hour = currentTime.getHours();
  var minutes = currentTime.getMinutes();
  var seconds = currentTime.getSeconds();

  invoice = "MA" + year;

  if (month < 10)
    invoice = invoice + "0" + month;
  else
    invoice = invoice + month;

  if (date < 10)
    invoice = invoice + "0" + date;
  else
    invoice = invoice + date;

  if (hour < 10)
    invoice = invoice + "0" + hour;
  else
    invoice = invoice + hour;

  if (minutes < 10)
    invoice = invoice + "0" + minutes;
  else
    invoice = invoice + minutes;

  if (seconds < 10)
    invoice = invoice + "0" + seconds;
  else
    invoice = invoice + seconds;

  return (invoice);
}

function loadname()
{
	document.cookie="abc";
}

function writeCookie(name, ID, pro, num, pri, spec)
{
  /*if (name=="")
  {
	alert("请先登錄");
  	return;
  }*/
  
  var test=false;
  
  //var values="," + escape(ID) + "#" + escape(pro) + "#" + escape(num) + "#" + escape(pri);
  var values="," + escape(ID) + "#" + escape(pro) + "#" + escape(num) + "#" + escape(pri) + "#" + escape(spec);
  var cookieValue = readCookie(name);
		sss=cookieValue.split(",")
		for (i=0;i<sss.length;i++){
		s=sss[i].split("#");
			for(j=0;j<s.length;j++){
				if(s[0]==ID)
				{

					cookieValue=cookieValue.replace(","+sss[i],"");

					nums=s[2];
					test=true;
					alert('此产品已在购物车，将在数量上加1');
					break;
				}
			}
		}
	if (test)
	{
		document.cookie = name + "=" + cookieValue+ "," + escape(ID) + "#" + escape(pro) + "#" + escape(parseInt(num)+parseInt(nums)) + "#" + escape(pri) + "#" + escape(spec);
		test=false;
	}
	else
	{
		document.cookie = name + "=" + cookieValue+values;
		//alert( name + "=" + cookieValue+values);
		alert ('产品已成功添加到购物车!');
	}
	
}
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;
}//readCookie(name)   此函数为返回已购买的所有内容,包括  物品ID,物品单价,物品名称,物品数量





