//===============================================================================================
//Developed  by Deoyani and Mohasin (2006)
//===============================================================================================
//Global variables used in this script

var http_root="http://astrostatistics.psu.edu/";
var testName=null;  
var processnum=null;
var categoryName=null;
var selectedTest=null;
var radio_selection="votable";
var help_page=null;
var error_check=1;
var test_no;
var file_reload=0;
var back_clicked;
var tool_tip=0;
var version_number=0;
var popup_visible=0;
var selectedTest_name_todisplay=null;
var ok_clicked=0;
var browser_name=null;
var test_submit_form =1;
//===============================================================================================
//Array for categories available one can increase count and add name of the category in array
var categoryCount=10;
var categoryArray=new Array(categoryCount);
categoryArray[0]="Descriptive Statistics";
categoryArray[1]="Statistical Tests";
categoryArray[2]="Exploratory Tools";
categoryArray[3]="Multivariate Analysis";
categoryArray[4]="Multivariate Classification";
categoryArray[5]="Curve Fitting";
categoryArray[6]="Censored Data";
categoryArray[7]="Non Parametric Methods";
categoryArray[8]="Two and k-sample Tests";
categoryArray[9]="Regression";

//===============================================================================================
//Array for tooal no of tests available
// One can increase count here and add name of test with other necessary info in array list below

var testCount=26;				//Total number of tests 
var testarray=new Array(testCount);
//testname[i,0] is for test name    			where i varies from 0 to testcount
//testname[i,1] total categories the test belongs to	where i varies from 0 to testcount
//testname[i,2] is for test help page			where i varies from 0 to testcount
//testname[i,3,j] is for category names			where i varies from 0 to testcount &&
//							where j varies from 0 to categoryCount 

testarray[0]=new Array(4);
testarray[0][0]="Quantile Quantile Plot";
testarray[0][1]=1;
testarray[0][2]="qqplot.htm";
testarray[0][3]=new Array(1);
	testarray[0][3][0]=categoryArray[2];

testarray[1]=new Array(4);
testarray[1][0]="Mean Standard Deviation ......";
testarray[1][1]=1;
testarray[1][2]="meansd.htm";
testarray[1][3]=new Array(1);
	testarray[1][3][0]=categoryArray[0];

testarray[2]=new Array(4);
testarray[2][0]="BoxPlot";
testarray[2][1]=2;
testarray[2][2]="boxplot.htm";
testarray[2][3]=new Array(2);
	testarray[2][3][0]=categoryArray[0];
	testarray[2][3][1]=categoryArray[2];


testarray[3]=new Array(4);
testarray[3][0]="Histogram";
testarray[3][1]=2;
testarray[3][2]="hist.htm";
testarray[3][3]=new Array(2);
	testarray[3][3][0]=categoryArray[0];
	testarray[3][3][1]=categoryArray[5];

testarray[4]=new Array(4);
testarray[4][0]="Weighted Mean";
testarray[4][1]=1;
testarray[4][2]="wmean.htm";
testarray[4][3]=new Array(1);
	testarray[4][3][0]=categoryArray[0];


testarray[5]=new Array(4);
testarray[5][0]="Probability Plot";
testarray[5][1]=1;
testarray[5][2]="prob.htm";
testarray[5][3]=new Array(1);
	testarray[5][3][0]=categoryArray[2];

testarray[6]=new Array(4);
testarray[6][0]="Kolmogorov Smirnov One Sample Test";
testarray[6][1]=3;
testarray[6][2]="ks1.htm";
testarray[6][3]=new Array(3);
	testarray[6][3][0]=categoryArray[1];
	testarray[6][3][1]=categoryArray[5];
	testarray[6][3][2]=categoryArray[7];
	
testarray[7]=new Array(4);
testarray[7][0]="Kolmogorov Smirnov Two Sample Test";
testarray[7][1]=2;
testarray[7][2]="ks2.htm";
testarray[7][3]=new Array(2);
	testarray[7][3][0]=categoryArray[7];
	testarray[7][3][1]=categoryArray[8];
	
testarray[8]=new Array(4);
testarray[8][0]="Shapiro-Wilks Test For Normality";
testarray[8][1]=1;
testarray[8][2]="shapiro.htm";
testarray[8][3]=new Array(1);
	testarray[8][3][0]=categoryArray[7];
	
testarray[9]=new Array(4);
testarray[9][0]="Single or Multiple Linear Regression Analysis";
testarray[9][1]=1;
testarray[9][2]="mulreg.htm";
testarray[9][3]=new Array(1);
	testarray[9][3][0]=categoryArray[9];

