function init(){
     clearTabs();
     setOnKeyPressEvents();
     getPage("home.html");
}

function ajaxFunction(art, sng)
{
	//     alert("In AJAX Func with " + art + " and " + sng);
     var xmlhttp;
     if (window.XMLHttpRequest)
     {
         // code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp=new XMLHttpRequest();
     }
     else if (window.ActiveXObject)
     {
         // code for IE6, IE5
         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     else
     {
         alert("Your browser does not support XMLHTTP! Please upgrade to a newer browser to use the searchable songbook.");
     }

     var url = "http://www.thesmartstoday.com/mobilemusicnj/search.php?artist=" + escape(art)+"&song="+escape(sng);

     xmlhttp.open("GET",url,true);
     xmlhttp.send(null);     
     xmlhttp.onreadystatechange =  function(){
	//alert(xmlhttp.readyState);
	                                if(xmlhttp.readyState == 4){
		                             document.getElementById("song_list").innerHTML=xmlhttp.responseText;
	                                }
                                    };
     //xmlhttp.send(null);
}
function waitfirst(){
	//alert("In waitfirst.");
	document.getElementById("song_list").innerHTML="<img src='http://www.thesmartstoday.com/mobilemusicnj/waiting.gif' alt='waiting annimation' />";
}
function clearTabs(){
              var oldtab = document.getElementById('global_var').innerHTML;
              if(oldtab!=""){
                    var oldli = document.getElementById(oldtab);
                    if(oldli){
                          if(oldli.id!="news.html"){
                                 oldli.setAttribute("className","");
                          }else{
                                 oldli.setAttribute("className","first");
                          }
                    }
              }
}

function setClass(id){
        var li = document.getElementById(id);
        if(li==null){
             if(id!="home.html") {
                 alert("Cannot set selected tab.");
             }
        }
        else
        {
	      clearTabs();
              li.setAttribute("className",li.className + " selected");
              document.getElementById('global_var').innerHTML=li.id;
        }
}
function checkEnter(e, artist, song){
	var characterCode;
	//alert(e.keyCode);
/*	if(e && e.which){
		e = e;
		characterCode=e.keyCode;
	}*/
	characterCode=e.keyCode;
	//alert(characterCode + "characterCode");
	if(characterCode==13){
		//	alert(characterCode + " " + artist + " " + song);
		waitfirst();
		ajaxFunction(artist, song);
		return false;
	}else{
		return true;
	}
}

function getPage(site){
     //alert("Entering getPage(" + site + ")");
     setClass(site);
     //alert("Exiting setClass(" + site + ")");
     var xmlhttp;
     if (window.XMLHttpRequest)
     {
         // code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp=new XMLHttpRequest();
     }
     else if (window.ActiveXObject)
     {
         // code for IE6, IE5
         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     else
     {
         alert("Your browser does not support XMLHTTP! Please upgrade to a newer browser to use the searchable songbook.");
     }
     //alert(site + " before escape.");
     var url = encodeURI(site);
     //alert(url + " after escape.");
     xmlhttp.open("GET",url,false);
     xmlhttp.send(null);     
     //alert("xmlhttp.readyState = " + xmlhttp.readyState);
     //xmlhttp.onreadystatechange = function () { 
            //alert("XMLHTTP returned with " + xmlhttp.readyState);
            if(xmlhttp.readyState == 4){
                 document.getElementById("content").innerHTML=xmlhttp.responseText;
            };
     //};
     //xmlhttp.send(null);
     //alert(site.indexOf("search_page"));
     /*if(site.indexOf("search_page")>0){
	var inputs = document.getElementsByTag("input");
	for(var i = 0; i<inputs.length; i++){
		inputs[0].onkeydown=checkEnter(event);
	}
	*/
}

