// Pagination script
resultsPerPage=12;
pageLinksInPagination=7;
mediaResultsPerPage=15;
function checkQueryString(){
var qrStr = window.location.search;
var spQrStr = qrStr.substring(1);
var arrQrStr = new Array();
// splits each of pair
var arr = spQrStr.split('&');
for (var i=0;i<arr.length;i++){
// splits each of field-value pair
var index = arr[i].indexOf('=');
var keystr = arr[i].substring(0,index);
var valstr = arr[i].substring(index+1);
if (keystr == 'slct_pages'){
if (valstr != '')
resultsPerPage = valstr;
}
// saves each of field-value pair in an array variable
arrQrStr[keystr] = valstr;
}
}
function dispPage(pageNo){
          checkQueryString();
            liItem = document.getElementsByName('list');
           // alert("length of liItem "+liItem.length);
            for(var i=0; i<liItem.length; i++){
                if(i<pageNo*resultsPerPage - resultsPerPage || i >=pageNo*resultsPerPage )
                    liItem[i].style.display='none';
                
                else
                    liItem[i].style.display='block';
            }
            if(liItem.length!=0)
              pagination(pageNo);
            
      }
function dispPage1(pageNo){
          checkQueryString();
            liItem = document.getElementsByName('list-item'); 
            for(var i=0; i<liItem.length; i++){
                if(i<pageNo*resultsPerPage - resultsPerPage || i >=pageNo*resultsPerPage )
                    liItem[i].style.display='none';
                else
                    liItem[i].style.display='block';
            }
            if(liItem.length!=0)
              pagination1(pageNo);

            
}
function pagination(currentPageNo){
            var liItem = document.getElementsByName('list');
            var maxNoOfPages = Math.ceil(liItem.length/resultsPerPage);
            var pageNosToDisplay="";
            if(currentPageNo%pageLinksInPagination==0)
                fromPage=currentPageNo-(pageLinksInPagination-1);
            else 
                fromPage = currentPageNo-currentPageNo%pageLinksInPagination + 1;
                if((maxNoOfPages-fromPage+1)>=pageLinksInPagination)
                    toPage = pageLinksInPagination;
                else
                    toPage = maxNoOfPages-fromPage+1;
            for(i=fromPage;i<(fromPage+toPage);i++){
                    if(i==fromPage){
                    //alert("inside i=fromPage, i= "+i);
                        if(i==currentPageNo)
                            pageNosToDisplay = pageNosToDisplay + "<li  class=\"first active\"><a href=\"#\" onclick=dispPage(" + i + ")>"+i+"</a></li>";
                        else
                            pageNosToDisplay = pageNosToDisplay + "<li  class=\"first\"><a href=\"#\" onclick=dispPage(" + i + ")>"+i+"</a></li>";
                    }
                    else if(i==(fromPage+toPage-1)){
        
                        if(i==currentPageNo)
                            pageNosToDisplay = pageNosToDisplay + "<li class=\"last active\"><a href=\"#\" onclick=dispPage(" + i + ")>"+i+"</a></li>";
                        else
                            pageNosToDisplay = pageNosToDisplay + "<li class=\"last\"><a href=\"#\" onclick=dispPage(" + i + ")>"+i+"</a></li>";
                    }
                    else
                        if(i==currentPageNo)
                            pageNosToDisplay = pageNosToDisplay + "<li class=\"active\"><a href=\"#\" onclick=dispPage(" + i + ")>"+i+"</a></li>";
                        //pageNosToDisplay = pageNosToDisplay + "<a href=# onclick=dispPage(" + i + ")>" + i + "</a> ";        
                        else
                            pageNosToDisplay = pageNosToDisplay + "<li><a href=\"#\" onclick=dispPage(" + i + ")>"+i+"</a></li>";
            }
                if(isPreviousNextLinksRequired(maxNoOfPages)){
                    pageNosToDisplay = previous(pageNosToDisplay,currentPageNo);
                    pageNosToDisplay = first(pageNosToDisplay);
                    pageNosToDisplay = next(pageNosToDisplay,maxNoOfPages,currentPageNo);
                    pageNosToDisplay = last(pageNosToDisplay,maxNoOfPages);
                }
            document.getElementById('leftPagingTextTop').innerHTML = "Displaying page "+currentPageNo+" of "+maxNoOfPages+" <a href=\"#\" onclick=\"showAll()\">Show all</a>";
            document.getElementById('pagingTop').innerHTML = pageNosToDisplay;
            document.getElementById('leftPagingTextBottom').innerHTML = "Displaying page "+currentPageNo+" of "+maxNoOfPages+" <a href=\"#\" onclick=\"showAll()\">Show all</a>";
            document.getElementById('pagingBottom').innerHTML = pageNosToDisplay;
            
}
function pagination1(currentPageNo){
           var liItem = document.getElementsByName('list-item');
            var maxNoOfPages = Math.ceil(liItem.length/resultsPerPage);
            var pageNosToDisplay="";
            if(currentPageNo%pageLinksInPagination==0)
                fromPage=currentPageNo-(pageLinksInPagination-1);
            else 
                fromPage = currentPageNo-currentPageNo%pageLinksInPagination+ 1;
                if((maxNoOfPages-fromPage+1)>=pageLinksInPagination)
                    toPage = pageLinksInPagination;
                else
                    toPage = maxNoOfPages-fromPage+1;
            for(i=fromPage;i<(fromPage+toPage);i++){
                    if(i==fromPage){
                    //alert("inside i=fromPage, i= "+i);
                        if(i==currentPageNo)
                            pageNosToDisplay = pageNosToDisplay + "<li  class=\"first active\"><a href=\"#\" class=\"selected\" onclick=dispPage1(" + i + ")>"+i+"</a></li>";
                        else
                            pageNosToDisplay = pageNosToDisplay + "<li  class=\"first\"><a href=\"#\" onclick=dispPage1(" + i + ")>"+i+"</a></li>";
                    }
                    else if(i==(fromPage+toPage-1)){
        
                        if(i==currentPageNo)
                            pageNosToDisplay = pageNosToDisplay + "<li class=\"last active\"><a href=\"#\" class=\"selected\" onclick=dispPage1(" + i + ")>"+i+"</a></li>";
                        else
                            pageNosToDisplay = pageNosToDisplay + "<li class=\"last\"><a href=\"#\" onclick=dispPage1(" + i + ")>"+i+"</a></li>";
                    }
                    else
                        if(i==currentPageNo)
                            pageNosToDisplay = pageNosToDisplay + "<li class=\"active\"><a href=\"#\" class=\"selected\" onclick=dispPage1(" + i + ")>"+i+"</a></li>";
                        //pageNosToDisplay = pageNosToDisplay + "<a href=# onclick=dispPage1(" + i + ")>" + i + "</a> ";        
                        else
                            pageNosToDisplay = pageNosToDisplay + "<li><a href=\"#\" onclick=dispPage1(" + i + ")>"+i+"</a></li>";
            }
                if(isPreviousNextLinksRequired(maxNoOfPages)){
                    pageNosToDisplay = previous(pageNosToDisplay,currentPageNo);
                    pageNosToDisplay = first(pageNosToDisplay);
                    pageNosToDisplay = next(pageNosToDisplay,maxNoOfPages,currentPageNo);
                    pageNosToDisplay = last(pageNosToDisplay,maxNoOfPages);
                }
            document.getElementById('leftPagingTextTop').innerHTML = "Displaying page "+currentPageNo+" of "+maxNoOfPages+" <a href=\"#\" onclick=\"showAll1()\">Show all</a>";
            document.getElementById('pagingTop').innerHTML = pageNosToDisplay;
            document.getElementById('leftPagingTextBottom').innerHTML = "Displaying page "+currentPageNo+" of "+maxNoOfPages+" <a href=\"#\" onclick=\"showAll1()\">Show all</a>";
            document.getElementById('pagingBottom').innerHTML = pageNosToDisplay;
            
}
function isPreviousNextLinksRequired(maxNoOfPages){
                if(maxNoOfPages > pageLinksInPagination){
                    return true;
                }
                return false;
}
    
