<!--

// ******************************
// LAUNCH WINDOW FUNCTIONS
// ******************************

// launchRemote function launches a new window with specific attributes. launch function supports.
function launch(newURL, newName, newFeatures) {
	var remote = open(newURL, newName, newFeatures);
	if (remote.opener == null)
		remote.opener = window;
	return remote;
}

function launchRemote(pageName, uniqueName, winHeight, winWidth, isModalMode) {
if(isModalMode && window.showModalDialog)//checks for showModalDialog support in browser
{
    window.showModalDialog(pageName,this,'dialogWidth:' + winWidth + 'px; dialogHeight:' + winHeight + 'px; status:no; center:yes')
}
else
{
	myRemote = launch(pageName, uniqueName, "height=" + winHeight + ",width=" + winWidth +",screenX=100,left=100,screenY=100,top=100,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0");
	myRemote.focus();
}
}


// ******************************
// String display functions
// ******************************
function GetStateNameFromAbbreviation(abbr) {
    var rv = abbr;
    if ('AL' == abbr) rv = 'Alabama'; else if ('AK' == abbr) rv = 'Alaska'; else if ('AZ' == abbr) rv = 'Arizona'; else if ('AR' == abbr) rv = 'Arkansas';
    else if ('CA' == abbr) rv = 'California'; else if ('CO' == abbr) rv = 'Colorado'; else if ('CT' == abbr) rv = 'Connecticut';
    else if ('DE' == abbr) rv = 'Deleware'; else if ('DC' == abbr) rv = 'District of Columbia';
    else if ('FL' == abbr) rv = 'Florida';
    else if ('GA' == abbr) rv = 'Georgia';
    else if ('HI' == abbr) rv = 'Hawaii';
    else if ('ID' == abbr) rv = 'Idaho'; else if ('IL' == abbr) rv = 'Illinois'; else if ('IN' == abbr) rv = 'Indiana'; else if ('IA' == abbr) rv = 'Iowa';
    else if ('KS' == abbr) rv = 'Kansas'; else if ('KY' == abbr) rv = 'Kentucky';
    else if ('LA' == abbr) rv = 'Louisiana';
    else if ('ME' == abbr) rv = 'Maine'; else if ('MD' == abbr) rv = 'Maryland'; else if ('MA' == abbr) rv = 'Massachusetts'; else if ('MI' == abbr) rv = 'Michigan'; else if ('MN' == abbr) rv = 'Minnesota'; else if ('MS' == abbr) rv = 'Mississippi'; else if ('MO' == abbr) rv = 'Missouri'; else if ('MT' == abbr) rv = 'Montana';
    else if ('NE' == abbr) rv = 'Nebraska'; else if ('NV' == abbr) rv = 'Nevada'; else if ('NH' == abbr) rv = 'New Hampshire'; else if ('NJ' == abbr) rv = 'New Jersey'; else if ('NM' == abbr) rv = 'New Mexico'; else if ('NY' == abbr) rv = 'New York'; else if ('NC' == abbr) rv = 'North Carolina'; else if ('ND' == abbr) rv = 'North Dakota';
    else if ('OH' == abbr) rv = 'Ohio'; else if ('OK' == abbr) rv = 'Oklahoma'; else if ('OR' == abbr) rv = 'Oregon';
    else if ('PA' == abbr) rv = 'Pennsylvania';
    else if ('RI' == abbr) rv = 'Rhode Island';
    else if ('SC' == abbr) rv = 'South Carolina'; else if ('SD' == abbr) rv = 'South Dakota';
    else if ('TN' == abbr) rv = 'Tennessee'; else if ('TX' == abbr) rv = 'Texas';
    else if ('UT' == abbr) rv = 'Utah';
    else if ('VT' == abbr) rv = 'Vermont'; else if ('VA' == abbr) rv = 'Virginia';
    else if ('WA' == abbr) rv = 'Washington'; else if ('WV' == abbr) rv = 'West Virginia'; else if ('WI' == abbr) rv = 'Wisconsin'; else if ('WY' == abbr) rv = 'Wyoming';

    return rv;
}

function toDollarAmountString(num)
{
    if (!isNaN(num))
    {
        var n = new Number(num);
        return "$" + addCommas(n.toFixed(2).toString());
    }
    else
    {   
        return null;
    }
}

