// JavaScript Document

// Code to enable routing of pdf files through to a new window to enable pdf conversion tracking
// MN Dec 2007
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function extractFileName(fullPath)
{
  var lastSlash // the position of the last slash in the path
  var fileName  // the name of the file
  lastSlash = fullPath.lastIndexOf("/")
  fileName = fullPath.substring(lastSlash+1,fullPath.length)
  return fileName
}


// ************************************* //
// **  PDF tracking for BUILDER       ** //
// ************************************* //
function pdfredirect () 
{ 
	setTimeout("pdfgo_now()",10000); 
}

function pdfgo_now ()   
{ 
	var pdffile = 'http://www.nhbcbuilder.co.uk/' + gup("pdf")
	window.location.href = pdffile; 
}
// to trigger redirect on builder - need to run the following on the page:
// <script>pdfredirect();



function fPDFWindow ()  
{  
	if (!document.getElementsByTagName) 
	{
		return false;
	}
	var tmp ="";
	var links = document.getElementsByTagName("a");
	for (var eleLink=0; eleLink < links.length; eleLink ++) {  
		if (links[eleLink].href.indexOf('.pdf') !== -1) {  
			links[eleLink].onclick =  function() {  
					window.open('http://www.nhbcbuilder.co.uk/pdfdownload/?pdf=' + this.href.substring(29),'DownloadPDFWindow','resizable,scrollbars');  					
					return false;  
				}		
		}
	}
		
}   


function addLoadEvent(func)
{
var oldonload = window.onload;
if (typeof window.onload != 'function') 
	{ 
	window.onload = func; 
	} 
	else 
	{ 
	window.onload = function() { oldonload(); func(); } } 
}

// to trigger pdf tracking on builder - need to run the following on the page:
// <script>addLoadEvent(fPDFWindow);

// ************************************* //
// **  PDF tracking for CORPORATE     ** //
// ************************************* //

function pdfredirect_c () 
{ 
	setTimeout("pdfgo_now_c()",10000); 
}

function pdfgo_now_c ()   
{ 
	var pdffile = 'http://www.nhbc.co.uk/' + gup("pdf")
	window.location.href = pdffile; 
}
// to trigger redirect on corporate - need to run the following on the page:
// <script>pdfredirect_c();



function fPDFWindow_c ()  
{  
	if (!document.getElementsByTagName) 
	{
		return false;
	}
	var tmp ="";
	var links = document.getElementsByTagName("a");
	for (var eleLink=0; eleLink < links.length; eleLink ++) {  
		if (links[eleLink].href.indexOf('.pdf') !== -1) {  
			links[eleLink].onclick =  function() {  
					window.open('http://www.nhbc.co.uk/pdfdownload/?pdf=' + this.href.substring(29),'DownloadPDFWindow','resizable,scrollbars');  					
					return false;  
				}		
		}
	}
		
}   

// to trigger pdf tracking on corporate - need to run the following on the page:
// <script>addLoadEvent(fPDFWindow_c);
