﻿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.",
	"msg09":"The comment field is required",
	"msg10":"Submit Success, thank you!",
	"msg11":"Success!  We will contact you soon.  You can still add this product to the quote list.",
	"msg12":"Success!  We will send email to you soon."
	};
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 submitproductRequests(id)
{
	var email=$("#email").val();
	var company=$("#company").val();
	var comments=$("#comments").val();
	if(email=="")
	{
		alert(message.msg07);
		return false;
	}
	if(!isEmail(email))
	{
		alert(message.msg08);
		return false;
	}
	if(comments=="")
	{
		alert(message.msg09);
		return false;
	}
	$.ajax({
		url: 'orderadd.php',
		type: 'post',
		data:{action:"usersubmproductdetails",id:id,email:email,company:company,comments:comments},
		dataType: 'json',
		error: function(){
			alert(message.msg04);
			},
		success: function(data){
			if(data.err=="0")
			{
				$("#details").hide();
				$("#google").attr("src","js/google.js");
				alert(message.msg11);
				$("#comments").val("");
			  
			 }
			else
			{
				 alert(message.msg04);
			}
			}
		});
}

function submitproductHistory()
{
	var email=$("#email").val();
	var comments=$("#comments").val();
	var ids=$("#ids").val();
	if(email=="")
	{
		alert(message.msg07);
		return false;
	}
	if(!isEmail(email))
	{
		alert(message.msg08);
		return false;
	}
	$.ajax({
		url: 'orderadd.php',
		type: 'post',
		data:{action:"usersubmproducthistory",id:ids,email:email,comments:comments},
		dataType: 'json',
		error: function(){
			alert(message.msg04);
			},
		success: function(data){
			if(data.err=="0")
			{
				//$("#google").attr("src","js/google.js");
				alert(message.msg12);
				$("#comments").val("");
				window.location=$("#lasturl").val();
			 }
			else
			{
				 alert(message.msg04);
			}
			}
		});
}
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 updateDetails(id,val)
{
	$.ajax({
		url: 'orderadd.php',
		type: 'post',
		data:{id:id,action:"updateDetails",Details:$(val).val()},
		dataType: 'json',
		error: function(){
			//alert(message.msg02);
			},
		success: function(data){
			if(data.err=="0")
			{
			// alert(message.msg03);
			 }
			else
			{
				//alert(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 writeHistory(product_id,product_url,product_img)
{
	var product_id_string=readCookie("product_id");
	var product_url_string=readCookie("product_url");
	var product_img_string=readCookie("product_img");
	
	var product_id_arr=product_id_string.split("|");
	var product_url_arr= product_url_string.split("|");
	var product_img_arr=product_img_string.split("|");
	var iswrited=false;
	var historynum=6;  
	if(product_id_arr=="")//没有浏览产品
	{
			if(product_id !="" && product_url !="" && product_img !="")
			{
				writeCookie("product_id", product_id);
				writeCookie("product_url", product_url);
				writeCookie("product_img", product_img);
				
				
			}
	}
	else//已经存在数据
	{
		
		if(product_id !="" && product_url !="" && product_img !="")
			{
				for(var i=0;i<product_id_arr.length;i++)
				{
					if(product_id_arr[i]==product_id)//当前产品已经在列表中
					{
						iswrited=true;
						product_id_arr=taxisarray(product_id_arr,i);
						product_url_arr=taxisarray(product_url_arr,i);
						product_img_arr=taxisarray(product_img_arr,i);
						break;
					}
				}

				if(iswrited==false)
				{
						product_id_arr.splice(0,0,product_id);
						product_url_arr.splice(0,0,product_url);
						product_img_arr.splice(0,0,product_img);
						if(product_id_arr.length>=historynum)
						{
							product_id_arr.splice(historynum,1);
							product_url_arr.splice(historynum,1);
							product_img_arr.splice(historynum,1);
						}
				}
				product_id_string =product_id_arr.join("|");
				product_url_string =product_url_arr.join("|");
				product_img_string=product_img_arr.join("|");
				writeCookie("product_id", product_id_string, 1);
				writeCookie("product_url", product_url_string, 1);
				writeCookie("product_img", product_img_string, 1);

			}
		
	}
}
function taxisarray(arr,n)
{
	
	var swapvalue=arr[n];
	
	for(var j=n;j>0;j--)
	{
		arr[j]=arr[j-1];
	}
	arr[0]=swapvalue;
	
	return arr;
}
function getHistoryPorudct()
{
	var product_id_string=readCookie("product_id");
	var product_url_string=readCookie("product_url");
	var product_img_string=readCookie("product_img");
	var product_id_arr=product_id_string.split("|");
	var product_url_arr= product_url_string.split("|");
	var product_img_arr=product_img_string.split("|");
	var writeString="<div id=\"ls_k\">";
	$("#a_acnew_history").hide();
	if(product_id_string !="")
	{
		writeString +="<table width=\"0\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#91A4D0\" height=\"70\" class=\"table_ls\">";
writeString +="                  <tr>";
		for(var i=0;i<6;i++)
			{
				if(i<product_id_arr.length)
				{
					writeString +="  <td width=\"115\" height=\"70\" bgcolor=\"#FFFFFF\" scope=\"col\"><a href=\""+product_url_arr[i]+"\"><img src=\""+product_img_arr[i]+"\" width=\"91\" height=\"54\" border=\"0\" \/></a><\/td>";
				}
				else
				{
					writeString +="  <td width=\"115\" height=\"70\" bgcolor=\"#FFFFFF\" scope=\"col\">&nbsp;<\/td>";
				}
			}
		writeString +="<\/tr>";
		writeString +="<\/table><\/div>";
		
		$("#history_table").html(writeString);
		$("#a_acnew_history").show();
	}
}
function deletehistory(id)
{
	if(id=="all")
	{
		var product_id_string=readCookie("product_id");
		var product_url_string=readCookie("product_url");
		var product_img_string=readCookie("product_img");
	}
	else
	{
	}
}
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 openwindow(w,h,url)
{
		window.open(url,"","scrollbars=yes,resizable=yes,width="+w+",height="+h);
}
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;
}
function AddToFavorite(){
	
	var title=document.title;
	var url=window.location;
	switch(getOs())
   {
       case 1:window.external.addFavorite(url,title);break;
       case 2:window.sidebar.addPanel(title, url, "");break;
       case 0:alert("err");break;
   }
}

function getOs()
{
   if(navigator.userAgent.indexOf("MSIE")>0)return 1;
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
   if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 3;   
   if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 4;
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 5;
   return 0;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function showuserquestdiv()
{
 	var obj=document.getElementById("details");
	obj.style.display=(obj.style.display=="none")?"":"none";
}
writeKeyWord();
// JavaScript Document