function showInDeadCenter(x, y, id) { 
	// First, determine how much the visitor has scrolled 
	var scrolledX, scrolledY; 
	if (self.pageYoffset) { 
		scrolledX = self.pageXoffset; 
		scrolledY = self.pageYoffset; 
	} 
	else if(document.documentElement && document.documentElement.scrollTop) { 
		scrolledX = document.documentElement.scrollLeft; 
		scrolledY = document.documentElement.scrollTop; 
	} 
	else if(document.body) { 
		scrolledX = document.body.scrollLeft; 
		scrolledY = document.body.scrollTop; 
	} 
	
	// Next, determine the coordinates of the center of browser's window 	
	var centerX, centerY; 
	if(self.innerHeight) { 
		centerX = self.innerWidth; 
		centerY = self.innerHeight; 
	} 
	else if(document.documentElement && document.documentElement.clientHeight) { 
		centerX = document.documentElement.clientWidth; 
		centerY = document.documentElement.clientHeight; 
	} 
	else if(document.body) { 
		centerX = document.body.clientWidth; 
		centerY = document.body.clientHeight; 
	} 
	
	// x is the width of the div, y is the height of the div passed as arguments to the function: 
	var leftoffset = scrolledX + (centerX - x) / 2; 
	var topoffset = scrolledY + (centerY - y) / 2; 
	// The initial width and height of the div can be set in the 
	// style sheet with display:none; id is passed as an argument to // the function 
	var o = document.getElementById(id); 
	var r = o.style; 
	r.position = 'absolute'; 
	r.top = topoffset + 'px'; 
	r.left = leftoffset + 'px'; 
	r.display = 'block'; 
} 

function popup(url, width, height, hide, params) {
    if(!params) {
        params = 'channelmode=no,directories=no,toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no';
    }
    var popup = window.open(url,'popup','width=' + width + ',height=' + height + ',' + params);
	if(hide) {
	    popup.moveTo(-window.screen.availWidth, -window.screen.availHeight);	    
		this.focus();
	    return;
	}
	popup.moveTo((window.screen.availWidth - width) / 2, (window.screen.availHeight - height) / 2);
	popup.focus();
}

function bookmarkMe(url, name) {
    try {
        window.external.AddFavorite(url,name);
    } 
    catch(e) { 
        var temp = 'CTRL';
        if(isMac()) {
            temp = 'CMD';
        }
        alert('Press ' + temp + '-D to Bookmark this Page');
    } 
}

function isEnterPress(e) {
    var key = e.keyCode || e.which;
    if(key == 13) {
        return true;
    }
    return false;
}

function urlEncode(str) {
    //return str.replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27');
	return escape(str);
}

function loading() {
    return '<div class="loading"><img src="/css/img/loading.gif" alt="" /><br/>Loading...</div>';
}

function processing() {
    return '<div class="processing"><img src="/css/img/loading.gif" alt="" /><br/>Processing...</div>';
}

function ajaxLoad(url, containerId, condition) {
	new Ajax(url, {
        method: 'get',
        onRequest: function() {
            try {
		        if(condition != 'a' && condition != 'h') {                
                    $(containerId).innerHTML = loading();            
                }
            } catch(e) {}
        },
        onComplete: function() {
            switch(condition) { 
                case 'h': // populating a hidden field
                    $(containerId).value = this.response.text;
		            break;
	            case 'a': // if condition is append
		            $(containerId).innerHTML += this.response.text;
		            break;
		        default:
		            $(containerId).innerHTML = this.response.text;
		            break;
	        }
        }
    }).request();		
}

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}

