/*
	Global Javascript File for www.oncimmune.com
	Created 8.1.2009
	By Jay Pilgreen
	copyright river City Studio
*/



	/* ----------------------- Risk Chart Functions ----------------------------- */

	/* --------- Toggle Inputs for non-smoker checkbox --------------- */

function toggleDivAlpha(e) {
	toggleDiv = document.getElementById("smokeInputs").style;
	
	if(e.checked == true) {
		toggleDiv.color = "#D0D0D0";
		toggleInputsActive("inactive");
		
	}	else {
		toggleDiv.color = "#666666";
		toggleInputsActive("active");
	}
}


function toggleInputsActive(command) {
	formInputs = document.forms["cancerForm"];
	
	if(command == "inactive") {
		for(i=0; i<formInputs.length; i++) {
			if(formInputs[i].getAttribute("toggle") == "true") {
				formInputs[i].checked = false;
				formInputs[i].value = "";
				formInputs[i].onfocus = function(){ this.blur(); return false };
// 				formInputs[i].onclick = function(){ this.value = ""; return false };
			}
		}
	}
	else {
		for(i=0; i<formInputs.length; i++) {
			if(formInputs[i].getAttribute("toggle") == "true") {
				formInputs[i].onfocus = null;
// 				formInputs[i].onclick = null;
			}
		}
	}
	
}



function toggleCurrentSmoker(e) {
	
	resetHidden();
	
	if(e.checked == true) {
		currentOptions = document.getElementById("currentSmokerOptions");
		currentOptions.style.display = "block";
		
		quittingOptions = document.getElementById("previousSmokerOptions");
		document.getElementById("quittingAgeInput").value = "";
		quittingOptions.style.display = "none";
	}
}

function togglePreviousSmoker(e) {
	
	resetHidden();

	if(e.checked == true) {
		quittingOptions = document.getElementById("previousSmokerOptions");
		quittingOptions.style.display = "block";
		
		currentOptions = document.getElementById("currentSmokerOptions");
		currentOptions.style.display = "none";
		document.getElementById("startingAgeInput").value = "";
		document.getElementById("packsPerDayInput").value = "";
	}
}

function resetHidden() {
	nonCheck = document.getElementById("nonSmokerCheck");
	nonCheck.checked = false;
	toggleDivAlpha(nonCheck);
}

function swapTab(e) {
	if(e.id == "physicianTab") {
		document.getElementById("patientTab").className = "";
	} else {
		document.getElementById("physicianTab").className = "";
	}
	e.className = "active";
	setTimeout(function(){fadeInBox(.1)}, 200);
}


	// ---------------------- Fade Functions ------------------------- //
	
function fadeOutBox(incomingOpacity) {
	var lForm = document.getElementById("homeContent");
	incomingOpacity = incomingOpacity / 2;
	if(incomingOpacity < .2) {
		incomingOpacity = .1;
	}
	// For Good Browsers
	lForm.style.opacity = incomingOpacity;
	// For IE
	ieOpacity = Math.round(incomingOpacity * 100);
	lForm.style.filter = "alpha(opactiy=" + ieOpacity + ")";
			
	if(incomingOpacity <= .2) {
		clearTimeout(fadeOutTimer);
	} else {
		fadeOutTimer = setTimeout(function(){fadeOutBox(incomingOpacity)}, 25);
	}
}
	
function fadeInBox(incomingOpacity) {
	var lForm = document.getElementById("homeContent");
	incomingOpacity = incomingOpacity * 2;
	if(incomingOpacity > 1) {
		incomingOpacity = 1;
	}
	// For Good Browsers
	lForm.style.opacity = incomingOpacity;
	// For IE
	ieOpacity = Math.round(incomingOpacity * 100);
	lForm.style.filter = "alpha(opactiy=" + ieOpacity + ")";
			
	if(incomingOpacity >= 1) {
		clearTimeout(fadeInTimer);
	} else {
		fadeInTimer = setTimeout(function(){fadeInBox(incomingOpacity)}, 25);
	}
}

	/* ------------------------------- Info Form Validation ---------------------------- */
	
function validateInfoForm(thisForm) {
// 	alert(thisForm.parentNode.id);
// 	return;

	incomplete = false;
	
	requiredFields = new Array(
		thisForm["First_Name"],
		thisForm["Last_Name"],
		thisForm["City"],
		thisForm["State"],
		thisForm["Phone"],
		thisForm["Email"]
	);
	
	for(i = 0; i < requiredFields.length; i++) {
		if(requiredFields[i].value == "") {
			requiredFields[i].style.border = "1px solid red";
			incomplete = true;
		} else {
			requiredFields[i].style.border = "1px inset #999";
		}
	}
	
	if(incomplete == false) {
		popForm(thisForm.parentNode.id, "/infoForm.php", thisForm);
	}
}



	/* ------------------- Son of Suckerfish Functionality --------------------------- */
	
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