testarray[10]=new Array(4);
testarray[10][0]="Correlation Matrix";
testarray[10][1]=2;
testarray[10][2]="cormat.htm";
testarray[10][3]=new Array(2);
	testarray[10][3][0]=categoryArray[0];
	testarray[10][3][1]=categoryArray[3];
		
testarray[11]=new Array(4);
testarray[11][0]="Principal Component Analysis";
testarray[11][1]=1;
testarray[11][2]="pca.htm";
testarray[11][3]=new Array(1);
	testarray[11][3][0]=categoryArray[3];

testarray[12]=new Array(4);
testarray[12][0]="H-clustering";
testarray[12][1]=1;
testarray[12][2]="hcluster.htm";
testarray[12][3]=new Array(1);
	testarray[12][3][0]=categoryArray[4];
		
testarray[13]=new Array(4);
testarray[13][0]="K-means Partitioning";
testarray[13][1]=1;
testarray[13][2]="kmeans.htm";
testarray[13][3]=new Array(1);
	testarray[13][3][0]=categoryArray[4];

testarray[14]=new Array(4);
testarray[14][0]="One and two sample t-test";
testarray[14][1]=1;
testarray[14][2]="ttest.htm";
testarray[14][3]=new Array(1);
	testarray[14][3][0]=categoryArray[1];

testarray[15]=new Array(4);
testarray[15][0]="Empirical Distibution Function";
testarray[15][1]=2;
testarray[15][2]="empdist.htm";
testarray[15][3]=new Array(2);
	testarray[15][3][0]=categoryArray[5];
	testarray[15][3][1]=categoryArray[7];
	
testarray[16]=new Array(4);
testarray[16][0]="Wilcoxon Rank-Sum Test";
testarray[16][1]=2;
testarray[16][2]="wrs.htm";
testarray[16][3]=new Array(2);
	testarray[16][3][0]=categoryArray[7];
	testarray[16][3][1]=categoryArray[8];
	
testarray[17]=new Array(4);
testarray[17][0]="Kruskal Wallis k-Sample Test";
testarray[17][1]=1;
testarray[17][2]="kw.htm";
testarray[17][3]=new Array(1);
	testarray[17][3][0]=categoryArray[8];
	
testarray[18]=new Array(4);
testarray[18][0]="Anova";
testarray[18][1]=2;
testarray[18][2]="anova.htm";
testarray[18][3]=new Array(2);
	testarray[18][3][0]=categoryArray[1];
	testarray[18][3][0]=categoryArray[3];
	
testarray[19]=new Array(4);
testarray[19][0]="Bivariate-Kendall, Spearman, Pearson";
testarray[19][1]=2;
testarray[19][2]="bivariate.htm";
testarray[19][3]=new Array(2);
	testarray[19][3][0]=categoryArray[2];
	testarray[19][3][1]=categoryArray[7];

testarray[20]=new Array(4);
testarray[20][0]="XY Plot";
testarray[20][1]=2;
testarray[20][2]="xyplot.htm";
testarray[20][3]=new Array(2);
	testarray[20][3][0]=categoryArray[2];
	testarray[20][3][0]=categoryArray[9];
	
testarray[21]=new Array(4);
testarray[21][0]="Covariance Analysis";
testarray[21][1]=2;
testarray[21][2]="covar.htm";
testarray[21][3]=new Array(2);
	testarray[21][3][0]=categoryArray[0];
	testarray[21][3][0]=categoryArray[3];
	
testarray[22]=new Array(4);
testarray[22][0]="Kernel Smoothing";
testarray[22][1]=1;
testarray[22][2]="ksmooth.htm";
testarray[22][3]=new Array(1);
	testarray[22][3][0]=categoryArray[5];

testarray[23]=new Array(4);
testarray[23][0]="Pair Plot";
testarray[23][1]=1;
testarray[23][2]="pairplots.htm";
testarray[23][3]=new Array(1);
	testarray[23][3][0]=categoryArray[2];

testarray[24]=new Array(4);
testarray[24][0]="Survival Analysis";
testarray[24][1]=1;
testarray[24][2]="survival.htm";
testarray[24][3]=new Array(1);
	testarray[24][3][0]=categoryArray[6];

testarray[25]=new Array(4);
testarray[25][0]="Testing for mean when variance is known";
testarray[25][1]=1;
testarray[25][2]="testmean.htm";
testarray[25][3]=new Array(1);
	testarray[25][3][0]=categoryArray[1];


