// Shows Only one DIV at a time based on a class and id ************************

function showonlyone(thechosenone) 
{
			// Change the styling on links if they are the active link
			var anch = thechosenone + "li";
      var newboxes = document.getElementsByTagName("a");
      for(var i=0; i<newboxes.length; i++) 
      {
            name = newboxes[i].getAttribute("name");
            if (name == 'navtwo') 
						{
                  if (newboxes[i].id == anch) 
									{
                  	 newboxes[i].style.color = '#000000';
									}
                  else 
									{
                     newboxes[i].style.color = '#999999';
                  }
      			}
      }
				
			//Show hide content divs based on the name attribute showcontent
      var newboxes = document.getElementsByTagName("div");
      for(var x=0; x<newboxes.length; x++) 
      {
            name = newboxes[x].getAttribute("name");
            if (name == 'showcontent') 
						{
                  if (newboxes[x].id == thechosenone) 
									{
                  	 newboxes[x].style.display = 'block';
									}
                  else 
									{
                     newboxes[x].style.display = 'none';
                  }
      			}
      }
	}
	//Hide email from spammers.  pass name and server in create email.
  function info_call(name,server){
    addrss=(name + '@' + server);
    document.write('<A href="mailto:' + addrss + '">' + addrss + '</a>');
  	//alert("here");
  }

	
//******************************************************************************
// Form Validation Below *******************************************************
/*
ShadowValidation
----------------

Generic Form Validation.
To activate this validation, add attributes to your form elements.
Attribute "validate" defines what type of validation you want.
Possible values for "validate" attribute:
	"not_empty" - element can't be empty.
	"integer" - element must have integer value.
	"number" - element must have numeric value.
	"email" - element value must be valid email address.
	"alphabet" - element value must consist only of given alphabet list in allow_only attribute.
			you can give ranges using ".." in the allow_only attribute.
	[function name] - vaidate using your own function. see below for more details.
You can join more than one validation type by using the "|" character.
For example:
	<input type="text" name="myinput" validate="not_empty|number" />
	will force not empty and numeric value.
Example for alphabet validation:
	<input type="text" name="myinput" validate="not_empty|alphabet" allow_only="a..zA..Z0..9" />
	will force not empty value that contains only english letters or digits.
Attribute "msg" defines the message to display when validation fails.
For example:
	<input type="text" name="myinput" validate="not_empty|number" msg="please enter value|invalid value" />
	will show "please enter value" if value is empty and "invalid value" if not numeric.
By default, the message will appear next to the form element.
You can have the message appear as alert dialog by adding show_alert attribute to the form.
For example:
	<form show_alert="1" onsubmit="return Validate(this);">
	will show the messages as alerts.
Attribute "error_container" defines where the message will appear in case of invalid input.
You must have corresponding <span> or <div> tag with that exact ID in the page. If this
attribute is missing, the message will appear after the input element.
For example:
	<input type="radio" name="gender" value="M" validate="not_empty" msg="please select gender" error_container="GenderErrorContainer" />
	and then have such code after the radio buttons:
	<span id="GenderErrorContainer"></span>
Advanced:
	You can use your own function to validate the data.
	For this, write the function name as the value of "validate" attribute.
	For example:
		<input type="text" name="myinput" validate="MyValidate" />
	The function must get the form element as its parameter and return true if valid or false otherwise.


Written by:
	© Shadow Wizard, 2006

*/

