// JavaScript Document


function DollarFormat(num) {

	var num = num.toString().replace(/\$|\,/g,'');

	num = num.toString().replace('(','-');

	num = num.toString().replace(')','');

	if(isNaN(num)){

		num = "0";

	}

	var	sign = (num == (num = Math.abs(num)));

		num = Math.floor(num*100+0.50000000001);

	var	cents = num%100;

		num = Math.floor(num/100).toString();

	

	if(cents < 10){

		cents = "0" + cents;

	}

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++){

		num = num.substring(0,num.length-(4*i+3))+','+

		num.substring(num.length-(4*i+3));

	}

	return (((sign)?'':'(') + '$' + num + '.' + cents + ((sign)?'':')'));

}


/* 



MORTGAGE LOAN CALCULATOR



COPYRIGHT NOTICE



Copyright 1997, 1998 Steven D. Witkop (Qube@ix.netcom.com)  All Rights Reserved.



This Javascript "Mortgage Loan calculator" Script  may be used and modified free of charge by anyone

so long as this copyright notice and the comments above remain intact.  By using this code you agree

to indemnify Steven D. Witkop from any liability that  might arise from it's use.



Selling the code for this program without prior written consent is expressly forbidden.  In other

words, please ask first before you try and  make money off of my program.



Obtain permission before redistributing this software over the Internet or in any other medium.

In all cases copyright and header must remain intact



LANGUAGE: JavaScript 1.1 compliant



PATTERN: MVC

  

 Modified by Randy Anderson 2005

 - Added call to DollarFormat function (in globalFunctions.js) which provides better output formatting

 - Removed font tags and restyled amort window

 - Added a condition to the makenumber function to return number passed as-is if its already a number

 - Added FSMC style sheet reference and print button to amort window

 - Changed text with alert if required fields are not filled in



*/



// initilize page variables

window.onerror=null

var bState = true;

var rec = 0;

var oTable = new Array();



// the colors for the amortization table... you will need to search and replace on these codes for the HTML form.

var bColor = '#FFFFFF' // white

var fColor = '#004000' //green

var gColor = '#CB301F' //red

// var fColor = '#CB301F' // red



// var bColor = 'WHITE'  // '#FFFFFF'

// var fColor = 'PURPLE' // '#000080'





// names for the collections (used for form validation)

oReq = new Collection("AMOUNT","RATE","","","","")

oVal = new Collection("AMOUNT","RATE","","","","")

oTst = new Collection("N","N","","","","")





//============================================================================

// Gets called when the user pressed one of the buttons.

// oForm: 		form elements

// oBtn:  		the name of the button that was pressed

// return value:	did we make it through?

//============================================================================



function controller(oForm, oBtn) {



   while (bState) {



      if (!Required(oForm))



         break;



      if (!Validate(oForm))



         break;



      if (!Create())



         break;



      if (!SetValue(oForm))



         break;



      if (!Amortize(oForm, oBtn))



         break;



      if (bState) {



          bState = false



      }



   }



   bState = true



}







//============================================================================

// Check if a form element is required by comparing the all of the form

// elements against a collection of required form control names.

// oView: 		form elements

// oReq		required elements

// return value:	did it pass the test?

//============================================================================



function Required(oView) {



   for (i in oView ) {



      for (j in oReq) {



          if (i == oReq[j]) {



             if (isMissing(oView[i])) {



               return(false)



             }



          }



      }



  }



  return(true)



}







//============================================================================

// Check if a form control is required and missing

// oView: 		a form control

// Return value:	do we have a problem?

//============================================================================



function isMissing(oCtrl) {



   if (oCtrl.value == "") {



      alert("Please enter a Mortgage Amount and Interest Rate");



      oCtrl.focus();



      oCtrl.select();



      return(true)



      }



   else



      {



      return(false)



   }



}







//============================================================================

// Check if a form element inputs need to be a certain type by

// comparing all of the form elements against a collection of

// form controls that need specific types of input data.

// oView: 		form elements

// oReq		required elements

// return value:	did it pass the test?

//============================================================================



function Validate(oView) {



   for (i in oView) {



      for (j in oVal) {



        if (i==oVal[j] && oTst[j]=="N") {



           if (isTest(oView[i], oTst[j])) {



               return(false)



           }



        }



     }



  }



  return(true)



}







//============================================================================

// Check if a form control input is the right type

// oView: 		a form control

// Return value:	do we have a problem?

//============================================================================



function isTest(oCtrl, oTest) {



   if (oTest=="N" && !isNumber(oCtrl.value) ) {



      alert(oCtrl.value+" contains an invalid character. Please type a number");



      oCtrl.focus();



      oCtrl.select();



      return(true)



      }



      else



      {



      return(false)



   }



}







//============================================================================

// Check if the result is a number

// input: 		a texbox value

// Return value:	true / false

//============================================================================



function isNumber(input) {



var result = ""



var nperiods = 0;



   for (var i=0;i<input.length;i++) {



      var ch = input.substring(i, i+1);



      if (!isNaN(parseInt(ch))) {



         result = result + ch



      }



      if (ch==".") {



        nperiods++;



      }



      if (nperiods==1){



         result = result + ch



      }



   }



   if (result == ""){



     return(false);



   }



return(true)



}







//============================================================================

// Make a string input into a number

// input: 		a texbox value

// Return value:	a number

//============================================================================



function makeNumber(input) {



var result = ""



var nperiods = 0;



   for (var i=0;i<input.length;i++) {



       var ch = input.substring(i, i+1);



       var flag = true;



       if (!isNaN(parseInt(ch))) {



          result = result + ch



       }



       if (ch==".") {



         nperiods++;



       }



       if (nperiods==1){



          result = result + ch



       }



     }

	 

	 // added this because values like 5.5 were being changed to bizare 5.1155 and causing inaccurate results

	 if (!isNaN(input)){

	 	

		result = input;

	 

	 }



  return(result)



}





