idArray = new Array();

function getFileCode(pageId)
{	
	chopId(pageId);
	return setFileCode();
}
	
function getSitePage()
{	
	return matching();
}

function oasDetail(sitePageTop, sitePageTopRight)
{
	this.sitePageTop=sitePageTop;
	this.sitePageTopRight=sitePageTopRight;
}	

function setFileCode()
{
	var i=0;		
	var tempCode=idArray[0];
	
	if (tempCode.indexOf(".tvb.com") > 0)
		for(;tempCode.substring(i,i+1)!=".";i++);
	else
		for(;tempCode.substring(i,i+4)!=".com";i++);
	
	var fileCode=tempCode.substring(0,i);
	
	//alert("File id : '"+ fileCode +"' at getsitepage.js");
	
	if (fileCode=="www" || fileCode=="tvb")
		fileCode="homepage";
	
	return fileCode;
}

function matching()
{	
	//for the page at the top folder, eg. tvcity.tvb.com/index.html
	//if (idArray.length==2)
	//	return (new oasDetail(dataIn[0].sitePageTop,dataIn[0].sitePageTopRight));
	
	//start the matching
	var counter=idArray.length-1;
	
	while(counter>0)
	{	
		var pageId="";		
		for(var i=1;i<=counter;pageId+=idArray[i],i++);
		
		for(var j=1; j<dataIn.length; j++)
		{	
			if(dataIn[j].id==pageId)
			{
				//alert("Data Id : '" +dataIn[j].id+"' at getsitePage.js");
				return (new oasDetail(dataIn[j].sitePageTop,dataIn[j].sitePageTopRight));
			}
		}
		counter--;
	}
	
	//for the general page
	//alert("Data Id : '" +dataIn[0].id+"' at getsitePage.js");
	return (new oasDetail(dataIn[0].sitePageTop,dataIn[0].sitePageTopRight));
}

function chopId(pageId)
{
	pageId=pageId.substring(7);
	var i=0, j=0, k=0;
		
	while(i<pageId.length)
	{	
		if (pageId.substring(i,i+1)=="/")
		{
			idArray[k]=pageId.substring(j,i+1);
			j=i+1;
			k++;
		}
		i++;
	}	
	idArray[k]=pageId.substring(j,i);
}