
//**********************************************************************

// Postcode Anywhere fuctions
// functions pcaAddressList() & pcaAddressDisplay()
// are defined locally in the code to populate the address controls displaying the data

		var account_code='DIREC11158';
		var license_code='ND62-PE61-DN56-TC69';
		var machine_id='';

		function pcaByPostcodeBegin(thispostcode)
		   {
			  var postcode = thispostcode;
		      var scriptTag = document.getElementById("pcaScriptTag");
		      var headTag = document.getElementsByTagName("head").item(0);
		      var strUrl = "";

		      //document.getElementById("divLoading").style.display = '';

		      //Build the url
		      strUrl = "https://services.postcodeanywhere.co.uk/inline.aspx?";
		      strUrl += "&action=lookup";
		      strUrl += "&type=by_postcode";
		      strUrl += "&postcode=" + escape(postcode);
		      strUrl += "&account_code=" + escape(account_code);
		      strUrl += "&license_code=" + escape(license_code);
		      strUrl += "&machine_id=" + escape(machine_id);
		      strUrl += "&callback=pcaByPostcodeEnd";

		      //Make the request
		      if (scriptTag)
		         {
		            //The following 2 lines perform the same function and should be interchangeable
		            headTag.removeChild(scriptTag);
		            //scriptTag.parentNode.removeChild(scriptTag);
		         }
		      scriptTag = document.createElement("script");
		      scriptTag.src = strUrl
		      scriptTag.type = "text/javascript";
		      scriptTag.id = "pcaScriptTag";
		      headTag.appendChild(scriptTag);
		   }

		function pcaByPostcodeEnd()
		   {
		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		            alert(pcaErrorMessage);
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  alert("Sorry, no matching items found. Please try another postcode.");
		               }
		            else
		               {
							pcaAddressList()
		               }
		         }
		   }

		function pcaFetchBegin(thisaddressid)
		   {
			  var address_id = thisaddressid;
		      var scriptTag = document.getElementById("pcaScriptTag");
		      var headTag = document.getElementsByTagName("head").item(0);
		      var strUrl = "";

		      //Build the url
		      strUrl = "https://services.postcodeanywhere.co.uk/inline.aspx?";
		      strUrl += "&action=fetch";
		      strUrl += "&id=" + escape(address_id);
		      strUrl += "&account_code=" + escape(account_code);
		      strUrl += "&license_code=" + escape(license_code);
		      strUrl += "&machine_id=" + escape(machine_id);
		      strUrl += "&callback=pcaFetchEnd";

		      //Make the request
		      if (scriptTag)
		         {
		            //The following 2 lines perform the same function and should be interchangeable
		            headTag.removeChild(scriptTag);
		            //scriptTag.parentNode.removeChild(scriptTag);
		         }
		      scriptTag = document.createElement("script");
		      scriptTag.src = strUrl
		      scriptTag.type = "text/javascript";
		      scriptTag.id = "pcaScriptTag";
		      headTag.appendChild(scriptTag);

		      //selectaddress.style.display = 'none';
		      //btnFetch.style.display = 'none';
		   }

		function pcaFetchEnd()
		   {
		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		            alert(pcaErrorMessage);
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  alert("Sorry, no matching items found");
		               }
		            else
		               {
							pcaAddressDisplay()
		               }
		         }
		   }

//**********************************************************************


     // JavaScript Functions Written by:
     //    Scott Mitchell
     //    mitchell@4guysfromrolla.com
     //    http://www.4GuysFromRolla.com



function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);
	
	//Make sure decimal point and trailing zeros are there
	var iDec = tmpNumStr.indexOf(".");
		if (iDec < 0)
			tmpNumStr = tmpNumStr + ".00"
		else
			if((tmpNumStr.length-iDec)<3)
				tmpNumStr = tmpNumStr + "0"
				

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}
	

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}


//========================================================================

function FormatPercent(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num*100,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf(")") != -1) {
		// We know we have a negative number, so place '%' inside of ')'
		tmpStr = tmpStr.substring(0,tmpStr.length - 1) + "%)";
		return tmpStr;
	}
	else
		return tmpStr + "%";			// Return formatted string!
}


//========================================================================


function FormatCurrency(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));

	if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
		// We know we have a negative number, so place '$' inside of '(' / after '-'
		if (tmpStr.charAt(0) == "(")
			tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
		else if (tmpStr.charAt(0) == "-")
			tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
			
		return tmpStr;
	}
	else
		return "$" + tmpStr;		// Return formatted string!
}


//========================================================================

