﻿// JScript File

if(document.getElementById) { // IE 5 and up, NS 6 and up
	var upLevel = true;
	}
else if(document.layers) { // Netscape 4
	var ns4 = true;
	}
else if(document.all) { // IE 4
	var ie4 = true;}
else {
	}

var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var nsf  = ((navigator.appName.indexOf("Netscape") != -1) || (navigator.appName.indexOf("Firefox") != -1));

function getPos(elm) {
    for(var
    zx=zy=0;elm!=null;zx+=elm.offsetLeft,zy+=elm.offsetTop,elm=elm.offsetParent);
    return {x:zx,y:zy}
}

function elementDisplay(elm){
    (elm.style.display=="block")? elm.style.display="none": elm.style.display="block";
}
		
function showObjectRelCenter(obj, x, y, loff, toff) {
    if (toff===undefined)
        toff=0;

	if (ns4) {
	    obj.display = "block";
	}
	else if (ie4 || upLevel) {
	    
	    if (nsf){
	        obj.style.left = ((window.innerWidth-x)/2)+loff+"px";
		    obj.style.top = toff+window.pageYOffset+(window.innerHeight/2)+"px";
	    }
	    if (ie){
	        
            var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	        
	        var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
            var dsoctop=document.all? iebody.scrollTop : pageYOffset;
	        obj.style.left = ((iebody.clientWidth-x)/2)+loff+"px";
		    obj.style.top = toff+dsoctop+(iebody.clientHeight/2)+"px";
	    }
		obj.style.display = "block";
	}
}

function showObjectRelLeft(obj, x, y, loff, toff) {
    if (toff===undefined)
        toff=0;
	if (ns4) {
	    obj.display = "block";
	}
	else if (ie4 || upLevel) {
	    if (nsf){
	        obj.style.left = Math.abs(loff)+"px";
		    obj.style.top = toff+window.pageYOffset+(window.innerHeight/2)+"px";
	    }
	    if (ie){
            var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	        
	        var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
            var dsoctop=document.all? iebody.scrollTop : pageYOffset;
	        obj.style.left = Math.abs(loff)+"px";
		    obj.style.top = toff+dsoctop+(iebody.clientHeight/2)+"px";
	    }
		obj.style.display = "block";	
	}
}

// Remove all spaces from a string
function removeSpaces(string) 
{
	var newString = '';
	for (var i = 0; i < string.length; i++) 
	{
		if (string.charAt(i) != ' ') newString += string.charAt(i);
	}
	return newString;
}

// Check that a US zip code is valid
function isValidUSZipcode(zipcode) 
{
   zipcode = removeSpaces(zipcode);
   if (!(zipcode.length == 5 || zipcode.length == 9 || zipcode.length == 10)) return false;
   if ((zipcode.length == 5 || zipcode.length == 9) && !isNumeric(zipcode)) return false;
   if (zipcode.length == 10 && zipcode.search && zipcode.search(/^\d{5}-\d{4}$/) == -1) return false;
   return true;
}

function isNumeric(string, ignoreWhiteSpace) 
{
	if (string.search) 
	{
		if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
	}
	return true;
}
