//////////////////////////////////scoll animation effect///////////////
function scrollSub(subId,height)
{
	var subNode=document.getElementById(subId);
	if(subNode.scrollDirection==1)
	{
		subNode.scrollDirection=0;
		setTimeout(scUPfunction(subNode),50);
	}
	else if(subNode.scrollDirection==0)
	{
		subNode.scrollDirection=1;
		subNode.style.display="block";
		setTimeout(scDOWNfunction(subNode,height),50);
	}
}
function scUPfunction(subObj)
{
	return function()
	{
		if (subObj.scrollDirection==1) return;
		var intHeight=parseInt(subObj.style.height,10)-20;
		if (intHeight<=0)
		{
			subObj.style.display="none";
			subObj.scrollDirection=0;
			return;
		}
		else
		{
			subObj.style.height=intHeight+"px";
		}
		setTimeout(scUPfunction(subObj),50);
	}
}
function scDOWNfunction(subObj,height)
{
	return function()
	{
		if (subObj.scrollDirection==0) return;
		var intHeight=parseInt(subObj.style.height,10)+20;
		if (intHeight>=height)
		{
			subObj.style.height=height+"px";
			return;
		}
		else
		{
			subObj.style.height=intHeight+"px";
		}
		setTimeout(scDOWNfunction(subObj,height),50);
	}
}
function getSimpleFontStyle(str)
{
	return "<div style='font-size:12px;font-family:Tahoma, Arial; padding-top:5px; padding-left:36px; color:#155E95;'>"+str+"</div>"
}
function getCheckFontStyle(str)
{
	return "<div style='font-size:12px;font-family:Tahoma, Arial; padding-top:5px; padding-left:36px; color:#014880;'>"+str+"</div>"
}
//////////////////////////////////scoll animation effect///////////////
///////////////left menu click//////////////////////////
function ChangeAddIcon(divObj) {
	if (divObj.style.backgroundImage == "url(images/left_click_add_icon.gif)") {
		divObj.style.background="url(images/left_unclick_add_icon.gif)";
	}
	else {
		divObj.style.background="url(images/left_click_add_icon.gif)";
	}

}
///////////////left menu click//////////////////////////

////////////////main mini and exit window operation//////////////////////////
function MiniWindow() {
	window.external.OnMinimize();
}
function ExitWindow() {
	window.external.OnOK(); 
}


function LeftNavigation( operationType ) {
	if ( parent.processFlag ) { return; }
	var openURL;
	//if can't click, then return;
	if (!navigationFlag) { return; }
	navigationFlag = false;
	allLeftRadioContainer.Disable();
	if ( divClickID == "Div_Main_DriverClone_Main" ) { $(divClickID).style.backgroundImage="url(images/left_main_menu2.gif)"; }
	else { $(divClickID).style.backgroundImage="url(images/left_click_menu.gif)"; }
	switch ( operationType ) {
		case 1:
			// backup 0 --- back drivers     1 ----- back file     2 -- back disk
			openURL = BackupLocation(parseInt(allLeftRadioContainer.value));
			break;
		case 2:
			// restore   0 --- restore drivers       1---- restore file
			openURL = RestoreLocation(parseInt(allLeftRadioContainer.value)-10);
			break;
		case 3:
			// clone   0 --- clone partition       1---- clone disk
			openURL =  CloneLocation(parseInt(allLeftRadioContainer.value)-20);
			break;
	}
	timeOutObject = setTimeout("ChangeNavigationFlag();",100);
	window.open(openURL,'IframeMainUI');
}

