﻿var brOK=false;
var isIE=false;
var vmin=2;
var vmax=5;
var vr=3;
var timer1;
var floatAD;
var contextMenuFlag=true;
var selectStartFlag=true;	//反白
var mouseMoveFlag=true;
var mouseDownFlag=true;
var dragStartFlag=true;		//拖拉
var printFlag=false;		//印表機列印
var docCopyFlag=true;		//複製

//=========================================================
//========右鍵,反白========
if(navigator.appName.indexOf('Internet Explorer')==-1||(navigator.userAgent.indexOf('MSIE')!=-1&&document.all.length!=0)){
	if(document.all){
		var mac,version;
		mac=navigator.userAgent.indexOf('Mac')!=-1;
		version=parseFloat('0'+navigator.userAgent.substr(navigator.userAgent.indexOf('MSIE')+5),10);
		if(!mac&&version>4){
			document.oncontextmenu=contextMenu;
		}else{
			document.onmousedown=mouseDown;
			document.onkeydown=mouseDown;
		}
		document.onselectstart=selectStart;
	}else if(document.layers){
		window.captureEvents(Event.MOUSEDOWN|Event.modifiers|Event.KEYDOWN|Event.MOUSEUP);
		window.onmousedown=mouseDown;
		window.onkeydown=mouseDown;
		window.onmouseup=mouseUp;
	}else if(document.getElementById&&!document.all){
		document.oncontextmenu=contextMenu;
		document.onmousedown=mouseDown1;
	}
}
function contextMenu(){
	return contextMenuFlag;
}
function mouseDown(e){
	var mac;
	mac=navigator.userAgent.indexOf('Mac')!=-1;
	if(document.all){
		if(event.button==2||(mac&&(event.ctrlKey||event.keyCode==91))){
			return mouseDownFlag;;
		}
	}else{
		if(e.which==3||(mac&&(e.modifiers==2||e.ctrlKey))){
			return mouseDownFlag;
		}else if(e.which==1){
			window.captureEvents(Event.MOUSEMOVE);
			window.onmousemove=mouseMove;
		}
	}
}
function mouseUp(e){
	if(e.which==1){
		window.releaseEvents(Event.MOUSEMOVE);
		window.onmousemove=null;
	}
}
function mouseDown1(e){
	return (e.target.tagName!=null&&e.target.tagName.search('^(INPUT|TEXTAREA|BUTTON|SELECT)$')!=-1);
}
function mouseMove(a){
	return mouseMoveFlag;
}
function selectStart(E){
	return selectStartFlag;
}
//========右鍵,反白========

//========拖拉文字========
document.ondragstart=dragStart;
function dragStart(){
	return dragStartFlag;
}
//========拖拉文字========

//========列表機列印========
if (!printFlag){
	document.write('<style type="text/css" media="print"><!--body{display:none}--></style>');
}

window.onbeforeprint=beforPrint;
window.onafterprint=afterPrint;
function beforPrint(){
	for(i=0;i<document.all.length;i++){
		if(document.all[i].style.visibility!="hidden"){
			document.all[i].style.visibility="hidden";
			document.all[i].id="printId";
		}
	}
}
function afterPrint(){
	for(i=0;i<document.all.length;i++){
		if(document.all[i].id=="printId") document.all[i].style.visibility="";
	}
}
//========列表機列印========

//========PrintScreen & Ctrl+C========
if (!docCopyFlag){
	if(navigator.appName.indexOf('Internet Explorer')==-1||(navigator.userAgent.indexOf('MSIE')!=-1&&document.all.length!=0)){
		if(document.all&&navigator.userAgent.indexOf('Opera')==-1){
			document.write('<div style="position:absolute;left:-1000px;top:-1000px"><input type="textarea" name="copyText" value=" " style="visibility:hidden"></div>');
			docCopy();
		}
	}
}
function docCopy(){
	copyText.createTextRange().execCommand("Copy");
	setTimeout("docCopy()",300);
}
//========PrintScreen & Ctrl+C========

//=========================================================

