function makeRequest(url, parameters) {
   var string = "OFF";
	var http_request = false;
   try {
      //If the javascript version is greater than 5.
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
      //If not, then use the older active x object.
      try {
         //If we are using Internet Explorer.
         http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
         //Else we must be using a non-IE browser.
         http_request = false;
      }
   }
   //If we are using a non-IE browser, create a javascript instance of the object.
   if (!http_request && typeof XMLHttpRequest != 'undefined') {
      http_request = new XMLHttpRequest();
   }

   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
   }

	//This is supposed to be asynchronous but Firefox seems to return 
	//undefined immediately and which basically kills this script. 
	//However, Internet Explorer works as expected returning the correct state once 
	//the server responded.  So, I am making it synchronous against my better judgment 
	//since there are times when we might have internet issues where response can take a while
	// and user will be waitting forever ... 
	//In any case for now this is a solution to a problem but not the best solution
 
   http_request.open("GET", url + parameters, false);
   http_request.send(null);
   if (http_request.status == 200) {
   	return http_request.responseText;
   } else {
			alert ("error in request");
	} 
}

function filterOnline(sender) {
   var getURLInfo = sender.search;
   var schoolInfo = getURLInfo.replace(/\?/, "");
   var tempSchool = schoolInfo.split("&");
   var schoolID = tempSchool[0];
	var tester = "";
  
   //the schoolID extracts out the the whole schoolId=xx
   tester = makeRequest("./t1.php?"+schoolInfo+"&isActive=1", '');
   if( tester == "OFF" ) {
      showflyout('simple.htm', 410, sender);
   } else if( tester == "OK") { 
     window.location = sender.href;
   } else {
		//place holder
     window.location = sender.href;
	 } 
}

   
VormoApp = function() {
	//Detect Internet Explorer and/or Firefox
	this.isMac = false;
	this.isIE = false;
	this.isIE7 = false;
	this.isFirefox = false;
	this.isOpera = false;
	this.isSafari = false;
	this.isWin = false;
	if (navigator.platform.indexOf("Mac")>-1) this.isMac = true;
	if (navigator.appName.indexOf("Explorer")>-1 & navigator.userAgent.indexOf('Opera')==-1) this.isIE = true;
	if (navigator.userAgent.indexOf("Firefox")>-1) this.isFirefox = true;
	if (navigator.userAgent.indexOf('Opera')>-1) this.isOpera = true;
	if (navigator.userAgent.indexOf("Safari")>-1) this.isSafari = true;
	if (navigator.appVersion.toLowerCase().indexOf("win") != -1) this.isWin = true;
	if (this.isIE) {
		var tmp=navigator.appVersion.split("MSIE")
		var browserVersion=parseFloat(tmp[1])
		if (browserVersion>=7) {
			//this.isIE = false;
			this.isIE7 = true;
		}
	}
};

//Methods for getting coordinates given a supplied event object
VormoApp.prototype.GetMouseX = function(e) {
	if (!e) e = window.event; //If no event was passed (it's only passed for FireFox), then set it to the last window.event
	if (!this.isSafari) var coord = (this.isIE) ? event.clientX + document.documentElement.scrollLeft : coord = e.pageX;
	else var coord = (this.isIE) ? event.clientX + document.body.scrollLeft : coord = e.pageX;
	return coord;
};
VormoApp.prototype.GetMouseY = function(e) {
	if (!e) e = window.event; //If no event was passed (it's only passed for FireFox), then set it to the last window.event
	if (!this.isSafari) var coord = (this.isIE) ? event.clientY + document.documentElement.scrollTop : coord = e.pageY;
	else var coord = (this.isIE) ? event.clientY + document.body.scrollTop : coord = e.pageY;
	return coord;
};

//Methods for getting the dimensions of the viewable part of the page
VormoApp.prototype.ViewableWidth = function() {
    var coord = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    if (this.isSafari) coord = document.clientWidth + document.body.scrollLeft;
    return coord;
};
VormoApp.prototype.ViewableHeight = function() {
    var coord = document.documentElement.clientHeight + document.documentElement.scrollTop;
    if (this.isSafari) coord = document.clientHeight + document.body.scrollTop;
    return coord;
};

