function virtualpaginate(className, chunksize, elementType){
    var elementType=(typeof elementType=="undefined")? "div" : elementType //The type of element used to divide up content into pieces. Defaults to "div"
    this.pieces=virtualpaginate.collectElementbyClass(className, elementType) //get total number of divs matching class name
    this.chunksize=(typeof chunksize=="undefined")? 1 : (chunksize>0 && chunksize <this.pieces.length)? chunksize : this.pieces.length
    this.pagecount=Math.ceil(this.pieces.length/this.chunksize) //calculate number of "pages" needed to show the divs
    this.showpage(-1) //show no pages (aka hide all)
    this.currentpage=0 //Having hidden all pages, set currently visible page to 1st page
    this.showpage(this.currentpage) //Show first page
}

virtualpaginate.collectElementbyClass=function(classname, element){
    //Returns an array containing DIVs with specified classname
    var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
    var pieces=[]
    var alltags=document.getElementsByTagName(element)
    for (var i=0; i<alltags.length; i++){
        if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
        pieces[pieces.length]=alltags[i]
    }
    return pieces
}


virtualpaginate.prototype.showpage=function(pagenumber){
    var totalitems=this.pieces.length //total number of broken up divs
    var showstartindex=pagenumber*this.chunksize //array index of div to start showing per pagenumber setting
    var showendindex=showstartindex+this.chunksize-1 //array index of div to stop showing after per pagenumber setting
    for (var i=0; i<totalitems; i++){
        if (i>=showstartindex && i<=showendindex)
        this.pieces[i].style.display="block"
        else
        this.pieces[i].style.display="none"
    }
    this.currentpage=parseInt(pagenumber)
    if (this.cpspan) //if <span class="paginateinfo> element is present, update it with the most current info (ie: Page 3/4)
    this.cpspan.innerHTML=''+(this.currentpage+1)+'/'+this.pagecount
}

virtualpaginate.prototype.paginate_build_selectmenu=function(paginatedropdown, anchortext){
    var instanceOfBox=this
    var anchortext=anchortext || new Array()
    this.selectmenupresent=1
    for (var i=0; i<this.pagecount; i++){
        if (typeof anchortext[i]!="undefined") //if custom anchor text for this link exists, use anchor text as each OPTION's text
        paginatedropdown.options[i]=new Option(anchortext[i], i)
        else //else, use auto incremented, sequential numbers
        paginatedropdown.options[i]=new Option("Page "+(i+1)+" of "+this.pagecount, i)
    }
    paginatedropdown.selectedIndex=this.currentpage
    paginatedropdown.onchange=function(){
        instanceOfBox.showpage(this.selectedIndex)
    }
}

virtualpaginate.prototype.paginate_build_regularlinks=function(paginatelinks){
    var instanceOfBox=this
    for (var i=0; i<paginatelinks.length; i++){
        var currentpagerel=paginatelinks[i].getAttribute("rel")
        if (currentpagerel=="previous" || currentpagerel=="next" || currentpagerel=="first" || currentpagerel=="last") //screen for these "rel" values
        paginatelinks[i].onclick=function(){
            instanceOfBox.navigate(this.getAttribute("rel"))
            return false
        }
    }
}


virtualpaginate.prototype.paginate_build_flatview=function(flatviewcontainer, anchortext){
    var instanceOfBox=this
    var flatviewhtml=""
    var anchortext=anchortext || new Array()
    for (var i=0; i<this.pagecount; i++){
        if (typeof anchortext[i]!="undefined") //if custom anchor text for this link exists
        flatviewhtml+='<a href="#flatview" rel="'+i+'">'+anchortext[i]+'</a> ' //build pagination link using custom anchor text
        else
        flatviewhtml+='<a href="#flatview" rel="'+i+'">'+(i+1)+'</a> ' //build  pagination link using auto incremented sequential number instead
    }
    flatviewcontainer.innerHTML=flatviewhtml
    this.flatviewlinks=flatviewcontainer.getElementsByTagName("a")
    for (var i=0; i<this.flatviewlinks.length; i++){
        this.flatviewlinks[i].onclick=function(){
            instanceOfBox.flatviewlinks[instanceOfBox.currentpage].className="" //"Unhighlight" last flatview link clicked on...
            this.className="selected" //while "highlighting" currently clicked on flatview link (setting its class name to "selected"
            instanceOfBox.showpage(this.getAttribute("rel"))
            return false
        }
    }
    this.flatviewlinks[this.currentpage].className="selected" //"Highlight" current page
    this.flatviewpresent=true //indicate flat view links are present
}



virtualpaginate.prototype.paginate_build_cpinfo=function(cpspan){
    this.cpspan=cpspan
    cpspan.innerHTML=''+(this.currentpage+1)+'/'+this.pagecount
}

