

function AccountAPI_Sim() {
	this.udbLogin = function(urlAfterLogined, x, y, width, height, arg) { alert('Sorry, not support udbLogin api!'); }
	this.logout = function() {alert('Sorry, not support logout api!');}
	this.getBindHistory = function() {
		return JSON.stringify([{account:"user1@189.cn", syncFolder:"X:", cryptFile:"C:\\.eDrive\\xxxx", needPassword:1},
		{account:"user2@189.cn", syncFolder:"X:", cryptFile:"C:\\.eDrive\\xxxx", needPassword:0},
		{account:"user3@189.cn", syncFolder:"D:\\disk", cryptFile:"", needPassword:0}]);

	}
	this.bindSyncSetting = function(account, syncFolder, cryptFile, needPassword) {alert('account:' + account + ' syncFolder:'+ syncFolder +' cryptFile:' + cryptFile + ' needPassword:' + needPassword);}
	this.getLoggedInAccount = function() {return "18900000000@189.cn";}
	this.tryLoadeDriveInfo = function(callbackFunc, tag) {
		setTimeout(function() {
			alert('ok');
			eval(callbackFunc)(0, JSON.stringify({code:"OK", detailMsg:"", info:{spaceCap:1024000000,spaceAva:1000000000,maxFileSize:100000000, flowCap:102400,flowAva:20000}}), tag);
		} , 2000);
	}
	this.tryLogin = function(account, password, autoLogin, callbackFunc, tag) {
		setTimeout(function() {
			alert('login ok');
			eval(callbackFunc)(0, JSON.stringify({code:"OK", detailMsg:""}), tag);
		} , 2000);
	}
	this.tryCheckUserSign = function(callbackFunc, tag) {
		setTimeout(function() {
			alert('check sign ok');
			eval(callbackFunc)(0, JSON.stringify({result:0}), tag);
		} , 2000);
	}
	this.tryUserSign = function(callbackFunc, tag) {
		setTimeout(function() {
			alert('check sign ok');
			eval(callbackFunc)(0, JSON.stringify({result:1, resultTip:"恭喜，你已获得100M空间！"}), tag);
		} , 2000);
	}
	
	this.changeUserConfig = function(account, config) {
	}
	this.getUserConfig = function(account) {
		return JSON.stringify({	cachedVDiskPassword: '123456',
  													autoMountVDisk: 1,
  													cachedAccountPassword: '123456',
  													autoLogin: 1
		});
	}
	this.deleteBindHistory = function(account) {
		alert('deleteBindHistory');
		return 0;
	}
	
}

function VDiskAPI_Sim() {
	this.tryCreateVDisk = function(drive, password, fsType, sizeGB, callbackFunc, tag) {
		setTimeout(function() {
			alert('ok');
			eval(callbackFunc)(0, JSON.stringify({cryptFile:"C:\\.eDrive\\xxxx"}), tag);
		} , 2000);
	}
	this.tryMountVDisk = function(cryptFile, password, callbackFunc, tag) {
		setTimeout(function() {
			alert('ok');
			eval(callbackFunc)(0, "", tag);
		} , 2000);
	}
	this.selectSyncFolder = function() { return "C:\\eDrive"}
	this.getLocalDriveInfo = function() {
		return JSON.stringify([{drive:"C:", fsType:"NTFS", freeSpaceGB:10}
		,{drive:"D:", fsType:"FAT32", freeSpaceGB:20}]);
	}
}

function FileShareAPI_Sim() {
	this.tryShareFile = function(fileId, email, mobile, callbackFunc, tag) {
		setTimeout(function() {
			alert('ok');
			eval(callbackFunc)(0, JSON.stringify({code:"OK", detailMsg:""}), tag);
		} , 2000);
	}
	this.tryUnshareFile = function(fileId, callbackFunc, tag) {
		setTimeout(function() {
			alert('ok');
			eval(callbackFunc)(0, JSON.stringify({code:"OK", detailMsg:""}), tag);
		} , 2000);
	}
}