//Utility methods
//Method walks up the DOM to get the offset pos of elements in order
//to calculate the absolute pos of a given element
VormoApp.prototype.getAbsolutePos = function(elem, dim, overridemaxsteps) {
    var maxSteps = 25;
    if (typeof(overridemaxsteps)!='undefined') maxSteps = overridemaxsteps;
    var runningCalc = 0;
    var elemDim;
    var tmpElem = elem;
    for (var i=1; i<=maxSteps; i++) {
        if (!tmpElem.offsetParent) break;
        runningCalc += (dim=='left') ? tmpElem.offsetLeft : tmpElem.offsetTop;
        tmpElem = tmpElem.offsetParent;
    }
    return runningCalc;
};
VormoApp.prototype.integerizePos = function(str) {
	var tmp = str;
	if (str.indexOf("px") > -1) {
		tmp = str.substring(0,str.indexOf("px"));
	}
	return tmp*1;
};
VormoApp.prototype.setImageSrc = function(imgObj, strSrc, scale) {
	imgObj.src = strSrc;
	if (this.isIE && !this.isIE7 (strSrc.indexOf(".png") > -1)) {
		var scaleStr = '';
		if (scale) scaleStr = ", sizingMethod='scale'";
		imgObj.src = 'images/dot_tran.gif';
		imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + strSrc + "'" + scaleStr + ");";
	}
};

//Invoke the class above. All other classes will be subs of this object.
var Vormo = new VormoApp();


//***********************************************************************************************
Vormo.Ajax = function () {
	Vormo.Ajax.count++;
	this.ID = Vormo.Ajax.count;
	this.http_request = false;
	this.RequestStatusCode = -1;
	this.RequestComplete = false;
	this.URL = "";
	this.PostData = "";
	this.ResponseText = "";
	this.ResponseXML;
}
Vormo.Ajax.count = 0;

Vormo.Ajax.prototype.GetXML = function (method) {
    var tmpMethod = 'get'
    if (typeof(method)=='string') {
        if (method=='post') tmpMethod = 'post';
    }
    method = tmpMethod;
    
	this.http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		this.http_request = new XMLHttpRequest();
		if (this.http_request.overrideMimeType) {
			this.http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			this.http_requestuest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!this.http_request) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}
	
	//Define the function that gets called when the readystate changes right
	//here so it's internal to the object
	var asynxml = this;
	this.http_request.onreadystatechange = function () {
    	if (asynxml.http_request.readyState == 4) {
			if (asynxml.http_request.status == 200 | asynxml.http_request.status == 304) {
				asynxml.RequestStatus = asynxml.http_request.readyState;
				asynxml.ResponseText = asynxml.http_request.responseText;
				asynxml.ResponseXML = asynxml.http_request.responseXML;
				asynxml.RequestComplete = true;
    			asynxml.ExecuteAfter.call();
			} else {
				asynxml.RequestStatus = asynxml.http_request.readyState;
				if (asynxml.ExecuteOnError) asynxml.ExecuteOnError.call();
			}
		}
	}
	if (this.URL=='' | this.URL==null) {
		alert('Error: invalid url');
		return;
	}
	if (method=='post') {
	    this.http_request.open('POST', this.URL, true);
    	this.http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    	this.http_request.send(this.PostData);
	} else {
	    this.http_request.open('GET', this.URL, true);
    	this.http_request.send(null);
	}
}

Vormo.Ajax.prototype.ExecuteAfter = function () {
	//alert('XML request complete');
}
Vormo.Ajax.prototype.ExecuteOnError = function () {
    //alert('XML request error')
}

//***********************************************************************************************



