window.onload=function(){
linkEmail();
externalLinks();
toggle.init();
toggle2.init();
}

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";
		if (anchor.getAttribute("href") &&  anchor.getAttribute("rel") == "external") anchor.rel = "nofollow";
	}
}

function linkEmail() {
  if(!document.getElementsByTagName) return;
  var allElts = document.getElementsByTagName("*");
  if(allElts.length == 0 && document.all) 
    allElts = document.all; //hack for IE5
  for(var i=0; i<allElts.length; i++) {
    var elt = allElts[i];
    var className = elt.className || elt.getAttribute("class") 
      || elt.getAttribute("className");
    if(className && className.match(/\bemail\b/)
        && elt.firstChild.nodeType == 3) {
      var addr = elt.firstChild.nodeValue;
      addr = addr.replace(/[ \[\{\(\|\/\\]at[ \]\}\)\|\/\\]/i, "@")
        .replace(/[ \[\{\(\|\/\\](dot|period)[ \]\}\)\|\/\\]/gi, ".");
      var lnk = document.createElement("a");
      lnk.setAttribute("href","mailto:"+addr);
      lnk.appendChild(document.createTextNode(addr));
      elt.replaceChild(lnk, elt.firstChild);
    }
  }
}

function checkme() {
	
	if(!document.getElementById || !document.createTextNode){return;}
	
	if (!document.getElementById('agree').checked) {
		alert('You must agree to the Terms and Conditions to continue.');
		return false;
	} else {
		return true;
	}
}

function popitup(url) {
	newwindow=window.open(url,'name','height=580,width=300');
	if (window.focus) {newwindow.focus()}
	return false;
}


var toggle = function(){ 
 var payment = null; 
 return { 
 	init : function(){ 
  attachListeners(); 
 }, 
 togglePayment : function(bShow){ 
  if(!payment ) return; 
  payment.style.display = (bShow?'block':'none'); 
 } 
 }; 
 function attachListeners(){ 
 payment = document.getElementById("explain"); 
 var ppYes = document.getElementById("loan_purpose_no"); 
 var ppNo = document.getElementById("loan_purpose_yes"); 
 if( ppYes && ppNo ) 
 { 
  ppYes.onclick = function(){toggle.togglePayment(true);}; 
  ppNo.onclick = function(){toggle.togglePayment(false);}; 
  toggle.togglePayment(ppYes.checked); 
 } 
 }; 
}(); 

var toggle2 = function(){ 
 var cctest = null; 
 return { 
 	init : function(){ 
  attachListeners(); 
 }, 
 togglecctest : function(ccShow){ 
  if(!cctest ) return; 
  cctest.style.display = (ccShow?'block':'none'); 
 } 
 }; 
 function attachListeners(){ 
 cctest = document.getElementById("creditcheckshow1"); 
 var ccYes = document.getElementById("creditcheckyes1"); 
 var ccNo = document.getElementById("creditcheckno1"); 
 if( ccYes && ccNo ) 
 { 
  ccYes.onclick = function(){toggle2.togglecctest(true);}; 
  ccNo.onclick = function(){toggle2.togglecctest(false);}; 
  toggle2.togglecctest(ccYes.checked); 
 } 
 }; 
}(); 


// ADMIN

function toggleit( targetId ){
if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

function go(box){
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function zPrint(oTgt){
	oTgt.focus();
	oTgt.print();
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}