function moneyFilter(key, textbox) {			
	if(key == 46) {
		textbox.value = '';
		return;	
	}
	var dFilterNum = textbox.value;
	var period = 0;
	if(dFilterNum.indexOf('.') != -1) {
			period++;
	}	
	if(key == 9) {
        return true;
    }
	else if(key == 8 && textbox.value.length != 0) {
		if(dFilterNum.indexOf('.') == (dFilterNum.length-1)) {
			period--;
		}
		dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);		
	}
	if(dFilterNum.indexOf('.') != -1 && (dFilterNum.length - dFilterNum.indexOf('.')) == 3) {
		return false;
	}	
 	else if((key > 47 && key < 58) || (key > 95 && key < 106) || key == 110  || key == 190) {
		switch(key) {
            case 96:
                dFilterNum += 0;
                break;
            case 97:
                dFilterNum += 1;
                break;
            case 98:
                dFilterNum += 2;
                break;
            case 99:
                dFilterNum += 3;
                break;
            case 100:
                dFilterNum += 4;
                break;
            case 101:
                dFilterNum += 5;
                break;
            case 102:
                dFilterNum += 6;
                break;
            case 103:
                dFilterNum += 7;
                break;
            case 104:
                dFilterNum += 8;
                break;
            case 105:
                dFilterNum += 9;
                break;
			case 110:
			case 190:
				if(period == 0) {
					dFilterNum += '.';				
				}				
				break;
            default:
                dFilterNum += String.fromCharCode(key);
                break;
		}
	}    
	setTimeout(function() {
        textbox.value = dFilterNum;
    },1);
    return false;
}

function floatFilter(key, textbox) {			
	if(key == 46) {
		textbox.value = '';
		return;	
	}
	var dFilterNum = textbox.value;
	var period = 0;
	if(dFilterNum.indexOf('.') != -1) {
			period++;
	}	
	if(key == 9) {
        return true;
    }
	else if(key == 8 && textbox.value.length != 0) {
		if(dFilterNum.indexOf('.') == (dFilterNum.length-1)) {
			period--;
		}
		dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);		
	}
	if(dFilterNum.indexOf('.') != -1 && (dFilterNum.length - dFilterNum.indexOf('.')) == 5) {
		return false;
	}	
 	else if((key > 47 && key < 58) || (key > 95 && key < 106) || key == 110  || key == 190) {
		switch(key) {
            case 96:
                dFilterNum += 0;
                break;
            case 97:
                dFilterNum += 1;
                break;
            case 98:
                dFilterNum += 2;
                break;
            case 99:
                dFilterNum += 3;
                break;
            case 100:
                dFilterNum += 4;
                break;
            case 101:
                dFilterNum += 5;
                break;
            case 102:
                dFilterNum += 6;
                break;
            case 103:
                dFilterNum += 7;
                break;
            case 104:
                dFilterNum += 8;
                break;
            case 105:
                dFilterNum += 9;
                break;
			case 110:
			case 190:
				dFilterNum += '.';				
				break;
            default:
                dFilterNum += String.fromCharCode(key);
                break;
		}
	}    
	setTimeout(function() {
        textbox.value = dFilterNum;
    },1);
    return false;
}

function showImg(id) {
	$('lrg' + id).style.display = 'block';
}

function hideImg(id) {
	$('lrg' + id).style.display = 'none';
}

function changePage(page) {
	var url = window.location + '';
	if(url.indexOf('page=') != -1) {
		var right = url.substring(url.indexOf('page='), url.length);
		right = right.substring(right.indexOf('&'), url.length);
		var left = url.substring(0, url.indexOf('page=')) + 'page=';
		url = left + page + right;
	}
	else {
		url += '?page=' + page;	
	}
	window.location = url;
}

function writeEmail(name, domain, ext) {
	var email = name + '@' + domain + '.' + ext;
	document.write('<a href="mailto:' + email + '" title="' + email + '">' + email + '</a>');
}

function clickLink(link) {
    // *********************************
    // FF/NN accept programmed events,
    // but default action will be taken only
    // from hardvare device input:
    if (document.createEvent) { // FF model
        var customClick = document.createEvent('MouseEvents');
        customClick.initEvent('click',0,0);
        link.dispatchEvent(customClick);
        // The old good click() is removed from link methods:
        try {link.click();} catch(e){}
    }
    // *********************************
    // IE accepts programmed events,
    // but default action will be taken only
    // from hardvare device input (like FF/NN):
    else if (document.createEventObject) { // IE model
        var customClick = document.createEventObject();
        link.fireEvent('onclick', customClick);
        // The old good click() was simply forgotten
        // by the brave IE team and allows to bypass security:
        link.click(); // equals to a hardware click
    }
}

function isMac() {
    version = navigator.appVersion;
    if(version.toLowerCase().indexOf('mac') != -1) {
        return true;
    }    
    return false;
}