function FileSyncAPI_Sim() {
	this.getSyncTaskQueueInfo = function(maxTasks) {
		return JSON.stringify({lastStamp:"123", info:[{fileId:"xxxx", localPath:"C:\\xxx\\xxxx.zip", fileName:"xxxx.zip", totalSize:102400, op:"up", status:1}
		,{fileId:"dddd", localPath:"C:\\xxx\\xxxx.rar", fileName:"xxxx.rar", totalSize:204800, op:"down", status:2}]});

		}
		this.getSyncProgress = function(fileIdArray) {
			return JSON.stringify({lastStamp:"123", progress:[{fileId:"xxxx", status:1, txSize:10000, txRate:80000}
			,{fileId:"dddd", status:2, txSize:0, txRate:0}]});

			}
			this.registerSyncObserver = function(callbackFunc) { alert('Sorry, not support registerSyncObserver api!'); }
			this.unregisterSyncObserver = function(callbackFunc) { alert('Sorry, not support unregisterSyncObserver api!'); }
		}

		function OpHistoryAPI_Sim() {
			this.getOpHistoryStat = function() {
				return JSON.stringify({totalOpCount:100, shareOpCount:20, acceptOpCount:30});
			}
			this.getAllOpHistoryInfo = function(maxRecords) {
				return JSON.stringify([{fileId:"10", op:"up", localPath:"C:\\xxx\\xxxx.jpg", fileName:"xxxx.jpg", date:"2011-10-07 17:00:00"}
				,{fileId:"11", op:"down", localPath:"C:\\xxx\\xxxx.txt", fileName:"xxxx.txt",date:"2011-10-07 16:30:00"}
				,{fileId:"12", op:"share", localPath:"C:\\xxx\\xxxx.rar", fileName:"xxxx.rar",date:"2011-10-07 16:20:10"}
				,{fileId:"13", op:"unshare", localPath:"C:\\xxx\\xxxx.doc", fileName:"xxxx.doc",date:"2011-10-07 16:10:08"}]);

			}
			this.getSharedHistoryInfo = function(maxRecords) {
				return JSON.stringify([{fileId:"12", op:"share", localPath:"C:\\xxx\\xxxx.rar", fileName:"xxxx.rar",date:"2011-10-07 16:20:10"}
				,{fileId:"13", op:"unshare", localPath:"C:\\xxx\\xxxx.doc", fileName:"xxxx.doc",date:"2011-10-07 16:10:08"}]);
			}
		}

		function FacilityAPI_Sim() {
			this.openPath = function(localPath, type) {window.open(localPath);}
			this.openSyncFolder = function() {window.open('c:\\');}
			this.redirectToView = function(url, x, y, width, height, arg) {
				// hard code here for test only
				var pos = url.indexOf("/") + 1;
				var prefix = url.substr(0, pos);
				if(prefix != 'share/' && prefix != 'wizard/') {
					return -9;
				}
				var newurl = '../' + url;//url.substr(pos, url.length);
				window.location = newurl + "?viewParam=" + escape(arg);
				return 0;
			}
			this.getViewParam = function() {
				var url = location.search.substr(1);
				if(url.length > 0) {
					ar = url.split(/[&=]/);
					if((ar.length % 2) == 0) {
						for(i=0;i<ar.length;i+=2) {
							if(ar[i] == "viewParam") {
								return unescape(ar[i+1]);
								//alert(unescape(ar[i+1]));
							}
						}
					}
				}
				return "";
			}
			this.setViewResult = function(result) {
				alert("setViewResult:" + result);
				return;
			}
			this.openURL = function(url) {window.open(url);}
			this.manageView = function(op) {
				if(op == 1) {
					window.close();
				} else {
					alert('Sorry, not support this operation in manageView api!');
				}
			}
			this.openeCloudPortal = function(operId) { window.open("http://cloud.189.cn"); }
			this.getProperty = function(clsName, propName) {
				return "test";
			}
		}

		function APIFactory_Sim() {
			return window.external;
			this.getAccountAPI = function() { return new AccountAPI_Sim(); }
			this.getVDiskAPI = function() { return new VDiskAPI_Sim(); }
			this.getFileShareAPI = function() { return new FileShareAPI_Sim(); }
			this.getFileSyncAPI = function() { return new FileSyncAPI_Sim(); }
			this.getOpHistoryAPI = function() { return new OpHistoryAPI_Sim(); }
			this.getFacilityAPI = function() { return new FacilityAPI_Sim(); }
		}

		//var APIFactory = new APIFactory_Sim();
