﻿$(function()
	{
		$('#fancybox-close').live("click",function()
			{
					$('#fancybox-wrap').remove();
					$('#fancybox-overlay').fadeOut("slow").remove();
				$('#bgDiv').remove();
				
			})
		
		$('#more_q').click(function()
			{
				$('#more_q').hide();
				$('#hide_q_block').show();
			})
		
		$('#tabdiv li').eq(0).show();
		if($('#top').length==0)
		{
				$('.bodybg').css("background-position","center 0");
		}
	})
	
 function closetop()
{					
					$('#top').hide();
					$('.bodybg').css("background-position","center 0");
}

	$(function()
{
    var tab_a=$('.tabpicli a');
    tab_a.mouseover(function()
    {
        j=tab_a.index($(this)[0]);
        tab_a.eq(j).addClass('ahove').siblings().removeClass('ahove');
        $('#tabdiv li').eq(j).show().siblings().hide();
    });
});


	$(function(){
	    $('.question h3').live("click",function()
	    {
	        $(this).siblings().slideToggle("normal");
	    
	    })
	})
	
	
	function webgg(htmlstr,url)
	{
		 show_windows();
		 html='';
	      html+='<h3 style="color:#000;">【激安公告】</h3>';
	        html+='<p>感謝大家的支持，這次團購己搶購一空，我們的團購會於每晚11:00公佈，密切留意！</p>';
	        html+='<p class="red">如果你想加推的話，請按<iframe src="http://www.facebook.com/plugins/like.php?href='+url+'&layout=button_count&show_faces=false&width=80&action=like&font=lucida+grande&colorscheme=light&height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:80px; height:25px; vertical-align:middle;" allowTransparency="true"></iframe>讓商戶知道你的支持！</p>';
	       html+='<p class="red">不想錯過下次的團購優惠，你可以訂閱每日最新激安優惠</p>';
		   html+='<p>你也可看看今日其他的團購</p><ul class="win_ul">';
		   html+=htmlstr;
		   //html+='<li><a href="">「蚌之誘惑」海鮮自助晚餐，任食超過任食超过50..！</a></li>';
		   //html+='<li><a href="">「蚌之誘惑」海鮮自助晚餐，任食超過任食超过50..！</a></li>';
		   //html+='<li><a href="">「蚌之誘惑」海鮮自助晚餐，任食超過任食超过50..！</a></li>';
		   html+='</ul>';
			$('#share_fb').html(html);
	}
	
	function fancyboxopen()
	{
		var sWidth,sHeight;
			sWidth=document.body.offsetWidth;
			sHeight=document.body.offsetHeight;
			var bgObj=document.createElement("div");
			bgObj.setAttribute('id','bgDiv');
			bgObj.style.position="absolute";
			bgObj.style.top="0";
			bgObj.style.background="#000";
			bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
			bgObj.style.opacity="0.6";
			
			bgObj.style.left="0";
			bgObj.style.width=sWidth + "px";
			bgObj.style.height=sHeight + "px";
			bgObj.style.zIndex = "1";
			document.body.appendChild(bgObj);
			
			
		 show_windows();
		 html='';
	      html+='<h3 class="colorb">會員登入</h3>';
	        html+='<form name="login" action="./userinfo.do?method=login" method="POST" class="follow-form">';
	        html+='<p class="logintext"> <label>Email</label>';
	        html+='<input type="text" value="" class="text field" id="loginemail" name="loginemail">沒有帳戶，<a href="register-and-pay.jsp">馬上申請!</a><br />';
	        html+='<label>密碼</label>';
	       html+='<input type="password" class="text field" id="loginpassword" name="loginpassword"><a href="javascript:fancyboxopen2();"  class="colorb">忘記密碼?</a></p>';
	       html+='<input type="checkbox" value="null" name="loginstatus" id="loginstatus"><a href="javascript:keeplogin();" class="colorb">記住您的密碼</a>';
	       html+='<a class="email-button" href="javascript:login();">登入</a>';
	       html+='</a></form>';
			$('#share_fb').html(html);
			
			
	}
	
	
	function fancyboxopen2()
	{
		 html='';
	      html+='<h3 class="colorb">忘記密碼</h3>';
	        html+='<form name="login" action="./userinfo.do?method=login" method="POST" class="follow-form">';
	        html+='<p class="logintext"> 請輸入您登記的電郵地址，我們會將重設密碼的指示寄給您。<br/><br/>';
	       
	        html+='<label>Email</label>';
	        html+='<input type="text" class="text field" id="resendemail" name="resendemail" style="width:270px";></p>';
	     
	       html+='<a class="email-button" href="javascript:getpassword();">提交</a>';
	       html+='</a></form>';
			$('#share_fb').html(html);
	}
	
	function fancyboxopen3()
	{
		var sWidth,sHeight;
			sWidth=document.body.offsetWidth;
			sHeight=document.body.offsetHeight;
			var bgObj=document.createElement("div");
			bgObj.setAttribute('id','bgDiv');
			bgObj.style.position="absolute";
			bgObj.style.top="0";
			bgObj.style.background="#000";
			bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
			bgObj.style.opacity="0.6";
			
			bgObj.style.left="0";
			bgObj.style.width=sWidth + "px";
			bgObj.style.height=sHeight + "px";
			bgObj.style.zIndex = "1";
			document.body.appendChild(bgObj);
			
			
		show_windows();
		 html='';
	      html+='<h3 class="colorb">忘記密碼</h3>';
	        html+='<form name="login" action="./userinfo.do?method=login" method="POST" class="follow-form">';
	         html+='<p class="logintext"> 請輸入您登記的電郵地址，我們會將重設密碼的指示寄給您。<br/><br/>';
	        html+='<label>Email</label>';
	        html+='<input type="text" class="text field" id="resendemail" name="resendemail" style="width:270px";></p>';
	     
	       html+='<a class="email-button" href="javascript:getpassword();">確定</a>';
	       html+='</a></form>';
			$('#share_fb').html(html);
			
			
	}
	
	function getpassword()
{
    var email = document.getElementById('resendemail').value;
    if(!isemail(email))
   	{
   		alert("請填寫正確的注冊郵箱地址！");
   		return;
   	}
	$.ajax({
	url: 'userinfo.do?method=getPasswordByEmail&entity.email='+email,
	type: 'POST',
	dataType: 'html',
	error: function(){alert('Error document');},
	success: function(result)
	{
		if(result == 'success')
		{
		  alert('重設密碼的訊息已送到您的電郵信箱!');
		  $('#fancybox-wrap').remove();
		  $('#fancybox-overlay').fadeOut("slow").remove();
		  $('#bgDiv').remove();
		  $('#tabdiv li').eq(0).show();
		}else{
			alert('此電郵地址並未有登記!');
		}
	}
	});
}