function addCommas(strNum)
{
    strNum += '';
    
    x = strNum.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? "." + x[1] : '';
    
    var rgx = /(\d+)(\d{3})/;	
    while (rgx.test(x1)) 
    {		
        x1 = x1.replace(rgx, '$1' + ',' + '$2');	
	}	
    
    return x1 + x2;
}


// ******************************
// CONFIRM FUNCTIONS
// ******************************


// ConfirmAction function adds confirmation box to any deletions
function ConfirmAction(url, text) {
	if (confirm('Are you sure you want to ' + text + '?')) {
		document.location = url;
	}		
}

// ConfirmActionButton function adds confirmation box to any button deletions
function ConfirmActionButton(url, text) {
	if (confirm('Are you sure you want to ' + text + '?')) {
		document.location = url;
    }
}


// ******************************
// FORM FUNCTIONS
// ******************************

// syncChecks is used on lists with multiple checkboxes to check all the checkboxes in the list
function syncChecks(formName)
{

for (var i=0;i<formName.elements.length;i++)
	{
	var e = formName.elements.elements[i];
	if (e.name != 'allbox')
		e.checked = formName.allbox.checked;
	}
}

function disableEnterKey(e)
{
 var key;     
 if(window.event) key = window.event.keyCode; //IE
 else key = e.which; //firefox     
 return (key != 13);
}

/* Sets all checkboxes in a form to checked if true, unchecked if false.*/
function setAllCheckboxes(vChecked)
{
    var elm=document.forms[0].elements;
    for(i=0;i<elm.length;i++)
    {
		if(elm[i].type=="checkbox")
		{
			elm[i].checked = vChecked;
		}
	}
 }
 
 /* Set all checkboxes in a form that match a prefix */
 function setAllCheckboxes(vChecked,prefix)
 {
    var elm=document.forms[0].elements;
    for(i=0;i<elm.length;i++)
    {
		if(elm[i].type=="checkbox")
		{
			if(elm[i].id != null && elm[i].id.indexOf(prefix) == 0)
			{
				elm[i].checked = vChecked;
			} 
		}
	}
 }
   
 /* Set all checkboxes in a form that match a prefix */
 function setAllCheckboxes(vChecked,prefix,includeDisabled)
 {
    var elm=document.forms[0].elements;
    for(i=0;i<elm.length;i++)
    {
		if(elm[i].type=="checkbox")
		{
			if(elm[i].id != null && (prefix == null || elm[i].id.indexOf(prefix) == 0))
			{
			    if(includeDisabled == null || includeDisabled || (!includeDisabled && !elm[i].disabled))
				        elm[i].checked = vChecked;
		    } 
		}
	}
 }

// selectLink is used on pulldown menus to automatically open a URL based on the user's selection

function selectLink(sURL)
{
        if (sURL != "") {
                // first param is the URL, second param is the frame name
                open(sURL,"_self");
                
                // parent.archive.location = sURL
        }
}


// calcResaleBid is used to auto-populate the second form field when the first is entered

function calcResaleBid() 
{
	origNoteValue=document.forms[0].origNoteValue
	origYieldRate=document.forms[0].origYieldRate
	bid_amount=document.forms[0].bid_amount
	bid_rate=document.forms[0].bid_rate

	if (bid_amount.value) {
		bid_rate.value = (origYieldRate.value * 1) * 92.1
	} else if (bid_rate.value) {
		bid_amount.value = (origNoteValue.value * 1) * 1.104
	}
}


// tabNext is used to automatically move the cursor to successive form fields

var text_field_object=null;
var text_field_length=0;
function tabNext(obj,event,len,next_field) 
{
	if (event == "down") {
		text_field_object=obj;
		text_field_length=obj.value.length;
	}
	else if (event == "up") {
		// check that the keypress didn't move fields, and that a character was added
		if (text_field_object == obj && text_field_length != obj.value.length) {
			if (obj.value.length == len) {
				next_field.focus();
				next_field.select();
			}
		}
	}
}

function setFocus(id)
{
    //  Firefox workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=53579
    if (isFirefox())
    {
        window.setTimeout("document.getElementById(\""+id+"\").focus();", 100)
    }
    else
    {
       document.getElementById(id).focus();
    }
}
	
// ******************************
// BROWSER DETECTION FUNCTIONS
// ******************************

