var gameover = '';
var sidArray = '';
var isMobile_check = '';
//Detect Device
var isMobile = false;
(function (a) {
(/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) ? isMobile = true: isMobile = false;
})(navigator.userAgent || navigator.vendor || window.opera, true, false);
if(isMobile) {
//window.location.href="http://www.fisherprice.com.tw/a-film-by-you/mobile/index.php?i=1722090502";
isMobileWeb='1';
}else{
isMobileWeb='0';
}
// alert(isMobileWeb);
/////////// Kuei Start ////////////
function SetCookie(name,value)
{
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
function delCookie(name)//删除cookie
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
function clickga(url){
ga('send','event',url,url,url);
if(window.console) console.log('clickga:'+url);
}
if(facebook_app_id!='')
{
window.fbAsyncInit = function() {
FB.init({
appId : facebook_app_id,
xfbml : true,
version : 'v2.3'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
function checkLoginStatus(response) {
if(window.console) console.log('checkLoginStatus');
if(response && response.status == 'connected') {
/*
if(window.console) {
if(window.console) console.log('Access Token: ' + response.authResponse.accessToken);
if(window.console) console.log(response);
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
console.log(response);
});
}
*/
FB.api('/me', function(response) {
$('#_fb_name').val(response.name);
$('#_fb_email').val(response.email);
$('#_fb_uid').val(response.id);
$('#_fb_gender').val(response.gender);
$('#_fb_link').val(response.link);
});
} else {
}
}
function getQueryString_kuei(param) {
var q = document.location.search || document.location.hash;
if (param == null) { return q; }
if (q) {
var pairs = q.substring(1).split("&");
for (var i = 0; i < pairs.length; i++) {
if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
return pairs[i].substring((pairs[i].indexOf("=") + 1));
}
}
}
}
var utm_source = getQueryString_kuei('utm_source');
var utm_content = getQueryString_kuei('utm_content');
var utm_campaign = getQueryString_kuei('utm_campaign');
var utm_medium = getQueryString_kuei('utm_medium');
var utm_term = getQueryString_kuei('utm_term');
var utm_source_cookie = getCookie('utm_source');
var utm_content_cookie = getCookie('utm_content');
var utm_campaign_cookie = getCookie('utm_campaign');
var utm_medium_cookie = getCookie('utm_medium');
var utm_term_cookie = getCookie('utm_term');
if((utm_source=='' || utm_source==undefined) && utm_source_cookie!='') utm_source = utm_source_cookie;
if((utm_content=='' || utm_content==undefined) && utm_content_cookie!='') utm_content = utm_content_cookie;
if((utm_campaign=='' || utm_campaign==undefined) && utm_campaign_cookie!='') utm_campaign = utm_campaign_cookie;
if((utm_medium=='' || utm_medium==undefined) && utm_medium_cookie!='') utm_medium = utm_medium_cookie;
if((utm_term=='' || utm_term==undefined) && utm_term_cookie!='') utm_term = utm_term_cookie;
function IsNumber(string,sign)
{
var number;
if (string==null) return false;
if ((sign!=null) && (sign!='-') && (sign!='+'))
{
alert('IsNumber(string,sign)的參數出錯:\nsign為null或"-"或"+"');
return false;
}
number = new Number(string);
if (isNaN(number))
{
return false;
}
else if ((sign==null) || (sign=='-' && number<0) || (sign=='+' && number>0))
{
return true;
}
else return false;
}
function ValidEmail(emailtoCheck)
{
var regExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if ( emailtoCheck.match(regExp) )
return true;
else
return false;
}
function checkField() {
if($('#uname').val()=='' || $('#uname').val()=='姓名'){
msg_trigger('msg-alert',"請填寫您的姓名!!");
// alert("請填寫您的姓名!!");
return false;
}
if($('#j-phone').val()=='' || $('#j-phone').val()=='手機號碼'){
msg_trigger('msg-alert',"請填寫您的行動電話!!");
// alert("請填寫您的行動電話!!");
return false;
}
/*
if (($('#_tel').val()!="") && (IsNumber($('#_tel').val())==false)) {
swal("手機電話需全為數字!!(請勿以符號或全形數字輸入)");
return false;
}
*/
if (($('#j-phone').val()!="") && ($('#j-phone').val().length != 10)) {
msg_trigger('msg-alert',"手機電話號碼有問題請檢查!! 謝謝!!(請勿以符號或全形數字輸入)");
return false;
}
if ($('#j-phone').val().substring(2,0)!='09') {
msg_trigger('msg-alert',"請填寫正確的手機號碼!! 謝謝!!");
return false;
}
if ((!$('#j-email').val() == "" && $('#j-email').val().indexOf('@',0) == -1) || (!$('#j-email').val() == "" && $('#j-email').val().indexOf('.',0) == -1)){
msg_trigger('msg-alert',"請填寫正確的email。");
return false;
}
if(!ValidEmail($('#j-email').val())){
msg_trigger('msg-alert',"請填寫正確電子信箱!!");
return false;
}
if($('#j-countie').val() == ''){
msg_trigger('msg-alert',"請選擇縣市!!");
return false;
}
if($('#j-district').val() == ''){
msg_trigger('msg-alert',"請選擇區域!!");
return false;
}
if($('#j-village').is(':visible') && $('#j-village').val() == ''){
msg_trigger('msg-alert',"請選擇 里!!");
return false;
}
if($('#j-address').val() == ''){
msg_trigger('msg-alert',"請填寫地址!!");
return false;
}
if($('#recaptcha_response').val()=='' || $('#recaptcha_response').val()==undefined){
msg_trigger('msg-alert','請勾選您不是機器人。');
return false;
}
return true;
}
$().ready(function(){
if(gameover=='1') msg_trigger('msg-alert','本活動已截止,感謝您的參與!');
//add facebook input
$( "body" ).append("");
var json_callback = function(msg){
//alert(msg);
if(window.console) console.log(msg);
var json = [msg];
var s = msg.Statuss;
if(s=='success') {
msg_trigger('msg-alert','謝謝您!已經收到您的資料!');
clickga('已經收到您的資料');
msg_boxs_close('msg-join')
}
else if(s=='already') {
msg_trigger('msg-alert','您已經填寫過了!');
clickga('重複填寫');
msg_boxs_close('msg-join')
}
else if(s=='shareSuccess') swal('分享成功');
else swal(s);
}
var ad1 = '';
var ad2 = '';
var area = '';
var shop = '';
var user_date = '';
if(window.console) console.log('actCode = '+actCode);
if(gameover!='1'){
//send
$('#j-submit').bind('click', function() {
if(window.console) {console.log('確認送出 click');}
var a = checkField();
if(a){
var area = '';
if($('#j-district').val()=='大安區' || $('#j-district').val()=='文山區') area = $('#j-village').val();
$.ajax({
url: 'https://sp.artstudio.com.tw/reg2016_artstudio.php',
crossDomain: true,
dataType: 'jsonp',
contentType: "application/json",
jsonpCallback: 'json_callback',
data: {
actCode: '201810_williamHsu',
uname: $('#uname').val(),
phone: $('#j-phone').val(),
email: $('#j-email').val(),
ad1: $('#j-countie').val(),
ad2:$('#j-district').val(),
area:area,
address:$('#j-address').val(),
recaptcha_response: $('#recaptcha_response').val(),
//agree: $('input[name=agree]:checked').val(),
utm_campaign:utm_campaign,
utm_medium:utm_medium,
utm_term:utm_term,
utm_source:utm_source,
utm_content:utm_content,
isMobileWeb:isMobileWeb
},
success:json_callback
//error: json_callback3
}).done(function(data){
//dddone();
});
}
});
}
});
$(window).on('load', function(){
//$( window ).load(function() {
if(window.console){console.log(window.location.host);}
});