//============================================================================

// Create a default instance of the object

// parm1:	Amount	- required

// parm2:	Rate		- required

// parm3:   	Term		- required

// parm4:	Payment

// parm5:	Interest

// parm6:	Frequency	- required

// parm7:	Periods

// return value:	did we create the oebject?

//============================================================================



function Create() {



   Mortgage = new Loan(50000, 8, 30, 0, 0, "Monthly", 0 );



   return(true)



}





//============================================================================

// Set the properties of the object based on form inputs

// oView: 		form elements

// return value:	did it get and set the properties?

//============================================================================



function SetValue(oView) {



   // get the properties mapped from the form



   Mortgage.Amount = makeNumber(oView.AMOUNT.value);



   // works like a masked edit

   oView.AMOUNT.value = calcRound(Mortgage.Amount);



   Mortgage.Rate = makeNumber(oView.RATE.value);



   Mortgage.Term = get_selection(oView.YEARS);



   Mortgage.Frequency = get_selection(oView.FREQUENCY);



   // set the number of periods

   Mortgage.calcPeriods();



   // set the monthly payment

   Mortgage.calcPayment();



   // set the total interest due

   Mortgage.calcInterest();



   // update the form view

   Show()



   return(true)



}





//============================================================================

// Amortize is called at the end of the controler loop and checks to see

// if the amortize button was pushed

// oForm: 		form elements

// oBtn:  		the name of the button that was pressed

// return value:	did we select the Amortize button?

//============================================================================



function Amortize(oForm, oBtn) {



   if (oBtn.name == "cmdCalc") {



      return(false)



   }



   if (confirm("An Amortization Table calculates the periodic payment breakdown for each specific category listed.")) {



      // need to create the table before you can show it

      createRecords();



      // display the table

      showAmortize(oForm);



      return(true)



    }



  return(false)



}







//============================================================================

// create Records computes the values associated with the Amortzation of a Mortgage Loan and

// adds those values to a record in the Amortization table container array

// return value:	did we calculate all values to display in the Amortization?

//============================================================================



function createRecords(){



   // re-init the record counter and container array

   rec = 0;



   oTable = new Array();



   // initialize variables

   var currInt = 0;



   var currPrin = 0;



   prevBalance = Mortgage.Amount;



   InterestRate = ( Mortgage.Rate / 100) / Mortgage.Periods;



   MonthlyPayment = Mortgage.Payment;



   //currStart = '2000';

   currStart = get_selection(document.MORTGAGE.START);



   // let the loops begin

   for(i=1;i<=30;i++) {



      for(j=1;j<=Mortgage.Periods;j++) {



         periodInt = prevBalance * InterestRate;



         periodPrin = MonthlyPayment - periodInt;



         currBal = prevBalance - periodPrin;



         currInt += periodInt;



         currPrin += periodPrin;



         prevBalance = currBal;



      }



      if( currBal <= 0 ){



         currBal = 0;



      }







      // set the parameters

      Year = currStart;

      Interest = calcRound(currInt);

      Principle = calcRound(currPrin);

      Balance = calcRound(currBal);



      // increment the container

      rec++



      // add a record to the table

      addRecord(Year, Interest, Principle, Balance);



      // re-init the private variables

      currInt = 0;

      currPrin = 0;

      currStart = parseInt(currStart);

      currStart += 1;



      // are we done?

      if(currBal<=0) {



         return(true)



      }



   }



   return (true)



}



//============================================================================

// Build a text string with a header, the table and a footer in HTML then

// diplay the table in a new window with only the menu active.

// oForm: 		form elements

// return value:	did we display the Amortization?

//============================================================================



function showAmortize(oForm) {



   // create the header



   text = ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n<html>\n<head>\n<title>Amortization Table</title>\n<style type="text/css">@import url("/siteAssets/css/v5.css");</style>\n<style type="text/css">@import url("/siteAssets/css/popup.css");</style>\n<style type="text/css" media="print">@import url("/siteAssets/css/print.css");</style>\n</head>\n\n');



   text = (text +'<body onload="window.focus();">\n');



   text = (text +"<p><strong>Amortization Table</strong></p>\n");



   text = (text +'<div class="printHide"><a href="javascript:window.print();"><img src="/siteAssets/images/button_print.gif" alt="Print" border="0"></a> <a href="javascript:window.close();"><img src="/siteAssets/images/button_close.gif" alt="Close" border="0"></a></div>\n');



   text = (text +"<p><strong>Mortgage Amount:</strong> " + DollarFormat(Mortgage.Amount) + "<br>\n");



   text = (text +"<strong>Interest Rate:</strong> " + Mortgage.Rate + "%<br>\n");



   text = (text +"<strong>Mortgage Length:</strong> " + Mortgage.Term + " Years<br>\n");



   text = (text +"<strong>Payment Frequncy:</strong> " + Mortgage.Frequency + "</p>\n");



   text = (text +'<table id="gridTable">\n');



   text = (text +"<tr>\n<th>Year</th>\n<th>Interest</th>\n<th>Principal</th>\n<th>Balance</th>\n</tr>\n");



   // create the Amortization table text by looping through a CONTAINER ARRAY



   for (var q = 1; q < oTable.length; q++) {



   		rowColor = (q % 2) ? '""' : '"stripe"';

     	text = (text +"<tr class=" + rowColor + ">\n<td>"+ oTable[q].Year +"</td>\n<td>"+ oTable[q].Interest +"</td>\n<td>"+ oTable[q].Principle +"</td>\n<td>"+ oTable[q].Balance +"</td>\n</tr>\n");



   }







   // create the footer



   text = (text +"</table>\n</body>\n</html>");







   // Create a new window to display the results



   oWindow=window.open("","displayWindow","width=580,height=480,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes");



   oWindow.document.write(text);



   oWindow.document.close();







   return(true)



}











