//Change Log:
//* Updated: July 11th, 07: Fixed bug with persistence not working. Doh.
//* Updated: July 9th, 07: Added session only persistence to tabs (set "enabletabpersistence" var below). Only .js file changed.
//* Updated Nov 8th, 06. Ability to select a tab dynamically, by calling a method (ie: via a link). Only .js file changed.




var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadstatustext="<table width=100%><tr><td align=center>Requesting content...</td><tr></table>"
var enabletabpersistence=1 //enable tab persistence via session only cookies, so selected tab is remembered (1=yes, 0=no)?


////NO NEED TO EDIT BELOW////////////////////////
var loadedobjects=""
var defaultcontentarray=new Object()
var bustcacheparameter=""

function ajaxpage(url, containerid, targetobj){
	var page_request = false;
	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest();
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){}
		}
	}else
		return false;
	
	var ullist=targetobj.parentNode.parentNode.getElementsByTagName("li")
	for (var i=0; i<ullist.length; i++)
		ullist[i].className=""  //deselect all tabs
	targetobj.parentNode.className="selected"  //highlight currently clicked on tab
	if (url.indexOf("#default")!=-1){ //if simply show default content within container (verus fetch it via ajax)
		window.document.getElementById(containerid).innerHTML=defaultcontentarray[containerid];
		return;
	}
	window.document.getElementById(containerid).innerHTML=loadstatustext;

	page_request.onreadystatechange=function(){ loadpage(page_request, containerid); };
	if (bustcachevar) //if bust caching of external page
	bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
	page_request.open('GET', url+bustcacheparameter, true);
	page_request.send(null);
}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		window.document.getElementById(containerid).innerHTML=page_request.responseText;
}

function loadobjs(revattribute){
	if (revattribute!=null && revattribute!=""){ //if "rev" attribute is defined (load external .js or .css files)
		var objectlist=revattribute.split(/\s*,\s*/) //split the files and store as array
		for (var i=0; i<objectlist.length; i++){
			var file=objectlist[i];
			var fileref="";
			if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
				if (file.indexOf(".js")!=-1){ //If object is a js file
					fileref=window.document.createElement('script');
					fileref.setAttribute("type","text/javascript");
					fileref.setAttribute("src", file);
				}else if (file.indexOf(".css")!=-1){ //If object is a css file
					fileref=window.document.createElement("link")
					fileref.setAttribute("rel", "stylesheet");
					fileref.setAttribute("type", "text/css");
					fileref.setAttribute("href", file);
				}
			}
			if (fileref!=""){
				window.document.getElementsByTagName("head").item(0).appendChild(fileref);
				loadedobjects+=file+" "; //Remember this object as being already added to page
			}
		}
	}
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
	var thetab=window.document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber];
	if (thetab.getAttribute("rel")){
		ajaxpage(thetab.getAttribute("href"), thetab.getAttribute("rel"), thetab);
		loadobjs(thetab.getAttribute("rev"));
	}
}

function savedefaultcontent(contentid){// save default ajax tab content
	if (typeof defaultcontentarray[contentid]=="undefined"); //if default content hasn't already been saved
		defaultcontentarray[contentid]=window.document.getElementById(contentid).innerHTML;

}

function startajaxtabs(){
	for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
		var ulobj=window.document.getElementById(arguments[i])
		var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
		var persisttabindex=(enabletabpersistence==1)? parseInt(getCookie(arguments[i])) : "" //get index of persisted tab (if applicable)
		var isvalidpersist=(persisttabindex<ulist.length)? true : false //check if persisted tab index falls within range of defined tabs
		for (var x=0; x<ulist.length; x++){ //loop through each LI element
			var ulistlink=ulist[x].getElementsByTagName("a")[0];
			ulistlink.index=x;
			if (ulistlink.getAttribute("rel")){
				var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+":"+window.location.port+"/")//
				ulistlink.setAttribute("href", modifiedurl); //replace URL's root domain with dynamic root domain, for ajax security sake
				savedefaultcontent(ulistlink.getAttribute("rel")); //save default ajax tab content
				ulistlink.onclick = function(){
					//var strUrl = this.getAttribute("altlink") ? this.getAttribute("altlink") : this.getAttribute("href");
					//alert(strUrl);
					//ajaxpage(strUrl, this.getAttribute("rel"), this);
					ajaxpage(this.getAttribute("href"), this.getAttribute("rel"), this);
					loadobjs(this.getAttribute("rev"));
					saveselectedtabindex(this.parentNode.parentNode.id, this.index);
					return false;
				}
				if ((enabletabpersistence==1 && persisttabindex<ulist.length && x==persisttabindex) || (enabletabpersistence==0 && ulist[x].className=="selected")){
					ajaxpage(ulistlink.getAttribute("href"), ulistlink.getAttribute("rel"), ulistlink); //auto load currenly selected tab content
					loadobjs(ulistlink.getAttribute("rev")); //auto load any accompanying .js and .css files
				}
			}
		}
	}
}

////////////Persistence related functions//////////////////////////

function saveselectedtabindex(ulid, index){ //remember currently selected tab (based on order relative to other tabs)
if (enabletabpersistence==1) //if persistence feature turned on
	setCookie(ulid, index);
}

