//by cenfun
var CookieName="smart_productid_"
function checkorder(productid,Item_Code)
{
	var productid_list=getCookie(CookieName+"productid_list");
		productid_list=replace(productid_list, "||||||", "|||") ;
	if(productid_list==null) productid_list="";
	if(checkCookieExist(CookieName+productid))
	{
		deleteCookie(CookieName+productid);
		productid_list=replace(productid_list, productid+"|||", "") ;
		alert("Cancel "+Item_Code+" succeed!");
	}
	else
	{
		saveCookie(CookieName+productid,Item_Code,1000);
		productid_list=productid_list+productid+"|||";
		alert("Add "+getCookie(CookieName+productid)+" succeed!");
	}
		saveCookie(CookieName+"productid_list",productid_list,1000);
}//
function cannelorder(productid,Item_Code)
{
	if(confirm("Delete "+Item_Code+"?"))
	{
	var productid_list=getCookie(CookieName+"productid_list");
		//alert(productid_list);
		productid_list=replace(productid_list, productid, "") ;
		productid_list=replace(productid_list, "||||||", "|||") ;
		if(productid_list==null) productid_list="";
		saveCookie(CookieName+"productid_list",productid_list,1000);
		if(checkCookieExist(CookieName+productid))
		{
			deleteCookie(CookieName+productid);
		}
		document.location='orders.asp';
	}
	else
	{
	return false;
	}
}//
function admin_Size(num,objname)
{
	var obj=document.getElementById(objname)
	if (parseInt(obj.rows)+num>=3) {
		obj.rows = parseInt(obj.rows) + num;	
	}
	if (num>0)
	{
		obj.width="90%";
	}
}
function replace(s, t, u) 
{
	if(s==null || s=="") return s;
	i = s.indexOf(t);
	r = "";
	if (i == -1) return s;
	r += s.substring(0,i) + u;
	if ( i + t.length < s.length)
	r += replace(s.substring(i + t.length, s.length), t, u);
	return r;
}
function intercept(s, start, end) 
{
	var r = "";
	var i = s.indexOf(start);
		if (i == -1) return r; 
	var end_str=s.substring(i+start.length,s.length);
		//alert(end_str);
	var j = end_str.indexOf(end);
		if (j == -1) return r; 
	var mid_str=end_str.substring(0,j);
	r = start + mid_str + end;
	return r;
}
function re_height(num,objname)
{
	var obj=document.getElementById(objname)
	if (parseInt(obj.height)+num>=0) {
		obj.height = parseInt(obj.height) + num;	
	}
}
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
function openScript(url, width, height){
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}

//by cenfun
function bbimg(e, o)
{
var zoom = parseInt(o.style.zoom, 10) || 100;
zoom += event.wheelDelta / 20;
if (zoom > 0) o.style.zoom = zoom + '%';
return false;
}

/****************************************************************************
 * Usage:     ImageLoader.add("a.gif", "b.gif", "c.jpg", ...); // add others..
 *            ImageLoader.onProgressChange = function() {...}
 *            ImageLoader.onLoadFinish = function() {...}
 *            ImageLoader.onTimeOut = somefunction;
 *            ImageLoader.startLoad();
 ****************************************************************************/

function ImageLoader() {}

// Internal varibles definition
ImageLoader._preImages = new Array();
ImageLoader._imageUrlBuffer = new Array();
ImageLoader._currentID = 0;
ImageLoader._loaded = new Array();
ImageLoader._loadedNum = 0;
ImageLoader._currentLoading = "";
ImageLoader._timeOut = 30 * 1000;
ImageLoader._timeElapsed = 0;
ImageLoader._checkInterval = 50;

// Event simulation
ImageLoader.onProgressChange = new Function();
ImageLoader.onLoadFinish = new Function();
ImageLoader.onTimeOut = new Function();

/**
* Add images to the image array
* @param image1, image2, ...
* @return none
*/
ImageLoader.add = function() {
for (var i = ImageLoader._currentID; i < arguments.length; ImageLoader._currentID++,i++) {
if (arguments[i] != null || arguments[i] != "") {
ImageLoader._imageUrlBuffer[i] = arguments[i];
}
}
}

/**
* Get the Resouces count to be loaded
* @param none
* @return the number of resources to load.
*/
ImageLoader.getResourceCount = function() {
return ImageLoader._imageUrlBuffer.length;
}

/**
* Get the  count of current loaded.
* @param none
* @return long the number of images that current loaded
*/
ImageLoader.getLoadedCount = function() {
return ImageLoader._loadedNum;
}

/**
* Get the current loading image url
* @param none
* @return string the url of the current loading image.
*/
ImageLoader.getCurrentLoading = function() {
return ImageLoader._currentLoading;
}

/**
* Set the timeout value. initial is 30 seconds.
* @param long millisecond time
* @return none
*/
ImageLoader.setTimeOut = function(ts) {
ImageLoader._timeOut = ts;
}

/**
* Get the timeout value
* @param none
* @return int the timeout value
*/
ImageLoader.getTimeOut = function() {
return ImageLoader._timeOut;
}