function previous(pageNosToDisplay,currentPageNo){
            if(currentPageNo==1)
                dispParameter=1;
            else
                dispParameter=currentPageNo-1;
            
            //pageNosToDisplay = "<a href=# onclick=dispPage("+dispParameter+")>\<</a> &nbsp;&nbsp;&nbsp;" + pageNosToDisplay;
            pageNosToDisplay = "<li class=\"arrow\"><a href=\"#\" class=\"back\" onclick=dispPage("+dispParameter+")>Previous page</a></li>" + pageNosToDisplay;
            return pageNosToDisplay;
}
    
function first(pageNosToDisplay){
            //pageNosToDisplay = "<a href=#  onclick=dispPage(1);pagination(1)>\<\<</a>&nbsp; &nbsp;" + pageNosToDisplay;
            pageNosToDisplay = "<li class=\"first\"><a href=\"#\" class=\"first\" onclick=dispPage(1);pagination(1)>First page</a></li>" + pageNosToDisplay;
            return pageNosToDisplay;
}
    
    
function next(pageNosToDisplay,maxNoOfPages,currentPageNo){
            if(currentPageNo==maxNoOfPages)
                dispParameter=maxNoOfPages;
            else
                dispParameter=currentPageNo+1;
            
            //pageNosToDisplay = pageNosToDisplay + "&nbsp;&nbsp;&nbsp;<a href=# onclick=dispPage("+dispParameter+")>\></a>";
            pageNosToDisplay = pageNosToDisplay + "<li class=\"arrow\"><a href=\"#\" class=\"next\" onclick=dispPage("+dispParameter+")>Next page</a></li>";
            return pageNosToDisplay;
}
function last(pageNosToDisplay,maxNoOfPages){
            //pageNosToDisplay = pageNosToDisplay + "&nbsp; &nbsp;<a href=#  onclick=dispPage("+maxNoOfPages+")>\>\></a>"
            pageNosToDisplay = pageNosToDisplay + "<li class=\"arrow\"><a href=\"#\" class=\"last\" onclick=dispPage("+maxNoOfPages+")>Last page</a></li>";
            return pageNosToDisplay;
}
    
    
function showAll(){
            liItem = document.getElementsByName('list');
            
            for(var i=0; i<liItem.length; i++){
                liItem[i].style.display='block';
            }
            //document.getElementById('paginationTop').style.display = 'none';
            //document.getElementById('paginationBottom').style.display = 'none';
           document.getElementById('leftPagingTextTop').innerHTML = "<p></p>";
           document.getElementById('pagingTop').innerHTML = "";
           document.getElementById('leftPagingTextBottom').innerHTML = "<p></p>";
           document.getElementById('pagingBottom').innerHTML = "";
            
}
function showAll1(){
            liItem = document.getElementsByName('list-item');
            
            for(var i=0; i<liItem.length; i++){
                liItem[i].style.display='block';
            }
            //document.getElementById('pagination1Top').style.display = 'none';
            //document.getElementById('pagination1Bottom').style.display = 'none';
           document.getElementById('leftPagingTextTop').innerHTML = "<p></p>";
           document.getElementById('pagingTop').innerHTML = "";
           document.getElementById('leftPagingTextBottom').innerHTML = "<p></p>";
           document.getElementById('pagingBottom').innerHTML = "";
            
} 
/* Text only and text sizes script */

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr');
//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;
/* This method changes the font size of page provided and target and inc factor */
function ts( trgt,inc ) {
    if (!document.getElementById) return
    var d = document,cEl = null,sz = startSz,i,j,cTags;
    
    //    sz += inc;
        sz = inc;
    if ( sz < 0 ) sz = 0;
    if ( sz > 6 ) sz = 6;
    startSz = sz;
        
    if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
    cEl.style.fontSize = szs[ sz ];
    for ( i = 0 ; i < tgs.length ; i++ ) {
        cTags = cEl.getElementsByTagName( tgs[ i ] );
        for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
    }
}
/* This method opens outlook mail window with predefined body text */
function sendPage()
{
mail_str = "mailto:?subject=Thames Water website: " + document.title;
mail_str += "&body=You have been sent a link from the Thames Water website. %0D%0A%0D%0A";
mail_str += "The page can be viewed by following this link: " + location.href; 
location.href = mail_str;
}
/*function sendPage()
{
mail_str = "mailto:?subject=View this page on the Thames Water website" + document.title;
mail_str += "&body=You have been sent a link from Thames Water official website %0D%0A%0D%0A" + document.title;
mail_str += ". You can view it at, " + location.href; 
location.href = mail_str;
}*/

