// new code for the tooltip
window.addEvent('load', function(){
	tt_onLoad();
});

function appearWindow(targetX,targetY,width,height,jsToExecute) {
	/*$('r').setStyle('height',(height-51));
	$('l').setStyle('height',(height-51));
	$('b').setStyle('width',(width-34));
	$('t').setStyle('width',(width-34));*/
	$('styled_content').setStyles({
		'width':width-34,
		'height':height-51,
		'left':20
	});
	$('styled_popup').setStyles({
		'width':width,
		'height':height
	});
	$('styled_popup').set({'opacity':'0'});

	$('styled_popup').setStyles({
		display:'block',
		left:targetX + 20,
		top:targetY-((height/2)-13)
	});
	if ((targetY-height) < 0) {
		targetY = height;
	}
	if (jsToExecute != "") {
		$('styled_popup').get('morph').addEvent('complete',function() {
			eval(jsToExecute);
		});
	}
	$('styled_popup').morph({'left':targetX + 40 + "px",'opacity':'1'});
}

function closeWindow() {
	curLoc = 0;
	var curLeft = $('styled_popup').offsetLeft;
	$('styled_popup').morph({'left':curLeft-20 + "px",'opacity':'0'});
	
	$("popup_body").innerHTML = "";
}

var curLoc = 0;


window.addEvent('domready',function() {
									
	$$(".moreInfo").addEvent('mouseover',function(event) {
		if (curLoc != 1) {
			curLoc = 1;
			var event = new Event(event);
			
			$("popup_body").innerHTML =  this.children[0].innerHTML;
	
			//var jsToRun = "AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','480','height','360','allowFullScreen','true','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','phantom','FlashVars','videos=videos1.xml' );";
			var areaLocation = this.getPosition();
			appearWindow(areaLocation.x, areaLocation.y,179,76);
	
			event.stop();
		} else {
			if ($("popup_body").innerHTML != this.children[0].innerHTML) {
				$('styled_popup').set({'opacity':'0'});
				var event = new Event(event);
				
				$("popup_body").innerHTML =  this.children[0].innerHTML;
		
				//var jsToRun = "AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','480','height','360','allowFullScreen','true','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','phantom','FlashVars','videos=videos1.xml' );";
				var areaLocation = this.getPosition();
				appearWindow(areaLocation.x, areaLocation.y,179,76);
			}
		
			event.stop();
		}

		return false;
	});
	
	/*$$(".moreInfo").addEvent('mouseleave',function(event) {
		closeWindow();

	});*/
});
//end of tooltip code

function showExtraWindow(targetX,targetY,width,height,jsToExecute) {
	$('extra_content').setStyles({
		'width':width-34,
		'height':height-51
	});
	$('extra_popup').setStyles({
		'width':width,
		'height':height
	});
	$('extra_popup').set({'opacity':'0'});
	
	$('extra_popup').setStyles({
		display:'block',
		left:targetX + 20,
		top:targetY-((height/2)-13)
	});
	if ((targetY-height) < 0) {
		targetY = height;
	}
	if (jsToExecute != "") {
		$('extra_popup').get('morph').addEvent('complete',function() {
			eval(jsToExecute);
		});
	}
	$('extra_popup').morph({'left':targetX + 40 + "px",'opacity':'1'});
}

//show extra questions
function showExtraQuestions(){
	$("extraQuestionText").setStyle("display","inline");
	$("acneExtra_row").inject($("extra_popup_body"));
	$("spacer1").setStyle("display","block");
	$("spacer2").setStyle("display","block");
	$("spacer3").setStyle("display","block");
	$("spacer4").setStyle("display","block");
	$("acneExtra_row").setStyle("display","block");
/*	$("popup_body").innerHTML =  $('extraQuestionContent').innerHTML;*/
	
	var areaLocation = $("extraQuestions").getPosition();
	showExtraWindow(areaLocation.x + 130, areaLocation.y,179,76);
}

function closeWindowExtra() {
	curLoc = 0;
	var curLeft = $('extra_popup').offsetLeft;
	$('extra_popup').morph({'left':curLeft-20 + "px",'opacity':'0'});
	
	$("extraQuestionText").setStyle("display","none");
	$("acneExtra_row").setStyle("display","none");
	$("spacer1").setStyle("display","none");
	$("spacer2").setStyle("display","none");
	$("spacer3").setStyle("display","none");
	$("spacer4").setStyle("display","none");
//	$("extraQuestionContent").inject(tempItem);
//	$("popup_body").innerHTML = "";
}