//===============================================================================================
var for_testlist_helppage=1;
function onLoad()
{

	check_browser();
	document.getElementById("descStats").style.display="none";
	if(browser_name == "Konqueror")
	{
	  	document.getElementById("inputFrameDiv").style.display="block";
		document.getElementById("inputFrameDiv").style.visibility = "hidden";
	}
	else
	{
		document.getElementById("inputFrameDiv").style.display="none";
	}
	document.getElementById("mainDiv").style.display="none";
	document.getElementById("testdiv5").style.display = "none";
	divs_category();
	categoryDisplay();
	for_testlist_helppage=1;

}
//===============================================================================================
var ascii_onload_var=1;
var ascii_error_check=0;
var ascii_cancel_check=1;

function ascii_file_check()
{
	if(ascii_onload_var != 1)
	{
		getFile(http_root+'/VOStatBeta1/temp1/viewdata'+processnum,'postFileReady');
	}
	else
	{
		ascii_onload_var=0;
	}
}
//===============================================================================================
//Called from new onload in stats1.cgi 
function new_delimiter_check(str,str1)
{
	processnum_new=str;
	test_no=str1;
	file_reload=1;
	getFile(http_root+'/VOStatBeta1/temp1/viewdata'+str,'postFileReady');
}
//===============================================================================================

function categoryDisplay()
{
	testlist_Display_check = 0;	
	var file_str= "<table id = \"mainTable\" name = \"MainTable\" border=1 cellspacing=0 cellpadding=0>\n";
        var i=0;
	var j=0;
	var catCount=categoryCount;
	while(catCount > 0)	
	{
		if(catCount < 3)
		{
			file_str+="<tr>";
			if(catCount == 1)
			{
				var one_test = categoryCount-1;

				file_str+="<td ></td>";	
				file_str+="<td  class=\"tool_link\" id=\"check_tooltip"+one_test+"\" OnClick=\"freezecategory('cat"+one_test+"',event);\"  onmouseover=\"displaypopup('cat"+one_test+"',event);\" onmouseout=\"removepopup('cat"+one_test+"')\" ><center>"+categoryArray[i]+"</center></td>\n";
				file_str+="<td ></td>";
			}
			if(catCount == 2)
			{
				var one_test = categoryCount-1;

				file_str+="<td class=\"tool_link\" id=\"check_tooltip"+one_test+"\" OnClick=\"freezecategory('cat"+one_test+"',event);\" onmouseover=\"displaypopup('cat"+one_test+"',event);\" onmouseout=\"removepopup('cat"+one_test+"')\"><center>"+categoryArray[i]+"</center></td>\n";
				i=i+1;	
				var two_test = categoryCount-2;

				file_str+="<td class=\"tool_link\" id=\"check_tooltip"+two_test+"\" OnClick=\"freezecategory('cat"+two_test+"',event);\" onmouseover=\"displaypopup('cat"+two_test+"',event);\" onmouseout=\"removepopup('cat"+one_test+"')\" ><center>"+categoryArray[i]+"</center></td>\n";

				file_str+="<td ></td>";
			}
			file_str+="</tr>";	
			catCount=0;
		}
		else
		{
			file_str+="<tr>";

			for(j=0;j<3;j++)
			{
				file_str+="<td class=\"tool_link\" id=\"check_tooltip"+i+"\" OnClick=\"freezecategory('cat"+i+"',event);\" onmouseover=\"displaypopup('cat"+i+"',event);\"  onmouseout=\"removepopup('cat"+i+"')\" ><center>"+categoryArray[i]+"</center></td>\n";

				i=i+1;
			}
			file_str+="</tr>";
		}
		catCount=catCount-3;

	}
	
	file_str+="</table>\n";
	var category = document.getElementById("mainDiv");
	category.innerHTML=file_str;
	category.style.display = "block";
}



// To display all categories available on the main vostat page