function FormatDateTime(datetime, FormatType)
/*
	 FomatType takes the following values
		1 - General Date = Friday, October 30, 1998
		2 - Typical Date = 10/30/98
		3 - Standard Time = 6:31 PM
		4 - Military Time = 18:31
*/
{
	var strDate = new String(datetime);

	if (strDate.toUpperCase() == "NOW") {
		var myDate = new Date();
		strDate = String(myDate);
	} else {
		var myDate = new Date(datetime);
		strDate = String(myDate);
	}


	// Get the date variable parts
	var Day = new String(strDate.substring(0,3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";	
	
	var Month = new String(strDate.substring(4,7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = "1"; }
	if (Month == "Feb") { Month = "February"; MonthNumber = "2"; }
	if (Month == "Mar") { Month = "March"; MonthNumber = "3"; }
	if (Month == "Apr") { Month = "April"; MonthNumber = "4"; }
	if (Month == "May") { Month = "May"; MonthNumber = "5"; }
	if (Month == "Jun") { Month = "June"; MonthNumber = "6"; }
	if (Month == "Jul") { Month = "July"; MonthNumber = "7"; }
	if (Month == "Aug") { Month = "August"; MonthNumber = "8"; }
	if (Month == "Sep") { Month = "September"; MonthNumber = "9"; }
	if (Month == "Oct") { Month = "October"; MonthNumber = "10"; }
	if (Month == "Nov") { Month = "November"; MonthNumber = "11"; }
	if (Month == "Dec") { Month = "December"; MonthNumber = "12"; }
	
	var curPos = 11;
	var MonthDay = new String(strDate.substring(8,10));
	if (FormatType == 5)
	{
		if (MonthDay.charAt(1) == " ")
		{
			MonthDay = MonthDay.charAt(0);
		}
	}
	else
	{
		if (MonthDay.charAt(1) == " ")
		{
			MonthDay = "0" + MonthDay.charAt(0);
			curPos--;
		}
	}
		
	var MilitaryTime = new String(strDate.substring(curPos,curPos + 5));
	
	var Year = new String(strDate.substring(strDate.length - 4, strDate.length));	
	
	//document.write(strDate + "");	

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 5)
		strDate = MonthDay + "/" + MonthNumber + "/" + Year;
	else if (FormatType == 3) {
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else {
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
				strDate = MilitaryTime + AMPM;
		}
	}	
	else if (FormatType == 4)
		strDate = MilitaryTime;


	return strDate;
}

//==================================================================
        function LTrim(str)
        /***
                PURPOSE: Remove leading blanks from our string.
                IN: str - the string we want to LTrim

                RETVAL: An LTrimmed string!
        ***/
        {
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(0)) != -1) {
                    // We have a string with leading blank(s)...

                    var j=0, i = s.length;

                    // Iterate from the far left of string until we
                    // don't have any more whitespace...
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;


                    // Get the substring from the first non-whitespace
                    // character to the end of the string...
                    s = s.substring(j, i);
                }

                return s;
        }

 //==================================================================
        function RTrim(str)
        /***
                PURPOSE: Remove trailing blanks from our string.
                IN: str - the string we want to RTrim

                RETVAL: An RTrimmed string!
        ***/
        {
                // We don't want to trip JUST spaces, but also tabs,
                // line feeds, etc.  Add anything else you want to
                // "trim" here in Whitespace
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                    // We have a string with trailing blank(s)...

                    var i = s.length - 1;       // Get length of string

                    // Iterate from the far right of string until we
                    // don't have any more whitespace...
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;


                    // Get the substring from the front of the string to
                    // where the last non-whitespace character is...
                    s = s.substring(0, i+1);
                }

                return s;
        }

//=============================================================
        function Trim(str)
        /***
                PURPOSE: Remove trailing and leading blanks from our string.
                IN: str - the string we want to Trim

                RETVAL: A Trimmed string!
        ***/
        {
                return RTrim(LTrim(str));
        }


 //===========================================================

        function Len(str)
        /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
        {  return String(str).length;  }


 //========================================================================

        function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }

 
// ========================================================================

        function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

//============================================================================

        function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }


// Keep in mind that strings in JavaScript are zero-based, so if you ask
// for Mid("Hello",1,1), you will get "e", not "H".  To get "H", you would
// simply type in Mid("Hello",0,1)

// You can alter the above function so that the string is one-based.  Just
// check to make sure start is not <= 0, alter the iEnd = start + len to
// iEnd = (start - 1) + len, and in your final return statement, just
// return ...substring(start-1,iEnd)


//========================================================================

// InStr function written by: Steve Bamelis - steve.bamelis@pandora.be

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}

//========================================================================


