function isIE6() {
	var isIE = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf('Opera') == -1);
	if(isIE) {
		var ie6xFilter = /^.*MSIE [6]\.[0-9].*$/;
		isIE = ie6xFilter.test(navigator.userAgent);
	}
	
	return isIE;
}

function launchSurvey(theRespondent, theSurveyID, theCampaignID, theURLPath) {	
	window.open(theURLPath+"master_system_login.php?resp="+theRespondent+"&survey="+theSurveyID+"&cID="+theCampaignID, "SurveyWindow", "height=600,width=780,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0");
}

function setupShadows(contentID, shadowPrefix) {
	return;

	if (document.getElementById) {
		// get a handle to the content box
		var theContentBox = document.getElementById(contentID);
		if (theContentBox) {
			// get the box's width, height, and current position
			var contentWidth = theContentBox.offsetWidth;
			var contentHeight = theContentBox.offsetHeight;
			var contentTop = theContentBox.offsetTop;
			var contentLeft = theContentBox.offsetLeft;
			//alert('content is '+contentWidth+' by '+contentHeight+' at '+contentTop+','+contentLeft);
			
			//now, get a handle to the shadow anchor
			var theShadowAnchor = document.getElementById(shadowPrefix+'_shadowAnchor');
			if (theShadowAnchor) {
				// set this element's position, so that the shadows can nudge away from it
				theShadowAnchor.style.top = contentTop+10+"px";
				theShadowAnchor.style.left = contentLeft+"px";

				//now, get a handle to the 2 shadows
				var shadow1 = document.getElementById(shadowPrefix+'_contentShadowBox1');
				if (shadow1) {
					// set this element's height/width
					shadow1.style.width = contentWidth+"px";
					shadow1.style.height = contentHeight-10+"px";
				}
				var shadow2 = document.getElementById(shadowPrefix+'_contentShadowBox2');
				if (shadow2) {
					// set this element's height/width
					shadow2.style.width = contentWidth+"px";
					shadow2.style.height = contentHeight-10+"px";					
				}
			}
		}		
	}
}

function confirmPrizeDecline() {
	// hide this one
	toggleBlockDisplay('prizeSlipContent');
	// and show this one
	toggleBlockDisplay('prizeSlipDeclineContent');
	
	if(isIE6()) {
		var curPrizeSlip = document.getElementById('prizeSlip');
		document.getElementById('prize_contentShadowBox1').style.height = curPrizeSlip.offsetHeight+'px';
		document.getElementById('prize_contentShadowBox2').style.height = curPrizeSlip.offsetHeight+'px';
	}
}

function finalDeclinePrize() {
	// the user is really declining now, so show them the decline message contents
	// hide this one
	toggleBlockDisplay('prizeSlipDeclineContent');
	// and show this one
	toggleBlockDisplay('prizeSlipDeclineFinal');
}

function restoreOldContents(type) {
	// show this one
	toggleBlockDisplay('prizeSlipContent');
	if (type=='decline') {
		// and hide this one
		toggleBlockDisplay('prizeSlipDeclineContent');
	}
	else if (type=='donate') {
		// and hide this one
		toggleBlockDisplay('prizeSlipDonationContent');
	}
	if(isIE6()) {
		var curPrizeSlip = document.getElementById('prizeSlip');
		document.getElementById('prize_contentShadowBox1').style.height = curPrizeSlip.offsetHeight+'px';
		document.getElementById('prize_contentShadowBox2').style.height = curPrizeSlip.offsetHeight+'px';
	}
}

function confirmPrizeDonation() {
	// hide this one
	toggleBlockDisplay('prizeSlipContent');
	// and show this one
	toggleBlockDisplay('prizeSlipDonationContent');
	if(isIE6()) {
		var curPrizeSlip = document.getElementById('prizeSlip');
		document.getElementById('prize_contentShadowBox1').style.height = curPrizeSlip.offsetHeight+'px';
		document.getElementById('prize_contentShadowBox2').style.height = curPrizeSlip.offsetHeight+'px';
	}	
}

function validatePrizeAccept() {
	if (isValidEmail(document.acceptForm.winnerEmail.value)) {
		document.acceptForm.submit();		
	}
	else {
		if (document.getElementById) {
			var thePrizeErrorBox = document.getElementById('prizeError');
			if (thePrizeErrorBox) {
				thePrizeErrorBox.innerHTML = "Please enter a valid e-mail address.";
				if(isIE6()) {
		var curPrizeSlip = document.getElementById('prizeSlip');
		document.getElementById('prize_contentShadowBox1').style.height = curPrizeSlip.offsetHeight+'px';
		document.getElementById('prize_contentShadowBox2').style.height = curPrizeSlip.offsetHeight+'px';
	}
			}
			else {
				alert('Please enter a valid e-mail address.');
			}
		}
		else {
			alert('Please enter a valid e-mail address.');
		}
	}
}

function isValidEmail(emailValue) {
	var x = emailValue;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(x);
}

function toggleBlockDisplay(elementID) {
	if (document.getElementById) {
		var theElement = document.getElementById(elementID);
		if (theElement) {
			if (theElement.style.display == "none") {
				theElement.style.display = "block";				
			}
			else {
				theElement.style.display = "none";
			}
		}
	}
}

function toggleBlockVisibility(elementID) {
	if (document.getElementById) {
		var theElement = document.getElementById(elementID);
		if (theElement) {
			if (theElement.style.visibility == "hidden") {
				theElement.style.visibility = "visible";				
			}
			else {
				theElement.style.visibility = "hidden";
			}
		}
	}
}

/*************************
Toggling this div was causing problems (I'd toggle it 
visible, then back to hidden), due to too many logical paths. 
So I'll just call this when I'm ready to show it, instead.
*************************/
function showMovieDiv() {
	if (document.getElementById) {
		var theElement = document.getElementById('movieDiv');
		if (theElement) {
			if (theElement.style.visibility == "hidden") {
				theElement.style.visibility = "visible";				
			}
		}
	}
}


function popupMedia(image, imageTitle, winWidth, winHeight, imageWidth, imageHeight) {
	var mediaImageSlip = document.getElementById('mediaImageSlip');
	var mediaImageSlipContent = document.getElementById('mediaImageSlipContent');
	
	mediaImageSlipContent.innerHTML = '<img src="'+image+'" width="'+imageWidth+'" height="'+imageHeight+'" onclick="toggleBlockDisplay(\'mediaImageSlipContainer\'); toggleBlockDisplay(\'dcModal\');"" border="0" style="cursor: pointer;">';
	mediaImageSlip.style.width = imageWidth+60+'px';
	mediaImageSlip.style.height = imageHeight+45+'px';
	
	var currentHeight = window.innerHeight ? window.innerHeight : (document.documentElement ? document.documentElement.clientHeight : document.body.clientHeight);
	var verticalPosition = window.scrollY ? window.scrollY : document.documentElement.scrollTop;
	var newTop = (currentHeight/2)-((imageHeight+45)/2)+verticalPosition;
	
	if(newTop <= 0) {
		newTop = 20;
	}
	
	mediaImageSlip.style.top = newTop+'px';
	
	toggleBlockDisplay('mediaImageSlipContainer');
	toggleBlockDisplay('dcModal');
}

function popupExternalActivity(activityURL) {	
	window.open(activityURL, "ActivityWindow", "height=600,width=800,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0");
}

if(isIE6()) {
	window.onscroll = ieDetail;
}

function ieDetail() {
	var dcModal = document.getElementById("dcModal");
	
	if(dcModal) {
		dcModal.style.top = (window.scrollY ? window.scrollY : document.documentElement.scrollTop) + "px";
	}
}