//===============================================================================================
//to check string  for ids
//This is for display list of tests in tooltip for perticular category 
function divs_category()
{
	var i=0;
	var j=0;
	var k=0;
	var no=1;
	var file_str="";
	var first_flag = 0;
	var test_id = null;		
	for(i=0;i<categoryCount;i++)
	{
		var i_string =  i.toString();
		no=1;
		first_flag = 0;	
		file_str+= "<div class=\"tip1\" id =\"cat"+i+"\" >\n";
		file_str+="<div class=\"SubTitle1\"> <b><u><center>"+categoryArray[i]+"</center></u></b></div>\n";
		file_str+="<table>\n";
		for(j=0;j<testCount;j++)
		{

		     var j_string = j.toString();
		     var test_id = i_string+j_string;
			//alert(test_id);
		     for(k=0;k<5;k++)
		     {		
			if(testarray[j][3][k] == categoryArray[i])	
			{
				if(first_flag == 0)
				{
					file_str+="<tr><td><input type='radio' id='"+test_id+"'  name='function"+i+"' value='"+testarray[i][2]+"' onClick='setTestname_Onclick("+j+")' checked=\"checked\" />"+testarray[j][0]+"</td></tr>\n";
					selectedTest = j;
				}
				else
				{
					file_str+="<tr><td><input type='radio' id='"+test_id+"'  name='function"+i+"' value='"+testarray[i][2]+"' onClick='setTestname_Onclick("+j+")' />"+testarray[j][0]+"</td></tr>\n";
				}

				no=no+1;
				first_flag = 1;
			}
		     }	
		}
		file_str+= "<tr><td><center><Button OnClick=\"OkClicked('cat"+i+"',"+i+")\" >Ok</Button>";
		file_str+= "<Button OnClick=\"removefreezecategory('cat"+i+"')\">Cancel</Button></center></td></tr>\n";
		file_str+= "</table>\n";
		file_str+= "</div>\n";
	}
	
	var cat_divs= document.getElementById("category_disp");
	cat_divs.innerHTML = file_str;
	cat_divs.style.display = "block";


}
function setTestname_Onclick(str)
{
	selectedTest=str;
}
function OkClicked(str1,str)
{
	document.getElementById("inputFrameDiv").style.visibility = "visible";
	ok_clicked=1;
	removefreezecategory(str1);
	for_testlist_helppage=0;
	if(processnum == null)
	{
		alert("Load File First");
	}	
	else
	{
		// this part is to check the id of the test selected
		// get it clicked programatically
		var l=0;
		var cat_no=str.toString();
		for(l=0;l<testCount;l++)
		{
			var l_string = l.toString();
			var test_id_select = cat_no+l_string;
			//alert(test_id_select);
			var test=document.getElementById(test_id_select);
			if(test != null)
			{
			//alert(test);
				if(test.checked)
				{
					test.click();
					//alert(testarray[selectedTest][0]);
				}
			}
		}

		
		selectedName = testarray[selectedTest][0];
		if(parent.ascii_error_check == 1)
		{
			alert("Please check the delimiter and load file/table again.");
		}
		else
		{
			for(i=0;i<testCount;i++)
			{
				if(selectedTest == testarray[i][2])
				{
					test_no=i;
		
				}
			}
			selectedName=selectedName.toUpperCase();
			var testName = document.getElementById("subtitle");
			selectedTest_name_todisplay=selectedName;

			testName.innerHTML ="<center>"+ selectedName +"</center>";
			//document.getElementById("inputFrame").style.display="block";
	  		document.getElementById("inputFrameDiv").style.display="block";
			var url=http_root+"cgi-bin/VOStatBeta1/stats1.cgi/process;"+processnum+";"+testarray[selectedTest][2]+";"+selectedName;
			var  input_frame = document.getElementById("inputFrame");
			input_frame.src=url;
			input_frame.style.display = "block";
		}
	}

}

//===============================================================================================
//These two functions are for display of test list on click of perticular category