function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (window.document.cookie.match(re)) //if cookie found
	return window.document.cookie.match(re)[0].split("=")[1]; //return its value
return ""
}

function setCookie(name, value){
	window.document.cookie = name+"="+value //cookie value is domain wide (path=/)
}
			<!--
// Written by Dexter Zafra at www.ex-designz.net
//Handle Check Username Availability Using Ajax
 var http = createRequestObjectvote();
 function createRequestObjectvote() 
     {
           var xmlhttp;
	 try 
                 { 
                    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
                 }
	  catch(e) 
                 {
	    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	    catch(f) { xmlhttp=null; }
	   			 }
	        if(!xmlhttp&&typeof XMLHttpRequest!="undefined") 
                        {
	  	   xmlhttp=new XMLHttpRequest();
	           }
		   return  xmlhttp;
 }
function comment_vote(add,i){
	var comment_check=window.document.getElementById("comment_"+i+"_check").value
		if (comment_check==0){
		var comment_numdiv=window.document.getElementById("comment_"+i+"_num")
		var comment_num=window.document.getElementById("comment_"+i+"_input").value
		comment_num=parseInt(comment_num)+parseInt(add)
		if (comment_num>0)
		{comment_numdiv.innerHTML="+"+comment_num}
		else
		{comment_numdiv.innerHTML=comment_num}
		
		window.document.getElementById("comment_"+i+"_input").value=comment_num
		window.document.getElementById("comment_"+i+"_check").value=1
			var postdata;
			var PostData;
			PostData = "id=" + i + "&stu=" + add ;
			http.open('POST', "/comment/comment_vote.asp", true);
			http.onreadystatechange = handleResponseTextvote;			
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.send(PostData);		
		}
		var comment_button=window.document.getElementById("comment_"+i+"_button")
		comment_button.innerHTML=""
	}
function handleResponseTextvote() 
  {
     try
         {
             if((http.readyState == 4)&& (http.status == 200))
                {
    	          var response = http.responseText;
                       var update = new Array();

                    if(response.indexOf('|') != -1) 
                       {
                          update = response.split('|');
                          var drelement = document.getElementById('dv'+update[0]);
                          var voteres = document.getElementById('vot'+update[0]);
                          var totalvote = document.getElementById('tv'+update[0]);
                          var starimg = document.getElementById('star'+update[0]);
                          drelement.style.display ='none';
                          voteres.innerHTML = update[2];
                          totalvote.innerHTML = update[3];
                          starimg.innerHTML = update[4].toString();
            			 }
	       		 }
       	 }
	catch(e){alert("an error occured");}
	finally{}
}
function comment_show(name,i,date){
	var comment_show=window.document.getElementById("hide_"+i)
	var comment_check=window.document.getElementById("comment_"+i+"_check").value
	var comment_numdiv=window.document.getElementById("comment_"+i+"_num")
	var comment_num=window.document.getElementById("comment_"+i+"_input").value	
	var comment_content=window.document.getElementById("comment_"+i+"_content").value	
	var cont
	cont="<div class=\"comment_detail\">"
	cont=cont+"<div class=\"comment_user\"><span style=\"font-weight: bold; color: rgb(51, 51, 51);\">"+name+"</span><br/>"+date+"</div>"
	cont=cont+"<div class=\"comment_title\">"+comment_content+"</div>"
	if (comment_num>0)
		{cont=cont+"<div id=\"comment_"+i+"_num\" class=\"comment_num\">+"+comment_num+"</div>"}
		else
		{cont=cont+"<div id=\"comment_"+i+"_num\" class=\"comment_num\">"+comment_num+"</div>"}	
	cont=cont+"<input type=\"hidden\" value=\""+comment_num+"\" id=\"comment_"+i+"_input\"/>"
	cont=cont+"<input type=\"hidden\" value=\""+comment_check+"\" id=\"comment_"+i+"_check\"/>"
	if (comment_check==0)
		{cont=cont+"<div id=\"comment_"+i+"_button\" class=\"comment_date\"><div onclick=\"comment_vote(1,"+i+")\" style=\"float: left; cursor: pointer;\"><img width=\"22\" style=\"width: 22px;\" src=\"/Themes/images/thumb_up.gif\"/></div> <div onclick=\"comment_vote(-1,"+i+")\" style=\"float: left; cursor: pointer; padding-left: 1px;\"><img style=\"width: 22px;\" src=\"/Themes/images/thumb_down.gif\"/></div></div>"}
		else
		{cont=cont+"<div id=\"comment_"+i+"_button\" class=\"comment_date\"></div>"}	
	cont=cont+"<br style=\"clear: both;\"/>"
	cont=cont+"</div>"
	comment_show.innerHTML =cont
	}
function dropchange(name,id,stu)
{
	var comment_show=window.document.getElementById("drop_select")
		comment_show.innerHTML ="<a href=\"/comment/comment_view.asp?id="+id+"&stu="+stu+"\" rel=\"ajaxcontentarea\" style=\"text-decoration:none\">"+name+"</a>"
	}