/* This method changes style sheet to textonly and vice versa */
function switchstyle()
{
  var hrefValue;
  var i, link_tag ;
  for (i = 0, link_tag = document.getElementsByTagName("link") ;i < link_tag.length ; i++ ){
   if ((link_tag[i].rel.indexOf( "stylesheet" ) != -1) && link_tag[i].title) {
    if(link_tag[i].title == "main") { //alert("if block");
                                      hrefValue = link_tag[i].href;
                               //alert(hrefValue); 
                               //alert("<%anc_Main_Style%>");
                               //alert(hrefValue.indexOf("<%anc_Main_Style%>"));
                              if( hrefValue.indexOf("<%anc_Main_Style%>") >= 0) {  
                                    link_tag[i].href = "<%anc_Textonly%>";                                                            }
                              else { //alert("else block");
                                          
                                    link_tag[i].href = "<%anc_Main_Style%>"; 
                                    }
                                                  }
             }
   }
}
 

// functions related to search form submit - added by Jagadish.
//function trim(s){
//var l=0;var r=s.length - 1;
//while(l<s.length && s[l]==''
//{l++;}
//while(r>l && s[r] == '')
//{r-=1;}
//return s.substring(l,r+1);
//}


function submitsearchagain(){
//alert("in search again");
var searchTerm = document.searchagainform.fSearchTerms.value;
//alert("*");
//alert(searchTerm);
document.searchagainform.wholesite.value='TWwebsite';
if (searchTerm.length > 0) document.searchagainform.submit();
}
 
