﻿// JavaScript Document
/*
Content: Active;
Remark: date,collection,home page;
Version: v0.1;
Author: guanxin.com JF.Z;
Date: 2010-07-1
*/
var Times;
var T = new Array();
var now= new Date();
var myDate = now.toLocaleString();
//格式化时间
Date.prototype.format = function(format)   
{   
   var o = {   
     "M+" : this.getMonth()+1, //month   
     "d+" : this.getDate(),    //day   
     "h+" : this.getHours(),   //hour   
     "m+" : this.getMinutes(), //minute   
     "s+" : this.getSeconds(), //second   
     "q+" : Math.floor((this.getMonth()+3)/3), //quarter   
     "S" : this.getMilliseconds() //millisecond   
   }   
   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,   
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
   for(var k in o)if(new RegExp("("+ k +")").test(format))   
     format = format.replace(RegExp.$1,   
       RegExp.$1.length==1 ? o[k] :    
         ("00"+ o[k]).substr((""+ o[k]).length));   
   return format;   
} 
//时间差
function DateDiff(sDate1,sDate2){ //sDate1和sDate2是年-月-日格式
	var aDate,oDate1,oDate2,iDays;
	aDate=sDate1.split("-");
	oDate1=new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0]);//转换为月-日-年格式 
	aDate=sDate2.split("-");
	oDate2=new Date(aDate[1] + '-'+aDate[2]+'-'+aDate[0]);
	iDays=parseInt((oDate2-oDate1)/1000);
	return iDays;
}
$(function DataTime(){
	var Length = $(".hidden").length;
	for(var i = 0; i < Length; i++){
		if($(".hidden").eq(i).val() == ""){
			Times = DateDiff(new Date().format("yyyy-MM-dd hh:mm:ss"),$(".ClosingTime").eq(i).text());
		}else{
			Times = $(".hidden").eq(i).val();
		}
		//clearInterval(T[i]);
		Times = Times - 1;
		var second = Math.floor(Times % 60);
		var minite = Math.floor((Times/60) % 60); 
		var hour = Math.floor((Times / 3600) % 24); 
		var day = Math.floor((Times / 3600 ) / 24);
		if(Times > 0){
			clearInterval(T[i]);
			$(".hidden").eq(i).val(Times);
			$(".MACCUTime").eq(i).text(day+"天"+hour+"时"+minite+"分"+second+"秒");
			T[i] = setInterval(function(){DataTime()},1000);
		}
		else{
			$(".MACCUTime").eq(i).text("已过期")
			$(".MACCUl li:eq("+i+") a").click(function(){
				return false;
			})
			$(".MACCUl li:eq("+i+") img").css({"-moz-opacity":".1"})
			$(".MACCUl li:eq("+i+") img").css({"opacity":"0.1"})
			$(".MACCUl li:eq("+i+") img").css({"filter":"gray"})
			$(".MACCUl li:eq("+i+") a").css({"cursor":"default"})
			$(".MACCUl li:eq("+i+") a").removeAttr("href");
			$(".Shopping").attr("disabled",true)
			$(".Shopping").unbind("click");
			clearInterval(T[i]);
		}

	}
});


$(function(){
	$(".collection").click(function(){
		//window.external.AddFavorite(window.location.href,"抢购乐园 关心网－关于心，传于情");
		var sURL = window.location.href;
		var sTitle = "抢购乐园 关心网－关于心，传于情";
		try 
		{ 
			window.external.addFavorite(sURL, sTitle); 
		} 
		catch (e) 
		{ 
			try 
			{ 
				window.sidebar.addPanel(sTitle, sURL, ""); 
			} 
			catch (e) 
			{ 
				alert("加入收藏失败，请使用Ctrl+D进行添加"); 
			} 
		} 

		return false;
	});
	$(".participate").click(function(){
		copyToClipBoard(window.location.href);
		alert("地址复制成功，请通过QQ、MSN发给您的好友吧，感谢您对关心网的关心与支持！");
		return false;
	})
});

function copyToClipBoard(txt)
{
 if(window.clipboardData)
 {
  // the IE-manier
  window.clipboardData.clearData();
  window.clipboardData.setData("Text", txt);
 }
 else if(navigator.userAgent.indexOf("Opera") != -1)
 {
  window.location = txt;
 }
 else if (window.netscape)
 {
  // dit is belangrijk maar staat nergens duidelijk vermeld:
  // you have to sign the code to enable this, or see notes below
  try {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  } catch (e) {
  alert("被浏览器拒绝！\n您可以在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
  }
  // maak een interface naar het clipboard
  var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
  if (!clip){return;}
  // alert(clip);
  // maak een transferable
  var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
  if (!trans){return;}
  // specificeer wat voor soort data we op willen halen; text in dit geval
  trans.addDataFlavor('text/unicode');
  // om de data uit de transferable te halen hebben we 2 nieuwe objecten 
  // nodig om het in op te slaan
  var str = new Object();
  var len = new Object();
  str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  var copytext = txt;
  str.data = copytext;
  trans.setTransferData("text/unicode",str,copytext.length*2);
  var clipid = Components.interfaces.nsIClipboard;
  if (!clip){return false;}
  clip.setData(trans,null,clipid.kGlobalClipboard);
 }
}

