function showid(id){
		 if($(id) && (typeof($(id)) != 'function')) {
				$(id).show();
		 }
} 

function hideid(id){
		 if($(id) && (typeof($(id)) != 'function')) {
				$(id).hide();
		 }
}

 
function hideAllBut( number, prefix, all, parent_prefix ) {
		for (var i in all){
				if( all[i] != number ){
					id = prefix + all[i];
					hideid(id);
					parent_id = parent_prefix + all[i];
					
				}else{
					id = prefix + all[i];
					showid(id);
				}
		} 	
}

function viewLargeImage(ifile,ix,iy,ititle) { 
	var win;
	var sWidth;
	var sHeight;
	var NS = (document.layers) ? 1 : 0;
	win = window.open("","imageviewer","width="+ix+",height="+iy+",menubar=no,toolbar=no");
	if (NS) {
		sWidth = win.innerWidth;
		sHeight = win.innerHeight;
	} else {
		sWidth = win.document.body.clientWidth;
		sHeight = win.document.body.clientHeight;
	}
	if(sWidth!=ix || sHeight!=iy) {
		win.close();
		setTimeout("ViewImage('"+ifile+"',"+ix+","+iy+",'"+ititle+"')", 250);
		return;
	}
	win.document.open();
	win.document.write("<html><head><title>"+ititle+"</title>");
	win.document.write("</head><body>");
	win.document.write('<div style="position:absolute;width:'+ix+'px;height:'+iy+'px;left:0px;top:0px">');
	win.document.write("<img src="+ifile+" width='"+ix+"' height='"+iy+"' onClick='javascript:window.close();'></div></body></html>");
	win.document.close();
}