function submitadvsearch(){
var check = 0;
//alert("in adv search");
var searchTerm = document.advsearchform.fSearchTerms.value;
//alert(searchTerm);
if (document.advsearchform.TWwebsite.checked){
document.advsearchform.wholesite.value='TWwebsite';
check++;
//alert(document.advsearchform.wholesite.value);
}
if (document.advsearchform.Yourhome.checked){
document.advsearchform.fYourhome.value='home_services';
check++;
//alert(document.advsearchform.fYourhome.value);
}
if (document.advsearchform.Yourbusiness.checked){
document.advsearchform.fYourbusiness.value='business_services';
check++;
//alert(document.advsearchform.fYourbusiness.value);
}
if (document.advsearchform.Community.checked){
document.advsearchform.fCommunity.value='community';
check++;
//alert(document.advsearchform.fCommunity.value);
}
if (document.advsearchform.Environment.checked){
document.advsearchform.fEnvironment.value='environment';
check++;
//alert(document.advsearchform.fEnvironment.value);
}
if (document.advsearchform.Careers.checked){
document.advsearchform.fCareers.value='careers';
check++;
//alert(document.advsearchform.fCareers.value);
}
if (document.advsearchform.Aboutus.checked){
document.advsearchform.fAboutus.value='about_us';
check++;
//alert(document.advsearchform.fAboutus.value);
}
if (document.advsearchform.Media.checked){
document.advsearchform.fMedia.value='media_centre';
check++;
//alert(document.advsearchform.fMedia.value);
}
if (document.advsearchform.Contactus.checked){
document.advsearchform.fContactus.value='contact_us';
check++;
//alert(document.advsearchform.fContactus.value);
}
if (searchTerm.length > 0 && check > 0) return true;//document.advsearchform.submit();
if (searchTerm.length > 0 && check == 0) {
document.advsearchform.wholesite.value='TWwebsite';
return true;
//document.advsearchform.submit();
}
return false;
}
 
