//cookie dao
function CookieDAO(){
	var o = this;	
	this.getCookie = function( exit_cookie_name ){
		var cookieStr = document.cookie;	
		if (cookieStr == ""){
			return; 
		}	
		var cookieValue = cookieStr.split("; "); 			
		var startPos = -1;
		var endPos = -1;
		for( var i=0; i < cookieValue.length; i++ ){
			startPos = cookieValue[i].indexOf( exit_cookie_name );	
			if (startPos != 0){
				continue;
			}	
			startPos += exit_cookie_name.length + 1;
			endPos = cookieValue[i].length;				
			var exit_cookie_value = decodeURI( cookieValue[i].substring( startPos,endPos ) );
			return exit_cookie_value;
		}
		return;
	};		
	this.setCookie = function( new_cookie_name ,new_cookie_value){
		var the_date = new Date("December 31, 2020");
		var expiresDate = the_date.toGMTString();
		document.cookie = new_cookie_name + "=" + escape( new_cookie_value ) + ";expires=" + expiresDate + ";path=/;"; 
	};		
	this.deleteCookie = function( del_cookie_name ){
		var exp = new Date();   
		exp.setTime( exp.getTime() - 1 );   
		var cval = o.getCookie( del_cookie_name );   
		document.cookie = del_cookie_name + "=" + cval + "; expires=" + exp.toGMTString();  
	};		
}

window["showNoteWin"] = window["showNoteWin"] || {}
showNoteWin = {
	//创建窗口
	init:function(ext_score, notice){
		var nt_ext = ext_score.split('|');
		var nt_score = notice.split('|');
		
		var winHtml = '';
		winHtml += '<div class="ntwin" id="ntwin">';
		winHtml += '	<div class="ntwin_1">';
		winHtml += '		<div class="ntwin_2">';
		winHtml += '<div class="ntwin_inner">';
		for(i=0; i<6; i++){
			if (nt_score[i] !='0' && nt_ext[i]){
				winHtml += '<span>'+ nt_ext[i] + (nt_score[i]>0 ? '</span> <em>+'+ nt_score[i] +'</em> ' : '</span> <em>'+ nt_score[i] +'</em> ');
			}
		}
		winHtml += '</div>';
		winHtml += '		</div>';
		winHtml += '	</div>';
		winHtml += '	<a href="javascript:void(0)" class="close" close="true">X</a>';
		winHtml += '</div>';
		
		$("body").prepend(winHtml);
		
		this.$winBox = $("#ntwin");
		
		var wTop = ((document.documentElement.clientHeight || document.body.clientHeight) - this.$winBox.height())/2;
		var wLeft = ((document.documentElement.clientWidth || document.body.clientWidth) - this.$winBox.width())/2;		
		
		this.$winBox.css({top: wTop+"px", left: wLeft+"px"});
		//ie6 
		if(!!window.ActiveXObject&&!window.XMLHttpRequest){
			this.$winBox.css({position: "absolute"});
			$(window).scroll(function(){
				var tempTop = wTop + (document.documentElement.scrollTop || document.body.scrollTop);
				showNoteWin.$winBox.css({top: tempTop+"px"});	  
			});
		}
		
		this.$winBox.animate({
			opacity:'show'
		}, 300);
		//关闭按钮监听
		this.$winBox.find("a[close]").click(function(){
			showNoteWin.closeWin();
		});
		//定时关闭
		setTimeout("showNoteWin.closeWin()", 2000);
	},
	//注消窗口
	closeWin:function(){
		this.$winBox.animate({
			opacity:'hide'
		}, 300, function(){
			showNoteWin.$winBox.remove();
		});
	}
}

function autoShowCredit(){
	var myCookie = new CookieDAO();
	var ext_score = myCookie.getCookie('ext_score');
	var notice = myCookie.getCookie('notice');
	if(notice){
		showNoteWin.init(ext_score, notice);
//		myCookie.setCookie("ext_score", '');
		myCookie.setCookie("notice", '');
	}else{
		return false;
	}
}
window.onload = function(){
	setTimeout("autoShowCredit()", 500);
}