virtualpaginate.prototype.buildpagination=function(divid, optnavtext){
    var instanceOfBox=this
    var paginatediv=document.getElementById(divid)
    if (this.chunksize==this.pieces.length){ //if user has set to display all pieces at once, no point in creating pagination div
        paginatediv.style.display="none"
        return
    }
    var paginationcode=paginatediv.innerHTML //Get user defined, "unprocessed" HTML within paginate div
    if (paginatediv.getElementsByTagName("select").length>0) //if there's a select menu in div
    this.paginate_build_selectmenu(paginatediv.getElementsByTagName("select")[0], optnavtext)
    if (paginatediv.getElementsByTagName("a").length>0) //if there are links defined in div
    this.paginate_build_regularlinks(paginatediv.getElementsByTagName("a"))
    var allspans=paginatediv.getElementsByTagName("span") //Look for span tags within passed div
    for (var i=0; i<allspans.length; i++){
    if (allspans[i].className=="flatview")
        this.paginate_build_flatview(allspans[i], optnavtext)
        else if (allspans[i].className=="paginateinfo")
        this.paginate_build_cpinfo(allspans[i])
    }
    this.paginatediv=paginatediv
}


virtualpaginate.prototype.navigate=function(keyword){
    if (this.flatviewpresent)
    this.flatviewlinks[this.currentpage].className="" //"Unhighlight" previous page (before this.currentpage increments)
    if (keyword=="previous")
    this.currentpage=(this.currentpage>0)? this.currentpage-1 : (this.currentpage==0)? this.pagecount-1 : 0
    else if (keyword=="next")
    this.currentpage=(this.currentpage<this.pagecount-1)? this.currentpage+1 : 0
    else if (keyword=="first")
    this.currentpage=0
    else if (keyword=="last")
    this.currentpage=this.pieces.length-1
    this.showpage(this.currentpage)
    if (this.selectmenupresent)
    this.paginatediv.getElementsByTagName("select")[0].selectedIndex=this.currentpage
    if (this.flatviewpresent)
    this.flatviewlinks[this.currentpage].className="selected" //"Highlight" current page
}


function ajaxRequestReturn(url, parameters, divx) {
	var ajaxRequest=null;

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Browser not suppported
				alert("Your browser not supported!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(divx);
			var tempresponse = ajaxRequest.responseText;
			ajaxDisplay.innerHTML = tempresponse;
		}
	}
	ajaxRequest.open('GET', url + "?" + parameters, true);
	ajaxRequest.send(null);
}

function callCollege(url, division) {
	var ajaxRequest=null;

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Browser not suppported
				alert("Your browser not supported!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(division);
			var tempresponse = ajaxRequest.responseText;
			ajaxDisplay.innerHTML = tempresponse;
		}
	}
	var params = "keyword=" + document.getElementById('school').value;
	//alert(url + "?" + params);
	ajaxRequest.open('GET', url + "?" + params, true);
	ajaxRequest.send(null);
}

function ajaxRequest(url, parameters) {
	var ajaxRequest=null;

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Browser not suppported
				alert("Your browser not supported!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxbox');
			var tempresponse = ajaxRequest.responseText;
			ajaxDisplay.innerHTML = tempresponse;
		}
	}
	ajaxRequest.open('GET', url + "?" + parameters, true);
	ajaxRequest.send(null);
}

function makePostRequest(url, parameters) {
	var ajaxRequest=null;

	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Browser not suppported
				alert("Your browser not supported!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			// Do nothing here
		}
	}
	ajaxRequest.open('POST', url, true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(parameters);
}

function makeFreeRequest(url, parameters) {
	var ajaxRequest=null;

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Browser not suppported
				alert("Your browser not supported!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			// Do nothing here
		}
	}
	ajaxRequest.open('GET', url + "?" + parameters, true);
	ajaxRequest.send(null);
}

//Browser Support Code
function cancelit(divisionx){
	document.getElementById(divisionx).innerHTML = "";
}

function submitit(useridx, divisionx){
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(divisionx);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var reply = document.getElementById('reply'+divisionx).value;
	if (reply != "") {
		var newreply = escape(reply.replace("/\n/g","<br />"));
		var str = "userid="+useridx+"&division="+divisionx+"&reply="+newreply+"&submit=yes";
		ajaxRequest.open("GET", "http://www.zillr.com/reply.php?"+str, true);
		ajaxRequest.send(null);
	} else {
		document.getElementById(divisionx).innerHTML = "";
	}
}

