﻿var WebName='';
var WebService='';
var WebURL='';
var WebURLSSL='';
$.ajax({ type: 'post', dataType:'json', async:true, cache:false,
	url: 'System_script.asp', 
	error: function (XMLHttpRequest, textStatus, errorThrown){
		alert('資料輸入格式或是內容輸入有錯誤!!\n\n敬請詳細檢查輸入的資料內容。');},
	success: function(data, textStatus){
		WebName=data["WebName"];
		WebService=data["WebService"];
		WebURL=data["WebURL"];
		WebURLSSL=data["WebURLSSL"];
	}
});	
var objLoading='<div style="margin: 16px"><img border="0" src="images/loading3.gif" align="middle"> Loading ...</div>';
$(document).ready(function(){
	//$('#main_Movie').html('<img border="0" src="images/Loading.gif" align="texttop"> Loading ...');
	//	$('#main_Movie').load('index_Movie.asp');
	//$('#main_Forum').html('<img border="0" src="images/Loading.gif" align="texttop"> Loading ...');
	//	$('#main_Forum').load('index_Forum.asp');
	// Update_Boutique(); //精選商品輪播
	setTimeout(function(){chk_Phone_Err();}, 4000);	//預設60000(1分鐘更新)

	//chk_Phone_Err();
	$('.MainSelect01 option:not(.slno)').css("background","#EAEAEA");
	var tmpFun=$.url().param('func');
	//var tmpMOD1=$.url().param('Products');
	if(tmpFun!=""){
		switch(tmpFun){
			case "doing":
				var tmpAID=$.url().param('aid');
				$('#Unit_Img').html('<img border="0" src="images-VType/Title10_15.gif" width="605" height="30">');
				$('#index_Content').html(objLoading).load('Activity_Main.asp?aid='+tmpAID); break;
			case "view":
				var tmpMID=$.url().param('m_no');
				var tmpDI=$.url().param('di_no');
				if(tmpDI==undefined){tmpDI=0};
				$('#index_Content').html(objLoading).load('TradeInformation.asp?ID='+tmpMID+'&di='+tmpDI); break;
			case "show":
				var tmpAR=$.url().param('area');
				var tmpPage=$.url().param('p');
				if(tmpPage==undefined){tmpPage=1};
				//alert(tmpAR1);
				Title_Img(tmpAR);
				$('#index_Content').html(objLoading).load('index_main.asp?area='+tmpAR+'&Page='+tmpPage); break;
			case "search":
				var url=$.url();
				var tmpUrl=url.attr('query');
				$('#index_Content').html(objLoading).load('index_mains.asp?'+tmpUrl); 
				$('#Unit_Img').html('<img border="0" src="images-VType/title07_15.gif" width="605" height="30">'); break;
			case "infor":
				var tmpVal=$.url().param('p');
				//alert(isNumber(tmpVal));
				Load_Service(tmpVal); break;
			case "login":
				Title_Img('1'); Login(); 
				$('#index_Content').html(objLoading).load('index_main.asp?area=1'); break;
			default:
				Title_Img('1');
				$('#index_Content').html(objLoading).load('index_main.asp?area=1'); break;
				break;
		}
	}
});
function chk_Phone_Err(){
	$.get("Chk_Phone_Err.asp", function(data) {
		if (data=="true"){
			alert("系統訊息通知：\n\n親愛會員由於過去有傳送活動簡訊失敗記錄，\n\n請會員確認行動電話，以免權利受損 !!!");
		}
	});
}
function Modal_Box(){
	$.fancybox('<div style="text-align:center; width:300px; font-size:12pt; letter-spacing:3pt; font-family:Verdana"><img border="0" src="images/loading3.gif" width="35" height="35" align="middle">處理中...</div>',{'modal' : true});
}
function main_menu(nVal){
	switch(nVal){
		case 1:
			location.href='?func=show&area=1'; break;
		case 2:
			location.href='?func=show&area=2'; break;
		case 3:
			location.href='?func=show&area=3'; break;
		case 4:
			location.href='?func=show&area=4'; break;
		case 5:
			location.href='?func=show&area=5'; break;
		case 6:
			location.href=WebURLSSL+'shop/'; break;
		default:
			break;
	}
}

function checkForm(){
	if ($('#SF1').val() == "0" ){ alert("請選擇 您要搜尋﹝產品類別﹞!!!"); $('#SF1').focus();return false;}
	$('#Unit_Img').html('<img border="0" src="images-VType/title07_15.gif" width="605" height="30">');
	var tmpVal='s1='+$('#SF1').val()+'&s2='+$('#SF2').val()+'&s3='+$('#SF3').val();
		tmpVal+='&s4='+$('#SF4').val()+'&s5='+$('#SF5').val()+'&s6='+$('#SF6').val();
	location.href='?func=search&'+tmpVal;
	//$('#index_Content').datagrid({url:'http://'}).html(objLoading).load('index_mainS.asp?'+tmpVal);
}
function SearchPage(nVal){
	//var tmpVal='s1='+$('#SF1').val()+'&s2='+$('#SF2').val()+'&s3='+$('#SF3').val();
	//	tmpVal+='&s4='+$('#SF4').val()+'&s5='+$('#SF5').val()+'&s6='+$('#SF6').val()+'&PAGE='+nVal;
	var url=$.url();
	var tmpUrl=url.attr('query');
		tmpUrl+='&PAGE='+nVal;
		$('#index_Content').load('index_mainS.asp?'+tmpUrl);
	$('#Unit_Img').html('<img border="0" src="images-VType/title07_15.gif" width="605" height="30">');
}

