/*
* sendto 
*  - function e-mail hiding. stops email address harvesters collecting e-mails by hiding
*     the address in this java code.
*  - param's 
*     name       - name to left of @
*     domain name - domain name address from @ to first .
*     dot        - the final bit of email address bit after first dot
*     comment    - this is the text displayed on the web page
*     class name  - if required set to the class name to use for the link
*     extension  - main to extension ie subject and body must be the complete string to append to the mailto
*                    eg ?Subject='Support Request'&amp;Body='drear Joe,'
*
*	eg sendto('fred','lasa','co.uk','e-mail support', 'links', 'email_link','?Subject='Support Request'&amp;Body='drear Joe,'');
*         will send an e-mail to fred@lasa.co.uk
*/
function sendto (name, domainname, dot, comment, classname, extension)
{
	address = name+"@"+domainname+"."+dot+extension;	
	document.write("<a href=");
	document.write("\"mail"+"to"+":"+address+"\" ");
	document.write("title=\"mail to "+address+"\" "); 
	if (classname !== "")
	   {document.write(" class=\""+classname+"\"");}
	document.write(">"+comment+"</a>");
}
/*
* amazonBook 
*  - function 	add a bbok image and link to amazon.co.uk to buy the given book
*  - param's 
*     bookId     - the id of the book obtained by looking the book on amazon
*     yourId     - your amazon affeliet Id
*     book       - true to indicate the inclusion of the front cover
*     description- text description to be added, as alt to image of front cover and for the text link
*
function amazonBook( bookId, youtId, book, description)
{
	if (book) {
		document.write(" <a href='http://www.amazon.co.uk/exec/obidos/ASIN/" + bookId + "/" + yourId + "'>")
		document.write("<img border='0' src='51OJn4NOMnL._SL160_.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=lasadevelopme-21&l=as2&o=2&a=0814479928" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />

	}
	address = name+"@"+domainname+"."+dot+extension;	
	document.write("<a href=");
	document.write("\"mail"+"to"+":"+address+"\" ");
	document.write("title=\"mail to "+address+"\" "); 
	if (classname !== "")
	   {document.write(" class=\""+classname+"\"");}
	document.write(">"+comment+"</a>");
}
*/
function targetBlank (url) {
	blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

function targetArticle (url) {
	try {
		blankWin = window.open(url,'Article','menubar=no,toolbar=no,location=no,directories=no,fullscreen=no,height=700,width=730,top=100, left=100, titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
		blankWin.focus();
	}
	catch(err)
	  {
	  txt="There was an error on this page.\n\n";
	  txt+="Error description: " + err.description + "\n\n";
	  txt+="Click OK to continue.\n\n";
	  alert(txt);
	  }

}

/*
* findLivePageWidth
*  function to return effective usable area inside the browser
*/
/*function findLivePageWidth() {

  	dojo.require("dijit.dijit");

	var aw = dijit.getViewport();
	var myWidth = aw['w'];
	return myWidth;
} 


function setWidth (id, MaxWidth)
{
	if (actWidth > MaxWidth) {
	 	MWidth = MaxWidth;
	}  else {
		MWidth = actWidth;
	}
	var 	element = dojo.byId(id);
	element.style.width = MWidth ;
}
*/

var maxWidth = 1022; /* maximum width of our page = width of header image */
var minWidth = 720;
var preWidth = 0;	/* width last viewed */
var actWidth;
var hdRatio = 222 / maxWidth;
var fontRatio = 16 / maxWidth;
var sideInc = 15;	/* increment to add to side bar top padding to make fit with header */
var spacerInc = 0;/* increment to add to middle spacer top padding to make fit with header */
var minFont = 12; 	/* minimum font size */

function OnresizeFixwidth ()
{
	try {
		actWidth = findLivePageWidth();
		/* work out the new width */
	  	if (actWidth > maxWidth) {
			newWidth = maxWidth;
	   	}  else {
	   		newWidth = actWidth;
	   	}
	  	if (newWidth < minWidth) {
			newWidth = minWidth;
	   	}  
		diff = newWidth - preWidth;
		if (diff <0) {diff = -diff;}
		if (diff >20 && !(newWidth > maxWidth && preWidth > maxWidth)) {
			/* change big anough and not both over max so modify sizes */
			preWidth = actWidth;
			headerHeight = newWidth * hdRatio;
			fntSize = newWidth * fontRatio;		
			if (fntSize <minFont) {fntSize = minFont;}
			element = document.body;
			element.style.fontSize = fntSize+"px";
			element = dojo.byId('header');
			element.style.width = newWidth+"px";
			element = dojo.byId('middlewrap');
			element.style.width = newWidth + "px";
			element = dojo.byId('middle');
			element.style.width = newWidth + "px";
			element = dojo.byId('sidewrap');
			element.style.paddingTop = headerHeight+sideInc+"px";
			element = dojo.byId('spacer');
			element.style.height = headerHeight+spacerInc+"px";
			
		}
	}
	catch(err)
  {
  txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.description + "\n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
  }
}
/*
* findLivePageWidth
*  function to return effective usable area inside the browser
*/
function findLivePageWidth() {
fred = window.innerWidth;
if (fred !== null & fred !== undefined) {
  return fred;
}

fred = document.body.clientWidth;
if (fred !== null & fred !== undefined) {
  return fred;
}

return (0);
} 

/*
	try {
		actWidth = findLivePageWidth();
		document.write('<link rel="stylesheet" href="/getStyles.php?width=' + actWidth + '" type="text/css">')
	}
	catch (err)
	  {
	  txt="There was an error on this page.\n\n";
	  txt+="Error description: " + err.description + "\n\n";
	  txt+="Click OK to continue.\n\n";
	  alert(txt);
	  }
*/
/*
dojo.addOnLoad(function(){ 
	OnresizeFixwidth();
})

dojo.connect(window, 'onresize', OnresizeFixwidth);

*/
/* ************************* ANCHORS ********************* */


var headerOffset = 240; // offset required to account for the header

 function scrollToAnchor(id){ 
	dojo.require("dijit.dijit");
 	node = dojo.byId(id);
	if (node) {
		var viewport = dijit.getViewport();
		var off = viewport['t']; // get current scroll position
		var cord = dojo.coords(node, true);
		var y = cord['y'];
		var isIe = dojo.isIE;
		if (isIe && isIe <= 6 ) {
			return true;
		}
		else {
			window.scrollBy(0, y - headerOffset - off);
			return false;
		}
	}
}


 function anchorEvent(href){ 
 	if (href) {
		var parts = href.split('#')
		return scrollToAnchor(parts[1]);
	}
	return(true);
}

dojo.addOnLoad(function(){
	
	var here = location.href;
	var callParts = here.split('#');
	here = callParts[0];
	
	if (callParts[1] ) {
		scrollToAnchor(callParts[1]);
	}

})
dojo.addOnLoad(function(){
    setTimeout(function(){
      dojo.require("dojox.analytics.Urchin")
      dojo.addOnLoad(function(){
        var tracker = new dojox.analytics.Urchin({
          acct: "UA-8713054-1" // your tracking # here
        })
      })
    }, 100)
  })

