//if (window.Event) {
//	document.captureEvents(Event.MOUSEUP); 
//}
//document.oncontextmenu = function nocontextmenu() {
//	event.cancelBubble = true;
//	event.returnValue = false;
//	return false;
//}
//document.onmousedown = function (e) {
//	if (window.Event) {
//		if (e.which == 2 || e.which == 3) return false;
//	}
//	else {
//		if (event.button == 2 || event.button == 3) {
//			event.cancelBubble = true;
//			event.returnValue = false;
//			return false;
//		}
//	}
//}
//document.ondragstart = function() {
//	return false;
//}
//document.onselectstart = function() {
//	return false;
//}
//// document.onselect = document.selection.empty();
//document.onkeydown = function() {
//	var iekey = event.keyCode; 
//	if(iekey == 42) {
//		window.clipboardData.clearData();
//	}
//}

/* *
 * 顯示載入信息
 */
function showLoader()
{
  $jQuery('#loader').show();
}

/* *
 * 隱藏載入信息
 */
function hideLoader()
{
  $jQuery('#loader').hide();
}

function checkSearchForm()
{
  if($jQuery.trim($jQuery('form[name="searchForm"] input[name="keywords"]').val()) == '')
  {
    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 add_email_list()
{ 
  if (check_email())
  {
		$jQuery.ajax({
			type: 'GET',
			url: 'common.php?act=email_list',
			cache: false,
			data: 'job=add&email=' + $jQuery('input[name="user_email"]').val(),
			beforeSend: function (XMLHttpRequest){      
				showLoader();
			},
			complete: function (XMLHttpRequest, textStatus){
				hideLoader();
			},
			error: function (XMLHttpRequest, textStatus, errorThrown){
				alert('對不起，系統目前發送郵件錯誤');
			},
			success: function (data, textStatus){
				alert(data);
  			$jQuery('input[name="user_email"]').val('');
			}
		});    
  }
}

function cancel_email_list()
{
  if (check_email())
  {
		$jQuery.ajax({
			type: 'GET',
			url: 'common.php?act=email_list',
			cache: false,
			data: 'job=del&email=' + $jQuery('input[name="user_email"]').val(),
			beforeSend: function (XMLHttpRequest){      
				showLoader();
			},
			complete: function (XMLHttpRequest, textStatus){
				hideLoader();
			},
			error: function (XMLHttpRequest, textStatus, errorThrown){
				alert('對不起，系統目前發送郵件錯誤');
			},
			success: function (data, textStatus){
				alert(data);
				$jQuery('input[name="user_email"]').val('');
			}
		});      
  }
}

function check_email()
{
  var msg = '';
  if($jQuery.trim($jQuery('input[name="user_email"]').val()) == '')
  {
    msg += '- 電子郵件不能為空!' + '\n';
  }
  else
  {
    REstr = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
    if (! REstr.test($jQuery('input[name="user_email"]').val()))
    {
        msg += '- 電子郵件格式不正確!' + '\n';
    }
  }

  if (msg.length > 0)
  {
    alert(msg);
    return false;
  }
  else
  {
    return true;
  }
}

function checkHTMLTag(checkObj,alertMsg)
{
  var checkStr = checkObj.value;
  var counts = 0;
  for(i = 0;i < checkStr.length; i++)
  {
    if(checkStr.charAt(i) == '<')
    {
      counts = 1;
      continue;
    }
    if(counts>=1&&checkStr.charAt(i) != '>')
    {
      counts++;
    }
    if(checkStr.charAt(i) == '>')
    {
      if(counts > 1)
      {
        alert(alertMsg + "若要使用\"<\" \">\"符號，建議您使用全形或以其他符號代替，謝謝。");
        checkObj.focus();
        return false;
      }
      else
      {
        counts=0;
      }
    }
  }
  return true;
}

if (navigator.appName.indexOf("Internet Explorer") != -1) document.onmousedown = noSourceExplorer;
function noSourceExplorer()
{ if (event.button == 2 | event.button == 3) alert("對不起喔 …… 請不要再按右鍵咯，謝謝您啊！"); }

var menuYloc = null;

$jQuery(document).ready(function(){      
  // GIF JPG 滑鼠改變圖像  
  $jQuery("img[src$=_out.gif], img[src$=_out.jpg], input[src$=_out.gif], input[src$=_out.jpg]")
    .css({cursor: 'pointer'})
    .hover(
      function () {
        var over_src = this.src.substring(0, this.src.lastIndexOf('_out' + this.src.substring(this.src.lastIndexOf('.')))) + '_over' + this.src.substring(this.src.lastIndexOf('.'));
        $jQuery(this).attr('src', over_src);
      },
      function () {
       var out_src = this.src.substring(0, this.src.lastIndexOf('_over' + this.src.substring(this.src.lastIndexOf('.')))) + '_out' + this.src.substring(this.src.lastIndexOf('.'));
        $jQuery(this).attr('src', out_src);
      }
    );
});

function addBookmarkForBrowser(sTitle, sUrl)
{
  if (window.sidebar && window.sidebar.addPanel) {
    addBookmarkForBrowser = function(sTitle, sUrl) {
      window.sidebar.addPanel(sTitle, sUrl, "");
    }
  } else if (window.external) {
    addBookmarkForBrowser = function(sTitle, sUrl) {
      window.external.AddFavorite(sUrl, sTitle);
    }
  } else {
    addBookmarkForBrowser = function() {
      alert("do it yourself");
    }
  }
  return addBookmarkForBrowser(sTitle, sUrl);
}