function isFirefox()
{
    return navigator.userAgent.indexOf('Firefox') > 0;
}

function isFirefox2()
{
    return isFirefox() && navigator.appVersion.charAt(0) == "5";
}

function isInternetExplorer()
{
    return navigator.userAgent.indexOf('MSIE') > 0;
}

function isSafari()
{
    return navigator.userAgent.indexOf('Safari') > 0;
}


// ******************************
// MATH FUNCTIONS
// ******************************

function roundToDecimalPlace(num, decimalPlaces)
{
    if (!isNaN(num))
    {
        var n = new Number(num);
        return n.toFixed(decimalPlaces);
    }
    else
    {
        return null;
    }
}
	
// ******************************
// VISIBILITY FUNCTIONS
// ******************************

// Shows or hides any element specified by the the id param. show == true => show, show == false => hide
function showHideContent(id, show)
{
	var elem = document.getElementById(id);
	if (elem) 
	{
		if (show) 
		{
			elem.style.display = '';
			elem.style.visibility = 'visible';
		} 
		else
		{
			elem.style.display = 'none';
			elem.style.visibility = 'hidden';
		}
	}
}

function isVisible(id)
{
    var isVisible2 = true;
    var elem = document.getElementById(id);
	if (elem) 
	{
		isVisible2 = !(elem.style.display == 'none' || elem.style.visibility == 'hidden');
    }
	return isVisible2;
}

function toggleVisibility(id)
{
   showHideContent(id,!isVisible(id));
}

/* -- Used to toggle sections throughout help section. Expects content in this format: -- */
/* -- <div class="collapsible"><h4 class="collapsed" onClick="toggleBlock(this,'divSection')">Who can borrow money on Prosper?</h4>
      <div id="divSection" style="display: none;" class="togglePanel"><p>Content.</p></div></div>   -- */
function toggleAnchor() {
	var hash = window.location.hash;
	hash = hash.substring(1);
	toggleBlock('div'+hash);
}
function toggleBlock(targetId) {
	var div = document.getElementById(targetId);
	if (div) {
		var subDivs = div.getElementsByTagName('div');
		for (var i = 0; i < subDivs.length; i++) {
			if (subDivs[i].className.match(/togglePanel/)) {
				var togglePanel = subDivs[i];
			}
		}
		var titlePanel = div.getElementsByTagName('h4')[0];
	
		if (togglePanel) {
			if (togglePanel.style.display != 'block') {
				togglePanel.style.display = 'block';
				titlePanel.className = 'expanded';
			} else	{
				togglePanel.style.display = 'none';
				titlePanel.className = 'collapsed';
			}
		}
	}
}
function toggleAll(parentDiv,targetDisplay) {
	var divs = parentDiv.getElementsByTagName('div');
	
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].className == 'collapsible') {
			var title = divs[i].getElementsByTagName('h4')[0];
			
			var subDivs = divs[i].getElementsByTagName('div');
			for (var j = 0; j < subDivs.length; j++) {
				if (subDivs[j].className.match(/togglePanel/)) {
					var togglePanel = subDivs[j];
				}
			}
			
			if (togglePanel.style.display != targetDisplay) {
				toggleBlock(divs[i].id);
			}
		}
	}
}

/* Use this to find the first instance of an element that partially matches the id substring. This is useful
   when dotNet adds each page and control prefixing the name of the element you are attempting to access.
   Limitations: this will not be useful on pages where more than one element matches the id sub string
  */
function findFullID(idSubstring)
{
	var elements = document.forms[0].elements;
    var fullId;
    var currentId;
    var currentIdString = '';
   
    if(elements)
	{
		for(i=0;i<elements.length;i++)
		{
			currentId = elements[i].id;
			if(currentId)
			{
				currentIdString = currentId.toString();
				if(currentIdString.indexOf(idSubstring) > -1)
				{
					fullId = elements[i].id;
					break;
				}
			}
		}
	}
    
    return fullId;
}

function genUrl(requests, fileName)
{
	var url=fileName;
	var i = 0;
	for(requestId in requests)
	{
		if(i == 0) 
			url = url + "?" + requestId + "=" + requests[requestId];
		else 
			url = url + "&" + requestId + "=" + requests[requestId];
		i++;
	}
	return url;
}


