// JavaScript Document
var objtmp = new ActiveXObject("RitAspServer.RitForAsp.1");

function usaDateFormatO(strDate,showTime)
{
		
		try
		{
			var stime=strDate.match(/[012]{0,1}[\d]{1}\:[\d]{1,2}\:[\d]{1,2}/);
		
		var sdate=strDate.match(/[\d]{1,4}\-[\d]{1,2}\-[\d]{1,2}/);
		var tdate=sdate[0];
		var ttime=stime[0];
		var dArr=new Array();
		var tArr=new Array();
		var returnvalue;
		
		if (tdate=="")
		{
			return "Unknow date!"	
		}
		else
		{
			dArr=tdate.split("-");
			var strDay="";
			var strDate;
			var strMonth;
			var strYear;
			
			var dateObj = new Date(dArr[0],dArr[1]*1-1,dArr[2]);
			strDay=engWeakday(dateObj);
			strMonth=engMonthName(dArr[1]*1-1)
			returnvalue=strDay+" "+strMonth +" "+ dArr[2]+", "+dArr[0];
			
		}
		
		if (ttime!="" && showTime)
		{
			tArr=ttime.split(":");
			if (tArr[0]*1<12) 
			{
				returnvalue=returnvalue+" "+tArr[0]+":"+tArr[1]+" AM";
			}
			else
			{
				returnvalue=returnvalue+" "+(tArr[0]*1-12)+":"+tArr[1]+" PM";	
			}
		}
		
		return returnvalue;
		}
		catch(e)
		{
		}
}

function engWeakday(dayFlag)
{
   try
   {
   var d, day, x;
   var x = new Array("Sunday", "Monday", "Tuesday");
   x = x.concat("Wednesday","Thursday", "Friday");
   x = x.concat("Saturday");
   
   day = dayFlag.getDay();
   return(x[day]);
   }
   catch(e)
   {
   }
}

function engMonthName(monthFlag)
{
	try
	{
	var x = getMonthNameFromLanguage(langType)
	return(x[monthFlag]);
	}
	catch(e)
	{
	}
}

var xmlStringAgent=function()
{
	this.attachVar=function(name,value)
	{
		eval("this."+name+"=\""+value+"\"")
	}
}
function analyseXml(str)
{
	try
	{
	var innerStr;
	var XSA=new xmlStringAgent();
	str=str.replace(/^\s+/,'');
	str=str.replace(/\s+$/,'');
	var arrtmp=str.match(/\<([\w\s]+)\>([^\<]+)\<\/\1\>/);
	while (arrtmp!=null)
	{
		str=str.replace(/\<([\w\s]+)\>[^\<]+\<\/\1\>/,"");
		XSA.attachVar(arrtmp[1],arrtmp[2]);
		arrtmp=str.match(/\<([\w\s]+)\>([^\<]+)\<\/\1\>/);
	}
	
	return XSA;
	}
	catch(e)
	{
	}
}

function getAllIBP(comObj)
{
	try
	{
	var arrayPoint=new Array();
	var ePointInfoXml="";
	//var pointNum=comObj.GetRitRPCount();
	var tmpXml="";
	var XSA;
	var bout;
	var i=0;
	var tmpDate=new Date();
	//for (i=0;i<pointNum;i++)
	//{
	//	tmpXml=comObj.GetRPDetailShow(i);
		//alert(tmpXml);
	//	XSA=analyseXml(tmpXml);
	//	arrayPoint[i]=XSA;
	//}
	while(true)
	{
		ePointInfoXml=comObj.GetRPDetailShow(1);
		//alert(ePointInfoXml);
		if(ePointInfoXml=="fs++")
		{
			break;
		}
		if (/\#$/.test(ePointInfoXml))
		{
			bout=true;
			ePointInfoXml=ePointInfoXml.substring(0,ePointInfoXml.length-1);
		}
		if(ePointInfoXml=="fs++")
		{
			continue;
		}
		XSA=analyseXml(ePointInfoXml);
		if(parent.STR_RESTORED)
		{
			XSA.Describe=XSA.Describe.replace("(Restored)","("+parent.STR_RESTORED+")");
		}
		arrayPoint[i++]=XSA;
		if (bout)
		{
			break;	
		}
	}
	
	for (j=0;j<arrayPoint.length;j++)
	{
		var tparr1=arrayPoint[j].Date.match(/(\d{4})\-(\d{1,2})\-(\d{1,2})\s+(\d{1,2})\:(\d{1,2})\:(\d{1,2})/)
		tpDateObj=new Date(tparr1[1],tparr1[2],tparr1[3],tparr1[4],tparr1[5],tparr1[6]);
		arrayPoint[j].attachVar("order",tpDateObj.getTime())
	}
	arrayPoint.sort(sortPoint);
	//for (j=0;j<arrayPoint.length;j++)
	//{
	//	alert(arrayPoint[j].Date)
	//}
	//alert("sdad"+arrayPoint.length);
	return arrayPoint;
	}
	catch(e)
	{
		return new Array();
	}
}
function sortPoint(a,b)
{
	try
	{
	return a.order-b.order;
	}
	catch(e)
	{
	}
}
//pointArray=getAllIBP(objtmp);
function getKDB()
{
	  var arrayPoint=new Array();
	  var ePointInfoXml="";
	//var pointNum=comObj.GetRitRPCount();
	var tmpXml="";
	var XSA;
	var bout;
	var i=0;
	var tmpDate=new Date();
	
		ePointInfoXml=objtmp.RitReadKDB();
		//if (ePointInfoXml.indexOf("#")>-1)
//		{
//			bout=true;
//			ePointInfoXml=ePointInfoXml.substring(0,ePointInfoXml.length-1);
//		}
		XSA=analyseXml(ePointInfoXml);
		arrayPoint[0]=XSA;
		return arrayPoint;
	
}
var KBDInfo = getKDB();
//是否有CBP
function hasCBP()
{
	if(KBDInfo[0].cbpOn=="1")
	{
		return true;
	}
	window.location.href="dow.htm";
	return false;
}
// 是否有GUI
function hasGUI()
{
	if(KBDInfo[0].uiType=="1")
	{
		return true;
	}
	window.location.href="dow.htm";
	return false;
}
function getRed()
{
	var arrayPoint=new Array();
	var ePointInfoXml="";
	var tmpXml="";
	var XSA;
	var bout;
	var i=0;
	var tmpDate=new Date();
	ePointInfoXml=objtmp.RitReadTactic(0);
	XSA=analyseXml(ePointInfoXml);
	arrayPoint[0]=XSA;
	return (arrayPoint[0].RitFreeSpace*1+arrayPoint[0].FlbUsedSpace*1)/1024;
	
}
