/*
  - $Id$
  - $Revision$
  - $Date$
  -
  - Copyright (C) 2004 PCCW-Cascade. All rights reserved.
*/

/* This js aims to centralize the system error handling.
*  All the system error is defined as an errorObj.
*  And the error should be synchronized with application error.
*  Also, the function related to error should be located in this js.
*/



var errorList = new Array();
var errCount = 0;

// Error type: 01 Netpass/Profile checking related message
errorList[errCount] = new errObj('01001', '此功能只限MOOV足本版會員使用，請先於上方登入。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('01017', '此功能只限MOOV足本版會員使用，請於上方登入或按「確定」/「OK」申請免費ID啦！', 'alertmsg', ''); errCount++;

// Error type: 02 Error to retrieve web site data from database
errorList[errCount] = new errObj('02001', 'Invalid URL parameter while retrieve contributor list.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02002', 'Invalid role ID.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02003', 'Invalid contributor ID.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02004', 'No album data retrieve for this person.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02005', 'No data retrieve for this contributor.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02006', 'Invalid album ID.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02007', 'Invalid product ID.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02008', 'No data retrieve for this product.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('02009', 'Invalid ptype (producttype).', 'alertmsg', ''); errCount++;

// Error type: 04 Checkout related error
errorList[errCount] = new errObj('04001', 'Cannot retrieve AccountModel, AccountModel is null.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04002', 'Music service status in NETPass profile inactive.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04003', '唔好意思，你的服務已被暫停﹐請聯絡我們的客戶服務熱線 1833 833 。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04004', '仲諗！即刻申請MOOV，大把音樂俾你揀！按左邊 [立即登記]。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04005', 'Invalid product Id during transaction.', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('04407', 'password validation fail', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04408', 'User Netvigator service has been suspended.', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('04410', 'Infranet system error. Undefine result code return.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04411', 'Cannot update payment table.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04412', 'Cannot update order by OrderDAO', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04413', 'Stream grant failed!!', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04414', 'Database exception during update order, paymentId = -1', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04415', 'Cannot process license acquire.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04416', 'Infranet return fail due to criteria related to user profile.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04417', 'Infranet return fail due to criteria related to the transaction.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04418', 'Cannot retrieve DRMClientInfo.', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('04420', 'Exceed spending limit.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04431', 'Fail to retrieve product data from database.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04432', 'Fail to determine producttype in productdetails.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04433', 'Please select a valid plan.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04434', 'Product KeyId is null', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04435', 'Duplicate checkout detected.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04436', 'Invalid PassId in URL', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04437', 'Payment PIN authentication system busy, please try again later.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04438', 'User do not have a valid pass for checkout, please go to <a href="http://moov.netvigator.com/music/registration.do">here to buy plan</a>.', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('04452', 'password unmatch!', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04453', 'System error.  IOException', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04454', 'IVMS return not predefined resultcode during buy pass action', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04455', 'IVMS system error during PASS purchase', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04456', 'Checkout country code allow list not set in config file, please check!', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04457', 'You are not in the allow country list to checkout.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04458', 'Invalid Magazine ID.', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04459', '無名無姓好難搵喎。俾多少少提示，請輸入關鍵字。', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('04460', '系統偵察到重複的播放要求，即係俗語一腳踏兩Player，請你遲少少再試啦。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04461', '近排個MOOV Player怕羞，有時唔敢見人。請你俾個機會佢，試試開多次個Player。, please try again', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04462', '近排個MOOV Player怕羞，有時唔敢見人。請你俾個機會佢，試試開多次個Player。', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('04463', '你要邊種類型？', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04464', '搵來搵去都無呢首歌。不過我地仲有好多歌俾你揀，再唔係個歌名俾我地，睇下有無辦法搵俾你？', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04465', '我地處理緊喇！請等一等。呢個時候想同你講，多謝你揀MOOV！', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('04466', '呢度淨係MOOVr先睇得喎...\n不如申請MOOV一齊玩啦！', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('04473', '你的電腦未能符合Microsoft Window Media安全系統元件要求。\n請按OK 並於以下網頁進行元件更新。', 'alertmsg', ''); errCount++;

// Error type: 05 Player related error
//errorList[errCount] = new errObj('05001', 'You have reached the max limit in MySong', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05002', 'The same product has already been added to MySong', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05003', '此功能只限MOOV足本版會員使用，請先於上方登入。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05004', '明星最怕撞衫，Playlist就最怕…撞名呀，不如試試改過第二個Playlist名。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05005', 'mmm…仲差少少，想提提你未入Playlist名。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05006', '唔好咁心急，揀個Playlist先啦。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05007', '唔好意思，雖然你見到呢個Playlist，但係其實佢已經唔存在喇 ，請你再揀過第二個啦。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05008', '做人留一線，日後好相見。唔好delete晒，留返最少一個Playlist好喎。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05009', '唔好意思，而家系統好忙，請你等一陣再試啦！', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05010', '唔好意思，而家系統好忙，請你等一陣再試啦！', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05011', '開唔到新Playlist喇，因為你已經用盡50個Playlist限額，好多謝你咁鐘意MOOV的音樂。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05012', 'Playlist話：「飽晒！我60個儲歌位都滿晒，唔該主人刪走部分歌曲先啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05013', '呢個Playlist出現問題，請你揀過第二個Playlist或者歌曲啦。', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('05101', '你已經連續聽住個<br>MOOV Player成180分鐘，使<br>唔使抖抖？仲繼唔繼續呀？', 'outputmsg', ''); errCount++;
errorList[errCount] = new errObj('05102', '見你無話繼續，咁暫時停一停個Player先。你隨時再聽返啦！', 'outputmsg', ''); errCount++;
errorList[errCount] = new errObj('05103', 'Playlist話：「多謝主人為我改個新名，個名好OK喎。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05104', 'Playlist話：「奇怪！改唔到個名，可唔可以再試多次呀？」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05105', 'Playlist話：「攪掂，已經儲低你個Playlist！我會好好睇實佢！」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05106', 'Playlist話：「唔好意思，我而家播緊歌，揀個第2個Playlist先啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05107', 'Playlist話：「同我改個名先啦！」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05108', 'Playlist話：「唔好咁心急，揀個Playlist先啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05109', 'Playlist話：「主人，我而家播緊歌呀，你都係忍忍手……陣間先刪除我啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05110', 'Playlist話：「你真係咁忍心要刪除我？」', 'outputmsg', ''); errCount++;
errorList[errCount] = new errObj('05111', 'Playlist話：「唔好意思，我播緊歌呀，陣間先修改我啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05112', 'Playlist話：「你一首歌都未入又要我播歌，我好難做喎。不如你入歌先啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05113', 'Playlist話：「飽晒！我60個儲歌位都滿晒，唔該主人刪走部分歌曲先啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05114', 'Playlist話：「提提你，使唔使儲存一下呢個播緊歌的Playlist先呢？」', 'outputmsg', ''); errCount++;
errorList[errCount] = new errObj('05115', 'Playlist話：「攪掂晒！歌曲已經儲存好晒！」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05116', 'Playlist話：「提一提你。就咁熄個Player又唔儲存，你Playlist入面所有加加減減，無save到呀。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05117', '未能成功更新playlist﹐請重新再試。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05118', 'Playlist話：「主人﹐個Playlist已經成功刪除了。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05119', '唔好意思，暫時播唔到呢首歌，聽住下一首先啦 !', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05120', '你一個Playlist都冇，新增一個先啦', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05121', '(Duration Timer)唔好意思，暫時播唔到呢首歌，聽住下一首先啦 !', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05122', 'Playlist話：「提提你，使唔使儲存一下呢個Playlist先呢？」', 'outputmsg', ''); errCount++;
errorList[errCount] = new errObj('05123', 'Playlist話：「飽晒！我10個儲歌位都滿晒，唔該主人刪走部分歌曲先啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('05124', 'Playlist話：「奇怪！呢個名無效，可唔可以用第二個呀？」', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('07001', '請輸入網上行登入名稱', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('07002', '請輸入密碼', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('07003', '請選擇服務計劃', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('07004', '請選擇接受服務條款及條件', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('07005', '你已經是moov.hk的現有用戶﹐請隨時享用我們為你提供的音樂內容。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('07006', '密碼錯誤！請你重新輸入！', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('07007', '你的登記要求正在處理中﹐請稍後片刻。', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('08003', '開唔到新Playlist喇，因為你已經用盡8個Playlist限額，好多謝你咁鐘意MOOV的音樂。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('08004', 'Playlist話：「飽晒！我15個儲歌位都滿晒，唔該主人刪走部分歌曲先啦。」', 'alertmsg', ''); errCount++;

errorList[errCount] = new errObj('10020', 'Playlist話：「飽晒！我40個儲歌位都滿晒，唔該主人刪走部分歌曲先啦。」', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('10021', 'Playlist話：「請先為你個腦點Playlist改個名先啦。」', 'alertmsg', ''); errCount++;

//EYE2
errorList[errCount] = new errObj('13010', '系統繁忙，請稍後再試。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('13020', '已超過播放表最多容量40首，請選擇其他播放表或先刪除這播放表內部份歌曲/影片。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('13021', '請輸入播放表名稱。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('13115', '內容已經儲存。', 'alertmsg', ''); errCount++;
//in PC Playlist pop up player, without choosing a playlist, pressing delete
errorList[errCount] = new errObj('13116', '請先選擇一個電腦自選播放表。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('13117', '確定刪除此播放表?', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('13118', '播放表已重新命名。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('13119', '請先選擇一個電腦自選播放表。', 'alertmsg', ''); errCount++;
errorList[errCount] = new errObj('13120', '播放表已刪除。', 'alertmsg', ''); errCount++;




/********************************************************
* Common error function
*********************************************************/

function errObj(errCode, msg, action, actionURL) {
	// errCode must be an 6 digit integer (but in String)
	// first 3 digit represent error type
	// last 3 digit represent message number
	this.errCode = errCode;
	// Error message
	this.msg = msg;
	// define the action need to perform for this error
	// e.g. alertmsg, popupurl, redirect, systemerr and may have more in the future.
	this.action = action;
	// define the URL (if necessary) to handle this error.
	this.actionURL = actionURL;
}

function errActionHandler(eObj, eAct) {
	switch(eAct) {
		case "alertmsg":
			var msgprompt = '[' + eObj.errCode + ']' + '\n' + eObj.msg;
			alert(msgprompt);
			break;
		case "globalbar":
			var globalmsg = '[' + eObj.errCode + '] ' + eObj.msg;
			top.alert(globalmsg)
			if (top.control_ipf)
				top.control_ipf.showGlobalMsg(globalmsg);
		case "redirect":
			top.location.href = eObj.actionURL;
			break;
	}
}

function getErrType(eObj) {
	var eCode = eObj.errCode;
	var eType = eCode.substr(0, 3);
	return eType;
}

function getErrMsgNum(eObj) {
	var eCode = eObj.errCode;
	var eNum = eCode.substr(3, 3);
	return eNum;
}

function getErrObj(eCode) {
	for (i=0;i<errorList.length;i++) {
		var eObj = errorList[i];
		if (eObj.errCode==eCode) {
			return eObj;
		}
	}
}

function showErr(eCode, act) {
	var eObj = getErrObj(eCode);

	if(act == undefined || act=='')
		var eAct = eObj.action;
	else
		var eAct = act;

	if (eAct=="outputmsg") {
		var msgprompt = '[' + eObj.errCode + ']' + '\n' + eObj.msg;
		return msgprompt;
	} else {
		errActionHandler(eObj, eAct);
	}
}
