/* page redirect if resolution is low */
function redirect() {
	if (screen.width <= 800) {
		window.location="index_lowres.html";
	} 
}
		
function tagcolor(ID) {
	if(screen.width <= 1024) {
		document.getElementById(ID).getElementsByTagName('p')[0].style.color = 'white';
	}
}

function change_nav(ID) {
	var link_array = document.getElementById('nav').getElementsByTagName('a');
	array_length = link_array.length;
	
	for(var i=0; i<array_length; i++) {	 	
	 	if(link_array[i].getAttribute('id') == ID) {
	 	 	link_array[i].className = 'active';
	 	 	/* 
	 	 	link_array[i].style.color = '#000';
	 	 	link_array[i].style.backgroundColor = '#aaa';
	 	 	*/
	 	} else {
	 	 	link_array[i].className = 'inactive';
	 	 	/*
	 	 	link_array[i].style.color = '#FFF';
	 	 	link_array[i].style.backgroundColor = '#000';
	 	 	*/
	 	}
	}
}


/* ******************************************************************
 * Makes sure required fields are not left blank
 ****************************************************************** */
function exists(userEntry) {
  var aCharExists = 0;
  var entry = userEntry;

  if (entry) {
    for (var i=0; i<entry.length; i++) {
      //spaces don't count as "existence"
      if (entry.charAt(i) != " ") {
        aCharExists = 1;
      }
    }
  }
  if (!aCharExists) {
    return 0;
  }
  return 1;
}


/* ******************************************************************
* Validates Contact Form
****************************************************************** */
function validateForm() {
  var fixThis = "";
  
  /* CHECK ALL FIELDS EXCEPT URL */
  if(!(exists(document.getElementById('from').value))) {
	fixThis += "Please enter your name in the 'From' field.\n";
  }
  if(!(exists(document.contact_form.msg.value))) {
    fixThis += "Please enter a message.\n";
  }
  if(!(exists(document.contact_form.email.value))) {
    fixThis += "Please enter your email address.\n";
  }  
  
  /* IF MISSING FIELD, POP UP MSG */
  if(fixThis != "") { 
	  alert(fixThis);
  } else {
    document.contact_form.submit();
  }
  
}