//===============================================================================================
// to check whether ascii or votable is selected
function radio_select(str)
{
	radio_selection = str;
}
//===============================================================================================
//to get delimiter for ascii file entered by user
function user_delimiter()
{
	var test_deli= document.getElementById("delimiter_test").value;

	if(test_deli == "")
	{
	 	test_deli=document.getElementById("sel_test").value;
	}

	alert(test_deli);
	if(new_win)
	{
		window.close();
	}
}
//===============================================================================================
function closewindow()
{
	window.close();
}
//===============================================================================================
//This is the main function called on 'Load File' click in stats1.cgi to load the file entered by user 
function showLoadedFileList(delimiter)
{	
	
	document.getElementById("testtd").style.display="none";
	if(delimiter == null && radio_selection == 'ascii') 
	{
		document.getElementById("testtd").style.display="none";
		ascii_delimiter_selection();
	}
	else
	{
		error_check=radioButtons(radio_selection);
		if(error_check == 1)
		{	
			
			ascii_cancel_check=0;
			if(selectedTest != null)
			{
				test_submit_form = 1;
				file_name_process = testarray[selectedTest][2];
				ascii_onload_var=0;
				processnum=Math.floor(Math.random()*5000);
				/*if(browser_name == "Konqueror")
				{
					//alert("test");
					document.uploadForm.target = document.filesListFrame;
					document.uploadForm.action = http_root+"cgi-bin/VOStatBeta1/stats1.cgi/load;"+processnum+";"+delimiter;
					document.uploadForm.submit();	
				}
				else
				{*/	
					//form.target = "inputFrame";
					//document.uploadForm.target = "inputFrame";
					//document.uploadForm.action = http_root+"cgi-bin/VOStatBeta1/stats1.cgi/new;"+processnum+";"+file_name_process+";"+delimiter+";"+selectedTest+";"+selectedTest_name_todisplay;
					//document.uploadForm.submit();
					document.forms[0].target = "inputFrame";
					document.forms[0].action = http_root+"cgi-bin/VOStatBeta1/stats1.cgi/new;"+processnum+";"+file_name_process+";"+delimiter+";"+selectedTest+";"+selectedTest_name_todisplay;
					document.forms[0].submit();
				//}

				//form.action = http_root+"cgi-bin/VOStatBeta1/stats1.cgi/new;"+processnum+";"+file_name_process+";"+delimiter+";"+selectedTest+";"+selectedTest_name_todisplay;
				//form.submit();
			}
			else
			{
				
				var form=document.getElementById("uploadForm");
				processnum=Math.floor(Math.random()*5000);
				form.action = http_root+"cgi-bin/VOStatBeta1/stats1.cgi/load;"+processnum+";"+delimiter;
				test_iframe= document.getElementById("inputFrame");
				form.target =test_iframe;
				form.submit();
				
			}
		}

	}
	
}

//===============================================================================================
function ascii_delimiter_selection()
{
	var delimiter_disp_block = document.getElementById("testdiv5");
	delimiter_disp_block.style.visibility='visible';
	delimiter_disp_block.style.width='425px';
	delimiter_disp_block.style.height='57px';
	delimiter_disp_block.style.background='white';
	delimiter_disp_block.style.display = "block";
	document.getElementById("testdiv5").style.display = "block";
}
function select_ascii_delimiter() 
{
	var delimiter=document.getElementById("delimiter").value;

	if(delimiter == "")
	{
	 	delimiter=document.getElementById("sel").value;
	}
	document.getElementById("testdiv5").style.display="none";
	//alert(delimiter);
	showLoadedFileList(delimiter);
}
function close_ascii_delimiter_window()
{
        if(ascii_cancel_check != 1)
	{
		fileNameDisplay();	
	} 
	document.getElementById("testdiv5").style.display = "none";
}
//===============================================================================================
// To display file name of the file entered by user
function fileNameDisplay()
{
	//alert("display file");
	uploaded_file=parent.document.getElementById("uploaded_file").value;
	uploaded_url=parent.document.getElementById("uploaded_url").value;
	var test1=parent.document.getElementById("testtd");
	if(uploaded_file)
	{
		var fileName = uploaded_file.split("\\");
		var num = uploaded_file.split("\\").length-1;	
		if(num == 0)
		{
			var fileName = uploaded_file.split("/");
			var num = uploaded_file.split("/").length-1;	
		}
	}
	else
	{
		var fileName = uploaded_url.split("/");
		var num = uploaded_url.split("/").length-1;	
	}

	test1.innerHTML="<br><font color =\"#000066\"><b><h3>Input file: "+fileName[num]+"</h3></b></font>"; 
	test1.style.display="block";

}
//===============================================================================================

//===============================================================================================
/// try other method to read file---- ** this is working
// These two functions are to check file properly loaded or not specially for ascii file
// to check delimeter 
//**************

function getFile(pURL,pFunc) 
{
   if (window.XMLHttpRequest) 
   { // code for Mozilla, Safari, etc
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=postFileReady;
      xmlhttp.open("GET", pURL, true);
      xmlhttp.send(null);
   }
   else if (window.ActiveXObject) 
	{ //IE
	      xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
	      if (xmlhttp) 
		{
        	 xmlhttp.onreadystatechange=postFileReady;
        	 xmlhttp.open('GET', pURL, false);
        	 xmlhttp.send();
      		}
   	}
}

