max_height = 100;

function rewrite (stringtmp) {
	//many organizations like the ampersand
	stringtmp = stringtmp.replace(/&/g,"q7x");
	//we used the semicolon as an ampersand placeholder
	stringtmp = stringtmp.replace(/;/g,"&");
	return (stringtmp);
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
 
}


var http = createRequestObject();

function sndReq(action) {
	http.open('get', 'http://wilkesbarre.org/cgi-bin/calendar/webcal.pl?'+action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        showMe();
        document.getElementById("foo").innerHTML = response;
        
    }
}

var xmlReq = createRequestObject();


function postReq(target, action, string) {

//we need to do some encoding of special characters to get them to the database
	string = rewrite(string);

	//alert (string);
	//return;
	xmlReq.open("POST",action,true);
	xmlReq.setRequestHeader("Content-Type",
	"application/x-www-form-urlencoded; charset=UTF-8");
	xmlReq.send(string);
	
	xmlReq.onreadystatechange = function() {
    	if(xmlReq.readyState == 4){
        	var response = xmlReq.responseText;
        	//showMe(target2);
        	document.getElementById(target).innerHTML = response;
        }
   }
   //alert('here');
    //xmlReq.send(null);

}

var xmlReq1 = createRequestObject();

function postReq1(target1, action1, string1) {
	setTimeout("postReq2('"+target1+"', '"+action1+"', '"+string1+"')",500)
}

function postReq2(target2, action2, string2) {

//we need to do some encoding of special characters to get them to the database
	string2 = rewrite(string2);
	
	//alert (string3);
	//return;
	xmlReq.open("POST",action2,true);
	xmlReq.setRequestHeader("Content-Type",
	"application/x-www-form-urlencoded; charset=UTF-8");
	xmlReq.send(string2);
	
	xmlReq.onreadystatechange = function() {
    	if(xmlReq.readyState == 4){
        	var response = xmlReq.responseText;
        	//showMe(target2);
        	document.getElementById(target2).innerHTML = response;
        }
   }
    //xmlReq.send(null);

}


function hideMe(){
	isIE=document.all;
	isNN=!document.all&&document.getElementById;
	isN4=document.layers;
	whichDog=isIE ? document.all.foo : document.getElementById("foo"); 


  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.foo.visibility="hide";
}

function showMe(){
	isIE=document.all;
	isNN=!document.all&&document.getElementById;
	isN4=document.layers;
	whichDog=isIE ? document.all.foo : document.getElementById("foo"); 


  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.foo.visibility="show";
}

function shift_layer(thelayer) {
	
	if (getheight(thelayer) > 0 ) {
		finalsmall = max_height;
		shrink_layer(thelayer);}
	else {
		finalbig=0;
		grow_layer(thelayer);
	}
}

function switch_search_pic(thelayer) {
	
	if (getheight(thelayer) > 0 ) {
		search_button ='images/search_04.jpg';}
	else {
		search_button ='images/search_05.jpg';
	}
	
	if (document.getElementById){document.getElementById('search_button').src = search_button;}
	else if (document.all){document.all['search_button'].src = search_button;}
	else if (document.layers){document.layers['search_button'].src = search_button;}

}



function grow_layer(thelayer) {
	finalbig = finalbig+10;
	this_layer = thelayer;
	finalbigpx = finalbig + 'px';
	toggleLayer(thelayer, finalbigpx);
	if (finalbig < max_height) {
		//alert('here');
		//document.getElementById('DEBUG').innerHTML = i+' '+finalsmall+' ' + maxdivtext +  ' ' + finalbig;
		setTimeout("grow_layer(this_layer)",1);
	} 
	if (finalbig > max_height) {finalbig = max_height;}
	
}

function shrink_layer(thelayer) {
	finalsmall = finalsmall-10;
	this_layer = thelayer;
	finalsmallpx = finalsmall + 'px';
	toggleLayer(thelayer, finalsmallpx);
	if (finalsmall > 0) {
		//alert('here');
		//document.getElementById('DEBUG').innerHTML = i+' '+finalsmall+' ' + maxdivtext +  ' ' + finalbig;
		setTimeout("shrink_layer(this_layer)",1);
	} 
	if (finalsmall < 0) {finalsmall = 0;}
	
}

function toggleLayer(whichLayer, height)
{
	//document.getElementById('DEBUG').innerHTML = whichLayer;
if (document.getElementById)
{
// this is the way the standards work
document.getElementById(whichLayer).style.height = height;
}
else if (document.all)
{
// this is the way old msie versions work
document.all[whichLayer].style.height = height;
}
else if (document.layers)
{
// this is the way nn4 works
document.layers[whichLayer].style.height = height;
}
}

function getheight(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
height = document.getElementById(whichLayer).style.height;
}
else if (document.all)
{
// this is the way old msie versions work
height = document.all[whichLayer].style.height;
}
else if (document.layers)
{
// this is the way nn4 works
height = document.layers[whichLayer].style.height;
}
//alert(height);
height = height.substring(0,height.length-2);
//alert(height);
return height;
}


function getheight(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
height = document.getElementById(whichLayer).style.height;
}
else if (document.all)
{
// this is the way old msie versions work
height = document.all[whichLayer].style.height;
}
else if (document.layers)
{
// this is the way nn4 works
height = document.layers[whichLayer].style.height;
}
//alert(height);
height = height.substring(0,height.length-2);
//alert(height);
return height;
}