function showExtraQuestionFemale(){
	$("makeup_row").setStyle("display","block");
}

function closeWindowFemale() {
	$("makeup_row").setStyle("display","none");
}

function showExtraQuestionMale(){
	$("ingrowing_row").setStyle("display","block");
	$("rashes_row").setStyle("display","block");
}

function closeWindowMale() {
	$("ingrowing_row").setStyle("display","none");
	$("rashes_row").setStyle("display","none");
}


var checkboxHeight = "18";
var radioHeight = "18";
var selectWidth = "134";

/* No need to change anything after this */

document.write('<style type="text/css">input.diagnosis { display: none; } select.diagnosis { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');


var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "diagnosis") {
				span[a] = document.createElement("span");
				span[a].innerHTML = "&nbsp;";
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "diagnosis") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
			
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				//check if there are extra questions for yes answers
				if(element.id == "acneYes"){
					showExtraQuestions();
				} else if (element.id == "acneNo"){
					closeWindowExtra();
				}
				//if female
				if(element.id == "sex-f"){
					showExtraQuestionFemale();
					closeWindowMale();
				}//if male 
				else if (element.id == "sex-m"){
					showExtraQuestionMale();
					closeWindowFemale();
				}
				
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;

			if (element.id == "extra1" || element.id == "extra2"){
				var curParent = this.parentNode;
			} else {
				var curParent = this.parentNode.parentNode;
			}
			curParent.parentNode.className = "questionRow";

		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "diagnosis") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "diagnosis") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "diagnosis") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "diagnosis") {
					inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				var curParent = this.parentNode.parentNode;
				curParent.parentNode.className = "questionRow";
				
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;


function checkEmpty(){

	//check all radio buttons
	var returnValue=true;
	var radioButtons = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
	for(a = 0; a < radioButtons.length; a++) {
		if(radioButtons[a].type == "radio" && radioButtons[a].className == "diagnosis" && radioButtons[a].name != "acneExtra" && radioButtons[a].name != "ingrowing" && radioButtons[a].name != "rashes" && radioButtons[a].name != "makeup") {
			var elemName = radioButtons[a].name;
			
			var curSelects = document.skinDiagnosis[elemName];
			if (!(curSelects[1].checked || curSelects[0].checked)) {
				document.getElementById(elemName+'_row').className = "questionRowError";
				
				//event.returnValue=false;

				returnValue = false;
			} else {
				document.getElementById(elemName+'_row').className = "questionRow";
			}

		} else if( radioButtons[a].name != "acneExtra") {
			var elemName = radioButtons[a].name;
			
			extraQuest1 = $("extra1");
			extraQuest2 = $("extra2");
				
			if (!(extraQuest1.checked || extraQuest2.checked)&&($('acneYes').checked)) {
				document.getElementById('acneExtra_row').className = "questionRowError";
				document.getElementById('acneExtra_row').setStyle('height','54px');
				
				//event.returnValue=false;

				returnValue = false;
			} else {
				document.getElementById('acneExtra_row').className = "questionRow";
			}

		}	
		
	}
	
	
	
	//check dropdowns
	var dropdownLists = document.getElementsByTagName("select");
	for(a = 0; a < dropdownLists.length; a++) {
		if(dropdownLists[a].className == "diagnosis") {
			option = dropdownLists[a].getElementsByTagName("option");
			active = option[0].childNodes[0].nodeValue;
			textnode = document.createTextNode(active);
			for(b = 0; b < option.length; b++) {
				if(option[b].selected == true) {
					if (option[b].value == "") {
						document.getElementById(dropdownLists[a].name+'_row').className = "questionRowError";
						if (returnValue == true) {
							returnValue = false;
						}							
					} else {
						document.getElementById(dropdownLists[a].name+'_row').className = "questionRow";
					}
				}
			}
		}
	}
	
	
	if (returnValue == false){
		//document.getElementById('errorBoxTop').style.display = "block";
		document.getElementById('errorBoxBottom').style.display = "block";
	}
	
	return returnValue;

	
}


