﻿function nuc_textCounter(field, countfield, maxlimit)
 {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function submit_on_change(theform){
document.getElementById(theform).submit();
}


function submitform(pressbutton){
	document.adminForm.func.value=pressbutton;
	try {
		document.adminForm.onsubmit();
		}
	catch(e){}
	document.adminForm.submit();
}



function submitform_dir(pressbutton){
	document.adminForm.directory.value=pressbutton;
	try {
		document.adminForm.onsubmit();
		}
	catch(e){}
	document.adminForm.submit();
}

function checkBox(id){

var element=document.getElementById(id);

element.checked=true;

//document.adminForm.checked;
}

//public form validations
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false}
else {return true}
}
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
  {
    if (validate_required(firstname,"Firstname must be completed.")==false)
  {firstname.focus();return false;}
      if (validate_required(familyname,"Familyname must be completed.")==false)
  {familyname.focus();return false;}
        if (validate_required(address1,"Address 1 must be completed.")==false)
  {address1.focus();return false;}
  
         if (validate_required(town,"Town must be completed.")==false)
  {town.focus();return false;}
           if (validate_required(postcode,"Postcode must be completed.")==false)
  {postcode.focus();return false;}
   
  if (thisform.email.value){
  if (validate_email(email,"Not a valid e-mail address!")==false)
    {email.focus();return false;}
    }
  }

}

function printpage() {
window.print();  
}


//http://www.alistapart.com/articles/imagegallery
/*
function showPic (pic, caption) {


 if (document.getElementById) {
  document.getElementById('placeholder') .src = pic;
  if (caption) {
   document.getElementById('desc') .childNodes[0].nodeValue = caption;
  }

  if (!caption) {
  {
   document.getElementById('desc') .childNodes[0].nodeValue = null;
  }
 
  if (summary) {
   document.getElementById('summ') .childNodes[0].nodeValue = summary;
  } 
   if (!summary)
  {
   document.getElementById('summ') .childNodes[0].nodeValue =null;
  }

  return false;
 } 
 
 else {
 return true;
 }
}
*/

function showPic (pic, caption,summary) {
 if (document.getElementById) {
  document.getElementById('placeholder') .src = pic;
  if (caption) {
   document.getElementById('desc') .childNodes[0].nodeValue = caption;
  }
    if (!caption) {
   document.getElementById('desc') .childNodes[0].nodeValue = "";
  }

    if (summary !="none") {
   document.getElementById('gallery_summary') .childNodes[0].nodeValue = summary;
  }

  return false;
 } else {
  return true;
 }
}


//password generator
function getRandomNum(lbound, ubound) {
return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar(number, lower, upper, other, extra) {
//var numberChars = "0123456789";
var numberChars = "23456789";
//var lowerChars = "abcdefghijklmnopqrstuvwxyz";
var lowerChars = "abcdefghijkmnpqrstuvwxyz";
//var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var upperChars = "ABCDEFGHJKLMNPQRSTUVWXYZ";
//var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
var otherChars = "_";
var charSet = extra;
if (number == true)
charSet += numberChars;
if (lower == true)
charSet += lowerChars;
if (upper == true)
charSet += upperChars;
if (other == true)
charSet += otherChars;
return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,
latterNumber, latterLower, latterUpper, latterOther) {
var rc = "";
if (length > 0)
rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
for (var idx = 1; idx < length; ++idx) {
rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
}
return rc;
}
