function populate_project_form(id) {
	
	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('project_form_container').innerHTML = xmlHttp.responseText;
			$.fancybox.resize();
		}
	}
	xmlHttp.open("GET","project_form.php?id=" + id, true );
	xmlHttp.send(null);	

}

function convert_ts() {
	
	var ts = document.getElementById('ts').value;
	
	var container = document.getElementById('ts_result');

	var mmToMonth = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");	
	var dt = new Date(ts * 1000);
	var mm = mmToMonth[dt.getMonth()];
	container.innerHTML = dt.getDate() + "-" + mm + "-" + dt.getFullYear() + " " + dt.getHours() + ":" + dt.getMinutes();	

}

function add_new_category() {
	
	var tbody = document.getElementById('category_table').getElementsByTagName('tbody')[0];
	var num_rows = document.getElementById('category_table').getElementsByTagName('tbody').length;
	var row = document.createElement('tr');
	
	var desc = document.createElement('input');
	desc.type = 'text';
	desc.className = 'field_text_focus';
	desc.name = 'categories[]';
	
	var box = document.createElement('input');
	box.type = 'checkbox';
	box.name = 'box';
	box.checked = true;
	
	var desc_cell = document.createElement('td');
	desc_cell.style.paddingTop = "5px";
	desc_cell.style.paddingBottom = "5px";
	desc_cell.appendChild(desc);
	
	var box_cell = document.createElement('td');
	box_cell.style.paddingTop = "5px";
	desc_cell.style.paddingBottom = "5px";
	box_cell.appendChild(box);
	
	row.appendChild(box_cell);
	row.appendChild(desc_cell);
	
	tbody.appendChild(row);
	
	desc.focus();
	

}


function get_whois() {
	
	var domain = document.getElementById('domain').value;
	
	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('whois_container').innerHTML = xmlHttp.responseText;
			$.fancybox.resize();
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","who_is.php?d=" + domain, true );
	xmlHttp.send(null);


}

function encrypt_text() {

	var original = document.getElementById('md5_original').value;

	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('encruption_results').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","encrypt.php?s=" + original, true );
	xmlHttp.send(null);

}

function show_site(type) {

	var loc = document.getElementById('site_preview').value;
	if ( type == 'local' ) {
		document.location = 'http://192.168.0.57/~martin/' + loc + '/';
	}
	if ( type == 'remote' ) {
		document.location = 'http://www.' + loc + '/';
	}
}

function home_search() {

	var criteria = document.getElementById('search').value;

	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('search_results_container').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","home_search.php?q=" + criteria, true );
	xmlHttp.send(null);

}

function renew_ssl( id ) {


	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('ssl_renewal_container').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","renew_ssl.php?renew=" + id, true );
	xmlHttp.send(null);

}

function renew_hosting( id ) {


	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('hosting_renewal_container').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","renew_hosting.php?renew=" + id, true );
	xmlHttp.send(null);

}

function filter_clients() {

	var filter = document.getElementById('client_search').value;
	var ac_filter = '';
	if ( document.getElementById('ac_filter') != undefined ) {
		ac_filter = '&ac_filter=' + document.getElementById('ac_filter').value;
	}

	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('list_container').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","filter_clients.php?filter=" + filter + ac_filter, true );
	xmlHttp.send(null);

}

function filter_domains() {

	var filter = document.getElementById('domain_search').value;

	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('list_container').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","filter_domains.php?filter=" + filter, true );
	xmlHttp.send(null);

}