// function to handle asynchronous call to read file
function postFileReady() 
{
   	if (xmlhttp.readyState==4) 
	{
      		if (xmlhttp.status==200) 
		{
			if(xmlhttp.responseText)
			{
				parent.ascii_error_check=0;
				fileNameDisplay();
				if(file_reload == 1)
				{
					if(parent.back_clicked != 1)
					{
						//OkClicked_test(test_no);
					}
				}

			}
			else
			{
				parent.ascii_error_check=1;
				parent.document.getElementById("inputFrameDiv").style.display="none";
				alert("Please check the delimiter and load file/table again.");
			}

		}
		else 
		{
	      		if (xmlhttp.status==404) 
			{
				parent.ascii_error_check=1;
				parent.document.getElementById("inputFrameDiv").style.display="none";
				alert("Please check the delimiter and load file/table again.");
			}
		}
          // here  'xmlhttp.responseText' contains file(read) contents		
         //document.getElementById('theDivToLoad').innerHTML=xmlhttp.responseText;
      	}
}

//===============================================================================================

//===============================================================================================
// If new file loaded when perticular test is already selected for previous file 
//called from the getFile function
//*****Not used for this
/*function OkClicked_test(str)
{
	var test_name_disp =  testarray[str][0];
	//parent.back_clicked=0;
	var testName = parent.document.getElementById("subtitle");
	testName.innerHTML ="<center>"+ test_name_disp.toUpperCase() +"</center>";
	parent.document.getElementById("inputFrame").style.display="block";
  	parent.document.getElementById("inputFrameDiv").style.display="block";
	var url=http_root+"cgi-bin/VOStatBeta1/stats1.cgi/process;"+processnum_new+";"+testarray[str][2]+";"+test_name_disp;
	var  input_frame = parent.document.getElementById("inputFrame");
	input_frame.src=url;
	input_frame.style.display = "block";
}
*/
//===============================================================================================
function saveLink()
{
	window.document.outputForm.submit();
}

//===============================================================================================
//Link for plots option on top toolbar called when that 'p s' button clicked
function psLink(str)
{
	test=document.getElementById("zip_plots").value;
	url =test;
	window.open(url,"_self");

/*	test=document.getElementById("plot").getAttribute("href");
	url =test;
	window.open(url,"_self");
*/
}

//===============================================================================================
//to view data (from the file loaded by user) in  tabular ascii format
function viewDataLink(str)
{
	if(str != null)
	{
		processnum = str;
	}
	if(processnum == null)
	{
		alert("Load File/table First");
	}
	else
	{
		url=http_root+"/VOStatBeta1/temp1/viewdata"+processnum;
		window.open(url,"_blank");
	}
}
//===============================================================================================
// to view R-code for perticular test
function rcodeLink(process_number)
{
	url = http_root+"VOStatBeta1/temp/runR"+process_number;
	window.open(url,"_blank");
//	window.open(url,"_blank","toolbar=no, location=yes, directories=no,\
//	status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, \
//	width=800, height=600");
}

//===============================================================================================
//Link to connect to applet version of VOPlot  feeding data directly
function voplot_link(str)
{

	if(str != null)
	{
		processnum = str;
	}

	if(processnum == null)
	{
		alert("Load File First");
	}
	else
	{
		url = http_root+"VOStatBeta1/VOPlot/loadjvt"+processnum+".html";
		window.open(url,"_blank");
	}
}	

//===============================================================================================
// Link for the help page
function helpPage(str)
{
	if(str == "list")
	{
		url = http_root+"VOStatBeta1/VOStat_help.htm";
	}
	else
	{
		if(str == null && ok_clicked == 0)
		{
			url = http_root+"VOStatBeta1/VOStat_help.htm";
		}
		else
		{	
			if(selectedTest != null)
			{
				url = http_root+"VOStatBeta1/VOStat_help.htm#"+testarray[selectedTest][2];
			}
			else
			{
				url = http_root+"VOStatBeta1/VOStat_help.htm#"+str+".htm";
			}
		}
	}

		window.open(url,"_blank");
	//window.open(url,"_blank","toolbar=no, location=yes, directories=no,\
	//status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, \
	//width=800, height=600");
	
}

//===============================================================================================
//link  for the vo site
function voi()
{
	url ="http://vo.iucaa.ernet.in/~voi/";
	window.open(url,"_blank");
//	window.open(url,"_blank","toolbar=no, location=yes, directories=no,\
//	status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, \
//	width=800, height=600");
}

//===============================================================================================
//link to pennstate astrostatistics webpage
function astrostats()
{
	url ="http://astrostatistics.psu.edu/";
	window.open(url,"_blank");
//	window.open(url,"_blank","toolbar=no, location=yes, directories=no,\
//	status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, \
//	width=800, height=600");
}

//===============================================================================================
//Link to caltech website
function caltech()
{
	url ="http://www.caltech.edu/";
	window.open(url,"_blank");
	//window.open(url,"_blank","toolbar=no, location=yes, directories=no,\
	//status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, \
	//width=800, height=600");
}