///Adds option to option list
function addOption(selectObject,optionText,optionValue) 
{
    var optionObject = new Option(optionText,optionValue);
    var optionRank = selectObject.options.length;
    //check for its existence first
    if (!isInList(selectObject,optionText,optionValue))
    {
		selectObject.options[optionRank]=optionObject;
    }
}

//selects all options in the given list (IMPORTANT so that values POSTBACK!)
function selectAllOptions(selectObject)
{
	var i = 0;
	for (i=0; i< selectObject.options.length; i++)
	{
		selectObject.options[i].selected = true;
	}
}

///Checks if option is already in given list
function isInList(selectObject, optionText, optionValue)
{ 
  var blnIsInList = false;
  for (i=0; i<selectObject.options.length; i++)
  {
     if (optionValue == selectObject.options[i].value)
     {
        blnIsInList = true;
        break
     }
  } 
  return blnIsInList;
}

//removes selected options from the given list
function removeOptions(selectObject) 
{
    //check if there's an item selected
     if (selectObject.selectedIndex!=-1) 
     {
		if (selectObject.options.length!=0) 
		{
			var i=0;
			//loop through all options
			for (i=selectObject.options.length - 1; i>=0; i--)
			{
				if (selectObject.options[i].selected == true)
				{
					selectObject.options[i]=null;
				}
			} 
			
		}
	} 
	else 
	{
        alert("Select an item first (if any) before clicking Remove.")
    }
}

function removeOption(selectObject, optionIndex)
{
	if(selectObject != null)
	{
		if (selectObject.options.length!=0) 
		{
			selectObject.options.remove(optionIndex);			
		}
	}
}

function removeOptionByValue(selectObject, val)
{
	if(selectObject != null)
	{
		if (selectObject.options.length!=0) 
		{
			var i=0;
			//loop through all options
			for (i=selectObject.options.length - 1; i>=0; i--)
			{
				if(selectObject.options[i] != null)
				{
					if (selectObject.options[i].value == val)
					{
						selectObject.options[i]=null;
					}
				}
			} 
		}
	}
}


// ******************************
// PAGING FUNCTIONS
// ******************************

/// <summary>
/// Navigates to the given url (url should end with a &page_index= type of variable)
/// after clicking on "Go" button in paging area. The entered pageNum is 1 (one) based.
/// page index is 0 (zero) based
/// Checks if the number given is less than or equal to max pagecount.
/// </summary>
function gotoPageNumber(url,pageNum,pageCount)
{
    if(!isNaN(pageNum) && pageNum > 0 && pageNum <= pageCount ) 
    {
        window.location.href = url + (pageNum-1);
    }
}

/// <summary>
/// Similar to gotoPageNumber, but submits the page uses .Net __doPostBack (POST not a GET)
/// after clicking on "Go" button in paging area. The entered pageNum is 1 (one) based.
/// but that is how ASP.Net 2.0 likes it.
/// Checks if the number given is less than or equal to max pagecount.
/// </summary>
function postBackPageNumber(controlID,pageNum,pageCount)
{
    if(!isNaN(pageNum) && pageNum > 0 && pageNum <= pageCount ) 
    {
        __doPostBack(controlID,'Page$'+ (pageNum));return false;
    }
}

// ******************************
// SESSION TIMEOUT WARNING FUNCTIONS
// ******************************
function displaySessionTimeoutAlert()
{
    alert('Your Prosper session is about to expire, at which point you will be signed out automatically. \nAs a security precaution, sessions expire after ' + _sessionTimeOutMinutes + ' minutes of inactivity. \n\nClick OK (within next 2 minutes) to continue your current session.');
    frames['sessionKeepAliveFrame'].location.href='/session_keep_alive.aspx';
    // defaultTimeOutMilliseconds is set programmatically  2 minutes less than session timeout
    startSessionTimeoutTimer(_sessionTimeOutWarningMilliseconds);
}
var _sessionTimeOutWarningMilliseconds = 1080000;var _sessionTimeOutMinutes = 20;
function startSessionTimeoutTimer(timeOutMilliseconds, sessionTimeOutMinutes)
{
    window.setTimeout('displaySessionTimeoutAlert()', timeOutMilliseconds);
    _sessionTimeOutWarningMilliseconds = timeOutMilliseconds;
    _sessionTimeOutMinutes = sessionTimeOutMinutes;
}