function show_windows(height)
{
			html='';
	        html='<div id="fancybox-overlay" style="background-color:#000; opacity:0.3; filter:alpha(opacity=30);display: block; "></div>';
	        html+='<div id="fancybox-wrap" style="opacity: 1; width: 450px; height:245px; display: block;top:'+($(document).scrollTop()+120)+'px;left:'+(document.body.offsetWidth-450)/2+'px"><div id="fancybox-outer"><div id="fancy-bg-n" class="fancy-bg"></div><div id="fancy-bg-ne" class="fancy-bg"></div><div id="fancy-bg-e" class="fancy-bg"></div><div id="fancy-bg-se" class="fancy-bg"></div><div id="fancy-bg-s" class="fancy-bg"></div><div id="fancy-bg-sw" class="fancy-bg"></div><div id="fancy-bg-w" class="fancy-bg"></div><div id="fancy-bg-nw" class="fancy-bg"></div><div id="fancybox-inner" style="top: 0px; left: 0px; width: 450px; height: 245px; overflow: auto;">';
	        html+=' <div style="width: 400px; height: 145px;" class="fanctbox-wrap" id="share_fb">';
	       html+='</div></div><a id="fancybox-close" style="display: inline;"></a><a id="fancybox-left" href="javascript:;" style="display: none;"><span id="fancybox-left-ico" class="fancy-ico"></span></a><a id="fancybox-right" href="javascript:;" style="display: none;"><span id="fancybox-right-ico" class="fancy-ico"></span></a></div></div>';
	      $('body').append(html);  
}

