function browser(){
 var bName = navigator.appName;
 var bVer  = parseInt(navigator.appVersion);
 this.IE=(bName == "Microsoft Internet Explorer");
 this.NS=(bName == "Netscape");
 this.IE3=(bName == "Microsoft Internet Explorer" && bVer < 4);
 this.IE4=(bName == "Microsoft Internet Explorer" && bVer >= 4);
 this.NS3= (bName == "Netscape" && bVer < 4);
 this.NS4= (bName == "Netscape" && bVer == 4);
 this.NS6= (bName == "Netscape" && bVer == 5);
}

var br=new browser();
//*************************************************
//function to trim the string
//*************************************************

function rtrim(argvalue) {
        while (1) {
	    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
		break;
	    argvalue = argvalue.substring(0, argvalue.length - 1);
	}
	return argvalue;
    }
function ltrim(argvalue) {
	while (1) {
	    if (argvalue.substring(0, 1) != " ")
		break;
	    argvalue = argvalue.substring(1, argvalue.length);
	}
	return argvalue;
}
function trim(argvalue) {
	var tmpstr = ltrim(argvalue);
	return rtrim(tmpstr);
}

function openwin(matchno){
var urlStr;
urlStr='wcmatches/match' + matchno + '.html'
window.open(urlStr,'','width=750,height=500,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,screenX=10,screenY=10');
return false;
}//end of openwin

function opensswin(matchno){
var urlStr;
if (matchno==12){
 matchno=matchno-11;
 urlStr='wcmatches/fmatch' + matchno + '.html'	
}else{
	if (matchno<=9){
	urlStr='wcmatches/ssmatch' + matchno + '.html'	
	}else{
	matchno=matchno-9
	urlStr='wcmatches/sfmatch' + matchno + '.html'	
	}
}

window.open(urlStr,'','width=750,height=500,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,screenX=10,screenY=10');
return false;
}//end of openwin


function windowopen(urlStr){
window.open(urlStr,'','width=750,height=500,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,screenX=10,screenY=10');
return false;
}//end of openwin

function KeyPressEvent()
{
	window.event.keyCode=0;
}
function CalculateSeedings()
{
	OriginalPoints();
	CalculatePoints();
	SortPointsArray();
	DisplayResults();
}

function OriginalPoints()
{
//Get the original copy
	for(var i=0;i<6;i++) {
		msglPoints[i]=msglPointsOriginal[i]; 
		mstrTeams[i]=mstrTeamsOriginal[i]
		msglPointsBonus[i]=msglPointsOriginal[i];
	};
}
function CalculatePoints()
{
	var llngIndex1, llngIndex2, llngPoints1, llngPoints2;
	var llngResult;
	
/*
	for(var i=0;i<9;i++)
	{
		llngResult = FIndex.cboResults[i].options[FIndex.cboResults[i].selectedIndex].value.split(',');
		alert(llngResult[4]);
	}
	return;
*/
//Accumulate the points based on the results 
	for(var i=0;i<9;i++)
	{
		llngResult = FIndex.cboResults[i].options[FIndex.cboResults[i].selectedIndex].value.split(',');

		llngPoints1=parseInt(llngResult[0]);
		llngPoints2=parseInt(llngResult[1]);
		llngIndex1=parseInt(llngResult[2]);
		llngIndex2=parseInt(llngResult[3]);
		
		msglPoints[llngIndex1]=msglPoints[llngIndex1]+llngPoints1;
		msglPoints[llngIndex2]=msglPoints[llngIndex2]+llngPoints2;
	}
//	SortPointsArray();
//	DisplayResults();
}
function SortPointsArray()
{
//Sort the array in descending sequence of points
	var lsglTempPoints;
	var lstrTempTeam;
	var lstrTempBonus;

		for(var i=0;i<6;i++){
			for(var j=i; j<6; j++){
				if(parseFloat(msglPoints[i])<parseFloat(msglPoints[j])){
				lsglTempPoints=msglPoints[i];
				msglPoints[i]=msglPoints[j];
				msglPoints[j]=lsglTempPoints;
				lstrTempTeam=mstrTeams[i];
				mstrTeams[i]=mstrTeams[j];
				mstrTeams[j]=lstrTempTeam;
				lstrTempBonus=msglPointsBonus[i];
				msglPointsBonus[i]=msglPointsBonus[j];
				msglPointsBonus[j]=lstrTempBonus;				
				}
			}
		}
}
function DisplayResults()
{
	for(var i=0;i<6;i++)
	{
	//	alert(msglPoints[i]);
		FIndex.txtTeam[i].value=mstrTeams[i];
		FIndex.txtPointOriginal[i].value=msglPointsBonus[i];
		FIndex.txtPoint[i].value=msglPoints[i];
	}
}