// JavaScript Document

var scrollCell, scrollCell2, contentHeight, contentHeight2, timer, timer2, lefttime, topStop, topStop2, theTimer;

function hideAllBadges(){
	document.getElementById('BadgeSet1').style.display = 'none';
	document.getElementById('BadgeSet2').style.display = 'none';
	document.getElementById('BadgeSet3').style.display = 'none';
	document.getElementById('BadgeSet4').style.display = 'none';
	document.getElementById('BadgeSet5').style.display = 'none';
	document.getElementById('BadgeSet6').style.display = 'none';
	document.getElementById('BadgeSet7').style.display = 'none';
	document.getElementById('BadgeSet8').style.display = 'none';
	document.getElementById('BadgeSet9').style.display = 'none';
	document.getElementById('BadgeSet10').style.display = 'none';
	document.getElementById('BadgeSet11').style.display = 'none';
	document.getElementById('BadgeSet12').style.display = 'none';
}

function showBadges(div){
	hideAllBadges();
	document.getElementById(div).style.display = 'block';
}

function progressReport(){
	window.open ('page/progressReport.php', 'report' ,'width=600,height=465,resizable=yes,scrollbars=yes');
}

function footerStuff(){
	document.write('<a href="mailto:office@urgentinc.org" style="color:#FFFFFF">office@urgentinc.org</a>');
}

function calendarEntry(number){
	whichDiv = 'calendarEntry' + number;
	
	if(document.getElementById(whichDiv).style.display == 'block'){
		document.getElementById(whichDiv).style.display = 'none';
	}else{
		document.getElementById(whichDiv).style.display = 'block';
	}
}

function showWelcomeMessage(number){
	if(document.getElementById('welcomeMessage' + number).style.display == 'inline'){
		document.getElementById('welcomeMessage' + number).style.display = 'none';
	}else{
		document.getElementById('welcomeMessage' + number).style.display = 'inline';
	}
}

function checkform(){ //alert('fire');
	var passedCheck = true;
	document.getElementById('nameField').style.color = 'black';
	document.getElementById('emailField').style.color = 'black';
	document.getElementById('addressField').style.color = 'black';
	document.getElementById('phoneField').style.color = 'black';
	document.getElementById('zipField').style.color = 'black';
	document.getElementById('errorMessage').innerHTML = '';
	
	if(document.getElementById('name').value == ''){
		passedCheck = false;
		document.getElementById('nameField').style.color = 'red';
	}	
	if(document.getElementById('email').value == ''){
		passedCheck = false;
		document.getElementById('emailField').style.color = 'red';
	}	
	if(document.getElementById('address').value == ''){
		passedCheck = false;
		document.getElementById('addressField').style.color = 'red';
	}	
	if(document.getElementById('phone').value == ''){
		passedCheck = false;
		document.getElementById('phoneField').style.color = 'red';
	}	
	if(document.getElementById('zip').value == ''){
		passedCheck = false;
		document.getElementById('zipField').style.color = 'red';
	}
	if(passedCheck == false){
		document.getElementById('errorMessage').innerHTML = '<p style="color:#FF0000; font-style:italic;">Please fill in all required fields.</p>';
	}

	return passedCheck; }

// DROP MENUS STUFF
function hideMenu(whichMenu){
	//alert(whichMenu);
	divtohide=document.getElementById(whichMenu);
	divtohide.style.display = 'none';
}

function hideAllMenus(doNotHideMenu){
	document.getElementById('dropMenu1').style.display = 'none';
	document.getElementById('dropMenu2').style.display = 'none';
	document.getElementById('dropMenu3').style.display = 'none';
	document.getElementById('dropMenu4').style.display = 'none';
	/*document.getElementById('dropMenu5').style.display = 'none';
	document.getElementById('dropMenu6').style.display = 'none';
	document.getElementById('dropMenu7').style.display = 'none';*/
}

function changeBack(whichMenu){
	//alert(whichMenu);
	theTimer = setTimeout("hideMenu('"+whichMenu+"')", 400);
} 

function showMenu(whichMenu, whichAnchor, positionx, positiony){
	hideAllMenus(whichMenu);
	clearTimeout(theTimer);
	positionMenu(whichMenu, whichAnchor, positionx, positiony);
	document.getElementById(whichMenu).style.display = 'block';		
}

function positionMenu(whichMenu, whichAnchor, positionx, positiony){
	var c = getAnchorPosition(whichAnchor);
	//alert("X = "+c.x+" , Y = "+c.y);
	if (document.getElementById) {
		var o = document.getElementById(whichMenu);
		//alert(o.style.left);
		if (o.style) {
			o.style.left = (c.x + positionx) + 'px';
			o.style.top = (c.y + positiony) + 'px';
		}
	}
}


// Show Hint Code
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML='<img src="/images/common/urgentLogo150.jpg" alt="URGENT, Inc." />';
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox
//  End show hint code

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
}

function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
}	

function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
}

function checkAuthCode(){
	var authCode = document.getElementById('authCode').value;
	if(authCode == 'SummerCamp2010'){
		$('#summercamp-pp').css('display','block');
		$('div.errormessage').html('');
	}else{
		$('div.errormessage').html('<em>Invalid Authorization Code</em>');
	}
}

jQuery(document).ready(function() {
		
	$("a.newsletter").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
		
	$("a.calendar").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
});