/////////////////main location  0 ----- summary     1-------- backup      2 --------- restore         3  ------- clone
//////////////////clickID is click div's id
function MainLocation( locationFlag, clickID ) {
	if ( parent.processFlag ) { return; }
	if ( !subFartherDivClickFlag ) { return; }
	if ( clickID != divClickID ) {
		if ( clickID == "Div_Main_DriverClone_Main" ) { $(clickID).style.backgroundImage="url(images/left_main_menu.gif)"; }
		else { $(clickID).style.backgroundImage="url(images/left_click_menu2.gif)"; }
		if ( divClickID == "Div_Main_DriverClone_Main" ) { $(divClickID).style.backgroundImage="url(images/left_main_menu2.gif)"; }
		else { $(divClickID).style.backgroundImage="url(images/left_click_menu.gif)"; }
		divClickID = clickID;
	}
	allLeftRadioContainer.unCheckAll();
	switch (locationFlag) {
		case 0:
			IframeMainUI.location = "summary.htm";
			break;
		case 1:	
			IframeMainUI.location = "Backup.html";
			break;
		case 2:	
			IframeMainUI.location = "Restore.html";
			break;
		case 3:	
			IframeMainUI.location = "Clone.html";
			break;
	}
}

function ChangeNavigationFlag() { allLeftRadioContainer.Enable();navigationFlag = true; }
////////////////////webmenu function//////////////////////////////////////
function iniTopMenu(clickedObj)
{	
	currentOpenedTopMenuButton=clickedObj;
	var menuTopLevelObj=document.getElementById(clickedObj.submenuid);
	menuUpObj=menuTopLevelObj
	
	appendedTopItem=clickedObj;
	//alert(menuTopLevelObj.clientWidth)
	menuTopLevelObj.style.left=-clickedObj.clientWidth+"px";
	sdObj.className=("menushadow")
	sdObj.style.height=menuTopLevelObj.clientHeight+"px";
	sdObj.style.width=menuTopLevelObj.clientWidth+"px";
	sdObj.style.top=(parseInt(menuTopLevelObj.offsetTop)+4)+"px";
	sdObj.style.left=(parseInt(menuTopLevelObj.offsetLeft)+4)+"px";
	clickedObj.parentNode.appendChild(sdObj);
	menuTopLevelObj.style.visibility="visible";
	sdObj.style.visibility="visible";
	
	//alert(menuTopLevelObj.visibility)
	var subMenuArr=menuTopLevelObj.childNodes;
	for (i=0;i<subMenuArr.length;i++) {
		subMenuArr[i].onmouseover=function() {
			isMove=false;
			var thisMenuSubListArr=this.parentNode.childNodes;
			for (i=0;i<thisMenuSubListArr.length;i++) {
				if (thisMenuSubListArr[i].className=="upMenuStyle") {
					thisMenuSubListArr[i].style.backgroundImage="url(images/topMenuDiv.jpg)";
				}
				thisMenuSubListArr[i].style.backgroundColor="";
				thisMenuSubListArr[i].style.color="#000000";
			}
			if (this.className=="upMenuStyle") {
				this.style.backgroundImage="none";
			}
			this.style.backgroundColor="#316AC5";
			this.style.color="#ffffff";
		}
		subMenuArr[i].onmouseout=function() {
			isMove=true;
			if (this.className=="upMenuStyle") {
				this.style.backgroundImage="url(images/topMenuDiv.jpg)";
			}
			this.style.backgroundColor="";
			this.style.color="#000000";
		}
		subMenuArr[i].onclick=function() {
			menuFireEvent(this.iid)
		}
	}
	submenuIsOpen=true;
}

function appendSubmenu(clickedObj) {
	setTimeout(clickTimeout(clickedObj),20)
}
function clickTimeout(obj) {
	return function() {
		iniTopMenu(obj);
	}
}

//submenu click
function menuFireEvent(id) {
	fffa();
	if ( parent.processFlag ) { return; }
	id = parseInt(id);
	switch (id) {
		case 19:
			FileExit();
			break;
		case 22:
			ToolsCheckImage();
			break;
		case 23:
			ToolsMountImage();
			break;
		case 24:
			ToolsUmountIMage();
			break;
		case 31:
			HelpHelp();
			break;
		case 32:
			window.external.Navigate("mainui/aboutus.html", 450, 295);
			break;
		case 33:
			window.open("http://www.farstone.com",'_blank');
			break;
	}
//	if (id==11) {
//		window.external.OnClose();
//	}
//	if (id==21) {
//		if (window.external.IsPendClose()==true) {
//			return;
//		}
//		clickNavButton(1);
//	}
//	if (id==22) {
//		if (window.external.IsPendClose()==true) {
//			return;
//		}
//		clickNavButton(6);
//	}
//	if (id==23) {
//		if (window.external.IsPendClose()==true) {
//			return;
//		}
//		clickNavButton(5);
//	}
//	if (id==31) { }
//	if (id==34) {
//		var isDoingThing=window.external.IsPendClose()
//		window.external.PendClose(false);
//		window.external.Navigate("mainui/about.htm",320,420);
//	}
}