/**
* Start to load the images.
* @param none
* @return none
*/
ImageLoader.startLoad = function() {
for (var i = 0; i < ImageLoader._imageUrlBuffer.length; i++) {
ImageLoader._preImages[i] = new Image();
ImageLoader._preImages[i].src = ImageLoader._imageUrlBuffer[i];
ImageLoader._loaded[i] = false;
}
ImageLoader.checkLoad();
}

/*-
* checkLoad
* Internal use only. 
* Do not use it directly. otherwise will encount an error.
*/
ImageLoader.checkLoad = function() {
if (ImageLoader._loadedNum == ImageLoader._preImages.length) { 
ImageLoader.onLoadFinish();
return;
}

if (ImageLoader._timeElapsed >= ImageLoader._timeOut) {
ImageLoader.onTimeOut();
return;
}

for (i = 0; i < ImageLoader._preImages.length; i++) {
if (ImageLoader._loaded[i] == false && ImageLoader._preImages[i].complete) {
ImageLoader._loaded[i] = true;
ImageLoader._currentLoading = ImageLoader._imageUrlBuffer[i];
ImageLoader._loadedNum++;
ImageLoader.onProgressChange();
}
}

ImageLoader._timeElapsed += ImageLoader._checkInterval;

setTimeout("ImageLoader.checkLoad()", ImageLoader._checkInterval);
}


var flag=false;
function DrawImage(ImgD,w,h){
var image=new Image();
image.src=ImgD.src;
var wh= image.width/image.height;
var scwh=w/h;

if(image.width>0 && image.height>0){
  flag=true;
   if(wh>=scwh){
        if(image.width>w){ 
            ImgD.width=w;
            //ImgD.height=wh*w
}else{
            ImgD.width=image.width; 
            ImgD.height=image.height;
        }
       //ImgD.alt=wh+":"+scwh+","+image.width+"x"+image.height;
   }
   else{
      if(image.height>h){ 
        ImgD.height=h;
        //ImgD.width=wh*h; 
      }else{
        ImgD.width=image.width; 
        ImgD.height=image.height;
      }
       //ImgD.alt=wh+":"+scwh+","+image.width+"x"+image.height;
   }
 }
} 

function ShowImage1(url,nw,nh,obg)
{
var imgid=document.getElementById(obg)
if (url!=""){
ImageLoader.add(url);
ImageLoader.onProgressChange = function() {imgid.innerHTML="无图片";}
ImageLoader.onLoadFinish = function() {imgid.innerHTML='<img src="'+url+'" onload="javascript:DrawImage(this,'+nw+','+nh+');" border=0>';}
ImageLoader.onTimeOut = function() {imgid.innerHTML="无图片";}
ImageLoader.startLoad();}
}

function ShowImage(url,nw,nh,obg)
{
var imgid=document.getElementById(obg)
if (url!="")
{imgid.innerHTML='<img src="'+url+'" onload="javascript:DrawImage(this,'+nw+','+nh+');" border=0>';}
}

//--------------------------------------------------↓↓↓↓↓↓↓↓↓↓↓↓  执行Cookie 操作
function saveCookie(name, value, expires, path, domain, secure)
{											// 保存Cookie
  var strCookie = name + "=" + value;
  if (expires)
  {											// 计算Cookie的期限, 参数为天数
     var curTime = new Date();
     curTime.setTime(curTime.getTime() + expires*24*60*60*1000);
     strCookie += "; expires=" + curTime.toGMTString();
  }//end if
  // Cookie的路径
  strCookie +=  (path) ? "; path=" + path : ""; 
  // Cookie的Domain
  strCookie +=  (domain) ? "; domain=" + domain : "";
  // 是否需要保密传送,为一个布尔值
  strCookie +=  (secure) ? "; secure" : "";
  document.cookie = strCookie;
}//end funciton saveCookie

function getCookie(name)
{											// 使用名称参数取得Cookie值, null表示Cookie不存在
  var strCookies = document.cookie;
  var cookieName = name + "=";  // Cookie名称
  var valueBegin, valueEnd, value;
  // 寻找是否有此Cookie名称
  valueBegin = strCookies.indexOf(cookieName);
  if (valueBegin == -1) return null;  // 没有此Cookie
  // 取得值的结尾位置
  valueEnd = strCookies.indexOf(";", valueBegin);
  if (valueEnd == -1)
      valueEnd = strCookies.length;  // 最後一个Cookie
  // 取得Cookie值
  value = strCookies.substring(valueBegin+cookieName.length,valueEnd);
  return value;
}//end function getCookie

function checkCookieExist(name)
{											// 检查Cookie是否存在
  if (getCookie(name))
      return true;
  else
      return false;
}//end function checkCookieExist

function deleteCookie(name, path, domain)
{											// 删除Cookie
  var strCookie;
  // 检查Cookie是否存在
  if (checkCookieExist(name))
  {										    // 设置Cookie的期限为己过期
    strCookie = name + "="; 
    strCookie += (path) ? "; path=" + path : "";
    strCookie += (domain) ? "; domain=" + domain : "";
    strCookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    document.cookie = strCookie;
  }//end if
}//end function deleteCookie