/* *
 * 顯示載入信息
 */
function showLoader()
{
  var obj = $('loader');
  if (!obj)
  {
    obj = document.createElement("DIV");
    obj.id = "loader";
    obj.innerHTML = "正在處理您的請求...";

    document.body.appendChild(obj);
  }
}

/* *
 * 隱藏載入信息
 */
function hideLoader()
{
	var obj = $("loader");
	obj.style.display = 'none';
	document.body.removeChild(obj);		
}

function checkSearchForm()
{
	if($F('keywords').empty())
	{
		alert('請輸入您想查詢的產品關鍵字');
		return false;
	}
	else
	{
		return true;
	}
}

document.getCookie = function(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");

  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
      return decodeURIComponent(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

document.setCookie = function(sName, sValue, sExpires)
{
  var sCookie = sName + "=" + encodeURIComponent(sValue);
  if (sExpires != null)
  {
    sCookie += "; expires=" + sExpires;
  }

  document.cookie = sCookie;
}

document.removeCookie = function(sName, sValue)
{
  document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

function roll(id, tag, step, delay)
{
	this.it = null;
	this.init = function()
	{
		if ($(id).scrollHeight > $(id).offsetHeight + this.maxHeight())
		{
			var its = this;
			this.it = setTimeout(function(){its.scroll();},delay);
			$(id).onmouseover = function(){clearTimeout(its.it);}
			$(id).onmouseout = function(){its.it=setTimeout(function(){its.scroll();},200);}
		}
	}
	this.scroll = function()
	{
		if ($(id).getElementsByTagName(tag)[0].offsetHeight - $(id).scrollTop < step)
		{
			this.pause();
		}
		else
		{
			$(id).scrollTop += step;
			var its = this;
			this.it = setTimeout(function(){its.scroll();},10);
		}				
	}
	this.pause = function()
	{
		clearInterval(this.it);
		$(id).appendChild($(id).getElementsByTagName(tag)[0]);
		$(id).scrollTop = 0;
		var its = this;
		this.it = setTimeout(function(){its.scroll();},delay);
	}
	this.maxHeight = function()
	{
		var h = 0;
		var tags = $(id).getElementsByTagName(tag);
		for (var i=0;i<tags.length;i++)
		{
			if (tags[i].offsetHeight > h) h = tags[i].offsetHeight;
		}
		return h;
	}
	this.init();
}

/* 修复IE6以下版本PNG图片Alpha */
function fixpng()
{
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])

  if ((version >= 5.5) && (document.body.filters))
  {
     for(var i=0; i<document.images.length; i++)
     {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
           var imgID = (img.id) ? "id='" + img.id + "' " : ""
           var imgClass = (img.className) ? "class='" + img.className + "' " : ""
           var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
           var imgStyle = "display:inline-block;" + img.style.cssText
           if (img.align == "left") imgStyle = "float:left;" + imgStyle
           if (img.align == "right") imgStyle = "float:right;" + imgStyle
           if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
           var strNewHTML = "<span " + imgID + imgClass + imgTitle
           + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
           + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
           + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
           img.outerHTML = strNewHTML
           i = i-1
        }
     }
  }
}

