function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function doSubmitMnu( pWho ){
var oFrm = document.getElementById( 'frmSubmitMnu' );
var oSrcPage = document.getElementById( 'srcpage' );
    if ( oFrm && oSrcPage ){
        oSrcPage.value = pWho ;
        oFrm.submit() ;
    }else{
        alert( 'Internal Error.' ) ;
    }
}

function doSubmitForm(){
	var oFrm = document.getElementById( 'frmSubmitForm' ) ;

	var ofname = document.getElementById( 'fname' );
	var olname = document.getElementById( 'lname' );
	var oemail = document.getElementById( 'email' );
	var ohomephone1 = document.getElementById( 'homephone1' );
	var ohomephone2 = document.getElementById( 'homephone2' );
	var ohomephone3 = document.getElementById( 'homephone3' ) ;
	
	var oworkphone1 = document.getElementById( 'workphone1' );
	var oworkphone2 = document.getElementById( 'workphone2' );
	var oworkphone3 = document.getElementById( 'workphone3' );

	var ocontacttime = document.getElementById( 'contacttime' );
	var omaritalstatus = document.getElementById( 'maritalstatus' );
	var ocoborrower = document.getElementById( 'coborrower' );
	var ocreditrating = document.getElementById( 'creditrating' );
	var oborrowamount = document.getElementById( 'borrowamount' );
	var ohomevalue = document.getElementById( 'homevalue' );
	var oaddress = document.getElementById( 'address' );
	var ocity = document.getElementById( 'city' );
	var ostate = document.getElementById( 'state' );
	var ozipcode = document.getElementById( 'zipcode' );
	var opropertytype = document.getElementById( 'propertytype' );
	var oloanpurpose = document.getElementById( 'loanpurpose' );
	var opropertyoweamount = document.getElementById( 'propertyoweamount' );
	var ointerest = document.getElementById( 'interest' );
	var oemployment = document.getElementById( 'employment' );
	var ooccupation = document.getElementById( 'occupation' );
	var oincome = document.getElementById( 'income' );
	var oshare = document.getElementById( 'share' );
	
    if (
/*        oFrm && ofname && olname && oemail && ohomephone1 && ohomephone2 &&*/
        ofname && olname && oemail && ohomephone1 && ohomephone2 &&
        ohomephone3 && oworkphone1 && oworkphone2 && oworkphone3 &&
        ocontacttime && omaritalstatus && ocoborrower && ocreditrating &&
        oborrowamount && ohomevalue && oaddress && ocity && ostate &&
        ozipcode && opropertytype && oloanpurpose && opropertyoweamount &&
        ointerest && oemployment && ooccupation && oincome && oshare
    ){
        if ( !test( ofname, '\'First name\'') ){ return ; }
        if ( !test( olname, '\'Last name\'') ){ return ; }
        if ( !test( oemail, '\'Email address\'') ){ return ; }
        if ( !testemail( oemail, '\'Email address\'') ){ return ; }
        if ( !testphone( ohomephone1, ohomephone2, ohomephone3, '\'Home phone number\'') ){ return ; }
        if ( !testphone( oworkphone1, oworkphone2, oworkphone3, '\'Work phone number\'') ){ return ; }
//        if ( !testcombo( ocontacttime, '\'Best time to contact\'') ){ return ; }
//        if ( !testcombo( omaritalstatus, '\'Marital Status\'') ){ return ; }
//        if ( !testcombo( ocoborrower, '\'Will you be applying with anyone else?\'') ){ return ; }
//        if ( !testcombo( ocreditrating, '\'Rate your credit\'') ){ return ; }
        if ( !test( oborrowamount, '\'How much do you want to borrow?\'') ){ return ; }
        if ( !test( ohomevalue, '\'What is the value of your home?\'') ){ return ; }
        if ( !test( oaddress, '\'Address\'') ){ return ; }
        if ( !test( ocity, '\'City\'') ){ return ; }
//        if ( !testcombo( ostate, '\'State\'') ){ return ; }
        if ( !test( ozipcode, '\'Zipcode\'') ){ return ; }
        if ( !test( opropertytype, '\'Property Type\'') ){ return ; }
        if ( !test( oloanpurpose, '\'Purpose of loan\'') ){ return ; }
        if ( !test( opropertyoweamount, '\'How much do you currently owe on this property?\'') ){ return ; }
        if ( !test( ointerest, '\'Current interest rate you are paying\'') ){ return ; }
        if ( !test( oemployment, '\'Your employment status\'') ){ return ; }
        if ( !test( ooccupation, '\'What\'s your occupation or type of business\'') ){ return ; }
        if ( !test( oincome, '\'What\'s your combined gross income\'') ){ return ; }

        oFrm.submit() ;
    }

}

function validEMail( sEMail ){
var iAtPos = -1 ;
var iAt2Pos = -1 ;
var iDotPos = -1 ;
    iAtPos = sEMail.indexOf( '@' ) ;
    if ( (iAtPos == -1) || (iAtPos == 0) || (iAtPos == (sEMail.length-1)) ){ return false ; }
    iAtPos = sEMail.indexOf( '@', iAtPos ) ;
    if ( iAt2Pos != -1 ){ return false ; }
    iDotPos = sEMail.indexOf( '.', iAtPos ) ;
    if ( (iDotPos == -1) || (iDotPos == (sEMail.length-1)) || (iDotPos == (iAtPos+1)) ){ return false ; }
    switch ( sEMail.charAt( 0 ) ){
        case '@': return false ; break ;
        case '.': return false ; break ;
    }
    switch ( sEMail.charAt( sEMail.length - 1 ) ){
        case '@': return false ; break ;
        case '.': return false ; break ;
    }
    return true ;
}

function testemail( obj, txt){
    if ( !validEMail( obj.value ) ){
        alert( txt + ' must be a valid E-Mail address.' ) ;
        obj.focus();
        return false ;
    }
    return true ;
}

function testcombo( obj, txt){
    if ( (obj.selectedIndex == -1) || (obj.selectedIndex == 0) ){
        alert( 'An option for ' + txt + ' must be selected.' ) ;
        obj.focus() ;
        return false ;
    }
    return true ;
}

function testphone( obj1, obj2, obj3, txt){
    if ( (obj1.value == '') &&
         (obj2.value == '') &&
         (obj3.value == '')
       ){
        alert( txt + ' must be filled.' ) ;
        obj1.focus() ;
        return false ;
    }
    return true ;
}

function test( obj, txt){
    if ( obj.value == '' ){
        alert( txt + ' must be filled.' ) ;
        obj.focus() ;
        return false ;
    }
    return true ;
}
function doSubmit(){
//var oState = document.getElementById( 'state' ) ;
//var oDesired = document.getElementById( 'desired' ) ;
//var oProperty = document.getElementById( 'property' ) ;
//var oAmount = document.getElementById( 'amount' ) ;
var oFrm = document.getElementById( 'frmSubmit' ) ;
    if ( oFrm ){
       oFrm.submit() ;
    }
}