function initForm()
{
  if (document.forms['login'].username.value != "Your email address is your username")
  {  
   document.forms['login'].password.select();
   document.forms['login'].password.focus();
   }
}

function doLogin()
{
  if(document.forms['login'].username.value == "") {
    alert('You have not entered your username, it is usually your email address');
	document.forms['login'].username.focus();
	return false;
  }
  else if(document.forms['login'].password.value == "") {
    alert('You have not entered your password, use the \'forgot password\' link below if you can\'t remember it');
	document.forms['login'].password.focus();
	return false;
	 }
  else
    return true;
}

function show(id)
{
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		el = document.getElementById('more' + id);
		el.innerHTML = 'Hide ' + id + ' history';
	} else {
		el.style.display = 'none';
		el = document.getElementById('more' + id);
		el.innerHTML = 'Show ' + id + ' history';
	}
}

function showMessage(id)
{
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		el = document.getElementById('img' + id);
		el.src = 'assets/graphics/downArrow.gif';
	} else {
		el.style.display = 'none';
		el = document.getElementById('img' + id);
		el.src = 'assets/graphics/upArrow.gif';
	}

}

function launchQuickContact() 
{
  var windowWidth = 400;
  var windowHeight = 100;
  var leftDistance = (screen.width - windowWidth);
  var topDistance = (screen.height - windowHeight);
  //
  var quickContactWindow = window.open('quickContact.php' ,'quickContactWindow','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance);
  quickContactWindow.focus();
  self.focus();
}

function quickContact(type)
{
  contactID = document.quickContact.contactID.value;
  if (type == 'edit') file='editContact'; else if (type == 'view') file='contactSearch'; else file='makeContact';
  if(contactID == '')
    alert('You need to select a contact');
  else if (opener && !opener.closed) {
    opener.location.href = file + '.php?contactID=' + contactID + '&action=' + type; document.quickContact.contactID.selectedIndex = 0; opener.focus(); } 
  else {
    document.quickContact.contactID.selectedIndex = 0;
	var main = window.open('http://hub.bluecrocodile.co.nz/' + file + '.php?contactID=' + contactID + '&action=' + type,'main');
	main.focus();   } 
} 

function valuesMatch(form, value1, value2)
{
  if (document.forms[form].elements[value1].value != document.forms[form].elements[value2].value) { 
    alert ('The new passwords you have entered do not match.');
	document.forms[form].elements[value2].value = "";
	document.forms[form].elements[value1].value = "";
	document.forms[form].elements[value1].focus();
	return false; }
  else
    return true;
}

function setPhysical() 
{
  
  if(document.forms['contactDetails'].elements['addressPhysicalCity'].value == "")
    document.forms['contactDetails'].elements['addressPhysicalCity'].value = document.forms['contactDetails'].elements['addressPostalCity'].value;
}
  
function addContact() 
{
  var windowWidth = 600;
  var windowHeight = 600;
  var leftDistance = (screen.width - windowWidth) / 2;
  var topDistance = (screen.height - windowHeight) / 2;
  //
  var contactWindow = window.open('contactList.php?type=email' ,'contactWindow','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance + ',scrollbars=0');
  contactWindow.focus();
} 


function assignToContact(mailRecID) 
{
  var windowWidth = 600;
  var windowHeight = 600;
  var leftDistance = (screen.width - windowWidth) / 2;
  var topDistance = (screen.height - windowHeight) / 2;
  //
  var contactWindow = window.open('contactList.php?type=assign&mailRecID=' + mailRecID ,'contactWindow','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance + ',scrollbars=0');
  contactWindow.focus();
} 

function cancelMembership(contactID)
{
  doDelete = confirm('Are you sure you wish to cancel?');
  if(doDelete)
    location.href = 'editContact.php?action=delete&contactID=' + contactID;
}

function formCheck() {
  args = formCheck.arguments;
  for(i = 1; i<args.length-1; i+=2) {
   if (document.forms[args[0]].elements[args[i]].value == "") {
    alert("You have forgotten to enter " + args[i+1]);
    document.forms[args[0]].elements[args[i]].select();
    document.forms[args[0]].elements[args[i]].focus();
    return false; } } 
}

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}  

function openPopup(pageID) 
{
  var windowWidth = 560;
  var windowHeight = 500;
  var leftDistance = (screen.width - windowWidth)/2;
  var topDistance = (screen.height - windowHeight)/2;
  //
  var popUp = window.open('textOnly.php?id=' + pageID ,'popUp','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance + ',scrollbars=yes');
  popUp.focus();
}

function downloadDetails(params) 
{
  var windowWidth = 400;
  var windowHeight = 100;
  var leftDistance = (screen.width - windowWidth)/2;
  var topDistance = (screen.height - windowHeight)/2;
  //
  var downloadDetails = window.open('assets/includes/report.php?' + params ,'downloadDetails','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance);
  downloadDetails.focus();
}

window.onload=startList;     