var Tool = {
		ShowLogin	: function (){
				var frm = '<div id="ballaninnerHTML"></div>';
				var bwh = 600+"px";
				var bht = 400+"px";
				$j.blockUI({css: { top: '20%' ,width: bwh, height: bht ,border:'none' ,background:'transparent'},message: frm });
				var strHTML = '<div id="ipeen_login_frame">'+
								'<div class="ipeen_logon_btn" style="height:255px; width:406px; overflow:hidden;"><a href="javascript:void(0);" onclick="Tool.loginCHK()" >登入</a></div>'+
								'<div class="close_btn_2"><a href="javascript:void(0);" title="關閉愛評網登入視窗" onclick="Tool.closea();"></a></div>'+
								'<p class="id_name">帳號&nbsp;/&nbsp;E-mail:</p><input type="text"  name="loginacc" id="loginacc" class="name" size="33"/>'+
								'<p class="password">密碼:</p><input name="loginpwd" id="loginpwd" type="password"  class="pass" size="28"/>'+
								'<p class="forget_pass"><a href="/signin/forget.php">忘記密碼</a></p><input name="" type="checkbox" value=""  class="remember"/>'+
								'<p class="remember_id">記住我的帳號</p><p class="join_ipeen_free">還沒加入愛評網的行列嗎??<a href="/register/register.php?event=1">點此免費加入</a></p><p id="errorid" class="wrong"></p></div>';
				document.getElementById('ballaninnerHTML').innerHTML = strHTML;
		},
		login		: function( i ){
			type = (i == 0)?4:5;
			Tool.view(type);
			V.type=i;
			if( !loginDialog.loggedIn() ) {
	            // loginDialog.show();
				Tool.ShowLogin();
				return false;
			}
			Tool.ajax(1);
		},		
		ajax		: function(c){
			$.ajax({
				url		: 'requests/updatePush.php',
				data	: 'type='+V.type,
				type	: 'POST',
				cache	: false,
				success	: function(res){
				
					if(c!=1){
						Tool.close();
					}						
					if(V.type == 1){
						window.open("http:\/\/www.plurk.com\/?qualifier=shares&status=參加 http:%2F%2Fevent.ipeen.com.tw%2Ficepuppylove (《我的初戀囧事徵文看電影》) ，就抽【初戀紅豆冰】特映券和限量好禮！");
					}else{
						window.open("http:\/\/www.facebook.com\/sharer.php?u=http:\/\/event.ipeen.com.tw/icepuppylove/");
					}
					window.location.reload();
				}
			});
		},
		loginCHK	: function (){
			if(document.getElementById('loginacc').value != '' && document.getElementById('loginpwd').value != ''){
		    	var item = {
							pram: 'account='+document.getElementById('loginacc').value+'&passwd='+document.getElementById('loginpwd').value,
							url:  '/cgi/proc_login.php',
							type: 'POST'
		            	};
				$.ajax({
					url: item.url,
					data: item.pram,
					type: item.type,
					cache: false,
					success: function(res){
						var resjson = eval('('+res+')');
						if(resjson.r == true || resjson.m == 'LOGINED'){
							Tool.ajax(0);
						}else{
							document.getElementById('errorid').innerHTML = "帳號、密碼錯誤";
						}
					}
				});
			}else{
				alert('帳號密碼不能空白');
			}	
		},
		close 		: function (){
				$j.unblockUI(); 	
		},
		closea		: function(){
				Tool.close();
				Tool.gotoback();
		},		
		gotoback	: function (){
				if(V.type == 1){
					window.open("http:\/\/www.plurk.com\/?qualifier=shares&status=參加 http:%2F%2Fevent.ipeen.com.tw%2Ficepuppylove (《我的初戀囧事徵文看電影》) ，就抽【初戀紅豆冰】特映券和限量好禮！");
				}else{
					window.open("http:\/\/www.facebook.com\/sharer.php?u=http:\/\/event.ipeen.com.tw/icepuppylove");
				}
				setTimeout("window.location.reload();",1500);
		},
		view		: function (type){
				$.ajax({
					url: 'requests/action.php',
					data: 'action='+type,
					type: 'POST',
					cache: false,
					success: function(res){}
				});
		}
};