function Validate(objForm) {
	var arrValidated=new Array();
	
	for (var i=0; i<objForm.elements.length; i++) {
		var element=objForm.elements[i];
		var elName=element.name;
		if ((!elName)||(elName.length == 0)||(arrValidated[elName]))
			continue;
		arrValidated[elName] = true;
		var validationType = element.getAttribute("validate");
		if ((!validationType)||(validationType.length == 0))
			continue;
		var strMessages=element.getAttribute("msg");
		if (!strMessages)
			strMessages = "";
		var arrMessages = strMessages.split("|");
		var arrValidationTypes = validationType.split("|");		
		for (var j=0; j<arrValidationTypes.length; j++) {
			var curValidationType = arrValidationTypes[j];
			var blnValid=true;
			switch (curValidationType) {
				case "not_empty":
					blnValid = ValidateNotEmpty(element);
					break;
				case "integer":
					blnValid = ValidateInteger(element);
					break;
				case "number":
					blnValid = ValidateNumber(element);
					break;
				case "email":
					blnValid = ValidateEmail(element);
					break;
				case "alphabet":
					blnValid = ValidateAlphaBet(element);
					break;
				default:
					try {
						blnValid = eval(curValidationType+"(element)");
					}
					catch (ex) {
						blnValid = true;
					}
			}
			if (blnValid == false) {
				var message="invalid value for "+element.name;
				if ((j < arrMessages.length)&&(arrMessages[j].length > 0))
					message = arrMessages[j];
				InsertError(element, message);
				if ((typeof element.focus == "function")||(element.focus)) {
					element.focus();
				}
				return false;
			}
			else
				ClearError(element);
		}
		
	}
	
	return true;
}

function ValidateNotEmpty(objElement) {
	var strValue = GetElementValue(objElement);
	return (strValue.length > 0);
}

function ValidateInteger(objElement) {
	var strValue = GetElementValue(objElement);
	return (!isNaN(parseInt(strValue)));
}

function ValidateNumber(objElement) {
	var strValue = GetElementValue(objElement);
	return (!isNaN(parseFloat(strValue)));
}

function ValidateEmail(objElement) {
	var strValue = GetElementValue(objElement);
	if (strValue.length < 5)
		return false;
	var arrTemp=strValue.split("@");
	if (arrTemp.length != 2)
		return false;
	var strLeftPart = arrTemp[0];
	var strRightPart = arrTemp[1];
	if ((strLeftPart.length == 0)||(strRightPart.length == 0))
		return false;
	arrTemp = strRightPart.split(".");
	if (arrTemp.length < 2)
		return false;
	for (var i=0; i<arrTemp.length; i++) {
		if (arrTemp[i].length == 0)
			return false;
	}
	return true;
}

function ValidateAlphaBet(objElement) {
	var strValue = GetElementValue(objElement);
	
	if (strValue.length == 0)
		return true;
	
	var strAllowOnly = objElement.getAttribute("allow_only");
	if (!strAllowOnly)
		strAllowOnly = "";
	
	if (strAllowOnly.length == 0)
		return true;
	
	var i=0;
	var arrAllowedChars=new Array();
	while (i < strAllowOnly.length) {
		if ((i < (strAllowOnly.length-2)) && (strAllowOnly.substr(i+1, 2) == "..")) {
			for (var j=strAllowOnly.charCodeAt(i); j<=strAllowOnly.charCodeAt(i+3); j++) {
				arrAllowedChars[arrAllowedChars.length] = String.fromCharCode(j);
			}
			i += (2*2);
			continue;
		}
		arrAllowedChars[arrAllowedChars.length] = strAllowOnly.charAt(i)+"";
		i++;
	}
	
	for (var i=0; i<strValue.length; i++)
		if (InArray(arrAllowedChars, strValue.substr(i, 1)) < 0)
			return false;
	
	return true;
}

function GetElementValue(objElement) {
	var result="";
	switch (objElement.type) {
		case "text":
		case "hidden":
		case "textarea":
		case "password":
			result = objElement.value;
			break;
		case "select-one":
		case "select":
			if (objElement.selectedIndex >= 0)
				result = objElement.options[objElement.selectedIndex].value;
			break;
		case "radio":
		case "checkbox":
			for (var i=0; i<objElement.form.elements.length; i++) {
				if (objElement.form.elements[i].name == objElement.name) {
					if (objElement.form.elements[i].checked)
						result += objElement.form.elements[i].value+",";
				}
			}
			break;
	}
	return result;
}