function isIE() {
	if(navigator.userAgent.indexOf('MSIE') != -1) {		
		return true; // if browser is IE
	}
	return false; // if browser is not IE
}

function isIE7() {
	if(navigator.userAgent.indexOf('MSIE 7') != -1) {		
		return true; // if browser is IE
	}
	return false; // if browser is not IE
}

function isIE6() {
	if(navigator.userAgent.indexOf('MSIE 6') != -1) {		
		return true; // if browser is IE
	}
	return false; // if browser is not IE
}

function isFF() {
    if(navigator.userAgent.indexOf('Firefox') != -1) {
        return true; // if browser is Firefox
	}
	return false; // if browser is not Firefox
}

function isSafari() {
    if(navigator.userAgent.indexOf('Safari') != -1) {
        return true; // if browser is Safari
	}
	return false; // if browser is not Safari
}

function isOpera() {
    if(navigator.userAgent.indexOf('Opera') != -1) {
        return true; // if browser is Opera
	}
	return false; // if browser is not Opera
}

function writeSwf(file,id,width,height,version,bgcolor,loop) {
    var html = 
        '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
        'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" ' +
        'width="' + width + '" height="' + height + '" id="top" align="middle">' +
        '<param name="allowScriptAccess" value="sameDomain" />' +
        '<param name="movie" value="' + file + '" />' +
        '<param name="quality" value="high" />' +
        '<param name="wmode" value="transparent" />' +
		'<param name="scale" value="noscale" />' +
	    '<param name="loop" value="' + loop + '" />' +
        '<param name="bgcolor" value="' + bgcolor + '" />' +
        '<embed src="' + file + '" quality="high" wmode="transparent" bgcolor="' + bgcolor + '" ' +
        'width="' + width + '" height="' + height + '" name="top" align="middle" allowScriptAccess="sameDomain" ' +
        'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
        '</object>';
    $(id).innerHTML = html;
}

function writeVideoSwf(file,id,width,height,version,bgcolor,loop) {
    var html = 
        '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
        'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,0,0" ' +
        'width="' + width + '" height="' + height + '" id="top" align="middle">' +
        '<param name="allowScriptAccess" value="sameDomain" />' +
        '<param name="movie" value="' + file + '" />' +						
        '<param name="quality" value="high" />' +
        '<param name="wmode" value="transparent" />' +
		'<param name="scale" value="noscale" />' +
	    '<param name="loop" value="' + loop + '" />' +
        '<param name="bgcolor" value="' + bgcolor + '" />' +
        '<param name="FlashVars" value="flvURL=' + file +'.flv&ControlPanelColor=0xfffbf0&buttonColor=0x000000&ControlPanelPosition=0&showControlPanel=1&ShowtimeColor=0xfffbf0&bAutoPlay=1&bAutoRepeat=0&BufferTime=5&tmeColor=0xfffbf0&loaColor=0x666666&GroundColor=0x000000&conNum=1" />' +
		'<param name="salign" value="lt" />' +
		'<embed src="' + file + '.swf" width="' + width + '" height="' + height + '" align="middle" quality="high" bgcolor="' + bgcolor + '" scale="noscale" salign="lt" FlashVars="flvURL=' + file + '.flv&ControlPanelColor=0xfffbf0&buttonColor=0x000000&ControlPanelPosition=0&showControlPanel=1&ShowtimeColor=0xfffbf0&bAutoPlay=1&bAutoRepeat=0&BufferTime=5&tmeColor=0xfffbf0&loaColor=0x666666&GroundColor=0x000000&conNum=1" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    $(id).innerHTML = html;
}

function deleteMe(id, tbl, el) {	
	if(confirm('Are you sure?')) {
		var url = 'deleteMe.php?id=' + id + '&tbl=' + tbl;
		new Ajax(url, {
			method: 'get',
			onComplete: function() {
				el.parentNode.parentNode.parentNode.removeChild(el.parentNode.parentNode);
			}
		}).request();
	}
}

// add text to field and position cursor at the end
function setCaretToEnd(el) {
    if(el.createTextRange) {
        var v = el.value;
        var r = el.createTextRange();
        r.moveStart('character', v.length);
        r.select();
    }
}

function insertAtEnd(el, txt) {
    el.value += txt;
    setCaretToEnd(el);
}