function getDimensions() {
var Dimensions = "";
// Get the dimensions; IE uses document.body.clientWidth/Height 
// and Netscape (all versions) as well as Opera use window.innerWidth/Height 
if ((navigator.userAgent.indexOf('MSIE') > -1) && (navigator.userAgent.indexOf('Opera') == -1)) {
Dimensions = document.body.clientWidth + " x " + document.body.clientHeight;
} else {
Dimensions = window.innerWidth + " x " + window.innerHeight;
}
// Get the current resolution, which is a browser independant value
var ScreenRes = screen.width + " x " + screen.height;
// Return the dimensions
return "Screen:" + ScreenRes + "\nAvailable:" + Dimensions;
}


//========================================================================


function availableWidth() {
var Width = "";
// Get the dimensions; IE uses document.body.clientWidth/Height 
// and Netscape (all versions) as well as Opera use window.innerWidth/Height 
if ((navigator.userAgent.indexOf('MSIE') > -1) && (navigator.userAgent.indexOf('Opera') == -1)) {
Width = parent.product.document.body.clientWidth;
} else {
Width = parent.product.window.innerWidth;
}
// Return the width
return Width;
}

//========================================================================


function availableHeight() {
var Height = "";
// Get the dimensions; IE uses document.body.clientWidth/Height 
// and Netscape (all versions) as well as Opera use window.innerWidth/Height 
if ((navigator.userAgent.indexOf('MSIE') > -1) && (navigator.userAgent.indexOf('Opera') == -1)) {
Height = parent.product.document.body.clientHeight;
} else {
Height = parent.product.window.innerHeight;
}
// Return the height
return Height;
}

//========================================================================

function openAWindow( pageToLoad, winName, full, width, height, center, tools, menus, resize) {
window.focus(winName);

	    xposition=0; yposition=0;
	    if (parseInt(navigator.appVersion) >= 4 )
	    {
	    	if (full)
	    	{
	      	width = screen.availWidth;
	      	height = screen.availHeight;
	    	}
	    
	    	else
	    	{
	    	if (center)
	    		{
			xposition = (screen.width - width) / 2;
	        	yposition = (screen.height - height) / 2;
	        	}
	    	}
	    }
	    else
	    {
	    	if (full)
	    	{
	    	width=640;
	    	height=480;
	    	}
	    }
	    
	    args = "width=" + width + ","
	    + "height=" + height + ","
	    + "location=0,"
	    + "menubar=" + menus +","
	    + "resizable=" + resize + ","
	    + "scrollbars=1,"
	    + "status=0,"
	    + "titlebar=0,"
	    + "toolbar=" + tools + ","
	    + "hotkeys=0,"
	    + "screenx=" + xposition + ","  //NN Only
	    + "screeny=" + yposition + ","  //NN Only
	    + "left=" + xposition + ","     //IE Only
	    + "top=" + yposition;           //IE Only
	    return(window.open( pageToLoad,winName,args));
}

//========================================================================

function openLandscapeWindow(targeturl,winname)
{
width = 1200
height = 800

xwin=window.open(targeturl,winname)

if (window.screen) {
	if (width > screen.availWidth) width = screen.availWidth-40
	if (height > screen.availHeight) height = screen.availHeight-40
}

if (window.screen) {
	xwin.moveTo(20,20);
	xwin.resizeTo(width,height)
}
setTimeout('xwin.focus();',250);
return xwin;
}

//========================================================================

function openPortraitWindow(targeturl,winname)
{

width = 800
height = 760

xwin=window.open(targeturl,winname)

if (window.screen) {
	if (width > screen.availWidth) width = screen.availWidth-40
	if (height > screen.availHeight) height = screen.availHeight-40
}

if (window.screen) {
	xwin.moveTo((screen.availWidth-800)/2,10);
	xwin.resizeTo(width,height)
  }
setTimeout('xwin.focus();',250);
return xwin;
}

//========================================================================

function printWindow(page)
{
	if (parseInt(navigator.appVersion) >= 4 )
	{
	      	width = screen.availWidth*0.9;
	      	height = screen.availHeight*0.6;

  	printWin=openAWindow(page,'printWin',0,width,height,1,0,0,1)
  	}
  	else
  	{
  	alert("Unable to provide Print facility -- use Print from File menu")
  	}
}

//========================================================================

function noclick()
{
       return false;
}

//========================================================================