function InsertError(element, strMessage) {
	if ((element.form.getAttribute("show_alert")) && (element.form.getAttribute("show_alert") != "0")) {
		alert(strMessage);
		return;
	}
	
	var strSpanID = GetErrorContainerID(element);
	var objSpan = document.getElementById(strSpanID);
	if (!objSpan) {
		if ((element.type == "radio")||(element.type == "checkbox")) {
			for (var i=0; i<element.form.elements.length; i++) {
				if (element.form.elements[i].name == element.name) {
					element = element.form.elements[i];
				}
			}
		}
		objSpan = document.createElement("span");
		objSpan.id = strSpanID;
		var nodeAfter=0;
		var nodeParent = element.parentNode;
		for (var i=0; i<nodeParent.childNodes.length; i++) {
			if (nodeParent.childNodes[i] == element) {
				if (i < (nodeParent.childNodes.length-1))
					nodeAfter = nodeParent.childNodes[i+1];
				break;
			}
		}
		if ((!nodeAfter)&&(nodeParent.parentNode)) {
			nodeParent = nodeParent.parentNode;
			for (var i=0; i<nodeParent.childNodes.length; i++) {
				if (nodeParent.childNodes[i] == element.parentNode) {
					if (i < (nodeParent.childNodes.length-1))
						nodeAfter = nodeParent.childNodes[i+1];
					break;
				}
			}
		}
		if (nodeAfter)
			nodeParent.insertBefore(objSpan, nodeAfter);
		else
			document.body.appendChild(objSpan);
	}
	if (objSpan.className.length == 0)
		objSpan.className = "validation_error";
	objSpan.innerHTML = strMessage;
}

function ClearError(element) {
	var strSpanID = GetErrorContainerID(element);
	var objSpan = document.getElementById(strSpanID);
	if (objSpan) {
		objSpan.innerHTML = "";
	}
}

function GetErrorContainerID(element) {
	var strSpanID = element.getAttribute("error_container");
	if (!strSpanID || strSpanID.length == 0) {
		strSpanID = element.name+"_val_error";
	}
	return strSpanID;
}

function InArray(arr, key) {
	for (var i=0; i<arr.length; i++) {
		if (arr[i] == key) {
			return i;
		}
	}
	return -1;
}

// Google Maps Below ***********************************************************

   var geocoder;
   var map;

   var techranch = "TechRanch";
   var address = "910 Technology Blvd, Bozeman MT";

   // On page load, call this function

   function Googinitialize()
   {
      // Create new map object
      map = new GMap2(document.getElementById("map_canvas"));

      // Create new geocoding object
      geocoder = new GClientGeocoder();

      // Retrieve location information, pass it to addToMap()
      geocoder.getLocations(address, addToMap);
   }

   // This function adds the point to the map

   function addToMap(response)
   {
      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);

      // Center the map on this point
      map.setCenter(point, 13);
			
			// Default User Interface
      map.setUIToDefault();
			
      // Create a marker
      marker = new GMarker(point);

      // Add the marker to map
      map.addOverlay(marker);
			
			// Setup the variables for formatting
      var streetAddress = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
			var streetAddress2 = " Suite A";
      var city = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
      var state = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
      var zip = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;
			var phone = "(406)556-0272";

      // Add address information to marker
      marker.openInfoWindowHtml('<strong><font color=blue>' + techranch + '</font></strong>' + '<br />' + 
         streetAddress + '<br />' + streetAddress2 + '<br />' +
         city + ', ' + state + ' ' + zip + '<br />' + phone);
   }
	 
	 
	 
// Popup Div for Pictures ******************************************************
function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar, winSize) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-winSize;//500 is half popup's height
	popUpDiv.style.top = 20 + 'px';
	//popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-500;//500 is half popup's width
	popUpDiv.style.left = '300px';
}
function popup(windowname, winSize) {
	blanket_size(windowname, winSize);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}