// ******************************
// MULTI-LINE TEXT BOX / TEXTAREA LIMITER
// ******************************
//see SetMultiLineTextBoxMaxLength
// Different browsers add different characters when pressing enter key
//"\r" (ex: on mac) one char, 
//"\n" (ex: on firefox) one char
//"\r\n" (ex: on IE) two char. 
//Regardless, C# translates all line breaks to \r\n.

function checkLength(field, len)
{
    var val = field.value;
    var lineBreakIsRN = false; // IE windows
    var lineBreakIsROnly = false; //IE Mac
    var lineBreakIsNOnly = false; //FireFox all
    
    if (val.indexOf('\r\n')!=-1)
    {
        //do nothing. this is IE on windows. Puts both characters for a newline, just what C# does. No need to alter.
        lineBreakIsRN = true;
    }
    else if (val.indexOf('\r')!=-1)
    {
       //this is IE on a Mac. Need to add the line feed
       val = val.replace(/\r/g, "\r\n" );
       lineBreakIsROnly = true;
    }   
    else if (val.indexOf('\n')!=-1)
    {
        //this is Firefox on any platform. Need to add carriage return  
        val = val.replace(/\n/g, "\r\n" );
        lineBreakIsNOnly = true;
    }
    
	if (val.length > len)
	{	
		field.value = val.substring(0, len); // too long...trim it!

	    if(lineBreakIsRN) {;}
		else if(lineBreakIsROnly)
		    {field.value = field.value.replace(/\n/g,"");} //remove all \n's put it back the way it was
		else if(lineBreakIsNOnly)
		    {field.value = field.value.replace(/\r/g,"");} //remove all \r's put it back the way it was
	}
}

// Extracts a number from a text input as a float, stripping %, comma's and dollar signs
// If after these characters are stripped and number is still unparsable then this returns
// NaN. Null input is also returned as NaN
function extractNumber(inputVal)
{
	var result = NaN;
	if(inputVal != null)
	{
		var cleanedInput = inputVal.replace(',','');
		cleanedInput = cleanedInput.replace('$','');
		cleanedInput = cleanedInput.replace('%','');
		result = parseFloat(cleanedInput);
	}	
	return result;
}


