
function initForm()
{
  if (document.forms['login'].username.value == "")
  {
   document.forms['login'].username.select();
   document.forms['login'].username.focus();
   }
  else
  {  
   document.forms['login'].password.select();
   document.forms['login'].password.focus();
   }
}


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(bulk) 
{
  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&bulk='+bulk ,'contactWindow','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance + ',scrollbars=0');
  contactWindow.focus();
} 


function assignToContact(mailRecID,mailDirection) 
{
  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 + '&mailDirection=' + mailDirection ,'contactWindow','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance + ',scrollbars=0');
  contactWindow.focus();
} 

function addAttachment() 
{
  var windowWidth = 600;
  var windowHeight = 150;
  var leftDistance = (screen.width - windowWidth) / 2;
  var topDistance = (screen.height - windowHeight) / 2;
  //
  var attachmentWindow = window.open('assets/includes/addAttachment.php','attachmentWindow','width=' + windowWidth + ',height=' + windowHeight + ',left=' + leftDistance + ',top=' + topDistance + ',screenX=' + leftDistance + ',screenY=' + topDistance + ',scrollbars=0');
  attachmentWindow.focus();
} 

