// site.js

	function populate5ColTable(data){
		
		if (data.length > 0){
			var tbl = $("body5");
			DWRUtil.removeAllRows(tbl);
			for (var i=0; i<data.length; i++){
				var row = document.createElement("tr");
				appendTD(row,document.createTextNode(data[i].name));
				appendTD(row,document.createTextNode(data[i].address));
				appendTD(row,document.createTextNode(data[i].city));
				appendTD(row,document.createTextNode(data[i].state));
				appendTD(row,document.createTextNode(data[i].phone));
				appendTD(row,createAnchor(data[i].mapquest,"map",true));
				tbl.appendChild(row);
			}
			var toshow = $("hidden5div");
			toshow.style.display="block";
		}
		else{
			var toshow = $("norecords");
			toshow.style.display="block";			
		}
	}
	function populate6ColTable(data){
		if (data.length > 0){
			var tbl = $("body6");
			DWRUtil.removeAllRows(tbl);
			for (var i=0; i<data.length; i++){
				var row = document.createElement("tr");
				appendTD(row,document.createTextNode(data[i].name));
				appendTD(row,document.createTextNode(data[i].address));
				appendTD(row,document.createTextNode(data[i].city));
				appendTD(row,document.createTextNode(data[i].state));
				appendTD(row,document.createTextNode(data[i].phone));
				appendTD(row,createAnchor(data[i].mapquest,"map",true));
				var tp = $("tp");				
				appendTD(row,createAnchor("schedule.do?id=" + data[i].instanceId + "&thirdParty=" + tp.value,"view",true));
				tbl.appendChild(row);
			}
			var toshow = $("hidden6div");
			toshow.style.display="block";
		}
		else{
			var toshow = $("norecords");
			toshow.style.display="block";			
		}
	}
	
	function createAnchor(url,name,newwindow){
		var anchor = document.createElement("a");
		anchor.setAttribute("href",url);
		if (newwindow){
			anchor.setAttribute("target","_blank");
		}
		anchor.appendChild(document.createTextNode(name));
		return anchor;
	}
		
	function appendTD(tr,el){
		var td = document.createElement("td");
		td.appendChild(el);
		tr.appendChild(td);
	}
	
	function hideDivs(){
		var e = $("hidden5div");
		e.style.display="none";
		e = $("hidden6div");
		e.style.display="none";
		e = $("norecords");
		e.style.display="none";
	}
	
	
	
	
	function show(el){
		hideDivs();
		var cat = $("categoryId");
		if (cat.value == ""){
			cat.value = $("hidden0").value;
		}
		var dm = $("deliveryMethod");
		if (dm.value == ""){
			dm.value = $("method0").value;
		}
		
		var r = $("radius");
		
		var zip = $("zipCode");
		
		var tp = $("tp");
		
		if(!isNaN(zip.value) && zip.value.length == 5){
			//alert ("Category: " + cat.value + "\nMethod: " + dm.value + "\nZipCode: " + zip.value + "\nRadius: " + r.value);
			if (dm.value == 1){		
				Locations.findLocations(populate5ColTable,cat.value,zip.value,r.value,tp.value);
			}
			else{
				Locations.findLocations(populate6ColTable,cat.value,zip.value,r.value,tp.value);
			}
		}
		return false;
	}
	
	function showSec(el){
		hideDivs();		
		var r = resetTabs(el);
		el.className="active";
		var p = $("para" + r);
		p.className="pg";
		
		var val = $("hidden" + r);
		var tgt = $("categoryId");
		tgt.value = val.value;
		
		val = $("method" + r);
		tgt = $("deliveryMethod");
		tgt.value = val.value;
		
		val = $("tp" + r);		
		var d = $("tpArea");
		if (val.value =="false"){			
			d.style.display="none";
			var tp = $("tp");
			tp.value="";
		}else{
			d.style.display="inline";
		}
		
		return false;
	}
	
	function resetTabs(elm){
		var el = $("nav");
		var ret = -1;
		var elem = el.getElementsByTagName("li");
		if(elem){			
			for (var i=0; i<elem.length; i++){
				if (elem[i] == elm){					
					ret = i;
				}
				var n = "para" + i;
				var p = $(n);										
				if (elem[i].className == "active"){
					elem[i].className = "inactive";					
					var pr = $(n);
					pr.className="nopg";
				}
			}
		}
			
		return ret;
	}
	
	function setCookie(c_name,value){		
		document.cookie = c_name+ "=" + escape(value) + ";path=" + escape("/");		
	}
	
	function acceptTerms(){
		setCookie("savonhealthtermsaccepted","true");
		var nextPage = document.getElementById("nextPage");
		if (nextPage && nextPage.value !=""){
			document.location= nextPage.value;		
		}
		else{
			document.location="services.jsp";
		}
		
			
	}
	
	function checkTerms(){		
		var accept= document.getElementById("accept");
		if (accept && accept.checked){
			acceptTerms();
		}
		else{
			document.location = "home.jsp";
		}
		return true;
	}		
		