function Update_Boutique(){
	$('#Boutique01').load('index_Random.asp');
	$('#Boutique02').load('index_Random.asp');
	setTimeout(function(){Update_Boutique();}, 10000);
}

function Run_PR(nURL,nWidth,nHeight){		
	$.fancybox({
		'href': nURL,'width': nWidth,'height': nHeight,
		//'hideOnOverlayClick'	: false,
		//'modal' 			: true,
		'scrolling': 'no','padding': 0,'autoScale': true,
		'centerOnScroll': true,'enableEscapeButton':false,
		'overlayOpacity': 0.7,'overlayColor' : '#000',
		'transitionIn'	: 'none','transitionOut': 'none',
		'type': 'iframe'
	});
}

function JoinCart(nID,nDimension){
	$.ajax({
		type: 'post', dataType:'json', async:true, cache:false,
		url: 'JoinCart.asp?BCID='+nID+'&dimension='+nDimension,
		error: function (XMLHttpRequest, textStatus, errorThrown){alert('ERROR: Ajax error:\n'+textStatus);},
		success: function(data, textStatus){	
		if (data["Status"]==true){ location.reload(); }else{
			switch(data["Err"]){
					case "101":
						alert('抱歉!! 您能加入購物車商品已滿!!!');
					//	$.fancybox.close();
						break;
					case "102":
						alert('抱歉!! 您目前選的商品數量已大於庫存!!!');
					//	$.fancybox.close();
						break;
					case "103":
						alert('抱歉!! 您目前選的商品抵用紅利不足!!!');
						break;
					default:
						break;
				}		
			};
		}
	});
}
function Login(){
	$.post('Member_Login_Chk.asp', function(data){
		if (data=='false'){
			$.fancybox({
				'href': "Member_Login.asp",'height': 410,'width': 600,
				'scrolling': 'no','padding': 10,'autoScale': true,
				'centerOnScroll': true,'enableEscapeButton':false,
				'overlayOpacity': 0.7,'overlayColor' : '#000',
				'transitionIn'	: 'none','transitionOut': 'none',
				'showCloseButton': false, 'type': 'ajax'
			});
		}
	});
}
function LogOut(nID){
	if(window.confirm('您確定要登出嗎？')){
		$.get("logout.asp",
		function(data){
			if (data=='true'){
				var tmpFun=$.url().param('func');
				if(tmpFun=="login"){
					location.href='index.asp';
				}else{
					location.reload(); 
				}
			}
		});
	}
}
function Title_Img(nVal){
//alert(nVal);
	switch(nVal){
		case "1":
			$('#menu_img4').html('<img border="0" src="images-VType/menu_over_04.gif">');
			$('#Unit_Img').html('<img border="0" src="images-VType/title01_15.gif" width="605" height="30">'); break;
		case "2":
			$('#menu_img5').html('<img border="0" src="images-VType/menu_over_05.gif">');
			$('#Unit_Img').html('<img border="0" src="images-VType/title02_15.gif" width="605" height="30">'); break;
		case "3":
			$('#menu_img6').html('<img border="0" src="images-VType/menu_over_06.gif">');
			$('#Unit_Img').html('<img border="0" src="images-VType/title03_15.gif" width="605" height="30">'); break;
		case "4":
			$('#menu_img7').html('<img border="0" src="images-VType/menu_over_07.gif">');
			$('#Unit_Img').html('<img border="0" src="images-VType/title04_15.gif" width="605" height="30">'); break;
		case "5":
			$('#menu_img8').html('<img border="0" src="images-VType/menu_over_08.gif">');
			$('#Unit_Img').html('<img border="0" src="images-VType/title05_15.gif" width="605" height="30">'); break;
		case "6":
			$('#Unit_Img').html('<img border="0" src="images-VType/title06_15.gif" width="605" height="30">'); break;
		case "7":	//商品搜尋
			$('#Unit_Img').html('<img border="0" src="images-VType/title07_15.gif" width="605" height="30">'); break;
		default:
			break;
	}
}

function Load_Service(nVal){
	$("html,body").animate({scrollTop:0},300);
	if(isNumber(nVal)==true){
		nVal=Number(nVal);
	}else{
		var nHostName =location.hostname;
		var nPort=location.port;
		if(nPort!=''){
			var nUrl=nHostName+':'+nPort;
		}else{
			var nUrl=nHostName;
		}
		location.href='http://'+nUrl+'/index.asp';
	}
	switch(nVal){
		case 1://購物須知
			$('#Unit_Img').html('<img border="0" src="images-VType/shopTitle01_15.gif" width="605" height="30">');
			$('#index_Content').html(objLoading).load('_ShoppingTips.asp');	break;
		case 2://關於紅利點數
			$('#Unit_Img').html('<img border="0" src="images-VType/shopTitle02_15.gif" width="605" height="30">');
			$('#index_Content').html(objLoading).load('_bouns_2.asp');	break;
		case 3://常見問題
			$('#Unit_Img').html('<img border="0" src="images-VType/shopTitle03_15.gif" width="605" height="30">');
			$('#index_Content').html(objLoading).load('_qanda2.asp');	break;
		case 4://隱私權聲明及使用政策
			$('#Unit_Img').html('<img border="0" src="images-VType/shopTitle04_15.gif" width="605" height="30">');
			$('#index_Content').html(objLoading).load('_PrivacyStatement.asp');	break;
		case 5://交易約定事項
			$('#Unit_Img').html('<img border="0" src="images-VType/shopTitle05_15.gif" width="605" height="30">');
			$('#index_Content').html(objLoading).load('_bond_2.asp');	break;
		default:
			break;
	}
}
function isNumber(val){
	var reg = /^[0-9]*$/;
	return reg.test(val);
}