// ******************************
// RADIO BUTTON HELPER FUNCTIONS
// ******************************
function getRadioButtonSelectedIndex(buttonGroupName) {
    var buttonGroup = document.getElementsByName(buttonGroupName);
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getRadioButtonSelectedIndex" function

function getRadioButtonSelectedValue(buttonGroupName) {
    var buttonGroup = document.getElementsByName(buttonGroupName);
   // returns the value of the selected radio button or "" if no button is selected
   var i = getRadioButtonSelectedIndex(buttonGroupName);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getRadioButtonSelectedValue" function

// ******************************
// Creates a cookie
// ******************************
function createCookie(name,value,days) 
{
  if (days) {
    var d = new Date();
    d.setTime(d.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+d.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function deleteCookie (cookie_name)
{ 
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString()+"; path=/";
}


// ******************************
// VALIDATION
// ******************************


// ***********************************************************
// Check that a valid path was submitted in a file input
// ***********************************************************
function isValidUploadFilePath(fileName)
{
	var filePathRegex = /^([a-zA-Z]{0,1})((:\\|\\|\/|\\\\|\/\/){0,1})(.*)\.([0-9a-zA-Z]{1,4})$/;
	/* optional drive letter, os independent root path symbol(s), any number of path symbols, a dot, and then a file extension 1 to 4 chars */

	var isValid = false;
	if(fileName != null && fileName != '')
	{
		isValid = fileName.match(filePathRegex);
	}	
		
	return isValid;
}

// ****************************************************************************************
// Used for validating if the user has submitted a valid image file in a file upload input
// ****************************************************************************************
function isValidImageFile(fileName)
{
	//alert(fileName);
	var isValid = false;
	var imageFileRegex = /^(.*)(.bmp$|.\.jpg$|.\.jpeg$|.\.gif$|.\.png$|.\.tif$|.\.tiff$)/;
	
	if(fileName != null)
	{
		var lowerFileName = fileName.toLowerCase();
		isValid = isValidUploadFilePath(lowerFileName) && lowerFileName.match(imageFileRegex);
	}
	
	return isValid;
}

//variable to hold table rows with validators
var tableRows = new Array();

function valHighlightAllInvalid_ClientValidate(sender, args)
{
   // Do nothing if client validation is not active
   if (typeof(Page_Validators) == "undefined")  return;

    ClearAllRowFormatting();
    
    //clear the array
    tableRows.length = 0;
    
    highlightValidatorContainers(Page_Validators)
}

function highlightValidatorContainers(validators, forceHighlight)
{
   // Do nothing if invalid validators array not defined
   if (typeof(validators) == "undefined")  return;

    for (i = 0; i < validators.length; i++) 
    {
        var val = validators[i];
        var tr = FindParentElementByTagName(val,'tr');
        if(tr && tr != 'undefined')
        {
            if(!tableRows.Contains(tr))
            { 
                tableRows.push(tr);
            }
            if(!val.isvalid || forceHighlight)
            {
                highlightInvalid(tr, val);
            }
        }
    }
}

function highlightInvalid(container, val)
{
    container.className = 'error_row';

    //addToolTipToControlToValidate(val)
    var controlId = val.controltovalidate;
    if (typeof(controlId) != "undefined")
    {
        var control = document.getElementById(controlId);
        if(control)
        {
            control.title = val.errormessage;
        }
        val.title = val.errormessage; 
    }
    else
    {
        //alert("no controltovalidate: " + controlId); 
        //optionally add tooltip to whole row (double errors will be overwritten by last error)
        container.title = val.errormessage != null && val.errormessage.length > 0 ? val.errormessage : 'please correct this field';
    }

}

//clears all formatting for all rows in the global tableRows variable
function ClearAllRowFormatting()
{
    for (i = 0; i < tableRows.length; i++) 
    {
       var tr = tableRows[i];
       tr.className = '';
       //tr.setAttribute("className", ""); 
       //alert(tr.className);
       //tr.style.backgroundColor='white';
       tr.title = '';
    }
}

//Finds an html element by tag name. Useful for finding the containing tr of a validator
function FindParentElementByTagName(element, tagname) {
    tagname = tagname.toLowerCase();
    var parentElement;
    while((element = element.parentNode) && !parentElement) 
    {
        if (element && element.tagName && element.tagName.toLowerCase() == tagname) 
        {
            parentElement = element;
        }
     }
    //if (parentElement) alert(parentElement.id);
    return parentElement;
}

//This prototype extends the DOM Array object adding support for "Contains" (there's no native Contains or InArray function)
Array.prototype.Contains = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

// ******************************
// AJAX functions
// ******************************

//  Reference: http://www.w3.org/TR/XMLHttpRequest/
function getXMLHttpRequest() {
    var xmlHttp = null;
    if(window.XMLHttpRequest) {
         try {
            xmlHttp = new XMLHttpRequest(); //IE7, Firefox, Safari
         } catch (e) {}    
    } else if (window.ActiveXObject) {
       try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //IE6
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE5.X
            } catch (e) {}
        }
    }
    return xmlHttp;
}



// Tooltips, based on qTip //
var tipTag = "abbr,acronym,span"; //Tags to check for //
var tooltipX = -5; //This is qTip's X offset//
var tooltipY = 3; //This is qTip's Y offset//

tooltip = {
  name : "tooltip",
  offsetX : tooltipX,
  offsetY : tooltipY,
  tip : null
}
tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "tooltip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	// if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle, elements;
	
	var elementList = tipTag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{	
		elements = document.getElementsByTagName(elementList[j]);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");				
				if(sTitle)
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.className = "hasTooltip";
					a.onmouseover = function(evt) {tooltip.show(evt,this.getAttribute('tiptitle'))};
					a.onmouseout = function() {tooltip.hide()};
				}
			}
		}
	}
}

tooltip.show = function (evt,text) {
	if (!this.tip) return;
	
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
	
	this.tip.innerHTML = "<div class='tooltipBody'>"+text+"</div>";
	this.tip.style.display = "block";
}
tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}


// Check for a Google Analytics tracker before using it //
function gaLoaded(path) {
	if (pageTracker) {
		pageTracker._trackPageview(path);
	}
}

/* Check for referral codes in query string, call pixel */
function setReferrals(qs) {
	var pass = "?";
	qs = qs.slice(1);
	pairs = qs.split('&');
	for (var i=0; i < pairs.length; i++) {
		values = pairs[i].split('=');
		if (values[0]=="refac"||values[0]=="refmc"||values[0]=="refd"||values[0]=="refl") {
			if (i > 0) { pass += "&"; }
			pass += pairs[i];
		}	
	}

	callPixel(pass);
}