function submitadvarticlesearch(){
var searchTerm = document.advarticlesearchform.fSearchTerms.value;
if (searchTerm.length > 0) return true;//document.advarticlesearchform.submit();
return false;
}
// Advance search inline javascript
function enablecontrols() {
if (document.getElementById("TWwebsite").checked) {
//alert("checked");
document.getElementById("Yourhome").disabled=true;
document.getElementById("Yourbusiness").disabled=true;
document.getElementById("Community").disabled=true;
document.getElementById("Environment").disabled=true;
document.getElementById("Media").disabled=true;
document.getElementById("Aboutus").disabled=true;
document.getElementById("Careers").disabled=true;
document.getElementById("Contactus").disabled=true;
} else {
//alert("unchecked");
document.getElementById("Yourhome").disabled=false;
document.getElementById("Yourbusiness").disabled=false;
document.getElementById("Community").disabled=false;
document.getElementById("Environment").disabled=false;
document.getElementById("Media").disabled=false;
document.getElementById("Aboutus").disabled=false;
document.getElementById("Careers").disabled=false;
document.getElementById("Contactus").disabled=false;
}
if (!(document.getElementById("Yourhome").checked) && !(document.getElementById("Yourbusiness").checked) 
&& !(document.getElementById("Community").checked) && !(document.getElementById("Environment").checked) 
&& !(document.getElementById("Media").checked) && !(document.getElementById("Aboutus").checked) 
&& !(document.getElementById("Careers").checked)&& !(document.getElementById("Contactus").checked)) {
//alert("nothing checked");
document.getElementById("TWwebsite").disabled=false;
} else {
//alert("something checked");
document.getElementById("TWwebsite").disabled=true;
}
}//END OF INLINE SCRIPT 


//News release search submit
function articlesearchsubmit(){
	var searchTerm = document.articlesearchform.fSearchTerms.value;
	var monthvalue = document.articlesearchform.month.value;
	var yearvalue = document.articlesearchform.year.value;
	if (monthvalue != "" && yearvalue != "") {
		if (monthvalue == "01")
			document.articlesearchform.sMonth.value = "January";
		if (monthvalue == "02")
			document.articlesearchform.sMonth.value = "February";
		if (monthvalue == "03")
			document.articlesearchform.sMonth.value = "March";
		if (monthvalue == "04")
			document.articlesearchform.sMonth.value = "April";
		if (monthvalue == "05")
			document.articlesearchform.sMonth.value = "May";
		if (monthvalue == "06")
			document.articlesearchform.sMonth.value = "June";
		if (monthvalue == "07")
			document.articlesearchform.sMonth.value = "July";
		if (monthvalue == "08")
			document.articlesearchform.sMonth.value = "August";
		if (monthvalue == "09")
			document.articlesearchform.sMonth.value = "September";
		if (monthvalue == "10")
			document.articlesearchform.sMonth.value = "October";
		if (monthvalue == "11")
			document.articlesearchform.sMonth.value = "November";
		if (monthvalue == "12")
			document.articlesearchform.sMonth.value = "December";
		return true;
	}
	if (monthvalue == "" && yearvalue == "") {
		if (searchTerm == 'Enter keywords (optional)')
			return false;
		else
			return true;
	}
	if ( (searchTerm.length == 0)  && (monthvalue == "" && yearvalue == "")) return false;
	//if (searchTerm.length > 0) return true;//document.articlesearchform.submit();
	return false;
}

 // Function being called when user press enter for search.