function add_new_email() {

	var new_email_container = document.getElementById('new_email_container');
	
	var num_rows = new_email_container.getElementsByTagName('tr').length;
	
	var new_row = new_email_container.insertRow(0);
	var new_cell = new_row.insertCell(0);
	
	
	var output = '';

	
	output += '<p><label for="new_email_' + num_rows + '">Email Address</label><br /><input type="text" name="new_email_' + num_rows + '" id="new_email_' + num_rows + '" class="field_text" onfocus="this.className=\'field_text_focus\'" onblur="this.className=\'field_text\'" value="" /></p>';
	output += '<p><label for="new_email_username_' + num_rows + '">Username</label><br /><input type="text" name="new_email_username_' + num_rows + '" id="new_email_username_' + num_rows + '" class="field_text" onfocus="this.className=\'field_text_focus\'" onblur="this.className=\'field_text\'" value="" /></p>';
	output += '<p><label for="new_email_password_' + num_rows + '">Password</label><br /><input type="text" name="new_email_password_' + num_rows + '" id="new_email_password_' + num_rows + '" class="field_text" onfocus="this.className=\'field_text_focus\'" onblur="this.className=\'field_text\'" value="" /></p>';
	output += '<p><label for="new_email_aliases_' + num_rows + '">Aliases</label><br /><textarea onkeyup="extend_textarea(\'new_email_aliases_' + num_rows + '\')" style="height: 50px;" name="new_email_aliases_' + num_rows + '" id="new_email_aliases_' + num_rows + '" class="field_textarea" onfocus="this.className=\'field_textarea_focus\'" onblur="this.className=\'field_textarea\'"></textarea></p>';
	output += '<p><label>This email account is </label> <input type="radio" name="new_email_active_' + num_rows + '" id="new_email_active_' + num_rows + '_yes" value="yes" checked="checked" /> <label for="new_email_active_' + num_rows + '_yes">Active</label> <input type="radio" name="new_email_active_' + num_rows + '" id="new_email_active_' + num_rows + '_no" value="no" /> <label for="new_email_active_' + num_rows + '_no">Inactive</label></p>';

	new_cell.innerHTML = output;

}


function show_domain_data( el ) {
	
	var sub_nav_domain = document.getElementById('sub_nav_domain');
	var sub_nav_hosting = document.getElementById('sub_nav_hosting');
	var sub_nav_email = document.getElementById('sub_nav_email');
	var sub_nav_ftp = document.getElementById('sub_nav_ftp');
	var sub_nav_cms = document.getElementById('sub_nav_cms');
	var sub_nav_stats = document.getElementById('sub_nav_stats');
	var sub_nav_ssl = document.getElementById('sub_nav_ssl');
	
	var domain_container = document.getElementById('domain_container');
	var hosting_container = document.getElementById('hosting_container');
	var email_container = document.getElementById('email_container');
	var ftp_container = document.getElementById('ftp_container');
	var cms_container = document.getElementById('cms_container');
	var stats_container = document.getElementById('stats_container');
	var ssl_container = document.getElementById('ssl_container');
	
	sub_nav_domain.className = 'normal';
	sub_nav_hosting.className = 'normal';
	sub_nav_email.className = 'normal';
	sub_nav_ftp.className = 'normal';
	sub_nav_cms.className = 'normal';
	sub_nav_stats.className = 'normal';
	sub_nav_ssl.className = 'normal';

	domain_container.style.display = 'none';
	hosting_container.style.display = 'none';
	email_container.style.display = 'none';
	ftp_container.style.display = 'none';
	cms_container.style.display = 'none';
	stats_container.style.display = 'none';
	ssl_container.style.display = 'none';
	
	document.getElementById('sub_nav_' + el).className = 'active';
	document.getElementById(el + '_container').style.display = '';
	
	document.getElementById('tab').value = el;
	
	return true;


}

function save_note( section, id ) {

	var inst = FCKeditorAPI.GetInstance("new_note");
	var note_content = inst.GetHTML();
	var fmt_data = URLEncode(note_content);
	
	
	data = "note_content=" + fmt_data + "&section=" + section + "&parent_id=" + id;

	if ( document.getElementById('edit_note_id') != undefined ) {
		data += "&edit_note_id=" + document.getElementById('edit_note_id').value;
	}

	
	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('notes_container').innerHTML = xmlHttp.responseText;	
			$.fancybox.close();
			$('.box_link').fancybox();
			return false;
		} else {
			return false;
		}
	}
	
	xmlHttp.open("POST","save_note.php?action=save",true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(data);

}

function edit_note( section, parent_id, note_id ) {

	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('new_note_form').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","edit_note.php?section=" + section + "&parent_id=" + parent_id + "&note_id=" + note_id, true );
	xmlHttp.send(null);


}

