// Remind
// Code By Mudoo 2008.8.1
// 
// Remind.js?2007-9-3

var remCommon = {
	// getElementById
	$ : function(element) {
		return typeof(element) == 'object' ? element : document.getElementById(element);
	},
	
	// 判断浏览器
	brower : function() {
		var ua = navigator.userAgent.toLowerCase();
		var os = new Object();
		os.isFirefox = ua.indexOf ('gecko') != -1;
		os.isOpera = ua.indexOf ('opera') != -1;
		os.isIE = !os.isOpera && ua.indexOf ('msie') != -1;
		os.isIE7 = os.isIE && ua.indexOf ('7.0') != -1;
		return os;
	},
	
	// 返回两个日期的天数差
	getDateDiff : function(sDate, eDate){
		var re = /^(\d{4})\S(\d{1,2})\S(\d{1,2})$/;
		var dt1, dt2;
		if (re.test(sDate)) {
			dt1 = new Date(RegExp.$1,RegExp.$2 - 1,RegExp.$3);
		}
		if (re.test(eDate)) {
			dt2 = new Date(RegExp.$1,RegExp.$2 - 1,RegExp.$3);
		}
		return Math.floor((dt2-dt1)/(1000 * 60 * 60 * 24));
	},

	// 获取服务器地址跟传进来的日期
	getPost : function() {
		var oScripts=document.getElementsByTagName("script");
		var sLen = oScripts.length;
		var sPath;
		for(var i=0; i<sLen; i++){
			var sSrc=oScripts[i].src.toLowerCase();
			if(sSrc.indexOf("remind.js")!=-1) sPath=oScripts[i].src;
		}
		
		var sPlace = sPath.indexOf('?');
		var strPath = sPath.substring(0, sPlace-9);
		var strDate = sPath.substr(sPlace + 1);
		//alert(strDate.replace(/.*(\d{4})\S(\d{1,2})\S(\d{1,2}).*/, '$1-$2-$3'));
		return {path : strPath, date : strDate};
	}
};


var postData = remCommon.getPost();
var remind = {
	// 参数设置
	serverPath	: postData.path,		// 服务器地址(存放Remind的地址)
	expireDate	: postData.date,		// 结束日期('2008-9-3')
	remDate		: 30,					// 提前提示天数
	timeLeft	: 10,					// 定时关闭时间(秒)
	doTimeout	: null,					// 计时关闭
	remTitle	: '系统提示',				// 弹出框标题
	remText		: '<strong>您的网站将于$date$到期</strong><p>为不影响您网站的正常访问，请尽快<a href="###">与商务领航客服联系</a>。</p>',
	
	// 初始化
	init : function() {
		remind.setStyle();
		var date = new Date()
		var now = date.getFullYear() +'-'+ (date.getMonth()+1) +'-'+ date.getDate();
		var diffDate = remCommon.getDateDiff(now, remind.expireDate);
		if(diffDate<=remind.remDate && diffDate>=0) remind.show(now, diffDate);
	},
	
	// 设置样式
	setStyle : function() {
		var os = remCommon.brower();
		var styleStr = ""+
			"<style type=\"text\/css\">\n"+
			"<!--\n"+
			"html, body {height: auto !important; height: 100%; overflow: auto; margin: 0}"+
			"#Remind {position: fixed !important; position: absolute; width: 260px; right: "+ ((os.isIE && !os.isIE7) ? "26px" : "10px") +"; bottom: 10px; background: #f1f7f8; padding: 2px;}"+
			((os.isIE && !os.isIE7) ? "* html #Remind {right: 26px}" : "") +
			"#Remind .remTitle {font-size: 12px; font-weight: bold; color: #2c71af; height: 28px; line-height: 28px; padding: 0 10px; overflow: hidden; background: url("+ remind.serverPath +"Images\/Rem_TitleBg.gif) repeat-x; border: #7b9fba solid 1px; border-bottom: none}"+
			"#Remind a.remClose {float: right; height: 10px; margin-top: 10px}"+
			"#Remind a.remClose img {width: 10px; height: 10px; border: none; background: url("+ remind.serverPath +"Images\/Rem_Close.gif) 0 0 no-repeat}"+
			"#Remind a.remClose:hover img {background: url("+ remind.serverPath +"Images\/Rem_Close.gif) -10px 0 no-repeat}"+
			"#Remind .remContWarp {background: url("+ remind.serverPath +"Images\/Rem_CongBg.gif) #fbfeff left bottom repeat-x; padding: 1px; border: #7b9fba solid 1px; border-top: none}"+
			"#remCont {height: 100px; font-size: 12px; color: #265e90; line-height: 20px; padding: 12px 10px 0 85px}"+
			((os.isIE && !os.isIE7) ? "#Remind #remCont {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src=\""+ remind.serverPath +"Images\/Rem_Icon.png\"); background: none;}" : "#Remind #remCont {background: url("+ remind.serverPath +"Images\/Rem_Icon.png) left top no-repeat;}") +
			"#remCont a {color: #0044dd; text-decoration: underline; position: relative}"+
			"#remCont strong {font-weight: bold}"+
			"#remCont p {margin-top: 10px}"+
			"\n-->"+
			"\n<\/style>";
		document.write(styleStr);
	},
	
	// 弹出
	show : function(now, dateLeft) {	
		// 生成弹出框
		var remObj = remCommon.$("Remind");
		var dateText = dateLeft==0 ? "明天" : ("<span style=\"font: bold 12px Tahoma; color: #ff6600; margin: 0 5px\">"+ dateLeft +"</span>天后");
		dateText = remind.remText.replace('$date$', dateText);
		
		if(remObj==null) {
			var html = ""+
				"<div id=\"Remind\">"+
				"	<div class=\"remTitle\"><a href=\"javascript:void(0);\" onclick=\"remind.hide();\" class=\"remClose\"><img src=\""+ remind.serverPath +"Images\/Space.gif\" \/><\/a>"+ remind.remTitle +"<\/div>"+
				"	<div class=\"remContWarp\">"+
				"		<div id=\"remCont\">"+ dateText +"<\/div>"+
				"	<\/div>"+
				"<\/div>";
			document.write(html);
			remObj = remCommon.$("Remind");
		}else{
			remCommon.$("remCont").innerHTML = dateText;
		}
		
		// 显示
		remObj.style.display = '';
		// 定时关闭
		clearTimeout(remind.doTimeout);
		remind.doTimeout = setTimeout(remind.hide, remind.timeLeft*1000);
		
		// 设置事件
		remObj.onmouseover = function() {
			clearTimeout(remind.doTimeout);
		}
		remObj.onmouseout = function() {
			remind.doTimeout = setTimeout(remind.hide, remind.timeLeft*1000);
		}
	},
	
	// 关闭
	hide : function() {
		clearTimeout(remind.doTimeout);
		var remObj = remCommon.$("Remind");
		remObj.style.display = 'none';
	}
};

try{
	remind.init();
}catch(e){}