//===============================================================================================
// Link for input file Loaded by user
function inputfile_link(str)
{
	if(str != null)
	{
		processnum = str;
	}

	if(processnum == null)
	{
		alert("Load File First");
	}
	else
	{
		url = http_root+"VOStatBeta1/temp1/testfile"+processnum;
		window.open(url,"_blank");
		//window.open(url,"_blank","toolbar=no, location=yes, directories=no,\
		//status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, \
		//width=800, height=600");
	}
}	
//===============================================================================================
//To display total no of tests present 
function list_link()
{
	url = http_root+"vostat_help_pages/index.htm";
	window.open(url,"_blank");
	//window.open(url,"_blank","toolbar=no, location=yes, directories=no,\
	//status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, \
	//width=800, height=600");
}  
//===============================================================================================
function nooutput_link()
{
	alert("Press Submit");
}
//===============================================================================================
function save_link()
{
	//alert("123");
	window.document.outputForm.submit();
}
//===============================================================================================
//Depending on the test specific contents resize the bottom frame
function frame_resize()
{
	if(browser_name == "Konqueror")
	{
		var test_height = document.getElementById('inputFrame').document.body.scrollHeight;
		//alert(test_height);	
	}
	else
	{
		document.getElementById('inputFrame').height=0;
		var the_height=document.getElementById('inputFrame').contentWindow.document.body.scrollHeight;
		//alert(the_height);		
		//change the height of the iframe
		document.getElementById('inputFrame').height=the_height;
		inputFrame_height=the_height;
	}
}

//===============================================================================================
// To display if user misses loading file 

function  Display_alert_message()
{
	if((selectedTest != null) || (testlist_Display_check  != 0))
	{	
		//fileNameDisplay();
	}
	document.getElementById("inputFrameDiv").style.display="none";
	alert("Choose correct filetype or file/table");
}

//===============================================================================================
//to check whether user selcted proper file and filetype

function radioButtons(radio_selection)
{

	var uploaded_file=document.getElementById("uploaded_file");
	var uploaded_url=document.getElementById("uploaded_url");
	
	lengthFile=uploaded_file.value.length;
	lengthUrl=uploaded_url.value.length;

	fileExt=uploaded_file.value.substring(lengthFile-3,lengthFile);
	urlExt=uploaded_url.value.substring(lengthUrl-3,lengthUrl);
	
	error_check=1;
	if(urlExt == "")
	{
		if(fileExt == "")
		{
			alert("Choose any file first");
			error_check=2;
		}
	}
	else
	{
		
		if(radio_selection == "ascii")
		{
			if(fileExt == "")
			{
				if((urlExt == "xml") ||(urlExt == "vot"))
				{
					Display_alert_message();
					error_check=2;
				}
			}
			else
			{
				if((fileExt == "xml") ||(fileExt == "vot"))
				{
					Display_alert_message();
					error_check=2;
				}
			}
		}

		if(radio_selection == "votable")
		{
			if(fileExt == "")
			{
				if(urlExt != "xml") 
				{
					if(urlExt != "vot")
					{
						Display_alert_message();
						error_check=2;
					}
				}
			}
			else
			{
				if(fileExt != "xml") 
				{
					if(fileExt != "vot")
					{
						Display_alert_message();
						error_check=2;
					}
				}
			}
		
		}
	}
	return error_check;
}
//===============================================================================================
//Code for detecting browser version
//This is for Mozilla ,mozillafirefox(versions 0,1,RC2), internet explorer, opera, Netscape, Seamonkey
function check_browser()
{
	browser_name =navigator.appName;
	var browser_version= navigator.appVersion;
	var browser_useragent=navigator.userAgent;
	//alert (browser_name);
	var versionindex_firefox5=navigator.userAgent.indexOf("1.5.0.7");
	if(versionindex_firefox5 != -1)
	{
		version_number=1;
	}	
	var versionindex_firefoxRC=navigator.userAgent.indexOf("1.0RC2");
	if(versionindex_firefoxRC != -1)
	{
		//alert(versionindex_firefoxRC);
		version_number=0;
	}
	if(browser_name == "Microsoft Internet Explorer")
	{
		
		var versionindex=navigator.userAgent.indexOf("MSIE")+5;
		version_number=navigator.userAgent.charAt(versionindex);

	}
	if(browser_name == "Opera")
	{
		var versionindex=navigator.userAgent.indexOf("Opera")+6;
		version_number=navigator.userAgent.charAt(versionindex);

	}
	if(browser_name == "Netscape")
	{
		var versionindex_firefox=navigator.userAgent.indexOf("Firefox")+8;
		version_number=navigator.userAgent.charAt(versionindex_firefox);
		//alert("versionindex_firefox ::: "+versionindex_firefox);
		if(versionindex_firefox == 7)
		{
			var versionindex_netscape=navigator.userAgent.indexOf("Netscape")+9;
			version_number=navigator.userAgent.charAt(versionindex_netscape);
			//alert("versionindex_netscape:::"+versionindex_netscape);
			if(versionindex_netscape == 8)
			{
				var versionindex_seam=navigator.userAgent.indexOf("SeaMonkey")+10;
				version_number=navigator.userAgent.charAt(versionindex_seam);
				//alert("versionindex_seam :::"+versionindex_seam);
				if(version_number == 9)
				{
					var versionindex_firefoxRC=navigator.userAgent.indexOf("1.0RC2");
					if(versionindex_firefoxRC != -1)
					{
						//alert(versionindex_firefoxRC);
						version_number=0;
						var versionindex_firefox3=navigator.userAgent.indexOf("1.0.3");
						if(versionindex_firefox3 != -1)
						{
							version_number=1;
					
						}						
	
					}

				}

				
			}
		}	
	}
	
	//alert(version_number);
}