function closeTopSubNenu() {
	if (currentOpenedTopMenuButton==null) {
		return;
	}
	var parentMenuObj=document.getElementById(currentOpenedTopMenuButton.submenuid);
	if (parentMenuObj==null) {
		return;
	}
	var listArray1=parentMenuObj.childNodes;
	for(i=0;i<listArray1.length;i++) {
		if (listArray1[i].style.backgroundColor=="") {	continue; }
		listArray1[i].style.backgroundColor="";
		listArray1[i].style.color="#000000";
		if (listArray1[i].className=="upMenuStyle") {
			listArray1[i].style.backgroundImage="url(images/topMenuDiv.jpg)";
		}
	}
	currentOpenedTopMenuButton.style.backgroundColor="";
	currentOpenedTopMenuButton.style.color="#000000";
	currentOpenedTopMenuButton=null;
	menuUpObj.style.visibility="hidden";
	sdObj.style.visibility="hidden";
	submenuIsOpen=false;
}
function showFileMenu() {
	if(currentOpenedTopMenuButton!=null) { closeTopSubNenu(); }
	var fileMenuTopObj=document.getElementById("fileTopMenu");
	fileMenuTopObj.focus();
	currentOpenedTopMenuButton=fileMenuTopObj;
	submenuIsOpen=true;
	fileMenuTopObj.style.backgroundColor="#316AC5";
	fileMenuTopObj.style.color="#ffffff";
	setTimeout(clickTimeout(fileMenuTopObj),20)
}
function showToolsMenu() {
	if(currentOpenedTopMenuButton!=null) { closeTopSubNenu(); }
	var toolsMenuTopObj=document.getElementById("toolsTopMenu");
	toolsMenuTopObj.focus();
	currentOpenedTopMenuButton=toolsMenuTopObj;
	submenuIsOpen=true;
	toolsMenuTopObj.style.backgroundColor="#316AC5";
	toolsMenuTopObj.style.color="#ffffff";
	setTimeout(clickTimeout(toolsMenuTopObj),20)
}
function showHelpMenu() {
	if(currentOpenedTopMenuButton!=null) { closeTopSubNenu(); }
	var helpMenuTopObj=document.getElementById("helpTopMenuA");
	helpMenuTopObj.focus();
	currentOpenedTopMenuButton=helpMenuTopObj;
	submenuIsOpen=true;
	helpMenuTopObj.style.backgroundColor="#316AC5";
	helpMenuTopObj.style.color="#ffffff";
	setTimeout(clickTimeout(helpMenuTopObj),20)
}
////////////////////webmenu function//////////////////////////////////////
////////////////////hot key function//////////////////////////////////////
function declareAltHotKey(key,fun) {
	key=key.toUpperCase();
	var tmpColl=new topMenuEventCollection();
	tmpColl.key=key;
	tmpColl.keyCodeNum=key.charCodeAt(0);
	tmpColl.fireFunction=fun;
	hotKeyList.push(tmpColl);
}

function declareCtrlHotKey(key,fun) {
	key=key.toUpperCase();
	var tmpColl=new topMenuEventCollection();
	tmpColl.key=key;
	tmpColl.keyCodeNum=key.charCodeAt(0);
	tmpColl.fireFunction=fun;
	ctrlHotKeyList.push(tmpColl);
}

var topMenuEventCollection=function() {
	this.key="";
	this.keyCodeNum=0;
	this.fireFunction=function(){}
}

