// Standard Functions

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";
	}
}

function showHide(id) {
	block = self.document.getElementById(id);
	if (block.className == "show")
		block.className = "hide";
	else
		block.className = "show";
}

function showExistingBusiness() {
	existBlock = self.document.getElementById('existingBusiness');
	existBlock.className = "show";
	existBlock2 = self.document.getElementById('existingBusiness2');
	existBlock2.className = "show";
	newBlock = self.document.getElementById('newBusiness');
	newBlock.className = "hide";
	newBlock2 = self.document.getElementById('newBusiness2');
	newBlock2.className = "hide";
}

function showNewBusiness() {
	existBlock = self.document.getElementById('existingBusiness');
	existBlock.className = "hide";
	existBlock2 = self.document.getElementById('existingBusiness2');
	existBlock2.className = "hide";
	newBlock = self.document.getElementById('newBusiness');
	newBlock.className = "show";
	newBlock2 = self.document.getElementById('newBusiness2');
	newBlock2.className = "show";
}

function showQuickContact(id) {
	var list = document.getElementById("contactBox");
	var divList = list.getElementsByTagName('div');
	for (var i=0; i<divList.length; i++) {
		if (divList[i].className == "qcaHide") divList[i].className = "qcaShow";
		if (divList[i].className == "qcShow") divList[i].className = "qcHide";
	}
	
	block = self.document.getElementById('quickContact_'+id);
	block.className = "qcShow";
	link = self.document.getElementById('quickContactAnchor_'+id);
	link.className = "qcaHide";
}

function showFullContact(id) {
	block = self.document.getElementById('extProfile_'+id);
	block.className = "show";
	block2 = self.document.getElementById('profileButtons_'+id);
	block2.className = "profButtons show";
	link = self.document.getElementById('extProfileAnchor_'+id);
	link.className = "hide";
}

function hideFullContact(id) {
	block = self.document.getElementById('extProfile_'+id);
	block.className = "hide";
	block2 = self.document.getElementById('profileButtons_'+id);
	block2.className = "profButtons hide";
	link = self.document.getElementById('extProfileAnchor_'+id);
	link.className = "show";
}

function addNotes(id) {
	block = self.document.getElementById('notes_'+id);
	block.className = "show";
}

function selectAll(formId) {
	
	var form = document.getElementById(formId);
	
	for (var i=0; i<form.elements.length; i++) {
		if (form.elements[i].type == 'checkbox') form.elements[i].checked = true;
	}
}

function openPopup(id) {
	popContainer = self.document.getElementById('progressChart');
	popContent = self.document.getElementById('con'+id);
	popContainer.innerHTML = popContent.innerHTML;
	window.location.hash="content";
}

// AJAX Functions

var xmlhttp;

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function addRemoveContact(id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="addRemoveContact.php";
url=url+"?id="+id;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=function(){contactAddedRemoved(id);};
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function contactAddedRemoved(id)
{
if (xmlhttp.readyState==4)
{
document.getElementById("addRemove"+id).onclick = "";
document.getElementById("addRemove"+id).onmouseout = "";
document.getElementById("addRemove"+id).onmouseover = "";
document.getElementById("addRemove"+id).className = "";
document.getElementById("addRemove"+id).src = "images/btnAdded.gif";
}
}

function removeContact(id)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="addRemoveContact.php";
url=url+"?id="+id;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=function(){contactRemoved(id);};
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function contactRemoved(id)
{
if (xmlhttp.readyState==4)
{
document.getElementById("contactProfile_"+id).className = "hide";
}
}

function submitRating(a,r)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="submitRating.php";
url=url+"?a="+a+"&r="+r;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=function(){ratingSubmitted(a);};
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function ratingSubmitted(a)
{
if (xmlhttp.readyState==4)
{
document.getElementById("rateAnswer_"+a).innerHTML=xmlhttp.responseText;
}
}

// Progress Functions

function submitLevel(level)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
	
	var form = document.getElementById('progress'+level);
	var progress = new Array();
	
	for (var i=0; i<form.elements.length; i++) {
		if (form.elements[i].checked == true) progress[i] = '1'; else progress[i] = '0';
	}
	
	var queryString = '';
	
	for (var j=0; j<progress.length; j++) {
		queryString = queryString+progress[j];
	}
	
var url="submitLevel.php";
url=url+"?level="+level+"&data="+queryString;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=function(){levelSubmitted(level);};
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function levelSubmitted(l)
{
if (xmlhttp.readyState==4)
{
document.getElementById("levelBtn_"+l).src='images/btnLevel.gif';
document.getElementById('progressChart').innerHTML=xmlhttp.responseText;
window.location.hash="content";
}
}

function taskChange(l) {
	document.getElementById("levelBtn_"+l).src='images/btnLevel2.gif';
}

// Scrollbar Position Functions

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}