/**
	* toggleDetails 
	* input number - database id of the detail to be toggled
	* input prefix - which type of detail to be toggled
	*/
	function toggleDetails(prefix, unique) {
		var textid = prefix + '_text_' + unique;
		var imageid = prefix + '_image_' + unique;
		var targetid = prefix + '_' + unique;
		if ($(targetid).visible()) {
			if ($(textid)) { $(textid).innerHTML = "Click to Show"; }
			if ($(imageid)) {	$(imageid).src = "/images/icon_tree_plus.gif"; }
			$(targetid).hide();
		} else {
			if ($(textid)) { $(textid).innerHTML = "Click to Hide";	}
			if ($(imageid)) {	$(imageid).src = "/images/icon_tree_minus.gif";	}
			$(targetid).show();
		}
	}
	
	function hideall(prefix) {
		var selector = 'div.' + prefix;
		$$(selector).each (
		function (detail) {
			targetid = detail.id;
			unique = targetid.substring(prefix.length+1);
		  textid = prefix + '_text_' + unique;
		  imageid = prefix + '_image_' + unique;
			if ($(textid)) { $(textid).innerHTML = "Click to Show";	}
			if ($(imageid)) {	$(imageid).src = "/images/icon_tree_plus.gif"; }
			$(targetid).hide();
		}
		);
	}		
		
	function showall(prefix) {
		var selector = 'div.' + prefix;
		$$(selector).each (
		function (detail) {
			targetid = detail.id;
			unique = targetid.substring(prefix.length+1);
		  textid = prefix + '_text_' + unique;
		  imageid = prefix + '_image_' + unique;
			if ($(textid)) { $(textid).innerHTML = "Click to hide";	}
			if ($(imageid)) {	$(imageid).src = "/images/icon_tree_minus.gif";	}
			$(targetid).show();
		}
		);
	}	

	function toggleDiv(divId, text) {
		var textid = divId + '_text';
		var textid2 = divId + '_text2';
		var targetid = divId;
		if ($(targetid).visible()) {
			if ($(textid)) { $(textid).innerHTML = "Show "+text; }
			if ($(textid2)) { $(textid2).innerHTML = "Show "+text; }
			$(targetid).hide();
		} else {
			if ($(textid)) { $(textid).innerHTML = "Hide "+text;	}
			if ($(textid2)) { $(textid2).innerHTML = "Hide "+text; }
			$(targetid).show();
		}
	}
	
	function showTab(profileNum, tabNum) {
	  // function to select content panel in "specialist" flyout based on tab clicked
		// tabNum is the tab/content panel we want to select
		// profileNum is the number of the profile based on the ID of the flyout ("TabbedPanels1", "TabbedPanels2", etc.)
		// for this to work, there must be no other child nodes in TabbedPanelsTabGroup and TabbedPanelsContentGroup containers; 
		// only tabs and content containers.

		var tabIndex = tabNum-1;
		var panelGroup = $('TabbedPanels'+profileNum); // this could be modified to be more generic for other tabbed pages
    counter = 0;
    while (panelGroup === "undefined" && counter++ < 500000) { //
      panelGroup = $('TabbedPanels'+profileNum);
    }
      
		
		// remove all the "selected" class from all tabs and content panels:
		panelGroup.getElementsBySelector('.selected').each(function(s) { s.removeClassName('selected');  });
		
		// add "selected" class to current tab
		panelGroup.getElementsBySelector('.TabbedPanelsTabGroup li')[tabIndex].addClassName('selected');
		
		// add "selected class to current content panel
		panelGroup.getElementsBySelector('.TabbedPanelsContentGroup .TabbedPanelsContent')[tabIndex].addClassName('selected');
	}
	
	function isEmailAddr(email) {
		var result = false
		var theStr = new String(email)
		var index = theStr.indexOf("@");

		if (index > 0) {
			var pindex = theStr.indexOf(".",index);
			if ((pindex > index+1) && (theStr.length > pindex+1))
				result = true;
		}
		return result;
	}

	function SUBSCRIBE(theForm) {
		
		if (theForm.first_name.value == "") {
			alert("Please type your name.");
			theForm.first_name.focus();
			return (false);
		}
		// They don't have to enter last name - just a nice to have
	/*
		if (theForm.last_name.value == "") {
			alert("Please type your lastname.");
			theForm.last_name.focus();
			return (false);
		}
		*/
		
		// They need to choose at least one subscription.
		if (!(theForm.newsletter.checked || theForm.postcard.checked || theForm.report.checked)) {
			alert("Please choose at least one subscription.");
			theForm.newsletter.focus();
			return (false);
		}
	
		// They also need to enter a valid email address - to get their subscriptions :)
		if (theForm.email.value == "") {
			alert("Please enter your email address.");
			theForm.email.focus();
			return (false);
		}

		if (!isEmailAddr(theForm.email.value)) {
			alert("Sorry, the email address you entered is invalid!\n\ne.g.:     yourname@yourdomain.com");
			theForm.email.focus();
			return (false);
		}
	
		return (true);
	}

  /*
    Parameters passed via bindAsEventListener
      container - div to contain popup contents
      url - url to display content
  */
  function load_popup(container, url) {
    var current = $(container).innerHTML;
    
    // Only load the popup contents once 
    if (current == '') {
      new Ajax.Updater(container, url);
      return 50;
    }
    return 5;
  }
  
  function show_specialistPanel(obj, specialist, rec, tab) {
    //override the existing hrefs - using javascript to display popups - original hrefs used if no javascript enabled.
    $("my_profile_"+specialist+"_"+rec).href = 'javascript:void(0);';
    $("contact_me_"+specialist+"_"+rec).href = 'javascript:void(0);';
    
    timeout = load_popup('specialist_'+specialist+'_'+rec, '/com/specialistpanelajax/'+specialist+'/'+rec); 
    setTimeout("profileFlyout.show('profile"+rec+"')",timeout);
    setTimeout("showTab("+rec+","+tab+")",timeout*20);
    return false;
  }
  
  function show_subscriptionsPanel(obj) {
    //override the existing hrefs - using javascript to display popups - original hrefs used if no javascript enabled.
    $("subscribe_click").href = 'javascript:void(0);';
    timeout = load_popup('subscriptionAjax', '/com/subscriptionspanelajax'); 
    setTimeout("subFlyout.show('subscriptionFlyOut')",timeout);
    return false;
  }
  
  function show_memberPanel(obj, panel) {
    //override the existing hrefs - using javascript to display popups - original hrefs used if no javascript enabled.
    $(panel+"_click").href = 'javascript:void(0);';
    timeout = load_popup(panel+"_div", '/com/memberpanelajax/'+panel); 
    setTimeout("memFlyout.show('"+panel+"FlyOut')",timeout);
    return false;
  }

  function show_joinPanel(obj) {
    //override the existing hrefs - using javascript to display popups - original hrefs used if no javascript enabled.
    $("join_click").href = 'javascript:void(0);';
    timeout = load_popup("join_div", '/com/joinpanelajax'); 
    setTimeout("joinFlyout.show('joinourteamFlyOut')",timeout);
    return false;
  }  
  
  function show_bookmarkPanel(obj) {
    //override the existing hrefs - using javascript to display popups - original hrefs used if no javascript enabled.
    $("bookmark_click").href = 'javascript:void(0);';
    timeout = load_popup("bookmark_div", '/bookmark/create');
    setTimeout("bookFlyout.show('bookmarkFlyout')",timeout);
    return false;
  }  
  
  function show_requestPanel(obj) {
    //override the existing hrefs - using javascript to display popups - original hrefs used if no javascript enabled.
    href = $("request_click").href;
    $("request_click").href = 'javascript:void(0);';
    timeout = load_popup("request_div", href);
    setTimeout("reqFlyout.show('requestFlyOut')",timeout);
    $('requestFlyOut').style.right = '170px';
    return false;
  }
  
  function show_calltoactionPanel(obj, num) {
    //override the existing hrefs - using javascript to display popups - original hrefs used if no javascript enabled.
    href = $("calltoaction-click"+num).href;
    $("calltoaction-click"+num).href = 'javascript:void(0);';
    timeout = load_popup("callToActionFlyoutContent"+num, href);
    setTimeout("callFlyout.show('callToActionFlyOut"+num+"')",timeout);
    $('requestFlyOut').style.right = '170px';
    return false;
  }  
/**  
var obj = { name: 'A nice demo' };

function handler(e) {
  var tag = Event.element(e).tagName.toLowerCase();
  var data = $A(arguments);
  data.shift();
  alert(this.name + '\nClick on a ' + tag + '\nOther args: ' + data.join(', '));
}

Event.observe(document.body, 'click', handler.bindAsEventListener(obj, 1, 2, 3));
// Now any click on the page displays obj.name, the lower-cased tag name
// of the clicked element, and "1, 2, 3".
**/