Flyout = function() {
    // Constants
    // Modify these if you like
    this.Zindex = 1000; //The z-index of the box - increase if you need to
    this.Xoffset = 6; //Number of pixels between the trigger element and the box
    this.Yoffset = -2; //Number of pixels above or below the top of the trigger element that the box appears
    this.Width = 400; //Default width of the box - overridden by the arguments in the Show() method
    this.ShowDelay = 1; //The number of microseconds before the animation begins;
    this.AnimationSteps = 6; //Number of steps in the flyout animation (smoothness)
    this.AnimationDelay = 15; //Number of microseconds before next animation step (slowness);
    this.closeImgOff = new Image();
        this.closeImgOff.src = 'images/x.gif'; //The "up" image for close button
    this.closeImgOn = new Image();
        this.closeImgOn.src = 'images/x-dn.gif'; //The "down" image for close button
        
    // Other variables for later
    this.MouseIsOver = true;
    this.Showing = false;
    this.X = 0;
    this.Y = 0;
    this.AnimationDirection = 1;
    /* -- Modified 12/28 -- */
    this.OriginX = 0; 
    /* -- /Modified 12/28 -- */
    this.Ajax = new Vormo.Ajax();
    this.HideTimeout;
    this.AnimationTimeout;
    this.Dragging = false;
    this.DragOffsetX = 0;
    this.DragOffsetY = 0;
    this.DragBaseX = 0;
    this.DragBaseY = 0;
    this.EndHeight;
    this.CurrentAnimationStep = 1;
    this.Pinned = true;
    this.Element;
    this.oldBodyMouseMove;
    this.oldBodyMouseUp;
    if (Vormo.isSafari) this.Xoffset += 6;
    if (Vormo.isSafari) this.Yoffset += 6;
    var flyout = this;
    
    this.MainDiv = document.createElement('div');
    this.MainDiv.className="flyout_main";
    this.MainDiv.style.left='-1000px';
    this.MainDiv.style.position='absolute';
    this.MainDiv.style.zIndex=this.Zindex;
    this.InnerDiv = document.createElement('div');
    this.InnerDiv.className="flyout_inner";
    this.HeaderDiv = document.createElement('div');
    this.HeaderDiv.className="flyout_header";
    this.ContentDiv = document.createElement('div');
    this.ContentDiv.className="flyout_content";
    
    this.LogoDiv = document.createElement('div');
    this.LogoDiv.className="flyout_header_logo";
    this.LogoText = document.createTextNode('Zip Code');
    this.LogoDiv.appendChild(this.LogoText);
    this.HeaderDiv.appendChild(this.LogoDiv);
    
    var closeDiv = document.createElement('div');
    closeDiv.className="flyout_header_close";
    closeDiv.onclick = function() {
        flyout.Hide();
    }
    this.closeTxt = document.createTextNode('Close ');
    this.closeImg = document.createElement('img');
    this.closeImg.src = this.closeImgOff.src;
    this.closeImg.onmousedown = function() {
        flyout.closeImg.src = flyout.closeImgOn.src;
    }
    this.closeImg.onmouseup = function() {
        flyout.closeImg.src = flyout.closeImgOff.src;
    }
    closeDiv.appendChild(this.closeTxt);
    closeDiv.appendChild(this.closeImg);
    this.HeaderDiv.appendChild(closeDiv);
    
    this.InnerDiv.appendChild(this.HeaderDiv);
    this.InnerDiv.appendChild(this.ContentDiv);
    this.MainDiv.appendChild(this.InnerDiv);
    document.body.appendChild(this.MainDiv);
    
    /* -- Modified 12/28 -- 8 */
    this.Animate = function(dir) {
        if (flyout.CurrentAnimationStep == 1){
            if (flyout.AnimationDirection==1 & !flyout.MouseIsOver) {
                clearTimeout(flyout.HideTimeout);
                clearTimeout(flyout.AnimationTimeout);
                flyout.Showing = false;
                flyout.Reset();
                return;
            }
            flyout.EndHeight = flyout.MainDiv.offsetHeight;
            flyout.CalcFinalPosition(flyout.X,flyout.Y);
        }

        if (flyout.CurrentAnimationStep > flyout.AnimationSteps) {
            flyout.CurrentAnimationStep = 1;
            clearTimeout(flyout.AnimationTimeout);
            //Apply the mouse functions for the main div after it reaches it's final destination;
            flyout.Showing = false;
            if (flyout.AnimationDirection==1) {
                flyout.MainDiv.onmouseover = flyout.MainDivMouseover;
                flyout.MainDiv.onmouseout = flyout.MainDivMouseout;
            } else {
                flyout.Reset();
            }
            flyout.AnimationDirection = 1;
            return;
        }
        //Calculate the increments to the target
        var thisX = Math.round((flyout.X-flyout.OriginX) / flyout.AnimationSteps) * flyout.CurrentAnimationStep + flyout.OriginX; 
        var thisW = Math.round(flyout.Width / flyout.AnimationSteps) * flyout.CurrentAnimationStep;
        var thisH = Math.round(flyout.EndHeight / flyout.AnimationSteps) * flyout.CurrentAnimationStep;
        if (flyout.AnimationDirection==-1) {
            thisX = flyout.X - (thisX - flyout.OriginX);
            thisW = flyout.Width - thisW;
            thisH = flyout.EndHeight - thisH;
        }
        
        if (flyout.CurrentAnimationStep == flyout.AnimationSteps) {
            if (flyout.AnimationDirection==1) {
                thisX = flyout.X;
                thisW = flyout.Width;
                thisH = 0;
            } else {
                thisX = flyout.OriginX;
                thisW = 1;
                thisH = 1;
            }
        }
        flyout.CurrentAnimationStep++;
        flyout.Display(thisW, thisH, thisX);
        flyout.AnimationTimeout = setTimeout(flyout.Animate,flyout.AnimationDelay);
    };
    this.Hide = function() {
        if (flyout.MainDiv.style.visibility=='hidden') return;
        flyout.AnimationDirection = -1;
        flyout.MainDiv.onmouseover = null;
        flyout.MainDiv.onmouseout = null;
        flyout.Animate();
    };
    this.Reset = function() {
        flyout.MainDiv.style.visibility='hidden';
        flyout.MainDiv.style.top = '-100px';
        flyout.MainDiv.style.height = 'auto';
        flyout.MainDiv.style.left = '-1000px';
        flyout.Pinned = false;
    };
    /* /-- Modified 12/28 -- 8 */
    
    this.MainDivMouseover = function() {
        clearTimeout(flyout.HideTimeout);
    };
    this.MainDivMouseout = function() {
        if (!flyout.Pinned) flyout.HideTimeout = setTimeout(flyout.Hide,15000);
    };
    this.MainDiv.onmousedown = function(e) {
        flyout.DragOffsetX = Vormo.GetMouseX(e);
        flyout.DragOffsetY = Vormo.GetMouseY(e);
        flyout.DragBaseX= Vormo.integerizePos(flyout.MainDiv.style.left);
        flyout.DragBaseY= Vormo.integerizePos(flyout.MainDiv.style.top);
        flyout.dragging = true;
        flyout.oldBodyMouseMove = document.onmousemove;
        flyout.oldBodyMouseUp = document.onmouseup;
        document.onselectstart = function() {return false };
        document.onmousemove = function(e) {
            if (flyout.dragging) {
                var x = Vormo.GetMouseX(e) - flyout.DragOffsetX;
                var y = Vormo.GetMouseY(e) - flyout.DragOffsetY;
                flyout.MainDiv.style.left = (flyout.DragBaseX + x) + 'px';
                flyout.MainDiv.style.top = (flyout.DragBaseY + y) + 'px';
                if (x!=0 | y!=0) { 
                    flyout.Pinned = true;
                    flyout.Element.onmouseout = null;
                }
            }
            return false;
            e.cancelBubble();
            e.stopPropagation = true;
        }
        document.onmouseup= function() {
            flyout.dragging=false;
            document.onmousemove = flyout.oldBodyMouseMove;
            document.onmouseup = flyout.oldBodyMouseUp;
            document.onselectstart = null;
        }
    }
    
    this.MainDiv.onmouseup = function() {
        flyout.dragging = false;
        document.onmousemove = flyout.oldBodyMouseMove;
        document.onmouseup = flyout.oldBodyMouseUp;
    }
    
    this.Reset();
};
/* -- Modified 12/28 -- */
Flyout.prototype.Show = function(w, url, logo, sender) {
    this.MouseIsOver = true;
    /* -- Modified 03/21 -- */
    if (sender!=this.Element) {
       this.Showing = false;
       clearTimeout(this.AnimationTimeout);
       clearTimeout(this.HideTimeout);
    }
    /* -- /Modified 03/21 -- */
    if (this.Showing) return
    if (this.Pinned) return;
    if (this.MainDiv.style.visibility=='visible' & sender==this.Element) {
        clearTimeout(this.HideTimeout);
        return;
    }
    this.Reset();
    this.Showing = true;
    clearTimeout(this.HideTimeout);
//    this.LogoImg.src = logo;
    this.Width = w;
    this.MainDiv.style.width = w + 'px'; //Temp set now for IE6 problem
    this.X = Vormo.getAbsolutePos(sender, 'left') + this.Xoffset + sender.offsetWidth;
    //this.OriginX = Vormo.getAbsolutePos(sender, 'left');
    this.Y = Vormo.getAbsolutePos(sender, 'top') + this.Yoffset;
    //this.CalcFinalPosition(x,y);
    
    this.MainDiv.onmouseover = null;
    this.MainDiv.onmouseout = null;
    this.GetContent(url);
    
    var flyout = this;
    this.Element = sender;
    this.Element.onmouseout = function() {
        flyout.MouseIsOver = true;
        setTimeout( function () { flyout.MouseIsOver = false }, 25000 );
        if (flyout.CurrentAnimationStep>1) return;
        if (flyout.Showing) return;
        if (!flyout.Pinned) flyout.HideTimeout = setTimeout(flyout.Hide,25000);
    }
};
Flyout.prototype.Display = function(w, h, x) {
    this.MainDiv.style.width = w + 'px';
    if (h==0) this.MainDiv.style.height = 'auto';
    else this.MainDiv.style.height = h + 'px';
    this.MainDiv.style.left = x + 'px';
    this.MainDiv.style.top = this.Y + 'px';
    this.MainDiv.style.visibility='visible';
};
Flyout.prototype.GetContent = function(url) {
    var flyout = this;
    this.Ajax.URL = url;
    this.Ajax.ExecuteAfter = function() {
        flyout.MainDiv.style.visibility="visible";
		
		//CHANGED: Check for empty response files. 
        //Do this by creating a temporary SPAN element, 
        //sticking the responseText in there and then 
        //detecting if there are any DIV elements inside.
		var temp = document.createElement("span");
		temp.innerHTML = flyout.Ajax.ResponseText;
		if (temp.getElementsByTagName("div").length<1) return false;
		
        flyout.ContentDiv.innerHTML = flyout.Ajax.ResponseText;
        if( flyout.ShowDelay && flyout.ShowDelay > 0 ) {
           flyout.AnimationTimeout = setTimeout(flyout.Animate,flyout.ShowDelay);
        }
        else {
           flyout.Animate();
        } 
    }
    this.Ajax.GetXML();
};
/* -- /Modified 12/28 -- */