/* Check if this was a referral from search engine, call pixel */
function searchReferrals(ref) {
	var engine = "";

	if (ref.search(/google/i) != -1) {
		engine = "google";		
	} else if (ref.search(/yahoo/i) != -1) {
		engine = "yahoo";
	} else if (ref.search(/bing/i) != -1) {
		engine = "bing";
	} else if (ref.search(/aol/i) != -1) {
		engine = "aol";
	}

	if (engine != "") {
		var query = "";
		var refmc = "";	
		var parts = ref.split("?");
		var qs = parts[1];
	
		if (qs) {
			pairs = qs.split('&');
			for (var i=0; i < pairs.length; i++) {
				values = pairs[i].split('=');
				
				if (engine == "google") {
					if (values[0]=="q") {
						query = values[1];
					}
				} else if (engine == "yahoo") {
					if (values[0]=="p") {
						query = values[1];
					}
				} else if (engine == "bing") {
					if (values[0]=="q") {
						query = values[1];
					}
				} else if (engine == "aol") {
					if (values[0]=="query"||values[0]=="q") {
						query = values[1];
					}
				}
			}
			
			
			if (query.search(/prosper/i) != -1) {
				refmc = "DWWZOMNI";
			} else if (query.search(/peer|p2p|person+to|people/i) != -1) {
				refmc = "ZTZXWLX ";		
			} else if (query.search(/social/i) != -1) {
				refmc = "HANUBHH";
			} else if (query.search(/online.*invest|invest.*online/i) != -1) {
				refmc = "DQYXYPV";
			} else if (query.search(/opportunities|opportunity/i) != -1) {
				refmc = "AROANRU";
			} else if (query.search(/strategies|strategy/i) != -1) {
				refmc = "BIWGNWW";
			} else if (query.search(/alternative/i) != -1) {
				refmc = "MLWAOMF";
			} else if (query.search(/short term/i) != -1) {
				refmc = "NMPNLRO";
			} else if (query.search(/invest/i) != -1) {
				refmc = "QNFZAEX";
			} else if (query.search(/personal/i) != -1) {
				refmc = "TQPZMWO";
			} else if (query.search(/borrow/i) != -1) {
				refmc = "PPRWJZA";
			} else if (query.search(/online/i) != -1) {
				refmc = "VVVNDMP";
			} else if (query.search(/motorcycle/i) != -1) {
				refmc = "IAGCLUT";
			} else if (query.search(/military/i) != -1) {
				refmc = "KMMECNE";
			} else if (query.search(/consolidation/i) != -1) {
				refmc = "LNHXXHI";
			} else if (query.search(/business/i) != -1) {
				refmc = "VQXPAGU";
			} else if (query.search(/home.*improvement/i) != -1) {
				refmc = "IATAELV";
			} else if (query.search(/student/i) != -1) {
				refmc = "XRYTLWI";
			} else if (query.search(/ring/i) != -1) {
				refmc = "SZLBRXI";
			} else if (query.search(/wedding/i) != -1) {
				refmc = "MJDNRHW";
			} else if (query.search(/baby|adoption/i) != -1) {
				refmc = "CSWWOTX";
			} else if (query.search(/small/i) != -1) {
				refmc = "KBBWFNX";
			} else if (query.search(/unsecured/i) != -1) {
				refmc = "NSNLOXJ";
			} else if (query.search(/loan/i) != -1) {
				refmc = "PMXEZBU";
			}
			
			if (refmc != "") {
				var pass = "?refac=ARVSD&refmc="+refmc+"&refd="+engine+":"+query;
				callPixel(pass);
			}
		}
	}
}

function callPixel(pass) {
	if (pass.length > 1) {
		var pixelURL = "/referrals/refer.aspx";
		var pixel = document.createElement("img");
		pixel.width = 1;
		pixel.height = 1;
		pixel.style.visibility = "hidden";
		pixel.src = pixelURL + pass;
	}
}


//* -- Perform on window load  -- *//
window.onload = function () {
	tooltip.init (); // Tooltips
	setReferrals(document.location.search);
	searchReferrals(document.referrer);
}