function moveChip(adName)
{
	if (brOK){
		eval("chip="+adName);
		if(!isIE)
		{
			pageX=window.pageXOffset;
			pageW=window.innerWidth;
			pageY=window.pageYOffset;
			pageH=window.innerHeight;
		} 
		else
		{
			pageX=window.document.body.scrollLeft;
			pageW=window.document.body.offsetWidth-8;
			pageY=window.document.body.scrollTop;
			pageH=window.document.body.offsetHeight;
		}
		chip.xx=chip.xx+chip.vx;
		chip.yy=chip.yy+chip.vy;
		chip.vx+=vr*(Math.random()-0.5);
		chip.vy+=vr*(Math.random()-0.5);
		if(chip.vx>(vmax+vmin))  chip.vx=(vmax+vmin)*2-chip.vx;
		if(chip.vx<(-vmax-vmin)) chip.vx=(-vmax-vmin)*2-chip.vx;
		if(chip.vy>(vmax+vmin))  chip.vy=(vmax+vmin)*2-chip.vy;
		if(chip.vy<(-vmax-vmin)) chip.vy=(-vmax-vmin)*2-chip.vy;
		if(chip.xx<=pageX)
		{
			chip.xx=pageX;
			chip.vx=vmin+vmax*Math.random();
		}
		if(chip.xx>=pageX+pageW-chip.w)
		{
			chip.xx=pageX+pageW-chip.w;
			chip.vx=-vmin-vmax*Math.random();
		}
		if(chip.xx>=680)
		{
			chip.xx=chip.xx-20;
			chip.vx=-vmin-vmax*Math.random();
		}
		if(chip.yy<=pageY)
		{
			chip.yy=pageY;
			chip.vy=vmin+vmax*Math.random();
		}
		if(chip.yy>=pageY+pageH-chip.h)
		{
			chip.yy=pageY+pageH-chip.h;
			chip.vy=-vmin-vmax*Math.random();
		}
		if(!isIE)
		{
			eval('document.getElementById("'+chip.named+'").top ='+chip.yy);
			eval('document.getElementById("'+chip.named+'").left='+chip.xx);
		}
		else
		{
			eval('document.getElementById("'+chip.named+'").style.pixelLeft='+chip.xx);
			eval('document.getElementById("'+chip.named+'").style.pixelTop ='+chip.yy);
		}
		chip.timer1=setTimeout("moveChip('"+chip.named+"')",80);
	}
}

function stopChip(adName)
{
	if (brOK){
		eval("chip="+adName);
		if(chip.timer1!=null)
		{
			clearTimeout(chip.timer1)
		}
	}
}

function floatAD(adName)
{
	if (adName!=""){
		if(navigator.appName.indexOf("Internet Explorer")!=-1)
		{
			if(parseInt(navigator.appVersion.substring(0,1))>=4) brOK=navigator.javaEnabled();
			isIE=true;
		}
		if(navigator.appName.indexOf("Netscape")!=-1)
		{
			if(parseInt(navigator.appVersion.substring(0,1))>=4) brOK=navigator.javaEnabled();
		}
		floatAD.named=adName;
		floatAD.vx=vmin+vmax*Math.random();
		floatAD.vy=vmin+vmax*Math.random();
		floatAD.w=1;
		floatAD.h=1;
		floatAD.xx=0;
		floatAD.yy=0;
		floatAD.timer1=null;
		moveChip(adName);
	}
}

function imgView(imgFilePath){
	//window.open("viewImage.asp?imgFilePath="+ imgFilePath,"","width=10,height=10,toolbar=no");
	window.open("viewImage.asp?imgFilePath="+ imgFilePath,"","width=10,height=10,toolbar=no,scrollbars=yes");
}

function chgShopItem(pdNo,count,size,color,bonus,extra,epPdNo,no,chgFlag,func){
	/*
	startPOSTRequest("shopItemChange.asp",false,"pdNo="+ pdNo +"&count="+ count +"&size="+ size +"&color="+ color +"&bonus="+ bonus +"&extra="+ extra +"&epPdNo="+ epPdNo +"&no="+ no +"&chgFlag="+ chgFlag);
	switch (responseText){
		case "0":
			if (func!=""){
				eval(func);
			}else{
				location.reload();
			}
			break;
		case "1":
			alert("參數錯誤!!");
			break;
		case "2":
			alert("選購失敗!!");
			break;
		case "3":
			alert("紅利點數不足!!");
			break;
		case "4":
			alert("選購加購商品前先購買主商品!!");
			break;
		case "5":
			alert("加購商品數量大於主商品數量!!");
			break;
		default:
			alert("未知錯誤!!");
			break;
	}
	*/
	var para;
		para="pdNo="+ pdNo +"&count="+ count +"&size="+ size +"&color="+ color +"&bonus="+ bonus +"&extra="+ extra +"&epPdNo="+ epPdNo +"&no="+ no +"&chgFlag="+ chgFlag;
	chkShopItem(para,func);
	return false;
}

function chkShopItem(para,func){
	var request;
	var actionUrl,async;
		actionUrl="shopItemChange.asp";
		async=false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			// 新版的 IE
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
					// 舊版的 IE
					request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("流覽器不支持XMLHTTP!!");
				return;
			}
		}
	}
	if (!request) {
		return false;
	}
	request.open("POST", actionUrl,async);
	request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	request.send(para);
	try{
		if(!async){
			request.onreadystatechange = handleShopItemStateChange(request,func);
		}else{
			handleShopItemStateChange(request,func);
		}
	}catch(e){}
}

function handleShopItemStateChange(request,func) {
	var responseText;
		responseText="";
	if(request.readyState == 4) {
		if(request.status == 200) {
			responseText=request.responseText;
			switch (responseText){
				case "0":
					if (func!=""){
						eval(func);
					}else{
						location.reload();
					}
					break;
				case "1":
					alert("參數錯誤!!");
					break;
				case "2":
					alert("選購失敗!!");
					break;
				case "3":
					alert("紅利點數不足!!");
					break;
				case "4":
					alert("選購加購商品前先購買主商品!!");
					break;
				case "5":
					alert("加購商品數量大於主商品數量!!");
					break;
				default:
					alert("未知錯誤!!");
					break;
			}
		}
	}
}