startList = function() {
			var ua = navigator.userAgent.toLowerCase();
			var is_pc_ie = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ) );
			var is_mac_ie = ( (ua.indexOf('msie') != -1 ) && ( ua.indexOf('mac') != -1 ));
			if(is_pc_ie){
				navRoot = document.getElementById("nav_list");
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];


					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						}
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						}

						if (node.childNodes[2]) {

							for (n=0; n<node.childNodes[2].childNodes.length; n++) {
								node2 = node.childNodes[2].childNodes[n];
								if (node2.nodeName=="LI") {
									node2.onmouseover=function() {
										this.className+=" over";
									}
									node2.onmouseout=function() {
										this.className=this.className.replace(" over", "");
									}

								}

							}


							if (node.childNodes[2].childNodes[0].childNodes[2]) {


								for (n=0; n<node.childNodes[2].childNodes[0].childNodes[2].childNodes.length; n++) {
									node3 = node.childNodes[2].childNodes[0].childNodes[2].childNodes[n];

									if (node3.nodeName=="LI") {
										node3.onmouseover=function() {
											this.className+=" over";
										}
										node3.onmouseout=function() {
											this.className=this.className.replace(" over", "");
										}

									}

								}
							}
						}




					}
				}
			}
		}



function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function highlightThis(navHighlight) {
		for (i=0; i<navHighlight.childNodes.length; i++) {

			node = navHighlight.childNodes[i];

			if(node.nodeName.toLowerCase() == 'a'){

				node.className = node.className.replace(/main_link/g, 'selectedTopNav2');

				}
			break;
		}
}

function init() {
	
	if(location.pathname.substring(1,8).toLowerCase() == "gateway"){	
		var filename = location.pathname.substring(9, location.pathname.lastIndexOf('/')).toUpperCase();
	}else{ 
		var filename = location.pathname.substring(1, location.pathname.lastIndexOf('/')).toUpperCase();
	}
	
	if (filename == "REHAB-TREATMENT") {
		filename = "REHAB-TREAT";
	}
		if (filename == "DRUG-REHAB") {
		filename = "DRUG-REHAB1";
	}
	
	
	
	
	if (filename != "/" && filename != "INH" && filename !="SIK" && filename !="SIT" && filename !="/GATEWAY-") {
	
		switch(filename) {			
//			case 'OPRS': 	str = "nav_services";	break;
			case 'REHAB-SERVICES':	str = "nav_services";	break;
//			case 'TA':		str = "nav_treatment";	break;
			case 'REHAB-TREATMENT':		str = "nav_treatment";	break;
//			case 'AGF':		str = "nav_about";		break;
			case 'ABOUT-GATEWAY':		str = "nav_about";		break;
//			case 'FL':		str = "nav_locations";	break;
			case 'ILLINOIS-LOCATIONS':		str = "nav_locations";	break;
			case 'CAREERS':	str = "nav_careers";	break;
			case 'CONTACT':	str = "nav_contact";	break;
			default: break;
		}
//		var navHighlight =	document.getElementById(str);
		
//		highlightThis(navHighlight);
	}

	if(filename != "/" && filename !="/GATEWAY-") {

	document.getElementById(filename).style.display = "block";
	document.getElementById("pushNav").style.display = "none";
	handleButton();


		var urlPath = location.pathname;
		var splitPathName_array = urlPath.split("/");
		var str = splitPathName_array[splitPathName_array.length-1];
		str = str.slice(0, str.indexOf('.'));

		if ((filename == "REHAB") && (str == "rehab-questions")) {
			document.getElementById('rehab-questions2').className = "subNavItemSelected";
		}				
		else if ((filename == "REHAB-PROFESSIONAL") && (str == "rehab-questions")) {
			document.getElementById('rehab-questions3').className = "subNavItemSelected";
		}
		else if ((str == "teen-rehab-help") || (str == "teen-rehab") || (str == "teen-rehab-test") || (str == "parent-rehab")) {
			document.getElementById('teen-rehab-checklist').className = "subNavItemSelected";			
        }
		else if ((str != "rehab-default") && (str != "drug-alcohol-rehab-treatment") && (str != "rehab") && (str != "Gateway-Alcohol-Drug-Rehab-Contact") && (str != "Gateway-Alcohol-Drug-Rehab-Careers")&& (str != "Gateway-Alcohol-Drug-Rehab")) {
			document.getElementById(str).className = "subNavItemSelected";		
        }


/*		if(str == "SIK_teenNeedsHelp") {
			document.getElementById('SIK_teenChecklist').className = "subNavItemSelected";
		}
		if(str == "SIK_teenNeedsHelp") {
			document.getElementById('SIK_teenChecklist').className = "subNavItemSelected";
		}
		else if(str == "SIK_teenMightNeedHelp") {
			document.getElementById('SIK_teenChecklist').className = "subNavItemSelected";
		}
		else if(str == "SIK_teenSelfTest") {
			document.getElementById('SIK_teenChecklist').className = "subNavItemSelected";
		}
		else if(str == "SIK_parentsNeedHelp") {
			document.getElementById('SIK_teenChecklist').className = "subNavItemSelected";
		}
		else if(str == "AGF_success") {
			document.getElementById('AGF_alumni').className = "subNavItemSelected";
		}
		else {
			if((str.substr(str.lastIndexOf("_")+1, 8) != "default") && (str.substr(str.lastIndexOf("_")+1, 7) != "results") && (str.substr(str.lastIndexOf("_")+1, 11) != "description") && (str.substr(str.lastIndexOf("_")+1, 3) != "you")) document.getElementById(str).className = "subNavItemSelected";
		}
*/		
		

	}
		
}


