
function updateField(pinput, plen){
var x = document.getElementById(pinput + 'chars');
var y = document.getElementById(pinput + 'input');

if(y.value.length > plen) {
	x.innerHTML = y.value.length - plen + ' characters to many';
	x.style.color = 'red';
}else if(y.value == ""){
	x.innerHTML = 'This field has a limit of ' + plen + ' characters';
	x.style.color = '#37539b';
}else{
	x.innerHTML = plen - y.value.length + ' characters remaining';
	x.style.color = '#37539b';
}
}



function openQuickEdit(formname)
{
if (screen)
{

var lngLeftPos = (screen.availWidth/2) - 400
var lngTopPos = (screen.availHeight/2) - 265

var thedate = new Date( );

 
var d = thedate.getDay( );
var h = thedate.getHours( );
var m = thedate.getMinutes( );
var s = thedate.getSeconds();

//alert(d + "a" + h + "b" + m + "c" + s);

//Get the window a unique name so that multiple forms can be opened...
var windowsname = "AdminForm" + d + "a" + h + "b" + m + "c" + s

}
//var paramsAdmin = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=720,height=550,left="+lngLeftPos+",top="+lngTopPos
//var paramsAdmin = "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=550,left="+lngLeftPos+",top="+lngTopPos
var paramsAdmin = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=550,left="+lngLeftPos+",top="+lngTopPos
var AdminForm = window.open(formname, windowsname, paramsAdmin);
if (parseInt(navigator.appVersion) >= 4){AdminForm.focus();}
}

function searchFormCheck(form)
{
var booAllBlank = true
var booFoundCheck = false

if (form.elements["search_string"].value=="")
{
	alert("please type some search text.");
	form.elements["search_string"].focus();
	return false;
}

for (i=0; i<form.elements.length; i++){
	//alert(form.elements[i].checked)

	if (form.elements[i].type=="checkbox")
	{
		booFoundCheck = true
		if (form.elements[i].checked==true){
		booAllBlank = false
		}
	}
}

if(booAllBlank && booFoundCheck)
{
	alert("Please select at least one location to search from.");
	form.elements[5].focus();
	return false;
}
}

function setColor(objName, fg)
{
  obj = findObj(objName);
  if (obj.style)
  {
    obj.style.color = fg;
  }
}

function setCheck(objName)
{
  obj = findObj(objName);

  if (obj.checked)
  {
    obj.checked = false;
  }else{
    obj.checked = true;
  }

	if(objName=="whole_site"){
	toggleWholeSite(obj.checked)
	}
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function showhide(myDiv) {
	//alert(myDiv);
	//function switchMenu(obj) {
	var el = document.getElementById(myDiv);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function swapPlusMinus(myImg){
	var s1 = document.getElementById(myImg);
	
	//alert(s1.src);
	if ( right(s1.src, 11) != 'ps_show.gif' ) {
		s1.src = '/images/ps_show.gif';
	}
	else {
		s1.src = '/images/ps_hide.gif';
	}
}


function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function tdover(td){
if(td){
td.className = td.className.replace('whatsnewunselect', 'whatsnewhover');
//alert(td.style.cursor);
td.style.cursor='hand';
}}
function tdout(td){
if(td){
td.className = td.className.replace('whatsnewhover', 'whatsnewunselect');
td.style.cursor='';
}}

function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,"");} 

function fnSearchTip(){

var searchTextStarter = 'type here to search cmf.org.uk';
var i = document.getElementById('iSearch');

//alert(i.style.color);
if(i.value == searchTextStarter)
{
	i.value = '';
	i.style.color='#000000';
}else{
	if(trim(i.value) == ''){
		i.value = searchTextStarter;
		i.style.color='#bbbbbb';
	}
}

//alert('cool');	
	
}