var tabLinks = new Array();
var contentDivs = new Array();
var lis = new Array();
function init() {

  // Grab the tab links and content divs from the page
	if (document.getElementById('tabs') != null)
		var tabListItems = document.getElementById('tabs').childNodes;
	else
		return;
	
  for ( var i = 0; i < tabListItems.length; i++ ) {
	if ( tabListItems[i].nodeName == "LI" ) {
	  var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
	  var id = getHash( tabLink.getAttribute('href') );
	  tabLinks[id] = tabLink;
	  contentDivs[id] = document.getElementById( id );
	  lis[id] = tabListItems[i];
	}
  }

  // Assign onclick events to the tab links, and
  // highlight the first tab
  var i = 0;

  for ( var id in tabLinks ) {
	tabLinks[id].onclick = showTab;
	tabLinks[id].onfocus = function() { this.blur() };
	if ( i == 0 ) {
			tabLinks[id].className = 'selected';
			lis[id].className = 'li_selected';
	}
	i++;
  }

  // Hide all content divs except the first
  var i = 0;

  for ( var id in contentDivs ) {
	if ( i != 0 ) contentDivs[id].className = 'tabContent hide';
	i++;
  }
}

function showTab() {
   var selectedId = getHash( this.getAttribute('href') );
  // Highlight the selected tab, and dim all others.
  // Also show the selected content div, and hide all others.
  for ( var id in contentDivs ) {
	
	if ( id == selectedId ) {
	  tabLinks[id].className = 'selected';
	  lis[id].className = 'li_selected';
	  contentDivs[id].className = 'tabContent';
	} else {
	  lis[id].className = '';
	  tabLinks[id].className = '';
	  contentDivs[id].className = 'tabContent hide';	  
	}
  }

  // Stop the browser following the link
  return false;
}

function getFirstChildWithTagName( element, tagName ) {
  for ( var i = 0; i < element.childNodes.length; i++ ) {
	if ( element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
  }
}

function getParent(tabid) {
	 var tabListItems = document.getElementById('tabs').childNodes;
	  for ( var i = 0; i < tabListItems.length; i++ ) {
		if ( tabListItems[i].nodeName == "LI" ) {
		  var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
		  var id = getHash( tabLink.getAttribute('href') );
		  if (tabid == id) {
			  	return tabListItems[i];
		  }		 
		}
	  }
}
		

function getHash( url ) {
  var hashPos = url.lastIndexOf ( '#' );
  return url.substring( hashPos + 1 );
}

function openpopup(link){
	winpops=window.open(link,"agence","fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=675,left=100,top=100,screenX=100,screenY=100");
}

function showMore (objId) {
	
	var display = $(objId).css("display");
	if (display == "block") {
		$(objId).slideUp("hide");
	} else {
		var cls = $(objId).attr("class");
		$("." + cls).hide();
		$(objId).slideDown("show");
	}
}


function validateEmail(str)  
{  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(str);   
}  


