//  *   The following JavaScripts have been designed to seperate	*
//  *	behavior from content										*
//  *   Ralph Garcia 3/14/06                                        *
//  *****************************************************************

//  *****************************************************************
//  *   addLoadEvent                                                *
//  *****************************************************************
//  *   Version .01                                                 *
//  *****************************************************************
//  *   allows multiple ON LOAD functions to be called              *
//  *   DO NOT DELETE		                                        *
//  *****************************************************************
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
  	window.onload = func;
  } else {
  	window.onload = function () {
		oldonload();
		func();
	}
  }
}


//  *****************************************************************
//  *   highlightPage - Highlight Top Navigation            	    *
//  *****************************************************************
//  *   Version 1.0                                                 *
//  *****************************************************************
//  *   Hilights Section Navigation on click : Behavior has been    *
//  *   uses function addClass created above                        *
//  *****************************************************************
/*
addLoadEvent(highlightPage);
function highlightPage() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("nav")) return false;
  var nav = document.getElementById("nav");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    var currenturl = window.location.href;
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "selected";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      document.body.setAttribute("id",linktext);
    }
  }
}

*/
/****************************************************
FORM FIELDs FOCUS
*****************************************************/

//focus for inquiry form
function setFocus()
{
document.inquiry_form.year.focus()
}
		
/****************************************************
DETECT FLASH PLAYER FUNCTIONS
*****************************************************/
		
/**
* borrowed from the mighty sIFR package:
    http://www.mikeindustries.com/blog/archive/2005/02/sifr-2.0-release-candidate-4
    sIFR v2.0 RC4 SOURCE
    Copyright 2004 - 2005 Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben
*/
var hasFlash = function(){
	var nRequiredVersion = 6;

	if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
		document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
		/*	If executed, the VBScript above checks for Flash and sets the hasFlash variable.
			If VBScript is not supported it's value will still be undefined, so we'll run it though another test
			This will make sure even Opera identified as IE will be tested */
		if(window.hasFlash != null){
			return window.hasFlash;
		};
	};

	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		return parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1)) >= nRequiredVersion;
	};

	return false;
}();

/* ENDS DETECTS FLASH */


//  *****************************************************************
//	*	POP UP LINKS FUNCTIONS
//  *****************************************************************
//  *   Version 1.0                                                 *
//  *****************************************************************
//  *   Based on class="popup" a link will automaticall call this   *
//  *****************************************************************


//addLoadEvent(preparePopup800); On Page load call this function
function preparePopup800() {
if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
	if (links[i].className.match("popup")) {
			links[i].onclick = function() {
			popUp800(this.getAttribute("href")); // call popUp800 function
			return false;
			}
		}
	}
}
function popUp800 (winURL) {
	window.open(winURL,"popup","width=800,height=600,resizable=yes,scrollbars=yes");
}

//addLoadEvent(preparePopup600); On Page load call this function

function preparePopup600() {
if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
	if (links[i].className.match("popup")) {
			links[i].onclick = function() {
			popUp600(this.getAttribute("href")); // call popUp800 function
			return false;
			}
		}
	}
}

function popUp600 (winURL) {
	window.open(winURL,"popup","width=600,height=250,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,");
	
}

/* showing and hiding with no EVENT HANDLER */
// toggle visibility

function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

addLoadEvent(prepareToggle);
	
function prepareToggle() {
if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
	if (links[i].className.match("toggler")) {
			links[i].onclick = function() {
			activateLink(this);
			return false;
			}
		}
	}
}

function activateLink(link) {
	var pagename = link.getAttribute("href").split("#")[1];
	showPage(pagename);
}

function showPage(pagename) {
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++ ) {
		if (divs[i].className == "toggle-card") {
			if (divs[i].getAttribute("id") != pagename) {	 
			divs[i].style.display = "none";
			} else {
				divs[i].style.display = "block";
			}
		}
	}
}

//TOGGLE ALL on page
function showAll() {
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++ ) {
		if (divs[i].className == "toggle-card") {	 
			divs[i].style.display = "block";
			} 
		}
	}
function collapseAll() {
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++ ) {
		if (divs[i].className == "toggle-card") {	 
			divs[i].style.display = "none";
			} 
		}
	}

//********************
//OLD STYLES*/

function validEmail(email) {
			invalidChars = " /:,;"
	
			if (email == "") {
				return false
			}
			for (i=0; i<invalidChars.length; i++) {
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) > -1) {
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {
				return false
			}
			if (periodPos+3 > email.length)	{
				return false
			}
			return true
		}

		function submitIt(carForm) {
			if (!validEmail(carForm.emailAddress.value)) {
				alert("Invalid email address")
				carForm.emailAddress.focus()
				carForm.emailAddress.select()
				return false
			}
	
			return true
		}



/*********************
NEW JS
**********************/
var testi = {};
testi.init = function ()
{
	testi.tip();
}
testi.tip = function ()
{
	//$('a').html('This link has been replaced');
	$('div').each( function() { jQuery.highlight(this, 'WASTE'); } );
}
//$(document).ready(testi.init);

/*********************
GENERATE UNIQUE ID
**********************/
$.generateId = function() {
        return arguments.callee.prefix + arguments.callee.count++;
};
$.generateId.prefix = 'client_';
$.generateId.count = 0;

$.fn.generateId = function() {
        return this.each(function() {
                this.id = $.generateId();
        });
};


var steps = {};
steps.init = function () {
	$('.steps').hide();
	$('#steps-process dt#step1').mouseover(steps.showOne);
	$('#steps-process dt#step2').mouseover(steps.showTwo);
	$('#steps-process dt#step3').mouseover(steps.showThree);
	$('#expand-steps').click(steps.showAll);
	$('#collapse-steps').click(steps.collapseAll);
}
steps.showOne = function () {
	//$('.steps').hide("normal");
	$('.steps.one').show("normal");
}
steps.showTwo = function () {
	//$('.steps').hide("normal");
	$('.steps.two').show("normal");
}
steps.showThree = function () {
	//$('.steps').hide("normal");
	$('.steps.three').show("normal");
}
steps.showAll = function () {
	$('.steps').show("normal");
}
steps.collapseAll = function () {
	$('.steps').hide("normal");
}

$(document).ready(steps.init);