function fireCtrlHotKey(code,fireFrom) {
	for (i=0;i<ctrlHotKeyList.length;i++) {
		if(ctrlHotKeyList[i].keyCodeNum==code) {
			ctrlHotKeyList[i].fireFunction();
			//alert(fireFrom.outerHTML);
		}
	}
}

function fireHotKey(code,fireFrom) {
	//alert(hotKeyList.length);
	for (i=0;i<hotKeyList.length;i++) {
		if(hotKeyList[i].keyCodeNum==code) {
			hotKeyList[i].fireFunction();
			//alert(fireFrom.outerHTML);
			if (fireFrom.tagName=="A" || toUpperCase(fireFrom.tagName)=="OBJECT") {
				fireFrom.blur();
			}
		}
	}
}

function fireUpKeyEvent() {
	if (!submenuIsOpen) return;
	subMenuListArray=document.getElementById(currentOpenedTopMenuButton.submenuid).childNodes;
	highLightIndex=0;
	tempIndexId=0;
	for(i=0;i<subMenuListArray.length;i++) {
		if (subMenuListArray[i].style.backgroundColor!="") {
			tempIndexId=i;
		}
		subMenuListArray[i].style.backgroundColor="";
		subMenuListArray[i].style.color="#000000";
		if (subMenuListArray[i].className=="upMenuStyle") {
			subMenuListArray[i].style.backgroundImage="url(images/topMenuDiv.jpg)";
		}
	}
	if (tempIndexId>0) {
		highLightIndex=tempIndexId-1;
	}
	if (tempIndexId==0) {
		highLightIndex=subMenuListArray.length-1;
	}
	subMenuListArray[highLightIndex].style.backgroundColor="#316AC5";
	subMenuListArray[highLightIndex].style.color="#ffffff";
	if (subMenuListArray[highLightIndex].className=="upMenuStyle") {
		subMenuListArray[highLightIndex].style.backgroundImage="none";
	}
}

function fireDownKeyEvent() {
	if (!submenuIsOpen) return;
	subMenuListArray=document.getElementById(currentOpenedTopMenuButton.submenuid).childNodes;
	highLightIndex=0;
	tempIndexId=-1;
	for(i=0;i<subMenuListArray.length;i++) {
		if (subMenuListArray[i].style.backgroundColor!="") {
			tempIndexId=i;
		}
		if (tempIndexId==subMenuListArray.length-1) {
			tempIndexId=-1;
		}
		subMenuListArray[i].style.backgroundColor="";
		subMenuListArray[i].style.color="#000000";
		if (subMenuListArray[i].className=="upMenuStyle") {
			subMenuListArray[i].style.backgroundImage="url(images/topMenuDiv.jpg)";
		}
	}
	if (tempIndexId<subMenuListArray.length-1) {
		highLightIndex=tempIndexId+1;
	}
	subMenuListArray[highLightIndex].style.backgroundColor="#316AC5";
	subMenuListArray[highLightIndex].style.color="#ffffff";
	if (subMenuListArray[highLightIndex].className=="upMenuStyle") {
		subMenuListArray[highLightIndex].style.backgroundImage="none";
	}
}

function fireLeftKeyEvent() {
	if (currentOpenedTopMenuButton==null) {
		return;
	}
	var inextId=-1;
	var tmpTopElementCon=currentOpenedTopMenuButton;
	for (var i=0;i<globeTopMenuListArray.length;i++) {
		if(globeTopMenuListArray[i]==tmpTopElementCon) {
			inextId=i;
			inextId-=1;
			break;
		}
	}
	if (inextId<0) {
		inextId=globeTopMenuListArray.length-1;
	}
	closeTopSubNenu();
	if(globeTopMenuListArray[inextId].id=="fileTopMenu") {
		showFileMenu();
	}	
	else if (globeTopMenuListArray[inextId].id=="toolsTopMenu") {
		showToolsMenu();
	}
	else if (globeTopMenuListArray[inextId].id=="helpTopMenuA")	{
		showHelpMenu();
	}
}

