// Fixes dropdown menu CSS hover pseudo-class in IE

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// New Window Links

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
window.onload = externalLinks;

// Fixes for IE's broken ass PNG support
/**********************************************************
Sleight
Original code (c) 2001 Aaron Boodman, http://www.youngpup.net
**********************************************************/
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			fnFixPng(img);
			img.attachEvent("onpropertychange", fnPropertyChanged);
		}
		img.style.visibility = "visible";
	}

	var nl = document.getElementsByTagName("INPUT");
	for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
		if (e.className && e.className.match(/\bimage\b/i) != null) {
			if (e.src.match(/\.png$/i) != null) {
				fnFixPng(e);
				e.attachEvent("onpropertychange", fnPropertyChanged);
			}
			e.style.visibility = "visible";
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "/imgs/sleight.gif";
		}
	}
}

function dbg(o) {
	var s = "";
	var i = 0;
	for (var p in o) {
		s += p + ": " + o[p] + "\n";
		if (++i % 10 == 0) {
			alert(s);
			s = "";
		}
	}
	alert(s);
}

function fnFixPng(img) {
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "/imgs/sleight.gif";
}

/**********************************************************
Sleight for Backgrounds
Original code (c) 2001 Aaron Boodman, http://www.youngpup.net
This version (c) 2003 Drew McLellan, http://www.allinthehead.com
**********************************************************/
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	window.attachEvent("onload", alphaBackgrounds);
}

function alphaBackgrounds(){
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
	for (i=0; i<document.all.length; i++){
		var bg = document.all[i].currentStyle.backgroundImage;
		if (itsAllGood && bg){
			if (bg.match(/\.png/i) != null){
				var mypng = bg.substring(5,bg.length-2);
				document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
				document.all[i].style.backgroundImage = "url('/imgs/sleight.gif')";
			}
		}
	}
}

/**********************************************************
Random Intro Quotes
**********************************************************/

var theQuotesfront = new Array() // do not change this
theQuotesfront[0] = '<img src="/imgs/introquote1.gif" height="160" width="190" border="0" alt="Testimonial">'
theQuotesfront[1] = '<img src="/imgs/introquote2.gif" height="160" width="190" border="0" alt="Testimonial">'
theQuotesfront[2] = '<img src="/imgs/introquote3.gif" height="160" width="190" border="0" alt="Testimonial">'
theQuotesfront[3] = '<img src="/imgs/introquote4.gif" height="160" width="190" border="0" alt="Testimonial">'

var j = 0
var p = theQuotesfront.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theQuotesfront[i]
}

var whichQuotefront = Math.round(Math.random()*(p-1));

function showQuotefront(){
document.write(theQuotesfront[whichQuotefront]);
}

/**********************************************************
Random Text Quotes
**********************************************************/

var theQuotes = new Array() // do not change this
theQuotes[0] = 'We need to be able to manage and implement technology that can adapt to changing business environments -- the Portellus lending solution can do this and more.<div class="author">- Steve Bowman<br />President<br />Harbourton Mortgage Investment Corp. (HMIC)</div>'
theQuotes[1] = 'We wanted a platform to create more efficiency and consistency in our underwriting process and allowed us to effectively manage the loan process through workflow automation – from beginning to end. Portellus was the clear solution for these needs.<div class="author">- Lorne Lahodny<br />President<br />Secured Funding Corp.</div>'
theQuotes[2] = 'Portellus has taken a great deal of time to develop a suite of next-generation products, and has married those products with a very customer-centric approach to delivering successful implementations in a timely fashion.<div class="author">- Andreas Markou<br />Executive Vice President<br />Alliance Mortgage Banking Corp.</div>'
theQuotes[3] = 'Portellus&#146; business rules technology gives us the ability to make decisions faster and more consistently, respond more quickly to new business conditions, and reduce program implementation and operational costs.<div class="author">- Fred Bai<br />Chief Information Officer<br />Encore Credit Corporation</div>'
theQuotes[4] = 'By joining forces with Portellus, we have generated another opportunity to help our customers streamline the way they operate.<div class="author">- Bill DuFour<br />President<br />Informative Research</div>'
theQuotes[5] = 'Portellus impressed us with their wonderfully engineered and flexible architecture. We look forward to extending our business through this new partnership.<div class="author">- Bob Sheng<br />Vice Chairman<br />DynaComware</div>'
theQuotes[6] = 'A partnership with Portellus is a natural fit, since both Veros and Portellus have such strong and advanced underlying technology.<div class="author">- Darius Bozorgi<br />President &amp; CEO<br />Veros</div>'
theQuotes[7] = 'This integration positions First American as a preferred provider with Portellus, providing seamless access to our entire array of mortgage origination products to LendingSuite user institutions.<div class="author">- Bill Sherakas<br />Chief Client Relations Officer<br />First American Real Estate Information Services</div>'
theQuotes[8] = 'ComplianceEase and Portellus are enabling mortgage originators of all sizes to audit up to 100% of their loan production, effectively mitigating operational risk with the click of a button from Portellus&#146; loan origination platform.<div class="author">- David Girling<br />Executive Vice President<br />ComplianceEase</div>'

var j = 0
var p = theQuotes.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theQuotes[i]
}

var whichQuote = Math.round(Math.random()*(p-1));

function showQuote(){
document.write(theQuotes[whichQuote]);
}

// Cookies //

var expDays = 120;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