function iframe(url)
	{
		html="";
		html+='<div id="fancybox-overlay" style="background-color: rgb(0, 0, 0); opacity: 0.3; cursor: pointer; height: 7643px; display: block;"></div>';
		html+='<div id="fancybox-wrap" style="width: 800px; height: auto; top: '+(document.body.scrollHeight-450)+'px; left: 203px; display: block;"><div id="fancybox-outer"><div id="fancybox-bg-n" class="fancybox-bg"></div><div id="fancybox-bg-ne" class="fancybox-bg"></div><div id="fancybox-bg-e" class="fancybox-bg"></div><div id="fancybox-bg-se" class="fancybox-bg"></div><div id="fancybox-bg-s" class="fancybox-bg"></div><div id="fancybox-bg-sw" class="fancybox-bg"></div><div id="fancybox-bg-w" class="fancybox-bg"></div><div id="fancybox-bg-nw" class="fancybox-bg"></div><div id="fancybox-content" style="border-width: 0px; width: 800px; height: 317px;"><iframe scrolling="auto" frameborder="0" src="'+url+'" hspace="0" name="fancybox-frame1304845363734" id="fancybox-frame"></iframe></div><a id="fancybox-close" style="display: inline;"></a><div id="fancybox-title" style="display: none;"></div><a id="fancybox-left" href="javascript:;"><span id="fancybox-left-ico" class="fancy-ico"></span></a><a id="fancybox-right" href="javascript:;"><span id="fancybox-right-ico" class="fancy-ico"></span></a></div></div>';
	    $('body').append(html);  
	};

function login()
{
    var email = document.getElementById('loginemail').value;
    var password = document.getElementById('loginpassword').value;
    var loginstatus = document.getElementById('loginstatus').value;
    if(email == "")
    {
    	alert('請填寫郵件地址！');
    	return;
    }
    if(password == "")
    {
    	alert('請填密碼！');
    	return;
    }
	$.ajax({
	url: 'userinfo.do?method=login&flg=ajaxlogin&entity.email='+email+'&entity.password='+password+'&loginstatus='+loginstatus,
	type: 'POST',
	dataType: 'html',
	error: function(){alert('Error document');},
	success: function(result)
	{
		if(result == 'success')
		{
		var url = location.search;
		if(url.indexOf("logout") != -1) 
     		self.location.href='welcome.jsp';
     	else
     		self.location.reload();
		}else if(result == 'verify'){
			alert('登錄失敗，請登錄您的註冊郵箱進行賬戶啟動！\n提示：電郵可能會意外掉進『垃圾郵件』信箱，\n請把admin@gigonzone.com加入您的聯絡人清單。');
		}
		else{
			alert('登錄失敗！');
		}
	}
	});
}

function keeplogin()
{
	document.getElementById('loginstatus').checked = true;
	document.getElementById('loginstatus').value = 'true';
}

function subscribe()
{ 
    var email = document.getElementById('email').value;
    if(!isemail(email))
   	{
   		alert("請輸入一個有效的電郵地址！");
   		return;
   	}
	$.ajax({
	url: 'maillist.do?method=saveMailList&entity.mailaddress='+email,
	type: 'POST',
	dataType: 'html',
	error: function(){alert('Error loading PHP document');},
	success: function(result)
			{
				if(result.length == 9)
				{
					alert("成功登記，你將會收到我們最新的優惠通訊！");
				}else{
					alert("你的電郵地址已登記，請重新填寫！");
				}
			}
	});
}