function handleButton() {
	var img_alt = new Array("After work drug rehab and alcohol rehab in Chicago and throughout Illinois. Call Gateway Alcohol & Drug Rehab Now, 1.877.321.RECOVER.","Become drug free at Gateway Alcohol and Drug Rehab in Chicago and throughout Illinois. Insurance Accepted.  Call Gateway Now, 1.877.321.RECOVER","Become alcohol free at Gateway Alcohol and Drug Rehab in Chicago and throughout Illinois. Insurance Accepted.  Call Gateway Now, 1.877.321.RECOVER.","After school drug rehab and alcohol rehab in Chicago and throughout Illinois. Call Gateway Alcohol & Drug Rehab Now, 1.877.321.RECOVER.","Need help understanding the signs & symptoms? Call Gateway Alcohol & Drug Rehab in Chicago and throughout Illinois now, 1.877.321.RECOVER.","Think your teen is in trouble and may need alcohol treatment or drug rehab?  Take our substance abuse test.","Think your elderly relative is in trouble and may need alcohol treatment or drug rehab?  Take our substance abuse test.","Think you are in trouble and may need alcohol treatment or drug rehab?  Take our substance abuse test.","Think someone you know is in trouble and may need alcohol treatment or drug rehab?  Take our substance abuse test.","Are you a teen in trouble and may need alcohol treatment or drug rehab?  Take our substance abuse test.");
	var img_link = new Array("../rehab-services/rehab-programs.aspx","../Contact/Gateway-Alcohol-Drug-Rehab-Contact.aspx","../Contact/Gateway-Alcohol-Drug-Rehab-Contact.aspx","../rehab-services/rehab-programs.aspx","../Contact/Gateway-Alcohol-Drug-Rehab-Contact.aspx","../rehab/teen-rehab.aspx","../rehab/older-adult-rehab.aspx","../drug-rehab/rehab-screening.aspx","../rehab/rehab-self-test.aspx","../rehab/teen-rehab-test.aspx ");
	var rand = Math.floor(Math.random()*(10)+1);
	var e = document.getElementById("subNavButton");
	var num = 0;


	var urlPath = window.location.href;
	var splitPathName_array = urlPath.split("/");
	var str = splitPathName_array[splitPathName_array.length-1];
	var filename = location.pathname.substring(1, location.pathname.lastIndexOf('/')).toUpperCase();
	str = str.slice(0, str.indexOf('.'));



	if(str == "teen-rehab-checklist") {
		num = 4;
	} else if ((str == "rehab") && (filename == "REHAB")) {
		num = 9;
	} else if(str == "teen-rehab-help") {
		num = 4;
	} else if(str == "teen-rehab") {
		num = 4;
	} else if(str == "teen-rehab-test") {
		num = 4;
	} else if(str == "parent-rehab") {
		num = 3;
	} else if(str == "rehab-expectations") {
		num = 2;
	} else if(str == "drug-addiction-rehab") {
		num = 1;
	} else if(str == "alcohol-addiction-rehab") {
		num = 3;
	} else if ((str == "rehab") && (filename == "DRUG-REHAB")) {
		num = 8;
	} else if (str == "rehab-screening"){
		num = 2;
	} else if (str == "rehab-self-test"){
		num = 5;
	} else if (str == "Gateway-Alcohol-Drug-Rehab-Lake-Villa"){
		num = 8;
	} else {
		num = rand;
	}

	if (img_link[num - 1] == "#"){
		e.innerHTML = "<img src=\"../images/button_" + (num) + ".jpg\" height=\"141\" width=\"175\" alt=\"" + img_alt[num - 1] + "\" runat=\"server\" />";
	} else {
		e.innerHTML = "<a href=\"" + img_link[num - 1] + "\" ><img src=\"../images/button_" + (num) + ".jpg\" height=\"141\" width=\"175\" alt=\"" + img_alt[num - 1] + "\" runat=\"server\" /></a>";
	}


	if ((str.indexOf('Gateway-Alcohol-Drug-Rehab-Careers')) !=-1 || (str.indexOf('Gateway-Alcohol-Drug-Rehab-Contact')) !=-1 || str == 'older-adult-rehab') {
		e.style.display = "none";
	}
	else {
		e.style.display = "block";
	}


}

