/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/	
var getElementsByClassName=function(className,tag,elm){if(document.getElementsByClassName){getElementsByClassName=function(className,tag,elm){elm=elm||document;var elements=elm.getElementsByClassName(className),nodeName=(tag)?new RegExp("\\b"+tag+"\\b","i"):null,returnElements=[],current;for(var i=0,il=elements.length;i<il;i+=1){current=elements[i];if(!nodeName||nodeName.test(current.nodeName)){returnElements.push(current);}}
return returnElements;};}
else if(document.evaluate){getElementsByClassName=function(className,tag,elm){tag=tag||"*";elm=elm||document;var classes=className.split(" "),classesToCheck="",xhtmlNamespace="http://www.w3.org/1999/xhtml",namespaceResolver=(document.documentElement.namespaceURI===xhtmlNamespace)?xhtmlNamespace:null,returnElements=[],elements,node;for(var j=0,jl=classes.length;j<jl;j+=1){classesToCheck+="[contains(concat(' ', @class, ' '), ' "+classes[j]+" ')]";}
try{elements=document.evaluate(".//"+tag+classesToCheck,elm,namespaceResolver,0,null);}
catch(e){elements=document.evaluate(".//"+tag+classesToCheck,elm,null,0,null);}
while((node=elements.iterateNext())){returnElements.push(node);}
return returnElements;};}
else{getElementsByClassName=function(className,tag,elm){tag=tag||"*";elm=elm||document;var classes=className.split(" "),classesToCheck=[],elements=(tag==="*"&&elm.all)?elm.all:elm.getElementsByTagName(tag),current,returnElements=[],match;for(var k=0,kl=classes.length;k<kl;k+=1){classesToCheck.push(new RegExp("(^|\\s)"+classes[k]+"(\\s|$)"));}
for(var l=0,ll=elements.length;l<ll;l+=1){current=elements[l];match=false;for(var m=0,ml=classesToCheck.length;m<ml;m+=1){match=classesToCheck[m].test(current.className);if(!match){break;}}
if(match){returnElements.push(current);}}
return returnElements;};}
return getElementsByClassName(className,tag,elm);};

/* Developed by Busker Web, http://buskerweb.com */

var quotes, quotes_length;
var switch_every = 5000; // How many milliseconds between each quote switch?

function init() {
  // Invisiblate all but the first quote
  quotes = getElementsByClassName('quote', 'div', document.getElementById('quotes'));
  quotes_length = quotes.length;
  for (var i = 0; i < quotes_length; i++) { quotes[i].style.display = 'none'; }
  quotes[0].style.display = '';
  setTimeout(function(){ switchQuote(0, 1); }, switch_every);
  
  if (document.getElementById('page_services_web_based_compliance_training') || document.getElementById('page_services_online_hr_library')) {
    var expanded = getElementsByClassName('expanded', 'li');
    var expanded_length = expanded.length;
    for (var n = 0; n < expanded_length; n++) {
      expanded[n].innerHTML = '<span>' + expanded[n].innerHTML + '</span>';
      expanded[n].style.display = 'none';
    }
  }
  
}

function expandHiddenItems(link) {
  var expanded = getElementsByClassName('expanded', 'li');
  var expanded_length = expanded.length;

  if (link.className == 'showing') {
    for (var i = 0; i < expanded_length; i++) { expanded[i].style.display = 'none'; }
    link.innerHTML = 'Click here to view the complete list.';
    link.className = '';
  } else {
    for (var n = 0; n < expanded_length; i++) { expanded[n].style.display = ''; }
    link.innerHTML = 'Click here to view the shortened list.';
    link.className = 'showing';
  }
}

function switchQuote(from, to) {
  quotes[from].style.display = 'none';
  quotes[to].style.display = '';
  from = to;
  to = (to == (quotes_length - 1)) ? 0 : to + 1;
  setTimeout(function(){ switchQuote(from, to); }, switch_every);
}

function youtube(target_id, movie_to_embed)
{
	var flash;
	switch (movie_to_embed)
	{
		case 'small_business_program':
			flash = '<object height="168" width="235"><param name="movie" value="http://www.youtube.com/v/O_GQUXRcdpU&amp;hl=en_US&amp;fs=1?rel=0" /></param><param name="allowFullScreen" value="true" /></param><param name="allowscriptaccess" value="always" /></param><embed src="http://www.youtube.com/v/O_GQUXRcdpU&amp;hl=en_US&amp;fs=1?rel=0" type="application/x-shockwave-flash" height="168" width="235"></object>';
			break;
	}
	document.getElementById(target_id).innerHTML = '<div class="object_wrapper">' + flash + '</div>';
}

function embedFlash(target_id, id, path, width, height, flash_vars) {
  document.getElementById(target_id).innerHTML = renderFlash(id, path, width, height, flash_vars);
}

function renderFlash(id, path, width, height) {
  var flash = '<div class="object_wrapper"><object type="application/x-shockwave-flash" data="' + path + '" width="' + width + '" height="' + height + '" id="' + id + '">';
  flash += ' <param name="movie" value="' + path + '">';
  flash += ' <param name="bgcolor" value="#000000">';
  flash += ' <param name="quality" value="best">';
  flash += ' <param name="wmode" value="transparent">';
  flash += ' <param name="salign" value="TC">';
  flash += ' <param name="FlashVars" value="playerMode=embedded">';
  flash += '</object></div>';
  return flash;
}

function show(id) { document.getElementById(id).style.display = ''; }
function hide(id) { document.getElementById(id).style.display = 'none'; }

function checkForm() {
  var r;
  var allow = true;
  var required = ['first_name','last_name','company_name','phone','email','comment'];
  for (var i = 0; i < required.length; i++) {
    r = document.getElementById(required[i]);
    if (!r.value) {
      r.parentNode.className = r.parentNode.className + ' error';
      allow = false;
    }
    else { r.parentNode.className = r.parentNode.className.replace(' error',''); }
  }
  if (!allow) { alert('All contact fields are required!'); }
  return allow;
}

function listenForPopupCloser(id)
{
	document.onclick = function(e)
	{
		var origin = window.event != undefined ? window.event.srcElement : (e.srcElement ? e.srcElement : e.target);
		if (origin.id !== id + '_trigger')
		{
			var waiting_for_document = origin;
			var inside_popup = false;
		
			while (waiting_for_document != document.body && inside_popup === false)
			{
				if (waiting_for_document.id === id)
					inside_popup = true;
				else
					waiting_for_document = waiting_for_document.parentNode;
			}
		
			if (!inside_popup)
				hide(id);
		}

	};
}