//===============================================================================================
function submit_click(total_no_columns,test_name_str)
{
	var check_column_selection=0;
	for(i=1;i<=total_no_columns;i++)
	{
		for(j=0;j<4;j++)
		{
			var test_column = (i*10)+j;
			var check_column_transform=document.getElementById(test_column);
			if(check_column_transform.checked)
			{
				check_column_selection = check_column_selection + 1;
			}
		}
		
	}	
	if(check_column_selection == 0 && ((test_name_str == 'ANOVA') || (test_name_str == 'PAIR PLOT') || (test_name_str == 'KRUSKAL WALLIS K-SAMPLE TEST')))
	{
		
		str=1;
		alert("Please select atleast two Columns");
		submit_process(test_name_str,str);

	}
	else
	{
		if(check_column_selection == 0 )
		{
			str=1;
			alert("Please Select atleast one column");
			submit_process(test_name_str,str);
		}
		else
		{
		
			if((test_name_str == 'ANOVA') || (test_name_str == 'PAIR PLOT') || (test_name_str == 'KRUSKAL WALLIS K-SAMPLE TEST')) 
			{
				if(check_column_selection == 1)
				{
					str=1;
					alert(" Please select atleast two Columns");
					submit_process(test_name_str,str);
				}
				else
				{
					//check_column_selection=0;
					str=3;
					submit_process(test_name_str,str);	
				}
			}
			else
			{
				//check_column_selection=0;
				str=3;
				submit_process(test_name_str,str);
				
			}
		}	
	}
}

function submit_process(test_name_str,str)
{
	
	if(str==1)
	{
		//var form=document.getElementById("processForm");
		//form.target = "test_frame";			
		document.processForm.target = "test_frame";
	}
	if(str == 3)	
	{
		//var form=document.getElementById("processForm");

		document.processForm.action = http_root+"cgi-bin/VOStatBeta1/stats1.cgi/Output;"+test_name_str;
		document.processForm.target = "_blank";	
		document.processForm.submit();
	}
}
//===============================================================================================
//For tooltips
var category=null;
var top_tip=0;
var left_tip=0;
var freezepopup=false;
var popup_keep_still=null;

function removepopup(str)
{
	if(freezepopup==false)
	{
		category=str;
		document.getElementById(category).style.visibility='hidden';
	}
}

function displaypopup(str,evnt)
{
	if(freezepopup==false)
	{
		category=str;
		document.getElementById(category).style.visibility='visible';	
	
		if(!IE)
		{
			top_tip=evnt.pageY;
			left_tip=evnt.pageX;
		}

		document.getElementById(category).style.top=top_tip+10 + "px"; 
		document.getElementById(category).style.left=left_tip-200 + "px";
	}
	
}

function freezecategory(str)
{
	if(freezepopup==false)
	{
		popup_keep_still=str;
		document.getElementById(popup_keep_still).style.visibility='visible';
		freezepopup=true;
	}
}
function removefreezecategory(str)
{
	freezepopup=false;
	removepopup(str);
}
//===============================================================================================
//for Internet Explorer mouse position

var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    left_tip = event.clientX + document.body.scrollLeft
    top_tip = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    left_tip = event.pageX
    top_tip = event.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true
}