function delete_note( section, parent_id, id ) {
	var xmlHttp = initiate_ajax();
	xmlHttp.onreadystatechange = function() {
		if ( xmlHttp.readyState == 4 ) {
			document.getElementById('notes_container').innerHTML = xmlHttp.responseText;
			return false;
		} else {
			return false;
		}
	}

	xmlHttp.open("GET","save_note.php?action=delete&section=" + section + "&parent_id=" + parent_id + "&id=" + id, true );
	xmlHttp.send(null);

}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function show_tools(id) {

	var tools = document.getElementById('note_tools_' + id);
	tools.style.display = '';
	return true;

}

function hide_tools(id) {

	var tools = document.getElementById('note_tools_' + id);
	tools.style.display = 'none';
	return true;

}

function update_product_grid() {

		// get url params
			var countryVal = document.getElementById('countrySelect').value;
			var grapeVal = document.getElementById('grapeSelect').value;
			var priceVal = document.getElementById('priceSelect').value;
			
			if ( document.getElementById('tippleVal') != undefined ) {
				var tippleVal = document.getElementById('tippleVal').value;
			} else {
				var tippleVal;
			}
			
			if ( document.getElementById('pageVal') != undefined ) {
				var pageVal = document.getElementById('pageVal').value;
			} else {
				var pageVal;
			}
			
			if ( document.getElementById('orderSelect') != undefined ) {
				var orderVal = document.getElementById('orderSelect').value;
			} else {
				var orderVal = '';
			}
		
			var grid = document.getElementById('grid').value;
		
		var xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				document.getElementById('product_list_container').innerHTML=xmlHttp.responseText;
				setForm();
				update_wine_search();
				update_breadcrumb();
				update_additional_info();
			}
		}
		xmlHttp.open("GET","product_list_grid.php?grid=" + grid + "&type=" + tippleVal + "&order=" + orderVal + "&active_page=" + pageVal + "&country=" + countryVal + "&grape=" + grapeVal + "&price=" + priceVal,true);
		xmlHttp.send(null);
}



function update_wine_search() {

		// get url params
			var countryVal = document.getElementById('countrySelect').value;
			var grapeVal = document.getElementById('grapeSelect').value;
			var priceVal = document.getElementById('priceSelect').value;
			
			if ( document.getElementById('tippleVal') != undefined ) {
				var tippleVal = document.getElementById('tippleVal').value;
			} else {
				var tippleVal;
			}
			
			if ( document.getElementById('pageVal') != undefined ) {
				var pageVal = document.getElementById('pageVal').value;
			} else {
				var pageVal;
			}
			
			if ( document.getElementById('orderSelect') != undefined ) {
				var orderVal = document.getElementById('orderSelect').value;
			} else {
				var orderVal = '';
			}
			var grid = document.getElementById('grid').value;
		
		
		var xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				document.getElementById('wine_search_container').innerHTML=xmlHttp.responseText;
				setForm();
			}
		}
		xmlHttp.open("GET","product_list_search.php?grid=" + grid + "&type=" + tippleVal + "&order=" + orderVal + "&active_page=" + pageVal + "&country=" + countryVal + "&grape=" + grapeVal + "&price=" + priceVal,true);
		xmlHttp.send(null);


}

function set_product_grid_page(p) {
	
	document.getElementById('pageVal').value = p;	
	
}

function set_featured(id) {
	
	var containerArray = document.getElementsByName('featured_text_container');
	for ( var a = 0; a < containerArray.length; a++ ) {
		containerArray[a].style.display = 'none';
	}

	document.getElementById('featured_text_container_' + id).style.display = '';
	
}

function update_image_grid() {
		var xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				document.getElementById('image_grid_container').innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET","update_uploaded_images.php",true);
		xmlHttp.send(null);
}

function filter_image_grid() {

	var selected_wine = document.getElementById('wine_filter').value;

	document.location = 'index.php?identifier=product-list&menu=image&filter=' + selected_wine;
	
	
}

function save_reassigned_image(elName,elValue,oldID) {
	
	var wine_image_array = elName.split('_');
	var wine_image_id = wine_image_array[wine_image_array.length-1];
	var selected_wine = document.getElementById('wine_filter').value;

		var xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				document.getElementById('image_grid_container').innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET","update_uploaded_images.php?filter=" + selected_wine + "&action=reassign&id=" + wine_image_id + "&new_wine=" + elValue + "&old_wine=" + oldID,true);
		xmlHttp.send(null);

}

