﻿var address = window.location.href;
var locID = address.slice(23,27); //use 34,39 for actual Recycle-Motion website 
var reason = 1;


function communityRedirect(){
  var goTo = document.getElementById('communitySelect').value;
  window.location = '/communities/' + goTo;
}

function headCommOn(){
if (locID != 'comm'){
document.getElementById('mH-CommunitiesLink').id = "mH-CommunitiesLinkActive";
}
}

function headCommOff(){
if (locID != 'comm'){
document.getElementById('mH-CommunitiesLinkActive').id = "mH-CommunitiesLink";
}
}


var pages=new Array(); 
pages[0]="";
pages[1]="abou";
pages[2]="comm";
pages[3]="recy";
pages[4]="educ";
pages[5]="kids";
pages[6]="link";
pages[7]="cont";

var linkID=new Array(); 
linkID[0]="mH-HomeLink";
linkID[1]="mH-AboutLink";
linkID[2]="mH-CommunitiesLink";
linkID[3]="mH-RecycleMotionLink";
linkID[4]="mH-EducationLink";
linkID[5]="mH-KidsLink";
linkID[6]="mH-LinksLink";
linkID[7]="mH-ContactLink";


headStay = function(){
var z = 0;
for (z=0;z<=7;z++){
  if (locID == pages[z]){
  document.getElementById(linkID[z]).id = linkID[z] + "Active"; 
  }
 }
}

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("mainHeadNav");
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", "");
   }
   }
  }
 }
}
window.onload=startList;


expandos = new Array();
expandos[0]="open";
expandos[1]="closed";
expandos[2]="closed";
expandos[3]="closed";
expandos[4]="closed";
expandos[5]="closed";
expandos[6]="closed";
expandos[7]="closed";
expandos[8]="closed";
expandos[9]="closed";
expandos[10]="closed";
expandos[11]="closed";
expandos[12]="closed";
expandos[13]="closed";



var FCTIMER = 15;
var FCBUSY = false;

function fcExpand(id, speed) {
if(!FCBUSY) {
var el = document.getElementById(id);
el.style.overflow = 'hidden';
var temph = el.offsetHeight;
el.style.height = 'auto';
if(temph !== el.offsetHeight) {
el.orgh = el.offsetHeight;
el.style.height = temph;
}
FCBUSY = true;
el.timer = setInterval(function(){fcSlide(el, 1, speed)}, FCTIMER);
}
}

function fcCollapse(id, speed) {
if(!FCBUSY) {
var el = document.getElementById(id);
el.style.overflow = 'hidden';
var temph = el.offsetHeight;
el.style.height = 'auto';
if(temph !== el.offsetHeight) {
el.orgh = el.offsetHeight;
el.style.height = temph;
}
FCBUSY = true;
el.timer = setInterval(function(){fcSlide(el, 0, speed)}, FCTIMER);
}
}

function fcToggle(id, speed) {
if(document.getElementById(id).offsetHeight > 0) {
fcCollapse(id, speed);
} else {
fcExpand(id, speed);
}
}

function fcSpecialToggle(id){
document.getElementById(FCCURR).style.display = 'none';
document.getElementById(id).style.display = 'inline';
FCCURR = id;
}



function fcSlide(el, direction, speed) {
var curh = el.offsetHeight;
if(direction == 0) { speed = 0 - speed; }

if(direction == 0 && (curh + speed) < 1) {
el.style.height = '0px';
clearInterval(el.timer);
FCBUSY = false;
} else if(direction == 1 && (curh + speed) > (el.orgh - 1)) {
el.style.height = el.orgh + 'px';
clearInterval(el.timer);
FCBUSY = false;
} else {
el.style.height = curh + speed + 'px';
}
}

function expHeadSwitch(id,num){
if(!FCBUSY){
  if (expandos[num] == "closed"){
  document.getElementById(id).setAttribute("class", "expandoOpen");
  expandos[num] = "open";
}
else{
document.getElementById(id).setAttribute("class", "expandoClosed");
expandos[num] = "closed";
}
}
}

function sagShow(show){
var showme = "saginawCal" + show;
document.getElementById(showme).style.display = "block";
}

function sagHide(){
document.getElementById('saginawCalOne').style.display = "none";
}

//Contact Page Scripts
var reasonContact=new Array(); 
reasonContact[0]="";
reasonContact[1]="renee@recyclemotion.org";
reasonContact[2]="renee@recyclemotion.org";
reasonContact[3]="renee@recyclemotion.org";
reasonContact[4]="monica@recyclemotion.org";
reasonContact[5]="mmwa@recyclemotion.org";
reasonContact[6]="mmwa@recyclemotion.org";
reasonContact[7]="mmwa@recyclemotion.org";
reasonContact[8]="sarah@recyclemotion.org";
reasonContact[9]="mmwa@recyclemotion.org";

var reasonDisplay=new Array(); 
reasonDisplay[0]=0;
reasonDisplay[1]=4;
reasonDisplay[2]=4;
reasonDisplay[3]=4;
reasonDisplay[4]=4;
reasonDisplay[5]=1;
reasonDisplay[6]=2;
reasonDisplay[7]=3;
reasonDisplay[8]=4;
reasonDisplay[9]=4;

function ContactMainChange(selectedobj){
  var selection = selectedobj.selectedIndex;
  var selectDisplay;
  var selectChange;
  for (d=0;d<=9;d++){
    if (selection == d){
	  var selectDisplay = reasonDisplay[d];
	  contactDisplay(selectDisplay);
	  var selectChange = reasonContact[d];
	  contactChange(selectChange);
	  if (reasonDisplay[d] == 4){
	    contactSubmit();
		}
	  else{}
	  }
	else{
	} 
  }
}
function contactDisplay(display){
contactHideFAQ();
contactHideSubmit();
var reason = display;
for (t=1;t<=4;t++){
  if (reason == t){
  var turnOn1 = "head" + t;
  var turnOn2 = "list" + t;
  document.getElementById(turnOn1).style.display = "block";
  document.getElementById(turnOn2).style.display = "block";
  }
  else{
  var turnOff1 = "head" + t;
  var turnOff2 = "list" + t;
  document.getElementById(turnOff1).style.display = "none";
  document.getElementById(turnOff2).style.display = "none";
  }
 }
}

function contactChange(newName){
 document.getElementById('whotomail').value = newName;
}

function ContactSubChange(selectedobj,questList){
  var numOptions = selectedobj.length;
  var selection = selectedobj.selectedIndex;
  var question;
  if (selection != numOptions){
    contactHideFAQ();
	contactFAQ(questList,selection);
  }
  else{
  contactDisplay(4);
  contactHideFAQ();
  contactSubmit();
  }  
}

function contactFAQ(list,number){
  var showMe = list + number;
  document.getElementById(showMe).style.display = "block"; 
}

function contactHideFAQ(){
  for (x=1;x<=4;x++){
    var firstList = "trash" + x;
	document.getElementById(firstList).style.display = "none";
	}
  for (y=1;y<=4;y++){
    var secondList = "recycle" + y;
	document.getElementById(secondList).style.display = "none";
	}
  for (z=1;z<=5;z++){  
    var thirdList = "yard" + z;
	document.getElementById(thirdList).style.display = "none";
	}
  }

function cleanContact(){
  var conval = document.getElementById('details').value;
  if (conval == "Please type your question here")
  {
  document.getElementById('details').value = "";
  }
  else {}
}

function contactSubmit(){
  document.getElementById('captcha').style.display = 'block';
}

function contactHideSubmit(){
document.getElementById('captcha').style.display = 'none';
}