function checkEnter(e,from){
e = e || window.event;
var characterCode = e.keyCode || e.which;
if (characterCode == 13){
//alert(from);
if (from == 'utility'){
//alert("utility got it");
document.testform.search-submit.click();
}
if (from == 'searchagain'){
//alert("search agian got it");
document.searchagainform.searchagainid.click();
}
if (from == 'advsearch'){
//alert("adv search got it");
document.advsearchform.advsearchid.click();
}
if (from == 'articlesearch'){
//alert("got it");
document.articlesearchform.articlesearchid.click();
}
if (from == 'advarticlesearch'){
//alert("advarticlesearch got it");
document.advarticlesearchform.advarticlesearchid.click();
}
}
}
 
// Utility functions for Building Water Supplies
function calcQuote()
{
    var VAT = "";
    var TotalPayable = "";
    var TotalFee = "";
    //CHECK IF IT HAS COMMAS IN IT, IF IT DOES ALERT THAT NUMBERS ARE NOT ALLOWED
    var str = String(document.BuildingWaterSupplies.ContractValue.value);
    if(document.BuildingWaterSupplies.ContractValue.value != "")
    {
        ContractValue = WholeNumber(document.BuildingWaterSupplies.ContractValue.value);
        if(ContractValue != 0)
        {
            if(ContractValue < 10000)
            {
                TotalFee = 0;
                VAT = 0;
                TotalPayable = 0;
            }
            else if(ContractValue < 38500)
            {
                TotalFee = 65;
                VAT = RoundUp(65 * 0.175);
                TotalPayable = 65 + VAT;
            }
            else
            {
                ContractValue = ContractValue * 0.0017;
                TotalFee = RoundUp(ContractValue);
                VAT = RoundUp(TotalFee * 0.175);
                TotalPayable = RoundUp(ContractValue + VAT);
            }
        }
        else
        {
            if(str.indexOf(",") >= 0){
                alert("Do not enter commas in the contract value");
            }
        }
    }
    if(str.indexOf(",") >= 0)
    {
        document.BuildingWaterSupplies.TotalFee.value = "";
        document.BuildingWaterSupplies.VAT.value = "";
        document.BuildingWaterSupplies.TotalPayable.value = "";
    }
    else
    {
        document.BuildingWaterSupplies.TotalFee.value = moneyCheck(TotalFee);
        document.BuildingWaterSupplies.VAT.value = moneyCheck(VAT);
        document.BuildingWaterSupplies.TotalPayable.value = moneyCheck(TotalPayable);
    }
}

//------------------------------------------------------
//function to ensure numbers follow correct money format
//------------------------------------------------------
function moneyCheck(x)
{
    var answer;
    var number = x.toString();
    //alert("number: "+number);
    var point = number.indexOf(".");
    //alert("pointplace: " +point);
    if(point>=1)
    {
        var firstpart = number.substring(0,point);
        var secondpart = number.substring(point+1,number.length);
        //alert("secondpart: "+secondpart);
        var checkpart = secondpart.substring(0,2);
        //alert("checkpart: "+checkpart);
        if(checkpart.length == 1)
        {
            secondpart=secondpart+"0";
            //alert("add zero secondpart: "+secondpart);
        }
        answer = firstpart+"."+secondpart;
        //alert("answer: "+firstpart+"."+secondpart);
    }
    else
    {
           answer = number +".00";
           //alert("answer: "+answer);
    }
    return answer;
}

//------------------------------------------------
//    round up to 2 dec. pl.
//------------------------------------------------
function RoundUp(x){
    //return (Math.round(x * 100)) / 100;
    return (Math.round(x * 100)) / 100;
} 
 
function WholeNumber(x){
    if(isNaN(x)){
//        alert("Not a number!");
        return 0;
    }
    else{
        var rem = x % Math.floor(x);
        //alert("Rem: " + rem);
        if(rem != 0){
            x = Math.round(x);
            //alert("Rounded to " + x);
            //    PUT THE NEW VALUE INTO THE CONTRACT VALUE FIELD
            //document.BuildingWaterSupplies.ContractValue.value = x;
        }
        return x;
    }
}
 