function set_offer_values() {
	
	var selected_wine = document.getElementById('wine').value;
	var price_field = document.getElementById('price');
	
	if ( selected_wine == '0' ) {
		price_field.value = '';
		return false;
	}
	
	var wine_array = selected_wine.split('|');
	var newPrice = parseFloat(wine_array[1]);	
	
	price_field.value = newPrice.toFixed(2);
	return true;
	
}

function check_related_wine(id) {

	var checkBox = document.getElementById('related_wines_' + id);
	if ( checkBox.checked == true ) {
		checkBox.checked = false;
	} else {
		checkBox.checked = true;
	}

}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

//	bookmark a page
	function bookmark_page( url, title ) {
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}


function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

//	limit number of characters in a textarea field
	function limit_characters( limit_field_el, limit_count_field_el, limit_num ) {
		var limit_field = document.getElementById(limit_field_el);
		var limit_count_field = document.getElementById(limit_count_field_el);
		if ( limit_field != undefined ) {
			if ( limit_field.value.length > limit_num ) {
				limit_field.value = limit_field.value.substring( 0, limit_num );
			} else {
				limit_count_field.innerHTML	= (limit_num - limit_field.value.length) + ' characters remaining';
			}		
		}	
	}


//	show events on the home page
		function show_events(type) {
			var tab_summary = document.getElementById('tab_summary');
			var tab_water = document.getElementById('tab_water');
			var tab_ashore = document.getElementById('tab_ashore');
			var container_summary = document.getElementById('event_summary');
			var container_water = document.getElementById('event_water');
			var container_ashore = document.getElementById('event_ashore');
			switch ( type ) {
				case 'water' :
					tab_summary.className = 'off';
					tab_water.className = 'on';
					tab_ashore.className = 'off';
					container_summary.style.display = 'none';
					container_water.style.display = '';
					container_ashore.style.display = 'none';
					break;
				case 'ashore' :
					tab_summary.className = 'off';
					tab_water.className = 'off';
					tab_ashore.className = 'on';
					container_summary.style.display = 'none';
					container_water.style.display = 'none';
					container_ashore.style.display = '';
					break;
				default :
					tab_summary.className = 'on';
					tab_water.className = 'off';
					tab_ashore.className = 'off';
					container_summary.style.display = '';
					container_water.style.display = 'none';
					container_ashore.style.display = 'none';
					break;
					
			}
		}


//	when the search field gets the focus
	function search_focus() {
		var search = document.getElementById('q');
		if ( search.value == 'Search...' ) {
			search.value = '';
		} else {
			search.select();
		}
		search.className = 'field_search_focus';
	}
	
//	when the search field loses the focus
	function search_blur() {
		var search = document.getElementById('q');
		if ( search.value == '' ) {
			search.value = 'Search...';
		}
		search.className = 'field_search';
	}

// 	retrieve a url parameter
	function get_url_parameter( name ) {
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null ) {
			return "";
		} else {
			return results[1];
		}
	}

//	preload images
	function preload_images () {
		arImageSrc = new Array ();
		arImageList = new Array ();
		for (counter in arImageSrc) {
			arImageList[counter] = new Image();
			arImageList[counter].src = arImageSrc[counter];
		}
	}

//	convert date and time to unixtimestamp
	function date_to_unixtime(target_field, month_el, day_el, year_el, hour_el, minute_el) {
		var target = document.getElementById(target_field);
		var year = document.getElementById(year_el).value;
		var month = document.getElementById(month_el).value;
		var day = document.getElementById(day_el).value;
		var hour = document.getElementById(hour_el).value;
		var minute = document.getElementById(minute_el).value;
		var second = '01';
		
		var errors = 0;
		var error_message = 'The following elements appear to be missing or incorrect' + "\n";
		if ( year.length != 4 ) {
			error_message += ' - you must enter a 4 digit year' + "\n";
			errors = 1;
		}
		if ( month > 12 ) {
			error_message += ' - the month must be between 1 and 12' + "\n";
			errors = 1;
		}
		if ( day > 31 ) {
			error_message += ' - the day must be between 1 and 31' + "\n";
			errors = 1;
		}
		if ( hour > 24 ) {
			error_message += ' - the hour must be 24 hour (e.g. 13 = 1pm)' + "\n";
			errors = 1;
		}
		if ( minute > 59 ) {
			error_message += ' - the minutes must be between 0 and 59' + "\n";
			errors = 1;
		}
		if ( errors == 1 ) {
			alert( error_message );
		} else {
			var humDate = new Date(Date.UTC(year, (nozeros(month)-1), nozeros(day), nozeros(hour), nozeros(minute), nozeros(second))); 
			target.value = (humDate.getTime()/1000.0);
		}
	
	}