//============================================================================

// Collection Constructor, a custom object to act as an array but provide

// more flexibility in the future.

//============================================================================



function Collection(item1, item2, item3, item4, item5, item6) {



   this.item1 = item1;



   this.item2 = item2;



   this.item3 = item3;



   this.item4 = item4;



   this.item5 = item5;



   this.item6 = item6;



}







//============================================================================

// Loan Constructor, defines what the Loan object will look like

// and how it will behave.

//============================================================================



function Loan(Amount, Rate, Term, Payment, Interest, Frequency, Periods ) {



   this.Amount = Amount;



   this.Rate = Rate;



   this.Term = Term;



   this.Payment = Payment;



   this.Interest = Interest;



   this.Frequency = Frequency;



   this.Periods = Periods;



   this.calcPeriods = calcPeriods;



   this.calcPayment = calcPayment;



   this.calcInterest = calcInterest;



}







//============================================================================

// Loan object method that calculates the monthly payment for a mortgage loan in the US

//============================================================================



function calcPayment() {



   this.Payment = (this.Amount*((this.Rate/(1200))/(1-(Math.pow(1+(this.Rate/(1200)),((this.Term*12)*-1))))));







  // handle bi-weekly



  if ( this.Periods == 26 ){



      this.Payment = this.Payment / 2;



   }



}







//============================================================================

// Loan object method that calculates the interest portion of a loan

//============================================================================



function calcInterest() {



   this.Interest = ((this.Payment*(this.Term*this.Periods))-this.Amount);



}







//============================================================================

// Loan object method that translates a selection drop down to a value

//============================================================================



function calcPeriods() {



   if (this.Frequency=="Monthly") { this.Periods=12 } else { this.Periods=26 }



}







//============================================================================

// Loan object method that shows the calculated amounts

//============================================================================



function Show(oView) {



	/* Commented out, returns NaN if the user enters "0", DollarFormat function looks cleaner

   	document.MORTGAGE.PAYMENT.value = calcRound(Mortgage.Payment)

   	document.MORTGAGE.INTEREST.value = calcRound(Mortgage.Interest)

	*/

	

	document.MORTGAGE.PAYMENT.value 	= DollarFormat(Mortgage.Payment);

   	document.MORTGAGE.INTEREST.value 	= DollarFormat(Mortgage.Interest);



}







//============================================================================

// oRecord Constructor, defines what the Amortzation record looks like

//============================================================================



function oRecord(Year, Interest, Principle, Balance){



   this.Year = Year;



   this.Interest = Interest;



   this.Principle = Principle;



   this.Balance = Balance;



}







//============================================================================

// addRecord defines how a record gets added to the container array

//============================================================================



function addRecord(Year, Interest, Principle, Balance){



   oTable[rec] = new oRecord(Year, Interest, Principle, Balance);



}







//============================================================================

// select_item Constructor, used to retrive the selected item from the dropdown

// control on a form.

// name: 		form element name

// value:  		the value of the options that was selected

// return value:	selected item

//============================================================================



function select_item(name, value) {



   this.name = name;



   this.value = value;



}







//============================================================================

// Common routine to retrieve the selected value from the drop down object

// select_object:	a drop down from control

// return value:	the selected objects name

//============================================================================



function get_selection(select_object) {



   contents = new select_item();



   for(var i=0;i<select_object.options.length;i++)



      if(select_object.options[i].selected == true) {



        contents.name = select_object.options[i].text;



        contents.value = select_object.options[i].value;



      }



   return(contents.name)



}







//============================================================================

// Common routine for rounding that also formats the results into US currency

// num: 		a number

// return value:  result is rounded and formated for currency $999,999.00

//============================================================================



function calcRound(num) {



   result="$"+Math.floor(num)+"." ;



   n = result.length;



   if (num>1000 && num<999999) {



     result="$"+result.substring(1,n-4)+","+result.substring(n-4,n);



   }



   if (num>1000000) {



     result = "$"+result.substring(1,n-7)+","+result.substring(n-7,n-4)+","+result.substring(n-4,n);



   }



   var cents=100*(num-Math.floor(num))+0.5;



   result += Math.floor(cents/10);



   result += Math.floor(cents%10);



   return(result)



}











//============================================================================

// A page specific routine to set the initial state when the page is reloaded.

//============================================================================



function setfocus() {



   document.MORTGAGE.AMOUNT.focus();

   document.MORTGAGE.AMOUNT.select();



}



//============================================================================

/* 	

	Name: 			InterestOnlyPayment

	Last Modified:	07/07/2005

	Description: 	Returns the monthly payment for an Interest Only loan

	

	Required variables:

	

		MortgageAmount: 	US currency format or Float (ex $450,000.00)

		InterestRate: 		Float	(ex 7.5)

		

	Dependent Functions:

	

		StripCurrency()		Found in globalFunctions.js

*/

//============================================================================



function InterestOnlyPayment(MortgageAmount, InterestRate) {

	var MortgageAmount	= StripCurrency(MortgageAmount);

	var InterestRate	= InterestRate;

	var AnnualRate  	= InterestRate / 100;

	var MonthlyRate		= AnnualRate / 12;	

	var returnVal		= Math.floor(MortgageAmount * MonthlyRate * 100) / 100;

	return returnVal;

}



function NumberOfPayments(Years){

	var returnVal = Num(Years) * 12;

	return returnVal;

}