// Used for PR09 Project foundation 
function applyshades(){
var liItem = document.getElementsByName("countylist");
for (var i=0,j=1;i<liItem.length;i++,j++){
if(j%2 != 0){
liItem[i].setAttribute("class","odd");
liItem[i].setAttribute("className","odd");
}
}
}



// paging.js - for consent register form
// paginationtable script for tables
resultsPerPage=12;
pageLinksInpaginationtable=7;
mediaResultsPerPage=15;
function dispPagetable(pageNo){
checkQueryString();
liItem = document.getElementById('list').rows;
for(var i=0; i<liItem.length; i++){
if(i<pageNo*resultsPerPage - resultsPerPage || i >=pageNo*resultsPerPage )
liItem[i].style.display='none';
else
liItem[i].style.display='block';
}
if(liItem.length!=0)
paginationtable(pageNo);
}
function paginationtable(currentPageNo){
var liItem = document.getElementById('list').rows;
var maxNoOfPages = Math.ceil(liItem.length/resultsPerPage);
var pageNosToDisplay="";
if(currentPageNo%pageLinksInpaginationtable==0)
fromPage=currentPageNo-(pageLinksInpaginationtable-1);
else 
fromPage = currentPageNo-currentPageNo%pageLinksInpaginationtable + 1;
if((maxNoOfPages-fromPage+1)>=pageLinksInpaginationtable)
toPage = pageLinksInpaginationtable;
else
toPage = maxNoOfPages-fromPage+1;
for(i=fromPage;i<(fromPage+toPage);i++){
if(i==fromPage){
if(i==currentPageNo)
pageNosToDisplay = pageNosToDisplay + "<li  class=\"first\"><a href=\"#\" class=\"selected\" onclick=dispPagetable(" + i + ") >"+i+"</a></li>";
else
pageNosToDisplay = pageNosToDisplay + "<li  class=\"first\"><a href=\"#\" onclick=dispPagetable(" + i + ")>"+i+"</a></li>";
}
else if(i==(fromPage+toPage-1)){
if(i==currentPageNo)
pageNosToDisplay = pageNosToDisplay + "<li class=\"last\"><a href=\"#\" class=\"selected\" onclick=dispPagetable(" + i + ") >"+i+"</a></li>";
else
pageNosToDisplay = pageNosToDisplay + "<li class=\"last\"><a href=\"#\" onclick=dispPagetable(" + i + ") >"+i+"</a></li>";
}
else
if(i==currentPageNo)
pageNosToDisplay = pageNosToDisplay + "<li><a href=\"#\" class=\"selected\" onclick=dispPagetable(" + i + ") >"+i+"</a></li>";
else
pageNosToDisplay = pageNosToDisplay + "<li><a href=\"#\" onclick=dispPagetable(" + i + ") >"+i+"</a></li>";
}
if(isPreviousNextLinksRequired(maxNoOfPages)){
pageNosToDisplay = previous(pageNosToDisplay,currentPageNo);
pageNosToDisplay = first(pageNosToDisplay);
pageNosToDisplay = next(pageNosToDisplay,maxNoOfPages,currentPageNo);
pageNosToDisplay = last(pageNosToDisplay,maxNoOfPages);
}
document.getElementById('leftPagingTextTop').innerHTML = "Displaying Page "+currentPageNo+" of "+maxNoOfPages+" <a href=\"#\" onclick=\"showAlltable()\" title=\"Show all\">Show all</a>";
document.getElementById('pagingTop').innerHTML = pageNosToDisplay;
document.getElementById('leftPagingTextBottom').innerHTML = "Displaying Page "+currentPageNo+" of "+maxNoOfPages+" <a href=\"#\" onclick=\"showAlltable()\" title=\"Show all\">Show all</a>";
document.getElementById('pagingBottom').innerHTML = pageNosToDisplay;
}  
function showAlltable(){
liItem = document.getElementById('list').rows;
for(var i=0; i<liItem.length; i++){
liItem[i].style.display='block';
}
document.getElementById('leftPagingTextTop').innerHTML = "<p></p>";
document.getElementById('pagingTop').innerHTML = "";
document.getElementById('leftPagingTextBottom').innerHTML = "<p></p>";
document.getElementById('pagingBottom').innerHTML = "";
}
/* Social Bookmarks */
function _formChecker(elem,limit,warning){var charsLeft=limit-elem.value.length;warning.innerHTML=charsLeft+" characters left";warning.className="";if(elem.value.length>limit){elem.value=elem.value.substring(0,limit);warning.innerHTML="Max 250 characters";warning.className="warning";elem.scrollTop=elem.scrollHeight-elem.clientHeight}}function formChecker(elem,limit){_formChecker(elem,limit,document.getElementById("warning"))
}
function formCheckerSide(elem,limit){_formChecker(elem,limit,document.getElementById("warning-side"))}
function popUp() {
document.getElementById("popupb").className="popupdisplay";
}
function popUpclose() {
document.getElementById("popupb").className="popupnodisplay";
scroll(0,1);
}
function inputvalues() {
var titler= document.title;
var urlr1= location.href;
var urlr= urlr1.replace(/#/g,"");
document.getElementById("title1").value=titler;
document.getElementById("url1").value=urlr;
return true;
}
function clearmessagecount (){
document.getElementById('warning-side').innerHTML = "";
}
function textonfocus(id,value){
document.getElementById(id).value="";
}
function textonblur(id,value){
if (document.getElementById(id).value.replace(/ /gi, '') == '')
document.getElementById(id).value = value;
}

function AdvancedWebsiteSearch(){
/*var includeText = trim(document.advsearchform.fSearchTerms.value).length;
var excludeText = trim(document.advsearchform.fSearchTermsNot.value).length;
var errorMessage;
var errMesg;
errorcount=0;
if((parseInt(includeText) == 0 && parseInt(excludeText) == 0) && !(advancedSearchChecked()) ){
errorcount= errorcount+1;
errorMessage = "* Please enter a keyword or select a section of the website to refine your search &nbsp;&nbsp;&nbsp;results";
errMesg = "* Please enter a keyword or select a section of the website to refine your search results";
document.getElementById('error_message').innerHTML = errorMessage+'<br>';
document.getElementById('error_message').title = errMesg;
scroll(0,0);
}else{
document.getElementById('error_message').innerHTML = "";
document.getElementById('error_message').title = "";
}
if(errorcount > 0)
    return false;
else 
   submitadvsearch();
   return true;

var searchTerm = document.advsearchform.fSearchTerms.value;
document.advsearchform.wholesite.value='TWwebsite';

if (searchTerm.length == 0 || searchTerm=='Search again') return false;
if (searchTerm.length > 0) document.advsearchform.submit();*/


}

/**** For Search Functionality for the section search******/

function submitsearch(){
	var searchTerm = document.getElementById("SectionSearchTerms").value;
	//document.secsearch.wholesite.value='TWwebsite';

	if (searchTerm.length == 0 || searchTerm=='Search this section') 
		return false;
	if (searchTerm.length > 0) document.secsearch.submit();
}

/*****Search Functionality Ends *****/

/*** Function for main site search field ***/
function submitMainSearch(){
	var searchTerm = document.getElementById("fSearchTerms").value;
	//document.testform.wholesite.value='TWwebsite';

	if (searchTerm.length == 0 || searchTerm=='Search our website...') 
		return false;
	if (searchTerm.length > 0) document.testform.submit();
}

/* Function for TW Live from homepage */
	function submitTWLiveSearch() {
		var url = "http://www.thameswater.co.uk/thameswaterlive/index.htm?k=";

		var searchterm = "";
		searchterm = document.getElementById('address-search').value;
		url += searchterm;
		window.open(url,"_blank");
		return false;
	}
