function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring (0,mlength)
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Pager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.inited = false;
    
    this.showRecords = function(from, to) {        
        var rows = document.getElementById(tableName).rows;
        // i starts from 1 to skip table header row
        for (var i = 1; i < rows.length; i++) {
            if (i < from || i > to)  
                rows[i].style.display = 'none';
            else
                rows[i].style.display = '';
        }
    }
    
    this.showPage = function(pageNumber) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}

        var oldPageAnchor = document.getElementById('pg' +this.currentPage);
        oldPageAnchor.className = 'pg-normal';
        
        this.currentPage = pageNumber;
        var newPageAnchor = document.getElementById('pg' +this.currentPage);
        newPageAnchor.className = 'pg-selected';
        
        var from = (pageNumber - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to);
    }   
    
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
    
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                        
    
    this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1); 
        this.pages = Math.ceil(records / itemsPerPage);
        this.inited = true;
    }

    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
    	
    	var pagerHtml = '<span onclick="' + pagerName + '.prev();" class="pg-normal"> &#171 Prev </span> | ';
        for (var page = 1; page <= this.pages; page++) 
            pagerHtml += '<span id="pg' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
        pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next &#187;</span>';            

        if(this.pages>1) {
        element.innerHTML = pagerHtml;
        }
    }
}

function Pager2(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.inited = false;
    
    this.showRecords = function(from, to) {        
        var rows = document.getElementById(tableName).rows;
        // i starts from 1 to skip table header row
        for (var i = 1; i < rows.length; i++) {
            if (i < from || i > to)  
                rows[i].style.display = 'none';
            else
                rows[i].style.display = '';
        }
    }
    
    this.showPage = function(pageNumber) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}

        var oldPageAnchor = document.getElementById('pg2' +this.currentPage);
        oldPageAnchor.className = 'pg-normal';
        
        this.currentPage = pageNumber;
        var newPageAnchor = document.getElementById('pg2' +this.currentPage);
        newPageAnchor.className = 'pg-selected';
        
        var from = (pageNumber - 1) * itemsPerPage + 1;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to);
    }   
    
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
    
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                        
    
    this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1); 
        this.pages = Math.ceil(records / itemsPerPage);
        this.inited = true;
    }

    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
    	
    	var pagerHtml = '<span onclick="' + pagerName + '.prev();" class="pg-normal"> &#171 Prev </span> | ';
        for (var page = 1; page <= this.pages; page++) 
            pagerHtml += '<span id="pg2' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
        pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next &#187;</span>';            

        if(this.pages>1) {
        element.innerHTML = pagerHtml;
        }
    }
}

function dri(reqid){
var answer = confirm ("Are you sure you want to delete this request?")
if (answer)
window.location='delete.php?act=reqin&rid=' + reqid;
}

function dro(reqid){
var answer = confirm ("Are you sure you want to delete this request?")
if (answer)
window.location='delete.php?act=reqout&rid=' + reqid;
}

function dmo(messid){
var answer = confirm ("Are you sure you want to delete this message?")
if (answer)
window.location='delete.php?act=messout&mid=' + messid;
}

function dmi(messid){
var answer = confirm ("Are you sure you want to delete this message?")
if (answer)
window.location='delete.php?act=messin&mid=' + messid;
}

function validateApp() {
if(document.apply.forename.value=='' || document.apply.forename.value=='' || document.apply.role.value=='' || document.apply.company.value=='' || document.apply.email.value=='' || document.apply.phone.value=='' || document.apply.address.value=='' || document.apply.postcode.value==''){
alert('Please fill out all fields marked with *');
return false;
} else {
document.apply.submit();
return true;
}
}
function validateContact() {
if(document.cform.cname.value=='' || document.cform.cemail.value=='' || document.cform.ccomments.value==''){
alert('Please fill out all fields');
return false;
} else {
document.apply.submit();
return true;
}
}

function validatePassChange() {

                var changeForm = document.getElementById("changeForm");
                if (changeForm.p1.value == "") {
                    alert("Please enter your current password.");
                    return false;
                }
                if (changeForm.p2.value == "") {
                    alert("Please enter your new password.");
                    return false;
                }
                if (changeForm.p3.value == "") {
                    alert("Please enter a new password in the 3rd box.");
                    return false;
                }
                if (changeForm.p2.value.length < 6) {
                    alert("Please enter a longer password.");
                    return false;
                }
                if (changeForm.p2.value != changeForm.p3.value) {
                    alert("Your new passwords don't match.");
                    return false;
                }
                
                var submitForm = document.getElementById("submitForm");
                submitForm.pen1.value = hex_md5(changeForm.p1.value);
                submitForm.pen2.value = hex_md5(changeForm.p2.value);
                submitForm.encform.value = '2';
                submitForm.submit();

            }

function SaveProfile(userid,otherid)
{
var xmlHttp;
var add;
var saveid;
saveid = 'save'+otherid;
document.getElementById(saveid).innerHTML = '<img border="0" src="../images/button_saved.png" width="192" height="43">';
var urlbit = "saveprofile.php?userid="+userid+"&otherid="+otherid;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {

if(xmlHttp.responseText=="Saved") {
     document.getElementById(saveid).innerHTML = '<img border="0" src="../images/button_saved.png" width="192" height="43">';
     }
      }
    }
  xmlHttp.open("GET",urlbit,true);
  xmlHttp.send(null);
  }