function setNum(){
	old_num = 0;
}
function faq(num,this_link){
	//if a section is already open, close it

	if (old_num != 0){
		document.getElementById("faq_"+old_num).className = "faq_hide";
		if (num == old_num) {
			old_num = 0;
		// if not, open new one
		} else {
			document.getElementById("faq_"+num).className = "faq_show";
			old_num = num;
		}

		// if no section is opne, open it and store it's number
	} else {
		document.getElementById("faq_"+num).className = "faq_show";
		old_num = num;

	}
}

function hide_faq(){
	for (n=1;n<=10;n++){
		document.getElementById("faq_"+n).className = "faq_hide";
	}
}


function external() {
    if (document.getElementsByTagName) {
	var a;
	a = document.getElementsByTagName('a');
	for (i = 0; i<a.length; i++) {
        if (a[i].getAttribute('href') && a[i].getAttribute('rel') == 'external'){
    		a[i].target = '_blank';

			}
		}
	 }
}

function validateForm(a) {

	if(document.all || document.getElementById) {
	    var email_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var err = new Boolean();
		err = false;

        if(a[0].value.replace(/^\s+|\s+$/g, "") == "" || a[0].value == "First Name Required.") {
            a[0].value = "First Name Required.";
            err = true;
        }

        if(a[1].value.replace(/^\s+|\s+$/g, "") == "" || a[1].value == "Last Name Required.") {
            a[1].value = "Last Name Required.";
            err = true;
        }

        if(a[2].value.length == 0 || a[2].value == "Email Required." || a[2].value == "Invalid Email Address." || a[2].value == "Emails do not match.") {
		    a[2].value = "Email Required.";
		    a[3].value = "";
		    err = true;
	    } else if(!email_filter.test(a[2].value)) {
		    a[2].value = "Invalid Email Address.";
		    a[3].value = "";
		    err = true;
        } else if(!email_filter.test(a[2].value) || !email_filter.test(a[3].value) || (a[2].value != a[3].value)) {
            a[2].value = "Emails do not match.";
            a[3].value = "";
            err = true;
        }


		if(err) return(false);
		else return(true);
	}
}

function validateCareers(a) {
    if(document.getElementById) {
        var loc = a[0].value;
        var type = a[1].value;

        if (loc != "F" && type != "F") return (true);
        else {
            if(loc == "F") document.getElementById("jobLocationsErr").style.display = "inline";
            else document.getElementById("jobLocationsErr").style.display = "none";
            if(type == "F") document.getElementById("jobTypesErr").style.display = "inline";
            else document.getElementById("jobTypesErr").style.display = "none";
            return (false);
        }
    }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      if(a.getAttribute("title") == title) a.href = "../styles/gateway_print.css";
    }
  }
}


function checkList(questions_num,limit_num) {
	var yes_num = 0;
	var no_num = 0;
	var unchecked_num = 0;
	for (i=1; i<=questions_num; i++){
		if (document.getElementById("radiobutton_yes_"+i).checked) {
			yes_num = yes_num + 1;
		}

		else if (document.getElementById("radiobutton_no_"+i).checked == false){
			unchecked_num = unchecked_num + 1;
		} else if (document.getElementById("radiobutton_no_"+i).checked){
			no_num = no_num + 1;
		}
	}
	if (unchecked_num>0){
		document.getElementById("help_response").className = "show";
		document.getElementById("yes_response").className = "hide";
		document.getElementById("no_response").className = "hide";
		document.getElementById("submit").value = "Re-submit";
	} else if (yes_num >=limit_num){
		document.getElementById("yes_response").className = "show";
		document.getElementById("no_response").className = "hide";
		document.getElementById("help_response").className = "hide";
		document.getElementById("submit").value = "Re-submit";
		document.getElementById("yes_num").innerHTML = yes_num;
	} else {
		document.getElementById("no_response").className = "show";
		document.getElementById("yes_response").className = "hide";
		document.getElementById("help_response").className = "hide";
		document.getElementById("submit").value = "Re-submit";
	}

}

function printResults(questions_num){
	setActiveStyleSheet("main_stylesheet");
	window.print();
}


function toggle() {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("displayText");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = "Click here to read more";
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = "Click here to read more";
	}
}

function checkTestimonialYear(obj)
{
	if(obj[1].checked && (obj[0].value == "" || isNaN(obj[0].value)))
	{
		alert("Please enter alumni year.");
		return false;
	}
	else return true;
}