Flyout.prototype.CalcFinalPosition = function(x,y) {
    this.MainDiv.style.Width = this.Width + 'px';
    //this.X = this.ValidatePos('left',(Vormo.GetMouseX(e)+0));
    //this.Y = this.ValidatePos('top',(Vormo.GetMouseY(e)+0));
    this.X = this.ValidatePos('left',x);
    this.Y = this.ValidatePos('top',y);
};
// Method checks if the box goes off the right or bottom of the viewable area
Flyout.prototype.ValidatePos = function(dim, pos) {
   var returnVal = pos;
   
   var pageDim;
   var itemDim;
   
   /* -- Modified 12/28 -- */
   if (dim=='left') {
       var pageDim = Vormo.ViewableWidth();
       var itemDim = pos + this.MainDiv.offsetWidth;
   }
   if (dim=='top') {
       var pageDim = Vormo.ViewableHeight();
       var itemDim = pos + this.MainDiv.offsetHeight;
   }
      
   if (itemDim > pageDim) {
       returnVal = pos - (itemDim - pageDim);
       if (dim=='left') returnVal -= 10; //Adjust for padding on left
       if (returnVal < 1) returnVal = 1;
   }
   /* -- /Modified 12/28 -- */
      
   return returnVal;
};


function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   
   if( sText.length < 5) IsNumber = false;
   
   return IsNumber;
}