//	get the current page
	function get_current_page() {
		var fullpath = location.pathname;
		var patharray = fullpath.split('/');
		var folderposition = patharray.length - 1;
		var filename = patharray[folderposition];
		var filearray = filename.split('.');
		var nav = filearray[0];
		return nav;
	}

//	open external links in a new window - replaces target="_blank"
	function externalLinks () { 
		if ( ! document.getElementsByTagName ) return; 
		var anchors = document.getElementsByTagName("a"); 
		for ( var i=0; i < anchors.length; i++ ) { 
			var anchor = anchors[i]; 
			if ( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" ) anchor.target = "_blank"; 
		} 
	} 

//	add given page to favourites (bookmark)
	function setBookmark ( url, str ) {
		if ( str == '' ) str = url;
		if ( document.all ) window.external.AddFavorite( url, str );
		else alert( 'Sorry, this function only works in Internet Explorer.\n\nPlease press CTRL and D to add a bookmark to \n"' + str + '".' );
	}

//	toggle a given elements visibility
	function toggle (el) {
		if ( document.getElementById(el) == undefined ) return false;
		if ( document.getElementById(el).style.display == 'none' ) {
			document.getElementById(el).style.display = '';
		} else {
			document.getElementById(el).style.display = 'none';
		}
		return true;
	}

//	show a given element
	function show (el) {
		if ( document.getElementById(el) != undefined ) document.getElementById(el).style.display = '';
	}

//	hide a given element
	function hide (el) {
		if ( document.getElementById(el) != undefined ) document.getElementById(el).style.display = 'none';
	}

//	manage the show/hide buttons
	function showhide( source_el, target_el ) {
		var source = document.getElementById(source_el);
		var target = document.getElementById(target_el);
		toggle(target_el);
		if ( target.style.display == 'none' ) {
			source.innerHTML = 'Show &darr;';
			source.className = 'showhide';
		} else {
			source.innerHTML = 'Hide &uarr;';
			source.className = 'hideshow';
		}
	}


//	activate the correct navigation
	function activate_nav() {

		var nav = get_current_page();
		if ( nav == '' ) {
			nav = 'index';
		}

		
		switch ( nav ) {
		
			case 'electrical-maintenance-services' :
			case 'electrical-contracting-services' :
			case 'emergency-electrical-callout' :
			case 'electrical-estimates' :
			case 'electrical-services' :
				document.getElementById('nav-electrical-services').className = 'active';
				document.getElementById('sub-nav-services').style.display = '';
				break;
				
			case 'directions-and-map' :
			case 'contact-us' :
				document.getElementById('nav-contact-us').className = 'active';
				document.getElementById('sub-nav-contact').style.display = '';
				break;
		
		}
		
		
		if ( nav == 'search' || nav == 'email' ) {
			nav = 'blank';
		}
		var parent_page = nav;
		var switch_on = parent_page;
		if ( document.getElementById('nav-' + nav) != undefined ) document.getElementById('nav-' + nav).className = 'active';
		

	}

//	make a textarea grow
	function extend_textarea(element) {

		if ( document.getElementById(el) == undefined ) return false;
		var el = document.getElementById(element);
		if ( el.value.length > 150 ) {
			el.style.height = "200px";
		} else {
			el.style.height = "50px";
		}
		return true;
	}

//	populate a business card
	function populate_business_card(card_id,card_type) {
		xmlHttp = initiate_ajax();
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				document.getElementById('business_card_content').innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET","business_card.php?card_id=" + card_id + "&card_type=" + card_type,true);
		xmlHttp.send(null);
	}



//	initialise an httpRequest object
	function initiate_ajax() {
		var xmlHttp;
		try {

			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {

			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		return xmlHttp;
	}


//	perform the following functions when the page loads
	window.onload = function(e) {
		externalLinks();
		activate_nav();
		initiate_ajax();
	}