function isemail(theStr){
		if(theStr.indexOf(' ')>0)
			return false;
	    var atindex=theStr.indexOf('@');
	    var dotindex=theStr.indexOf('.',atindex);
	    var flag=true;
	    thesub=theStr.substring(0,dotindex+1);
	    if((atindex<1)||(atindex!=theStr.lastIndexOf('@'))||(dotindex<atindex+2)||(theStr.length<=thesub.length)){
	      flag=false;
	    }else{
	     var thesub1=theStr.substring(dotindex+1);
	     if((thesub1.indexOf('@')>0) || (thesub1.indexOf(',')>0) || (thesub1.indexOf('，')>0) || (thesub1.indexOf(';')>0) || (thesub1.indexOf(':')>0))
	    	flag=false;
	     else
	      flag=true;
	    }
      return(flag);
   }

   	function emailopen(id,name)
	{
		   show_windows();
		   $('#fancybox-inner').css('height','275px');
		   $('#fancybox-wrap').css('height','275px');
		   html='';
	       html+='<h3 class="colorb">Email給朋友</h3>';
	       html+='<input type="hidden" name="productid" id="productid" value="'+id+'">';
		   html+='<input type="hidden" name="product" id="product" value="'+name+'">';
	       //html+='<form name="login" action="./userinfo.do?method=login" method="POST">';
	       html+='<div class="f_l fontc"><div><div>朋友的電郵地址:</div><div><input type="text" name="friendaddress" id="friendaddress"></div><div>(請以分號分隔電郵地址)</div></div>';
		   html+='<div><div>你的稱呼:</div><div><input type="text" name="nickname" id="nickname"></div></div>';
		   html+='<div><div>你的電郵地址:</div><div><input type="text" name="myaddress" id="myaddress"></div></div></div>';
		   html+='<div class="f_r fontd"><div>訊息 :</div><div><textarea onfocus="if(value==\'限二百五十個字\'){value=\'\'}" name="content" id="content" value="限二百五十個字" class="paygive_input2"></textarea></div></div>';
		   html+='<div class="clear"><a href="javascript:send()" class="email-button" style="float:left;margin-top:19px;margin-left: 87px;margin-right:9px;">發送</a><a href="javascript:colsewinds()" class="email-button"  style="float:left;margin-top:19px;">取消</a></div>';
		   //html+='</form>';
		   $('#share_fb').html(html);
	}
	
	function colsewinds()
	{
		   $('#fancybox-wrap').remove();
		   $('#fancybox-overlay').fadeOut("slow").remove();
	}

function Trim(str,is_global) 
{ 
	var result; 
	result = str.replace(/(^\s+)|(\s+$)/g,""); 
	if(is_global.toLowerCase()=="g") 
	result = result.replace(/\s/g,""); 
	return result; 
}

	function send()
{
    var friendaddress = document.getElementById('friendaddress').value;
    friendaddress = Trim(friendaddress,'g');
    var nickname = document.getElementById('nickname').value;
    var myaddress = document.getElementById('myaddress').value;
    var content = document.getElementById('content').value;
    var product = document.getElementById('product').value;
    var productid = document.getElementById('productid').value;
    
    var patrn=/^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$/; 
	if (!patrn.exec(friendaddress))
	{
		alert("請填寫正確的電郵地址；若有多個電郵地址，請用英文分號隔開!");
		return; 
	}
    if(nickname == "")
    {
    	alert('請填你的稱呼！');
    	return;
    }
    if(myaddress == "")
    {
    	alert('請填你的電郵地址！');
    	return;
    }
    if(content == "")
    {
    	alert('請填内容！');
    	return;
    }
    if(content.length > 250)
    {
    	alert('限二百五十個字！');
    	return;
    }
	$.ajax({
	url: 'maillist.do?method=mailShare&friendaddress='+friendaddress+'&nickname='+nickname+'&myaddress='+myaddress+'&content='+content+'&productid='+productid+'&product='+product,
	type: 'POST',
	dataType: 'text',
	error: function(){Dialog.alert('Error document');},
	success: function(result)
	{
		if(result.length > 6)
		{
			alert('郵件已發送！');
			colsewinds();
		}else{
			alert('發送失敗！');
		}
	}
	});
}