var flyout1;
var schoolID;

showflyout = function(url, w, sender) {
   var showflyouts = 1;
   var getURLInfo = sender.search;
   
   
   schoolID = getURLInfo.replace(/\?/, "");
   //var tempSchool = schoolInfo.split("&");
   //schoolID = tempSchool[1];
 	
   if (showflyouts == "false") {
      return;
   }
   
   if( ! flyout1 ) {
      flyout1 = new Flyout(); 
   }
   
   flyout1.ShowDelay = 0;
   flyout1.Show(w, url, '', sender);
}


function submitform()
{
   var zipInfo = document.zipform.zip.value;
   
   if(IsNumeric(zipInfo) ) {
      window.location = "/t1.php?"+schoolID+"&zip="+zipInfo;
   } else {
      alert("Please enter proper five digit zip code!");
   }
}


function checkEnter( e ) {

   var characterCode;

   if( e && e.which) {
      e = e
      characterCode = e.which
   } else {
      e = event
      characterCode = e.keyCode
   }

   if(characterCode == 13) {
      var zipInfo = document.zipform.zip.value;
      if(IsNumeric(zipInfo) ) {
         window.location = "/t1.php?"+schoolID+"&zip="+zipInfo;
         Id = schoolID.split("=");
         document.zipform.schoolID.value = Id[1];
      } else {
         alert("Please enter proper five digit zip code!");
      }
      return false;
   } else {
      return true;
   }

}