function fireRightKeyEvent() {
	if (currentOpenedTopMenuButton==null) {	return;	}
	var inextId=-1;
	var tmpTopElementCon=currentOpenedTopMenuButton;
	for (var i=0;i<globeTopMenuListArray.length;i++) {
		if(globeTopMenuListArray[i]==tmpTopElementCon) {
			inextId=i;
			inextId+=1;
			break;
		}
	}
	if (inextId==-1) { return; }
	if (inextId>globeTopMenuListArray.length-1) { inextId=0; }
//	alert(globeTopMenuListArray[inextId].id);
	closeTopSubNenu();
	if(globeTopMenuListArray[inextId].id=="fileTopMenu") { showFileMenu(); }	
	else if (globeTopMenuListArray[inextId].id=="toolsTopMenu") { showToolsMenu(); }
	else if (globeTopMenuListArray[inextId].id=="helpTopMenuA") { showHelpMenu(); }
}

function fireEnterKeyEvent()
{
	if (!submenuIsOpen) return;
	subMenuListArray=document.getElementById(currentOpenedTopMenuButton.submenuid).childNodes;
	for(i=0;i<subMenuListArray.length;i++) {
		if (subMenuListArray[i].style.backgroundColor!="") {
			menuFireEvent(subMenuListArray[i].iid);
		}
	}
}

function fireEscKeyEvent()
{
	closeTopSubNenu();
}

function fireOtherKeyEvent(code)
{
	if (currentOpenedTopMenuButton==null) { return; }
	var parentMenuObj=document.getElementById(currentOpenedTopMenuButton.submenuid);
	if (parentMenuObj==null) { return; }
	var listArray1=parentMenuObj.childNodes;
	var currentPressKey=(String.fromCharCode(code));
	for(i=0;i<listArray1.length;i++) {
		if (currentPressKey==listArray1[i].hotkeyflag) {
			if (listArray1[i].style.display=="none") { return; }
			listArray1[i].click();
			return;
		}
	}
}

function isTopSubMenuOpened() {
	if(currentOpenedTopMenuButton==null) { return false; }
	else { return true; }
}
////////////////////hot key function//////////////////////////////////////

///////////////////window function///////////////////////////////////////
function moveWindow() {
	if (isMove) {
		closeTopSubNenu();
		window.external.OnMoveWindow();
	}
}
//////////////////file operation //////////////////////////////////////
function FileExit() { ExitWindow(); }
//////////////////file operation finish//////////////////////////////////////
/////////////////tools operation////////////////////////////////////////
function BrowseImageForImage() {
	var browseFile = Main_Object.BrowerImgFile();
	if ( browseFile == "" ) { return ""; }
//	Int    IsImgLegal(char *imgFile); 0 合法，非0非法, check image start
	if (Main_Object.IsImgLegal(browseFile)!=0) {
		RIT_popMsg('',264,135,'ok',GS("BrowseImageForImageImageBad"),'alert');
		return "";
	}
	else {
		var hasPwd = Main_Object.IsImgHasPwd(browseFile);
		if( hasPwd!=0 ) {
			window.external.SetStaticData(browseFile);
			window.external.Navigate("mainui/check.html", 300, 200);
			var returnString = window.external.GetStaticData();
			if( returnString != "ok" ) {
				return "";
			}
		}
	}
	return browseFile;
}
function ToolsCheckImage() {
	var browseFile = BrowseImageForImage();
	if (browseFile!="") {
		window.external.SetStaticData(browseFile);
		IframeMainUI.location = "CheckImageProcess.html";
	}
}
function ToolsMountImage() {
	IframeMainUI.location = "Mount.htm";return;
	var browseFile = BrowseImageForImage();
	if (browseFile!="") {
		window.external.SetStaticData(browseFile);
		IframeMainUI.location = "MountImage.htm";
	}
}
function ToolsUmountIMage() {
	IframeMainUI.location = "UnMountImage.htm";
	//Main_Object.UmountIMageFile();
}
/////////////////tools operation////////////////////////////////////////
////////////////help operation /////////////////////////////////////////
function HelpHelp() {
	var helpPath = window.external.GetCurPath();
	window.showHelp(helpPath+"/../DClone.CHM");
}
////////////////help operation /////////////////////////////////////////
