//icon js functions

//Form button rollovers
function goLite(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#f2f2f2";
   window.document.forms[FRM].elements[BTN].style.backgroundColor = "#1e1e8c";
   window.document.forms[FRM].elements[BTN].style.borderColor = "#1e1e8c";
}

function goDim(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#1e1e8c";
   window.document.forms[FRM].elements[BTN].style.backgroundColor = "#f2f2f2";
   window.document.forms[FRM].elements[BTN].style.borderColor = "#1e1e8c";
}

//Nav rollovers
function swapImage(img,filename){
	var itm = "document." + img + ".src = 'media/" + filename + "'";
	//msgbox(filename);
	eval(itm);
}

function checkRegistration(){
	//validate required fields
	//firstname,lastname,email,username,pass,pass2,hospital,city,state OR province,zip,country
	var msg = "";
	if (document.getElementById("firstname").value == ""){
		msg += "Firstname\n";
	}
	if (document.getElementById("lastname").value == "") {
		msg += "Lastname\n";
	}
	if (document.getElementById("email").value == "") {
		msg += "Email\n";
	}
	if (document.getElementById("user").value == "") {
		msg += "Username\n";
	}
	if (document.getElementById("pass").value == "") {
		msg += "Password\n";
	}
	if (document.getElementById("pass2").value == "") {
		msg += "Password verify\n";
	}		
	if (!blnHospitalSelected) {
		msg += "Hospital\n";
	}
	if (!blnStaffPosSelected) {
		msg += "Staff Position\n";
	}		
	if (document.getElementById("city").value == "") {
		//msg += "City\n";
	}	
	if (document.getElementById("state").selectedIndex == "0") {
		if(document.getElementById("state_prov").selectedIndex == "0"){
			if(document.getElementById("country").selectedIndex < 4){
				msg += "State OR State/Prov\n";
			}
		}
	}	
	if (document.getElementById("zip").value == "") {
		msg += "Zip Code\n";
	}		
	if (document.getElementById("country.selectedIndex") == "0") {
		msg += "Country\n";
	}					
	//pass and pass2 must match
	if(document.getElementById("pass").value != document.getElementById("pass2").value){
		msg += "Passwords must match";
	}
	if(document.getElementById("pass").value.length < 6 || document.getElementById("pass2").value.length < 6){
		msg += "Passwords must be at least 6 characters in length";
	}
	//city,state,zip entered must match that of the hospital
	//done during server validation
	
	if(msg != ""){
		alert("Please correct the following:\n\n" + msg);

	}
	else{
		registration.submit();
	}
	
}

function checkSessionRegistration(){
	//validate required fields
	//firstname,lastname,email,hospital,city,state OR province,zip,country,phone,rep,numParticipants,typeParticipants
	var msg = "";
	if (regform.firstname.value == ""){
		msg += "Firstname\n";
	}
	if (regform.lastname.value == "") {
		msg += "Lastname\n";
	}
	if (regform.email.value == "") {
		msg += "Email\n";
	}
	if (regform.phone_number.value == "") {
		msg += "Phone Number\n";
	}
	if (regform.draeger_rep.value == "") {
		msg += "Draeger Rep\n";
	}
	if (regform.audience_size.value == "") {
		msg += "Audience Size\n";
	}		
	//TARGET AUDIENCE AT LEAST ONE SELECTED	
	var boxes = regform.tgt.length;
	var flg = 0;
	for (var i = 0; i < boxes; i++) {
		if (regform.tgt[i].checked) {
			flg = 1;
		}
	}
	if (flg == 0){
		msg += "Target Audience\n";	
	}
	
	
	
	if (regform.hospital.selectedIndex == "0") {
		msg += "Hospital\n";
	}	
	if (regform.city.value == "") {
		msg += "City\n";
	}	
	if (regform.state.selectedIndex == "0") {
		if(regform.state_prov.selectedIndex == "0"){

				msg += "State OR State/Prov\n";
			
		}
	}	
//	if (regform.zip.value == "") {
//		msg += "Zip Code\n";
//	}		
	if (regform.country.selectedIndex == "0") {
		msg += "Country\n";
	}					
	
	if(msg != ""){
		alert("Please correct the following:\n\n" + msg);

	}
	else{
		regform.submit();
	}
	
}

function checkEnter(e){
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
//e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
document.forms[0].submit() //submit the form
return false 
}
else{
return true 
}


}

