﻿function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function addFavorite(){
    var url=location.href;
    var description=document.title;
    try{//IE
        window.external.addFavorite(url,description);
    }catch(e){//FF
        window.sidebar.addPanel(description,url,"");
    }
}

function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        searchKey_onclick(); 
                        return false;
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        searchKey_onclick(); 
                        return false;
                  } 
            } 
      } 
}

function fixNum(el){
	el.value = el.value.replace(/\D/g, '');
}

function fixPhone(el){
	el.value = el.value.replace(/\D/g, '');
	el.value = el.value.replace(/^1/, '');
}

function checkPop() {
	url = "images/check.gif";
	twin = window.open(url,"sp","width=418,height=225,toolbar=0,scrollbars=1,status=0,resizable=1");
}

function checkLoan(valid){  
  if(valid && (document.payday.requested_amount.options[document.payday.requested_amount.selectedIndex].value > 500)){
    if(confirm("Requesting $500 or less greatly increases your chance of getting a loan.  Would you like to reduce your requested amount to $500?")){    
      for(var i = 0; i < document.payday.requested_amount.options.length; i++){
        if(document.payday.requested_amount.options[i].value == 500){
           document.payday.requested_amount.selectedIndex = i;
           break;
        }
      }    
    }
  }
  
  return valid;
}

function showProccessing(valid){
  
  if(valid){
    div = MM_findObj("processing");
    div.style.display="none";
    setTimeout('document.images["loading"].src = "/images/loading.gif"', 10);
  }
  
  return valid;
}


//input vailed css
function toggleErrorCss(obj,add){
    jQuery("#"+obj).removeClass("MaskedEditError");
    if(add){
        jQuery("#"+obj).addClass("MaskedEditError");
    }
}