function calcIO(){

	var MortgageAmount 	= document.getElementById('MortgageAmount').value;

	var InterestRate	= document.getElementById('InterestRate').value;

	var returnVal 		= InterestOnlyPayment(MortgageAmount, InterestRate);

	document.getElementById('resultPayment').value 	= DollarFormat(returnVal) + ' a month';

}

http://www.google-analytics.com/urchin.js

//-- Google Analytics Urchin Module
//-- Copyright 2005 Google, All Rights Reserved.

//-- Urchin On Demand Settings ONLY
var _uacct="";			// set up the Urchin Account
var _userv=1;			// service mode (0=local,1=remote,2=both)

//-- UTM User Settings
var _ufsc=1;			// set client info flag (1=on|0=off)
var _udn="auto";		// (auto|none|domain) set the domain name for cookies
var _uhash="on";		// (on|off) unique domain hash for cookies
var _utimeout="1800";   	// set the inactive session timeout in seconds
var _ugifpath="/__utm.gif";	// set the web path to the __utm.gif file
var _utsp="|";			// transaction field separator
var _uflash=1;			// set flash version detect option (1=on|0=off)
var _utitle=1;			// set the document title detect option (1=on|0=off)
var _ulink=0;			// enable linker functionality (1=on|0=off)
var _uanchor=0;			// enable use of anchors for campaign (1=on|0=off)

//-- UTM Campaign Tracking Settings
var _uctm=1;			// set campaign tracking module (1=on|0=off)
var _ucto="15768000";		// set timeout in seconds (6 month default)
var _uccn="utm_campaign";	// name
var _ucmd="utm_medium";		// medium (cpc|cpm|link|email|organic)
var _ucsr="utm_source";		// source
var _uctr="utm_term";		// term/keyword
var _ucct="utm_content";	// content
var _ucid="utm_id";		// id number
var _ucno="utm_nooverride";	// don't override

//-- Auto/Organic Sources and Keywords
var _uOsr=new Array();
var _uOkw=new Array();
_uOsr[0]="google";	_uOkw[0]="q";
_uOsr[1]="yahoo";	_uOkw[1]="p";
_uOsr[2]="msn";		_uOkw[2]="q";
_uOsr[3]="aol";		_uOkw[3]="query";
_uOsr[4]="lycos";	_uOkw[4]="query";
_uOsr[5]="ask";		_uOkw[5]="q";
_uOsr[6]="altavista";	_uOkw[6]="q";
_uOsr[7]="search";	_uOkw[7]="q";
_uOsr[8]="netscape";	_uOkw[8]="query";
_uOsr[9]="earthlink";	_uOkw[9]="q";
_uOsr[10]="cnn";	_uOkw[10]="query";
_uOsr[11]="looksmart";	_uOkw[11]="key";
_uOsr[12]="about";	_uOkw[12]="terms";
_uOsr[13]="excite";	_uOkw[13]="qkw";
_uOsr[14]="mamma";	_uOkw[14]="query";
_uOsr[15]="alltheweb";	_uOkw[15]="q";
_uOsr[16]="gigablast";	_uOkw[16]="q";
_uOsr[17]="voila";	_uOkw[17]="kw";
_uOsr[18]="virgilio";	_uOkw[18]="qs";
_uOsr[19]="teoma";	_uOkw[19]="q";

//-- Auto/Organic Keywords to Ignore
var _uOno=new Array();
//_uOno[0]="urchin";
//_uOno[1]="urchin.com";
//_uOno[2]="www.urchin.com";

//-- Referral domains to Ignore
var _uRno=new Array();
//_uRno[0]=".urchin.com";