function showCountryOptions(){
	var objCountry = document.getElementById("country");
	var objStateRow = document.getElementById("staterow");
	var objStateProvRow = document.getElementById("stateprovrow");
	var objTownCell = document.getElementById("towncell");
	var objCityCell = document.getElementById("citycell");
	var objCountyRow = document.getElementById("countyrow");	

switch(objCountry.value)
{
	case "United States":
		objCountyRow.style.display = "none";  		
		objStateProvRow.style.display = "none";
		objStateRow.style.display = "inline";		
		objCityCell.style.display = "inline";
		objTownCell.style.display = "none";
		break;    
	case "Canada":
		objCountyRow.style.display = "none";  	
		objStateProvRow.style.display = "inline";
		objStateRow.style.display = "none";		
		objCityCell.style.display = "inline";
		objTownCell.style.display = "none";		
		break;
	case "Mexico":
		objCountyRow.style.display = "none";  	
		objStateProvRow.style.display = "none";		
		objStateRow.style.display = "inline";		
		objCityCell.style.display = "inline";
		objTownCell.style.display = "none";
		break;
	case "England":
		objCountyRow.style.display = "inline";
		objStateProvRow.style.display = "none";		
		objStateRow.style.display = "none";
		objCityCell.style.display = "none";
		objTownCell.style.display = "inline";		
		break;
	case "Scotland":
		objCountyRow.style.display = "inline";
		objStateProvRow.style.display = "none";		
		objStateRow.style.display = "none";
		objCityCell.style.display = "none";
		objTownCell.style.display = "inline";		
		break;
	case "Wales":
		objCountyRow.style.display = "inline";
		objStateProvRow.style.display = "none";		
		objStateRow.style.display = "none";
		objCityCell.style.display = "none";
		objTownCell.style.display = "inline";		
		break;
	case "Northern Ireland":
		objCountyRow.style.display = "inline";
		objStateProvRow.style.display = "none";		
		objStateRow.style.display = "none";
		objCityCell.style.display = "none";
		objTownCell.style.display = "inline";		
		break;
	case "Republic of Ireland":
		objCountyRow.style.display = "inline";
		objStateProvRow.style.display = "none";		
		objStateRow.style.display = "none";
		objCityCell.style.display = "none";
		objTownCell.style.display = "inline";		
		break;
	default:
		objCountyRow.style.display = "none";  	
		objStateProvRow.style.display = "none";
		objStateRow.style.display = "none";
		objCityCell.style.display = "inline";
		objTownCell.style.display = "none";
		
	}	
	
}

function checkHospitalSelect(oSelect){
    document.getElementById('hdnHospital').value = oSelect.options[oSelect.selectedIndex].value;
    return (oSelect.selectedIndex > 0);
}


function checkStaffPosSelect(oSelect) {
    document.getElementById('hdnStaffPos').value = oSelect.options[oSelect.selectedIndex].value;
    return (oSelect.selectedIndex > 0);
}

function getJobTitles(){
	var objCountry = document.getElementById("country");
	var country = objCountry.options[objCountry.selectedIndex].text;

	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getJobTitles', country, getResultJobTitles);
}
function getResultJobTitles(results){
    //alert(results);
    blnStaffPosSelected = false;
		var obj = document.getElementById("spos");
		//ClearOptions(obj);
		//alert(obj.innerHTML);
		obj.innerHTML = results;
		getCityStateHospitals();
}

function getCityStateHospitals(){
//ajax calls only work if config is same as calling page (http vs https)
	var city = document.getElementById("city").value;
	//var state = "";
	var objState = document.getElementById("state");
	var objStateProv = document.getElementById("state_prov");
	var objCountry = document.getElementById("country");
	var objCounty = document.getElementById("county");
	var country = objCountry.options[objCountry.selectedIndex].text;
	var state = objState.options[objState.selectedIndex].text;
	var county = objCounty.options[objCounty.selectedIndex].text;
	if(state == ""){
		state = objStateProv.options[objStateProv.selectedIndex].text;
	}
	if(state == "" || city == "") {
		if(country != "England" && country != "Scotland" && country != "Wales" && country != "Northern Ireland" && country != "Republic of Ireland"){
			var theHTML = "<select name=\"hospital\" id=\"hospital\" onChange=\"blnHospitalSelected=checkHospitalSelect(this);\" style=\"font-size:10px;\">";
			theHTML = theHTML + "<option>--- Enter City/State first before selecting Hospital ---</option>";
			theHTML = theHTML + "</select>";
			document.getElementById("hosp").innerHTML = theHTML;
			return true;	
		}

	}

	//DWREngine._execute(_cfscriptLocation, null, 'getCityStateHospitals', city,state, getResultCityStateHospitals);
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getCityStateHospitals', city, state, country, county, getResultCityStateHospitals);
}

function getResultCityStateHospitals(results){
		//alert(results);
		var obj = document.getElementById("hosp");
		//alert(obj.innerHTML);
		//ClearOptions(obj);
		obj.innerHTML = results;		
}


function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();

		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength){
		this.relatedElement.className = 'toomuch';
		this.value = this.value.substring(0,maxLength);
	}
	else{
		this.relatedElement.className = '';
		this.relatedElement.firstChild.nodeValue = currentLength;
	}
	// not innerHTML
}
function setCurrentSection(){
	var objLI = document.getElementById("currentSection");
	if(objLI == null){
		return;	
	}
	var s = objLI.className;
	if(s == ""){

		objLI.style.display= 'inline';
		objLI.style.borderWidth='0';

	}
	else{
		//alert(objLI.outerHTML);
		//objLI.style.display='inline';
		//objLI.childNodes(0).style.backgroundColor = '#5050aa';
		//objLI.childNodes(0).style.display = 'block';
		//objLI.childNodes(1).style.backgroundColor = '#ffffff';
		//alert(objLI.childNodes(0).outerHTML);
	}
}
function launchWebex(){

	var leftVal = (screen.width - 800) / 2;
	var topVal = (document.body.clientHeight - 600) / 2;
	var theOptions = "toolbar=no,status=no,resizable=yes,scrollbars=yes,width=800,height=600,left="+leftVal+",top="+topVal;
	window.open("http://icon.webex.com","webx",theOptions);
}

function showEventList(strDay,strMonth,strYear)	{
	//DWRUtil.useLoadingMessage();
	var theDate = strMonth + "/" + strDay + "/" + strYear;
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getListingForDayHTML', theDate, showEventListResult);
}
	
function showEventListResult(r) {
	$('academydetails').innerHTML = r + '<p><input type="button" value="Join Webcast" onclick="javascript:launchWebex();">';
	//$('echoScreen').innerHTML = r;
}
