﻿var message={
	"msg00":"failed to add commodity",
	"msg01":"only for the number",
	"msg02":"data is not successfully updated, please try again",
	"msg03":"has been updated",
	"msg04":"System busy, please try again",
	"msg05":"Do you want to remove this item?",
	"msg06":"delete the wrong products, please try again",
	"msg07":"The Email field is required",
	"msg08":"Invalid Email address. An e-mail address must contain the @ symbol."
	};
function DrawImage(ImgD,iwidth,iheight){
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= iwidth/iheight){
			if(image.width>iwidth){
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
				
		}else{
			if(image.height>iheight){
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
}
function addBuyCar(postdata)
{
	$.ajax({
		url: 'orderadd.php',
		type: 'post',
		data:postdata,
		dataType: 'json',
		error: function(){
			alert(message.msg00);
			},
		success: function(data){
			if(data.err=="0")
			{
			  window.location="orderlist.php";
			 }
			else
			{
				 alert(message.msg00);
			}
			}
		});
}
function upNum(id,div,val)
{
	if($(val).val()=="" || isNaN($(val).val()))
	{
		ShowMessage(div,message.msg01);
		return false;
	}
	$.ajax({
		url: 'orderadd.php',
		type: 'post',
		data:{id:id,action:"update",count:$(val).val()},
		dataType: 'json',
		error: function(){
			ShowMessage(div,message.msg02);
			},
		success: function(data){
			if(data.err=="0")
			{
			 ShowMessage(div,message.msg03);
			 }
			else
			{
				 ShowMessage(div,message.msg04);
			}
			}
		});
}
function remove(id,div)
{
	if(window.confirm(message.msg05)==false)
	{
		return false;
	}
	$.ajax({
		url: 'orderadd.php',
		type: 'post',
		data:{id:id,action:"delete"},
		dataType: 'json',
		error: function(){
			ShowMessage(div,message.msg06);
			},
		success: function(data){
			if(data.err=="0")
			{
			  $("#list_"+id).hide();
			  
			 }
			else
			{
				 ShowMessage(div,message.msg06);
			}
			}
		});
}
function ShowMessage(div,msg)
{
	$(div).html(msg);
	setTimeout("$(\""+div+"\").html(\'\');",4000);
}
function isEmail(str)
{
	var re = /^[_a-zA-Z0-9\-\.]+@([\-_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
	if(re.test(str))
		return true;
	else
		return false;
	}
	
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 = unescape(document.cookie.substring(offset, end));
    }
  }
  return cookieValue;
}

function ShowCart()
{
	document.write("<div id=\"orderDatelist\"></div>");
	$(document).ready(function(){
	
	$.get("GetCookies.php?st="+new Date().getTime(), function(data){ // grab content from another page
					var casrinfo=data;
					var writestr="";
	if(casrinfo!="")
	{
		var goodslist=casrinfo.split("$$");
			writestr +="<table width=\"215\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#CCCCCC\">";
			writestr +="<tr>";
			writestr +="  <td width=\"154\" height=\"25\" bgcolor=\"#FFFFFF\">Item Name<\/td>";
			writestr +="  <td width=\"61\" height=\"25\" bgcolor=\"#FFFFFF\">Quantity<\/td>";
			writestr +="<\/tr>";
		for(var i=0;i<goodslist.length;i++)
			{
				var goods=goodslist[i].split("||");
				if(goods.length>3)
				{
					var pname=goods[1].replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ").replace("+"," ");
					writestr +="<tr>";
					writestr +="  <td height=\"20\" bgcolor=\"#FFFFFF\" class=\"bulee\">&nbsp;<a href=\""+goods[2]+"\" title=\""+pname+"\">"+pname.substr(0,26)+"</a><\/td>";
					writestr +="  <td bgcolor=\"#FFFFFF\" class=\"bulee\">"+goods[4]+"<\/td>";
					writestr +="<\/tr>";
				}
			}
			writestr +="<tr>";
			writestr +="<td height=\"20\" bgcolor=\"#FFFFFF\" class=\"bulee\">&nbsp;<\/td>";
			writestr +="<td bgcolor=\"#FFFFFF\" class=\"bulee\"><a href=\"orderlist.php\">more..<\/a><\/td>";
			writestr +="<\/tr>";
		writestr +="<\/table>";
		$("#orderDatelist").html(writestr);
	}
					
					
		});
	
 });
	
}
function checkform()
{
	if($("#email").val()=="")
	{
		alert(message.msg07);
		return false;
	
	}
	if(!isEmail($("#email").val()))
	{
		alert(message.msg08);
		return false;
	}
	$("#keyword").val(readCookie("keyword"));
}
function browsefile(txt,img,path)
{
	var url="../upload/FileShow.asp";
	var query="?Query="+txt;
	if(txt=="")
	{
		alert("err:1");
		return false;
	}else if(img!=""){
			query +="|"+img;
	}
	url +=query+"&spath="+path;
	window.open(url,'','scrollbars=no,resizable=no,width=500,height=435');
}
function goOrderList()
{
	window.location="orderlist.php";
	}

function writeKeyWord()
{
	var keyword=Request("keyword");
	if(keyword!="")
	{
		writeCookie("keyword", keyword);
	}
}
function writeCookie(name, value)
{
  var expire = "";
    expire = new Date((new Date()).getTime() + 24 * 3600000);
    expire = "; expires=" + expire.toGMTString()+";path=/";
  document.cookie = name + "=" + escape(value) + expire;
}

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 = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function Request(){
var Url=window.location.href;
var u,g,StrBack='';
if(arguments[arguments.length-1]=="#")
   u=Url.split("#");
else
   u=Url.split("?");
if (u.length==1) g='';
else g=u[1]; 
if(g!=''){
   gg=g.split("&");
   var MaxI=gg.length;
   str = arguments[0]+"=";
   for(i=0;i<MaxI;i++){
      if(gg[i].indexOf(str)==0) {
        StrBack=gg[i].replace(str,"");
        break;
      }
   }
}
return StrBack;
}
writeKeyWord();
// JavaScript Document