function fixMisingImages() {
	$$('img').each(function(el) {	
		el.onerror = function() {
			var div = el.parentNode;
			div.innerHTML = '<div style="margin-top: 40px">No Image Available</div>';
		}
	});  	
}

function scrollBottom() {
    var x, y;
    // Firefox         
    if(window.innerHeight && window.scrollMaxY) { 
        x = window.innerWidth + window.scrollMaxX;
        y = window.innerHeight + window.scrollMaxY;                
    } 
    // all but Explorer Mac         
    else if(document.body.scrollHeight > document.body.offsetHeight) { 
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;         
    } 
    // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
    else { 
        x = document.body.offsetWidth;       
        y = document.body.offsetHeight;         
    }
    window.addEvent('domready', function() {
        window.scroll(x,y);
    });
}

function clock(containerId) { 
	var date = new Date();
	var hrs = date.getHours();
	var min = date.getMinutes(); 
	var sec = date.getSeconds();
	var col = ':';
	var spc = ' ';
	var apm;
	
	if(12 < hrs) { 
		apm = 'PM';
		hrs -= 12;
	}
	else {
		apm = 'AM';
	}
	if(hrs == 0) { 
		hrs = 12;
	}
	if(min <= 9) {
		min = '0' + min;
	}
	if(sec <= 9) {
		sec = '0' + sec;
	}
		
	var day = dateFormat(date, 'dddd, mmmm d, yyyy '); // requires date.format.js

	$(containerId).innerHTML = day + hrs + col + min + col + sec + spc + apm;
}

function checkMaxLength(el, max) {
    if(el.value.length > max) {
        el.value = el.value.substring(0, max);
    }
    $('charsRemaining').innerHTML = max - el.value.length;
}

function doNothing() {}

window.addEvent('domready', function() {	
	// map on contact page
	/*if(window.location.toString().indexOf('/contact') != -1) {		
		if(GBrowserIsCompatible()) {
			var address = $('address').value;
			
			var map = $('map');
			
			var geocoder = new GClientGeocoder();   
			geocoder.getLatLng(    
				address,    
				function(point) {      
					if (!point) {        
						map.innerHTML = '<p>' + address + '<br/>Could Not Be Found!</p>';
						//map.style.paddingTop = document.documentElement.clientHeight / 2 - 40 + 'px';
						return;
					} 
					map = new GMap2(map);
					map.addControl(new GSmallMapControl());
					map.addControl(new GMapTypeControl());
					var html = $('contactInfo').innerHTML;
					if(!isIE() && html.indexOf('<script') != -1) {
						var temp = html;
						var html = temp.substring(0, temp.indexOf('<script'));
						html += temp.substring(temp.indexOf('<\/script>')+9, temp.length);						
					}
					html = '<div id="contactInfo">' + html + '</div>';
					
					//point = new GLatLng(27.8761666667,-83.188);
					map.setCenter(point, 13);
					var marker = new GMarker(point);        
					GEvent.addListener(marker, 'click', function() {
						marker.openInfoWindowHtml(html);
					});
					map.addOverlay(marker);        
					//marker.openInfoWindowHtml(html);
				}  
			);  
		}	
	}*/
});

function changeCountry(el) {
	if(el.value != 227) {
		$('state').style.display = 'none';
		$('stateName').style.display = 'inline';
		$('stateName').value = '';
	}
	else {
		$('state').style.display = 'inline';
		$('stateName').style.display = 'none'; 		
	}
	for(var i=0; i<el.length; i++) {
		if(el[i].value == el.value) {
			$('countryName').value = el[i].text;
			break;
		}
	}
	if(el.value == 0) {
		$('countryName').style.display = 'inline';
		$('countryName').value = '';
	}
	else {
		$('countryName').style.display = 'none';
	}
}

function changeState(el) {
	for(var i=0; i<el.length; i++) {
		if(el[i].value == el.value) {			
			$('stateName').value = el[i].text;
			break;
		}
	}
}

function selectMe(id, value) {
	var el = $(id);
	for(var i=0; i<el.length; i++) {
		if(el[i].value == value) {			
			el[i].selected = true;
			break;
		}
	}
	if(id == 'hear') {
		$('hearOther').style.display = 'none';
		if(value == 'Other') {
			$('hearOther').style.display = 'inline';
		}
	}
}