function CursorWait()
{
                var Els = document.all;
                var noEls = Els.length;
 		var totalForms = document.forms.length;
 			    
                for ( var i = 0 ; i < noEls ; i++ )
                {
                        with (Els[i])
                        {
                                onclick = noclick;
                                style.cursor = "wait";
                        }
                }

		for ( var curFrm = 0; curFrm < totalForms; curFrm ++ )
		{
 			var e = document.forms[ curFrm ].elements;

			for ( var i = 0; i < e.length; i++ )
			{
				//e[i].disabled = true;
                        	e[i].style.cursor = "wait";
                        }

		}
		IframeCursorWait(document.frames)
}

//========================================================================
function FrameCursorWait(thisframe)
{
                var Els = thisframe.document.all;
                var noEls = Els.length;
 		var totalForms = thisframe.document.forms.length;
 			    
                for ( var i = 0 ; i < noEls ; i++ )
                {
                        with (Els[i])
                        {
                                onclick = noclick;
                                style.cursor = "wait";
                        }
                }

		for ( var curFrm = 0; curFrm < totalForms; curFrm ++ )
		{
 			var e = thisframe.document.forms[ curFrm ].elements;

			for ( var i = 0; i < e.length; i++ )
			{
				//e[i].disabled = true;
                        	e[i].style.cursor = "wait";
                        }

		}
		IframeCursorWait(thisframe.document.frames)
}

//========================================================================

function IframeCursorWait(frm)
{

//alert("totalFrames " + frm.length);

//var totalForms,frmchild,totalChildFrames,Els,noEls;

for (var cf=0; cf < frm.length; cf++)
	{
	//alert("cf " + cf);
	var totalForms = frm(cf).document.forms.length
	var frmchild = frm(cf).document.frames
	var totalChildFrames = frmchild.length
  	var Els = frm(cf).document.all;
        var noEls = Els.length;
        
    //alert(frm(cf).name);
    //alert(frm(cf).location);
    //alert("totalForms " + totalForms);
    //alert("totalChildFrames " + totalChildFrames);
    //alert("noEls " + noEls);
    
                for ( var i = 0 ; i < noEls ; i++ )
                {
                        with (Els[i])
                        {
                                onclick = noclick;
                                style.cursor = "wait";
                        }
                }
		for ( var curForm = 0; curForm < totalForms; curForm ++ )
		{
 			var e = frm(cf).document.forms[ curForm ].elements;

			for ( var i = 0; i < e.length; i++ )
			{
				//e[i].disabled = true;
                        	e[i].style.cursor = "wait";
                        }

		}
		x=IframeCursorWait(frmchild)
		//alert(x)
	}
return("returned");
}

//========================================================================

function AltWait()
{
    document.body.onclick = noclick;
    document.styleSheets[0].addRule ( "*", "cursor:wait" );
    var totalForms = document.forms.length;
    for ( var curFrm = 0; curFrm < totalForms; curFrm ++ )
    {
        var e = document.forms[ curFrm ].elements;
        for ( var i = 0; i < e.length; i++ )
            e[i].onclick = noclick;
    }
}

//========================================================================

function changeDisplay( elementId, setTo ) {
	if( document.getElementById ) { var theElement = document.getElementById( elementId ); } else {
		if( document.all ) { var theElement = document.all[ elementId ]; } else { var theElement = new Object(); } }
	if( !theElement ) { return; }
	if( theElement.style ) { theElement = theElement.style; }
	if( typeof( theElement.display ) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ) { window.alert( 'Nothing works in this browser.' ); return; }
	theElement.display = setTo;
}

//========================================================================

function changeDisplayInFrame( elementId, setTo, thisframe ) {
//alert("hello");
//alert(thisframe.name);
	if( document.getElementById ) { var theElement = thisframe.document.getElementById( elementId ); } else {
		if( document.all ) { var theElement = thisframe.document.all[ elementId ]; } else { var theElement = new Object(); } }
	if( !theElement ) { return; }
	if( theElement.style ) { theElement = theElement.style; }
	if( typeof( theElement.display ) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ) { window.alert( 'Nothing works in this browser.' ); return; }
	theElement.display = setTo;
}

//========================================================================

function delayNow(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 

//========================================================================

function alertSize() {
  var myWidth = 0, myHeight = 0;
  alert("Hello Mum")
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

//========================================================================

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

//========================================================================

//Give the function an amount and it will return that amount rounded to the nearest hundredth
//and with two digits following a decimal point.

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

//========================================================================

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
// end of function CommaFormatted()


//**********************************************************
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

//**********************************************************
function isUKDate(dtStr,promptStr){
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var preStr = ""
	strYr=strYear

	if (!isWhitespace(promptStr)) preStr = promptStr + "\n\n"

	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert(preStr + "The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert(preStr + "Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert(preStr + "Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(preStr + "Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert(preStr + "Please enter a valid date")
		return false
	}
return true
}

//**********************************************************