//-- **** Don't modify below this point ***
var _uff,_udh,_udt,_ubl=0,_udo="",_uu,_ufns=0,_uns=0,_ur="-",_ufno=0,_ust=0,_ubd=document,_udl=_ubd.location,_udlh="",_utcp="/",_uwv="1";
var _ugifpath2="http://www.google-analytics.com/__utm.gif";
if (_udl.hash) _udlh=_udl.href.substring(_udl.href.indexOf('#'));
if (_udl.protocol=="https:") _ugifpath2="https://ssl.google-analytics.com/__utm.gif";
if (!_utcp || _utcp=="") _utcp="/";
function urchinTracker(page) {
 if (_udl.protocol=="file:") return;
 if (_uff && (!page || page=="")) return;
 var a,b,c,v,z,k,x="",s="",f=0;
 var nx=" expires=Sun, 18 Jan 2038 00:00:00 GMT;";
 var dc=_ubd.cookie;
 _udh=_uDomain();
 _uu=Math.round(Math.random()*2147483647);
 _udt=new Date();
 _ust=Math.round(_udt.getTime()/1000);
 a=dc.indexOf("__utma="+_udh);
 b=dc.indexOf("__utmb="+_udh);
 c=dc.indexOf("__utmc="+_udh);
 if (_udn && _udn!="") { _udo=" domain="+_udn+";"; }
 if (_utimeout && _utimeout!="") {
  x=new Date(_udt.getTime()+(_utimeout*1000));
  x=" expires="+x.toGMTString()+";";
 }
 if (_ulink) {
  if (_uanchor && _udlh && _udlh!="") s=_udlh+"&";
  s+=_udl.search;
  if(s && s!="" && s.indexOf("__utma=")>=0) {
   if (!(_uIN(a=_uGC(s,"__utma=","&")))) a="-";
   if (!(_uIN(b=_uGC(s,"__utmb=","&")))) b="-";
   if (!(_uIN(c=_uGC(s,"__utmc=","&")))) c="-";
   v=_uGC(s,"__utmv=","&");
   z=_uGC(s,"__utmz=","&");
   k=_uGC(s,"__utmk=","&");
   if ((k*1) != ((_uHash(a+b+c+z+v)*1)+(_udh*1))) {_ubl=1;a="-";b="-";c="-";z="-";v="-";}
   if (a!="-" && b!="-" && c!="-") f=1;
   else if(a!="-") f=2;
  }
 }
 if(f==1) {
  _ubd.cookie="__utma="+a+"; path="+_utcp+";"+nx+_udo;
  _ubd.cookie="__utmb="+b+"; path="+_utcp+";"+x+_udo;
  _ubd.cookie="__utmc="+c+"; path="+_utcp+";"+_udo;
 } else if (f==2) {
  a=_uFixA(s,"&",_ust);
  _ubd.cookie="__utma="+a+"; path="+_utcp+";"+nx+_udo;
  _ubd.cookie="__utmb="+_udh+"; path="+_utcp+";"+x+_udo;
  _ubd.cookie="__utmc="+_udh+"; path="+_utcp+";"+_udo;
  _ufns=1;
 } else if (a>=0 && b>=0 && c>=0) {
  _ubd.cookie="__utmb="+_udh+"; path="+_utcp+";"+x+_udo;
 } else {
  if (a>=0) a=_uFixA(_ubd.cookie,";",_ust);
  else a=_udh+"."+_uu+"."+_ust+"."+_ust+"."+_ust+".1";
  _ubd.cookie="__utma="+a+"; path="+_utcp+";"+nx+_udo;
  _ubd.cookie="__utmb="+_udh+"; path="+_utcp+";"+x+_udo;
  _ubd.cookie="__utmc="+_udh+"; path="+_utcp+";"+_udo;
  _ufns=1;
 }
 if (_ulink && v && v!="" && v!="-") {
  v=_uUES(v);
  if (v.indexOf(";")==-1) _ubd.cookie="__utmv="+v+"; path="+_utcp+";"+nx+_udo;
 }
 _uInfo(page);
 _ufns=0;
 _ufno=0;
 _uff=1;
}
function _uInfo(page) {
 var p,s="",pg=_udl.pathname+_udl.search;
 if (page && page!="") pg=_uES(page,1);
 _ur=_ubd.referrer;
 if (!_ur || _ur=="") { _ur="-"; }
 else {
  p=_ur.indexOf(_ubd.domain);
  if ((p>=0) && (p<=8)) { _ur="0"; }
  if (_ur.indexOf("[")==0 && _ur.lastIndexOf("]")==(_ur.length-1)) { _ur="-"; }
 }
 s+="&utmn="+_uu;
 if (_ufsc) s+=_uBInfo();
 if (_uctm) s+=_uCInfo();
 if (_utitle && _ubd.title && _ubd.title!="") s+="&utmdt="+_uES(_ubd.title);
 if (_udl.hostname && _udl.hostname!="") s+="&utmhn="+_uES(_udl.hostname);
 s+="&utmr="+_ur;
 s+="&utmp="+pg;
 if (_userv==0 || _userv==2) {
  var i=new Image(1,1);
  i.src=_ugifpath+"?"+"utmwv="+_uwv+s;
  i.onload=function() {_uVoid();}
 }
 if (_userv==1 || _userv==2) {
  var i2=new Image(1,1);
  i2.src=_ugifpath2+"?"+"utmwv="+_uwv+s+"&utmac="+_uacct+"&utmcc="+_uGCS();
  i2.onload=function() { _uVoid(); }
 }
 return;
}
function _uVoid() { return; }
function _uCInfo() {
 if (!_ucto || _ucto=="") { _ucto="15768000"; }
 var c="",t="-",t2="-",t3="-",o=0,cs=0,cn=0,i=0,z="-",s="";
 if (_uanchor && _udlh && _udlh!="") s=_udlh+"&";
 s+=_udl.search;
 var x=new Date(_udt.getTime()+(_ucto*1000));
 var dc=_ubd.cookie;
 x=" expires="+x.toGMTString()+";";
 if (_ulink && !_ubl) {
  z=_uUES(_uGC(s,"__utmz=","&"));
  if (z!="-" && z.indexOf(";")==-1) { _ubd.cookie="__utmz="+z+"; path="+_utcp+";"+x+_udo; return ""; }
 }
 z=dc.indexOf("__utmz="+_udh);
 if (z>-1) { z=_uGC(dc,"__utmz="+_udh,";"); }
 else { z="-"; }
 t=_uGC(s,_ucid+"=","&");
 t2=_uGC(s,_ucsr+"=","&");
 t3=_uGC(s,"gclid=","&");
 if ((t!="-" && t!="") || (t2!="-" && t2!="") || (t3!="-" && t3!="")) {
  if (t!="-" && t!="") c+="utmcid="+_uEC(t);
  if (t2!="-" && t2!="") { if (c != "") c+="|"; c+="utmcsr="+_uEC(t2); }
  if (t3!="-" && t3!="") { if (c != "") c+="|"; c+="utmgclid="+_uEC(t3); }
  t=_uGC(s,_uccn+"=","&");
  if (t!="-" && t!="") c+="|utmccn="+_uEC(t);
  else c+="|utmccn=(not+set)";
  t=_uGC(s,_ucmd+"=","&");
  if (t!="-" && t!="") c+="|utmcmd="+_uEC(t);
  else  c+="|utmcmd=(not+set)";
  t=_uGC(s,_uctr+"=","&");
  if (t!="-" && t!="") c+="|utmctr="+_uEC(t);
  else { t=_uOrg(1); if (t!="-" && t!="") c+="|utmctr="+_uEC(t); }
  t=_uGC(s,_ucct+"=","&");
  if (t!="-" && t!="") c+="|utmcct="+_uEC(t);
  t=_uGC(s,_ucno+"=","&");
  if (t=="1") o=1;
  if (z!="-" && o==1) return "";
 }
 if (c=="-" || c=="") { c=_uOrg(); if (z!="-" && _ufno==1)  return ""; }
 if (c=="-" || c=="") { if (_ufns==1)  c=_uRef(); if (z!="-" && _ufno==1)  return ""; }
 if (c=="-" || c=="") {
  if (z=="-" && _ufns==1) { c="utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)"; }
  if (c=="-" || c=="") return "";
 }
 if (z!="-") {
  i=z.indexOf(".");
  if (i>-1) i=z.indexOf(".",i+1);
  if (i>-1) i=z.indexOf(".",i+1);
  if (i>-1) i=z.indexOf(".",i+1);
  t=z.substring(i+1,z.length);
  if (t.toLowerCase()==c.toLowerCase()) cs=1;
  t=z.substring(0,i);
  if ((i=t.lastIndexOf(".")) > -1) {
   t=t.substring(i+1,t.length);
   cn=(t*1);
  }
 }
 if (cs==0 || _ufns==1) {
  t=_uGC(dc,"__utma="+_udh,";");
  if ((i=t.lastIndexOf(".")) > 9) {
   _uns=t.substring(i+1,t.length);
   _uns=(_uns*1);
  }
  cn++;
  if (_uns==0) _uns=1;
  _ubd.cookie="__utmz="+_udh+"."+_ust+"."+_uns+"."+cn+"."+c+"; path="+_utcp+"; "+x+_udo;
 }
 if (cs==0 || _ufns==1) return "&utmcn=1";
 else return "&utmcr=1";
}
function _uRef() {
 if (_ur=="0" || _ur=="" || _ur=="-") return "";
 var i=0,h,k,n;
 if ((i=_ur.indexOf("://"))<0) return "";
 h=_ur.substring(i+3,_ur.length);
 if (h.indexOf("/") > -1) {
  k=h.substring(h.indexOf("/"),h.length);
  if (k.indexOf("?") > -1) k=k.substring(0,k.indexOf("?"));
  h=h.substring(0,h.indexOf("/"));
 }
 h=h.toLowerCase();
 n=h;
 if ((i=n.indexOf(":")) > -1) n=n.substring(0,i);
 for (var ii=0;ii<_uRno.length;ii++) {
  if ((i=n.indexOf(_uRno[ii].toLowerCase())) > -1 && n.length==(i+_uRno[ii].length)) { _ufno=1; break; }
 }
 if (h.indexOf("www.")==0) h=h.substring(4,h.length);
 return "utmccn=(referral)|utmcsr="+_uEC(h)+"|"+"utmcct="+_uEC(k)+"|utmcmd=referral";
}
function _uOrg(t) {
 if (_ur=="0" || _ur=="" || _ur=="-") return "";
 var i=0,h,k;
 if ((i=_ur.indexOf("://")) < 0) return "";
 h=_ur.substring(i+3,_ur.length);
 if (h.indexOf("/") > -1) {
  h=h.substring(0,h.indexOf("/"));
 }
 for (var ii=0;ii<_uOsr.length;ii++) {
  if (h.toLowerCase().indexOf(_uOsr[ii].toLowerCase()) > -1) {
   if ((i=_ur.indexOf("?"+_uOkw[ii]+"=")) > -1 || (i=_ur.indexOf("&"+_uOkw[ii]+"=")) > -1) {
    k=_ur.substring(i+_uOkw[ii].length+2,_ur.length);
    if ((i=k.indexOf("&")) > -1) k=k.substring(0,i);
    for (var yy=0;yy<_uOno.length;yy++) {
     if (_uOno[yy].toLowerCase()==k.toLowerCase()) { _ufno=1; break; }
    }
    if (t) return _uEC(k);
    else return "utmccn=(organic)|utmcsr="+_uEC(_uOsr[ii])+"|"+"utmctr="+_uEC(k)+"|utmcmd=organic";
   }
  }
 }
 return "";
}
function _uBInfo() {
 var sr="-",sc="-",ul="-",fl="-",je=1;
 var n=navigator;
 if (self.screen) {
  sr=screen.width+"x"+screen.height;
  sc=screen.colorDepth+"-bit";
 } else if (self.java) {
  var j=java.awt.Toolkit.getDefaultToolkit();
  var s=j.getScreenSize();
  sr=s.width+"x"+s.height;
 }
 if (n.language) { ul=n.language.toLowerCase(); }
 else if (n.browserLanguage) { ul=n.browserLanguage.toLowerCase(); }
 je=n.javaEnabled()?1:0;
 if (_uflash) fl=_uFlash();
 return "&utmsr="+sr+"&utmsc="+sc+"&utmul="+ul+"&utmje="+je+"&utmfl="+fl;
}
function __utmSetTrans() {
 var e;
 if (_ubd.getElementById) e=_ubd.getElementById("utmtrans");
 else if (_ubd.utmform && _ubd.utmform.utmtrans) e=_ubd.utmform.utmtrans;
 if (!e) return;
 var l=e.value.split("UTM:");
 var i,i2,c;
 if (_userv==0 || _userv==2) i=new Array();
 if (_userv==1 || _userv==2) { i2=new Array(); c=_uGCS(); }

 for (var ii=0;ii<l.length;ii++) {
  l[ii]=_uTrim(l[ii]);
  if (l[ii].charAt(0)!='T' && l[ii].charAt(0)!='I') continue;
  var r=Math.round(Math.random()*2147483647);
  if (!_utsp || _utsp=="") _utsp="|";
  var f=l[ii].split(_utsp),s="";
  if (f[0].charAt(0)=='T') {
   s="&utmt=tran"+"&utmn="+r;
   f[1]=_uTrim(f[1]); if(f[1]&&f[1]!="") s+="&utmtid="+_uES(f[1]);
   f[2]=_uTrim(f[2]); if(f[2]&&f[2]!="") s+="&utmtst="+_uES(f[2]);
   f[3]=_uTrim(f[3]); if(f[3]&&f[3]!="") s+="&utmtto="+_uES(f[3]);
   f[4]=_uTrim(f[4]); if(f[4]&&f[4]!="") s+="&utmttx="+_uES(f[4]);
   f[5]=_uTrim(f[5]); if(f[5]&&f[5]!="") s+="&utmtsp="+_uES(f[5]);
   f[6]=_uTrim(f[6]); if(f[6]&&f[6]!="") s+="&utmtci="+_uES(f[6]);
   f[7]=_uTrim(f[7]); if(f[7]&&f[7]!="") s+="&utmtrg="+_uES(f[7]);
   f[8]=_uTrim(f[8]); if(f[8]&&f[8]!="") s+="&utmtco="+_uES(f[8]);
  } else {
   s="&utmt=item"+"&utmn="+r;
   f[1]=_uTrim(f[1]); if(f[1]&&f[1]!="") s+="&utmtid="+_uES(f[1]);
   f[2]=_uTrim(f[2]); if(f[2]&&f[2]!="") s+="&utmipc="+_uES(f[2]);
   f[3]=_uTrim(f[3]); if(f[3]&&f[3]!="") s+="&utmipn="+_uES(f[3]);
   f[4]=_uTrim(f[4]); if(f[4]&&f[4]!="") s+="&utmiva="+_uES(f[4]);
   f[5]=_uTrim(f[5]); if(f[5]&&f[5]!="") s+="&utmipr="+_uES(f[5]);
   f[6]=_uTrim(f[6]); if(f[6]&&f[6]!="") s+="&utmiqt="+_uES(f[6]);
  }
  if (_userv==0 || _userv==2) {
   i[ii]=new Image(1,1);
   i[ii].src=_ugifpath+"?"+"utmwv="+_uwv+s;
   i[ii].onload=function() { _uVoid(); }
  }
  if (_userv==1 || _userv==2) {
   i2[ii]=new Image(1,1);
   i2[ii].src=_ugifpath2+"?"+"utmwv="+_uwv+s+"&utmac="+_uacct+"&utmcc="+c;
   i2[ii].onload=function() { _uVoid(); }
  }
 }
 return;
}
function _uFlash() {
 var f="-",n=navigator;
 if (n.plugins && n.plugins.length) {
  for (var ii=0;ii<n.plugins.length;ii++) {
   if (n.plugins[ii].name.indexOf('Shockwave Flash')!=-1) {
    f=n.plugins[ii].description.split('Shockwave Flash ')[1];
    break;
   }
  }
 } else if (window.ActiveXObject) {
  for (var ii=10;ii>=2;ii--) {
   try {
    var fl=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+ii+"');");
    if (fl) { f=ii + '.0'; break; }
   }
   catch(e) {}
  }
 }
 return f;
}
function __utmLinker(l,h) {
 if (!_ulink) return;
 var p,k,a="-",b="-",c="-",z="-",v="-";
 var dc=_ubd.cookie;
 if (!l || l=="") return;
 var iq = l.indexOf("?"); 
 var ih = l.indexOf("#"); 
 if (dc) {
  a=_uES(_uGC(dc,"__utma="+_udh,";"));
  b=_uES(_uGC(dc,"__utmb="+_udh,";"));
  c=_uES(_uGC(dc,"__utmc="+_udh,";"));
  z=_uES(_uGC(dc,"__utmz="+_udh,";"));
  v=_uES(_uGC(dc,"__utmv="+_udh,";"));
  k=(_uHash(a+b+c+z+v)*1)+(_udh*1);
  p="__utma="+a+"&__utmb="+b+"&__utmc="+c+"&__utmz="+z+"&__utmv="+v+"&__utmk="+k;
 }
 if (p) {
  if (h && ih>-1) return;
  if (h) { _udl.href=l+"#"+p; }
  else {
   if (iq==-1 && ih==-1) _udl.href=l+"?"+p;
   else if (ih==-1) _udl.href=l+"&"+p;
   else if (iq==-1) _udl.href=l.substring(0,ih-1)+"?"+p+l.substring(ih);
   else _udl.href=l.substring(0,ih-1)+"&"+p+l.substring(ih);
  }
 } else { _udl.href=l; }
}
function __utmLinkPost(f,h) {
 if (!_ulink) return;
 var p,k,a="-",b="-",c="-",z="-",v="-";
 var dc=_ubd.cookie;
 if (!f || !f.action) return;
 var iq = f.action.indexOf("?"); 
 var ih = f.action.indexOf("#"); 
 if (dc) {
  a=_uES(_uGC(dc,"__utma="+_udh,";"));
  b=_uES(_uGC(dc,"__utmb="+_udh,";"));
  c=_uES(_uGC(dc,"__utmc="+_udh,";"));
  z=_uES(_uGC(dc,"__utmz="+_udh,";"));
  v=_uES(_uGC(dc,"__utmv="+_udh,";"));
  k=(_uHash(a+b+c+z+v)*1)+(_udh*1);
  p="__utma="+a+"&__utmb="+b+"&__utmc="+c+"&__utmz="+z+"&__utmv="+v+"&__utmk="+k;
 }
 if (p) {
  if (h && ih>-1) return;
  if (h) { f.action+="#"+p; }
  else {
   if (iq==-1 && ih==-1) f.action+="?"+p;
   else if (ih==-1) f.action+="&"+p;
   else if (iq==-1) f.action=f.action.substring(0,ih-1)+"?"+p+f.action.substring(ih);
   else f.action=f.action.substring(0,ih-1)+"&"+p+f.action.substring(ih);
  }
 }
 return;
}
function __utmSetVar(v) {
 if (!v || v=="") return;
 var r=Math.round(Math.random() * 2147483647);
 _ubd.cookie="__utmv="+_udh+"."+_uES(v)+"; path="+_utcp+"; expires=Sun, 18 Jan 2038 00:00:00 GMT;"+_udo;
 var s="&utmt=var&utmn="+r;
 if (_userv==0 || _userv==2) {
  var i=new Image(1,1);
  i.src=_ugifpath+"?"+"utmwv="+_uwv+s;
  i.onload=function() { _uVoid(); }
 }
 if (_userv==1 || _userv==2) {
  var i2=new Image(1,1);
  i2.src=_ugifpath2+"?"+"utmwv="+_uwv+s+"&utmac="+_uacct+"&utmcc="+_uGCS();
  i2.onload=function() { _uVoid(); }
 }
}
function _uGCS() {
 var t,c="",dc=_ubd.cookie;
 if ((t=_uGC(dc,"__utma="+_udh,";"))!="-") c+=_uES("__utma="+t+";+");
 if ((t=_uGC(dc,"__utmb="+_udh,";"))!="-") c+=_uES("__utmb="+t+";+");
 if ((t=_uGC(dc,"__utmc="+_udh,";"))!="-") c+=_uES("__utmc="+t+";+");
 if ((t=_uGC(dc,"__utmz="+_udh,";"))!="-") c+=_uES("__utmz="+t+";+");
 if ((t=_uGC(dc,"__utmv="+_udh,";"))!="-") c+=_uES("__utmv="+t+";");
 if (c.charAt(c.length-1)=="+") c=c.substring(0,c.length-1);
 return c;
}
function _uGC(l,n,s) {
 if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
 var i,i2,i3,c="-";
 i=l.indexOf(n);
 i3=n.indexOf("=")+1;
 if (i > -1) {
  i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
  c=l.substring((i+i3),i2);
 }
 return c;
}
function _uDomain() {
 if (!_udn || _udn=="" || _udn=="none") { _udn=""; return 1; }
 if (_udn=="auto") {
  var d=_ubd.domain;
  if (d.substring(0,4)=="www.") {
   d=d.substring(4,d.length);
  }
  _udn=d;
 }
 if (_uhash=="off") return 1;
 return _uHash(_udn);
}
function _uHash(d) {
 if (!d || d=="") return 1;
 var h=0,g=0;
 for (var i=d.length-1;i>=0;i--) {
  var c=parseInt(d.charCodeAt(i));
  h=((h << 6) & 0xfffffff) + c + (c << 14);
  if ((g=h & 0xfe00000)!=0) h=(h ^ (g >> 21));
 }
 return h;
}
function _uFixA(c,s,t) {
 if (!c || c=="" || !s || s=="" || !t || t=="") return "-";
 var a=_uGC(c,"__utma="+_udh,s);
 var lt=0,i=0;
 if ((i=a.lastIndexOf(".")) > 9) {
  _uns=a.substring(i+1,a.length);
  _uns=(_uns*1)+1;
  a=a.substring(0,i);
  if ((i=a.lastIndexOf(".")) > 7) {
   lt=a.substring(i+1,a.length);
   a=a.substring(0,i);
  }
  if ((i=a.lastIndexOf(".")) > 5) {
   a=a.substring(0,i);
  }
  a+="."+lt+"."+t+"."+_uns;
 }
 return a;
}
function _uTrim(s) {
  if (!s || s=="") return "";
  while ((s.charAt(0)==' ') || (s.charAt(0)=='\n') || (s.charAt(0,1)=='\r')) s=s.substring(1,s.length);
  while ((s.charAt(s.length-1)==' ') || (s.charAt(s.length-1)=='\n') || (s.charAt(s.length-1)=='\r')) s=s.substring(0,s.length-1);
  return s;
}
function _uEC(s) {
  var n="";
  if (!s || s=="") return "";
  for (var i=0;i<s.length;i++) {if (s.charAt(i)==" ") n+="+"; else n+=s.charAt(i);}
  return n;
}
function __utmVisitorCode() {
 var r=0,t=0,i=0,i2=0,m=31;
 var a=_uGC(_ubd.cookie,"__utma="+_udh,";");
 if ((i=a.indexOf(".",0))<0) return;
 if ((i2=a.indexOf(".",i+1))>0) r=a.substring(i+1,i2); else return "";  
 if ((i=a.indexOf(".",i2+1))>0) t=a.substring(i2+1,i); else return "";  
 var c=new Array('A','B','C','D','E','F','G','H','J','K','L','M','N','P','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9');
 return c[r>>28&m]+c[r>>23&m]+c[r>>18&m]+c[r>>13&m]+"-"+c[r>>8&m]+c[r>>3&m]+c[((r&7)<<2)+(t>>30&3)]+c[t>>25&m]+c[t>>20&m]+"-"+c[t>>15&m]+c[t>>10&m]+c[t>>5&m]+c[t&m];
}
function _uIN(n) {
 if (!n) return false;
 for (var i=0;i<n.length;i++) {
  var c=n.charAt(i);
  if ((c<"0" || c>"9") && (c!=".")) return false;
 }
 return true;
}
function _uES(s,u) {
 if (typeof(encodeURIComponent) == 'function') {
  if (u) return encodeURI(s);
  else return encodeURIComponent(s);
 } else {
  return escape(s);
 }
}
function _uUES(s) {
 if (typeof(decodeURIComponent) == 'function') {
  return decodeURIComponent(s);
 } else {
  return unescape(s);
 }
}



