// JavaScript Document

showLogin = false;
showSearch = false;
	
function hideLabel(labelName) {
	//document.getElementById(labelName).style.display = "none";
}
	
function hideForm(formName) {
	document.getElementById(formName).style.display = "none";
}
	
function showForm(formName) {
	document.getElementById(formName).style.display = "inline";
}

  if(window.attachEvent)
    window.attachEvent("onload",setListeners);
  
  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "" && event.srcElement.style.backgroundColor != "#ffffff"){
      event.srcElement.style.backgroundColor = "#ffffff"; /* color of choice for AutoFill */
      //document.all['googleblurb'].style.display = "block";
    }
  }
	
function showAddressForm(formNo,selected) {
	formName = formNo + '_addr_form';
	if (selected == 'new')
	{
		document.getElementById(formName).style.display = "block";
	}
	else
	{
		document.getElementById(formName).style.display = "none";
	}
}	
function hideAddressForm(formName) {
	document.getElementById(formName).style.display = "none";
}

function changeHeader() {
	document.getElementById('nav-logo').style.backgroundImage = "http://www.pmamarketing.com/barnardos/www/image-cache/4_820x260.jpg";
}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

function openWin(url,width,height) {
	var newWin = window.open(url,'popup','scrollbars=yes,status=no,resizeable=no,location=no,directories=no,toolbar=no,menubar=no,width='+width+',height='+height)
}
