var _url='';
var ldStr='Loading...';
var _loadingStr='<br><br><center>Loading...<br><img src="http://www.hsdm.com/resources/images/pbar.gif"></img></center><br><br>';
var iLinks=new Array();
var iTabs=new Array("gamelab","mathlab","robotolab","contact","about","register","Q&C","match");

for(i=0;i<iTabs.length;i++){
        iLinks[iTabs[i]]=new Object();  
}
iLinks["gamelab"].value="compgame.html";        
iLinks["mathlab"].value="math.html";
iLinks["robotolab"].value="robotolab.html";
iLinks["contact"].value="contact.html";
iLinks["about"].value="/robotolab/index.html";
iLinks["register"].value="/robotolab/EForm.html";
iLinks["Q&C"].value="/robotolab/Q&C.html";
iLinks["match"].value="cgi-bin/directory.pl";


function init(){
var page=window.location.search;
if(page.length<=1){page='robotolab';}else{
page=page.replace(/\?/,"");
}

if(window.location.host!='www.hsdm.com'){
	//window.location='http://www.hsdm.com';
	//return;
}
getDataById(page);
}

function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
        
    self.xmlHttpReq.open('GET', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(null);//getquerystring());
}

function getquerystring() {
    //var form     = document.forms['f1'];
    //var word = form.word.value;
    qstr = '';// 'w=' + escape(word);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
	var att=document.getElementById('content').attributes;			
	document.getElementById('content').innerHTML = str;        
}
function getData(data){
	var url=data.id;
	_url='http://www.hsdm.com/';	
	if(url=='gamelab'){
		_url=_url+iLinks["gamelab"].value;
		data.style.background='rgb(255,225,153)';
	}else if(url=='mathlab'){
		_url=_url+iLinks["mathlab"].value;
		data.style.background='rgb(204,225,204)';
	}else if(url=='robotolab'){
		_url=_url+iLinks["robotolab"].value;
		data.style.background='rgb(204,204,255)';
	}else if(url=='contact'){
		_url=_url+iLinks["contact"].value;
		data.style.background='rgb(255,255,204)';
	}else if(url.match(/^id=/)){
                _url=_url+iLinks["match"].value+"?"+url;
	}else{
		_url=_url+iLinks["robotolab"].value;
		data.style.background='rgb(204,204,255)';
	}	
	
	setTimeout("xmlhttpPost(_url)",1000);		
	updatepage(_loadingStr);		
}


function goTo(data){	
	window.location="http://www.hsdm.com/index.html?"+data.id;
}

function getDataById(idStr){
	var url=idStr;
	_url='http://www.hsdm.com/';	
	if(url=='gamelab'){
		_url=_url+iLinks["gamelab"].value;
		
	}else if(url=='mathlab'){
		_url=_url+iLinks["mathlab"].value;
		
	}else if(url=='robotolab'){
		_url=_url+iLinks["robotolab"].value;
		
	}else if(url=='contact'){
		_url=_url+iLinks["contact"].value;
		
	}else if(url=='about'){
		_url=_url+iLinks["about"].value;		
	}else if(url.match(/^id=/)){
		_url=_url+iLinks["match"].value+"?"+url;
	}else{
                _url=_url+iLinks["robotolab"].value;
        }   
	updatepage(_loadingStr);
	setTimeout("xmlhttpPost(_url)",1000);	
}

function showInfo(data){
	var url=data.id;			
	if(url=='gamelab'){		
		data.style.background='rgb(255,225,153)';
	}else if(url=='mathlab'){		
		data.style.background='rgb(204,225,204)';
	}else if(url=='robotolab'){
		data.style.background='rgb(204,204,255)';
	}else if(url=='contact'){
		data.style.background='rgb(255,255,204)';
	}		
}

function hideInfo(data){	
	data.style.background='transparent';
}