function delete_zill(zill_id, pid){
	var ajaxRequest;  // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.getElementById('field'+zill_id).innerHTML = "<font color=\"GRAY\">Deleted</font>";
		}
	}
	document.getElementById('field'+zill_id).innerHTML = "<img src=\"http://www.zillr.com/images/spacer.gif\" width=\"10\" height=\"20\"><div align=\"right\" style=\"COLOR:GRAY\"> Deleted&nbsp;&nbsp;&nbsp;&nbsp;</div><img src=\"http://www.zillr.com/images/spacer.gif\" width=\"10\" height=\"10\">";
	var str = "a=delete&zid=" + zill_id + "&pid=" + pid;
	ajaxRequest.open("GET", "http://www.zillr.com/zills.php?"+str, true);
	ajaxRequest.send(null);
}

function encodeMyHtml(encodedHtml) {
	encodedHtml = encodedHtml.replace(/\//g,"%2F");
	encodedHtml = encodedHtml.replace(/\?/g,"%3F");
	encodedHtml = encodedHtml.replace(/=/g,"%3D");
	encodedHtml = encodedHtml.replace(/&/g,"%26");
	encodedHtml = encodedHtml.replace(/@/g,"%40");
	return encodedHtml;
}

function show_reply_box(useridx, divisionx){
	var responseText = "<form name=\"reply_form"+divisionx+"\"><div><textarea id=\"reply"+divisionx+"\" name=\"reply"+divisionx+"\" cols=\"60\" rows=\"3\" class=\"areainput\"></textarea><br> <input type=\"button\" onclick=\"javascript:this.disabled=true;this.value='sending ... ';submitit('"+useridx+"', '"+divisionx+"')\" value=\"send a zill\" class=\"button\"> &nbsp;&nbsp;&nbsp;&nbsp;<input type=\"button\" onclick=\"cancelit('"+divisionx+"')\" value=\"close\" class=\"button\"> <br><br></div></form>";
	var jsDisplay = document.getElementById(divisionx);
	jsDisplay.innerHTML = responseText;
	putFocus("reply_form"+divisionx+"", "reply"+divisionx+"");
}

function putFocus(formInst, elementInst) {
	if (document.forms.length > 0) {
		document.forms[formInst].elements[elementInst].focus();
	}
}

function set_division_message(id, message) {
	var jsDisplay = document.getElementById(id);
	jsDisplay.innerHTML = message;
}

function accept_chat(userid) {
	var urlx = "http://www.zillr.com/xchat.php?pid="+userid+"&status=1";
	var windowx = "window_"+userid;
	var paramsx = "menubar=no,width=325,height=350,scrollbars=no,left=300,top=100,directories=no,location=no,resizable=yes,status=no,toolbar=no";
	if (window.open(urlx, windowx, paramsx)){
		document.getElementById('chat'+userid).innerHTML="";
	}else{
		alert("Turn off your popup blocker!");
	}
}

function invite_chat(userid) {
	var urlx = "http://www.zillr.com/xchat.php?pid="+userid+"&invite_status=1";
	var windowx = "window_"+userid;
	var paramsx = "menubar=no,width=325,height=350,scrollbars=no,left=300,top=100,directories=no,location=no,resizable=yes,status=no,toolbar=no";
	if (window.open(urlx, windowx, paramsx)){
		//document.getElementById('chat'+userid).innerHTML="<div align=right>Chat Accepted </div>";
	}else{
		alert("Turn off your popup blocker!");
	}
}

function deny_chat(userid) {
	makeFreeRequest("http://www.zillr.com/deny_chat.php", "pid="+userid+"&status=0");
	document.getElementById("chat"+userid).innerHTML="";
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength){
		obj.value=obj.value.substring(0,mlength);
	}
}

function registerMe() {
	var ajaxRequest=null;

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Browser not suppported
				alert("Your browser not supported!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('msg_error');
			var returned = ajaxRequest.responseText;
			if(returned.indexOf("Successful,")>0) {
				window.location="http://www.zillr.com/edit_profile.php?welcome=1";
			} else {
				ajaxDisplay.innerHTML = returned;
			}
		}
	}
	document.getElementById('msg_error').innerHTML = 'Please wait ....';
	var email = document.getElementById('email').value;
	var firstname = document.getElementById('firstname').value;
	var lastname = document.getElementById('lastname').value;
	var userpass = document.getElementById('userpass').value;
	var userpass1 = document.getElementById('userpass1').value;

	var firstname = encodeURIComponent(firstname);
	var lastname = encodeURIComponent(lastname);
	var userpass = encodeURIComponent(userpass);
	var userpass1 = encodeURIComponent(userpass1);
	var txtcaptcha = document.getElementById('txtcaptcha').value;

	var parameters = "m=register&a=xdo&email="+email+"&firstname="+firstname+"&lastname="+lastname+"&userpass="+userpass+"&userpass1="+userpass1+"&txtcaptcha="+txtcaptcha;
	var url = "http://www.zillr.com/nofile.php";

	//alert(url+"?"+parameters);

	ajaxRequest.open('GET', url + "?" + parameters, true);
	ajaxRequest.send(null);
}