//////////////////////////////////////////////////////////////////
// Constants

var winparams = '';
var winHeight = (window.screen.height/2) - 350 ;
var winWidth = (window.screen.width/2) - 300 ;

winparams += 'height=600,';
winparams += 'width=700,';
winparams += 'toolbar=1,';
winparams += 'menubar=1,';
winparams += 'directories=0,';
winparams += 'location=0,';
winparams += 'status=1,';
winparams += 'resizable=1,';
winparams += 'scrollbars=1,';
winparams += 'top=' + winHeight + ',';
winparams += 'left=' + winWidth + ',';

var winparamsCalc = '';
var winHeightCalc = (window.screen.height/2) - 500 ;
var winWidthCalc = (window.screen.width/2) - 468 ;

winparamsCalc += 'height=500,';
winparamsCalc += 'width=468,';
winparamsCalc += 'toolbar=0,';
winparamsCalc += 'menubar=0,';
winparamsCalc += 'directories=0,';
winparamsCalc += 'location=0,';
winparamsCalc += 'status=0,';
winparamsCalc += 'resizable=1,';
winparamsCalc += 'scrollbars=1,';
winparamsCalc += 'top=' + winHeight + ',';
winparamsCalc += 'left=' + winWidth + ',';

var winparams2 = '';
var winHeight2 = (window.screen.height/2) - 150 ;
var winWidth2 = (window.screen.width/2) - 175 ;

winparams2 += 'height=300,';
winparams2 += 'width=350,';
winparams2 += 'toolbar=0,';
winparams2 += 'menubar=0,';
winparams2 += 'directories=0,';
winparams2 += 'location=0,';
winparams2 += 'status=1,';
winparams2 += 'resizable=1,';
winparams2 += 'scrollbars=0,';
winparams2 += 'top=' + winHeight2 + ',';
winparams2 += 'left=' + winWidth2 + ',';


var winparams3 = '';
var winHeight3 = (window.screen.height/2) - 600 ;
var winWidth3 = (window.screen.width/2) - 300 ;

winparams3 += 'height=580,';
winparams3 += 'width=620,';
winparams3 += 'toolbar=0,';
winparams3 += 'menubar=0,';
winparams3 += 'directories=0,';
winparams3 += 'location=0,';
winparams3 += 'status=1,';
winparams3 += 'resizable=0,';
winparams3 += 'scrollbars=0,';
winparams3 += 'top=' + winHeight3 + ',';
winparams3 += 'left=' + winWidth3 + ',';

var winparams4 = '';
var winHeight4 = (window.screen.height/2) - 200 ;
var winWidt4 = (window.screen.width/2) - 350 ;

winparams4 += 'height=250,';
winparams4 += 'width=350,';
winparams4 += 'toolbar=0,';
winparams4 += 'menubar=0,';
winparams4 += 'directories=0,';
winparams4 += 'location=0,';
winparams4 += 'status=0,';
winparams4 += 'resizable=0,';
winparams4 += 'scrollbars=0,';
winparams4 += 'top=' + winHeight + ',';
winparams4 += 'left=' + winWidth + ',';

var winparams544x339 = '';
var winHeight544x339 = (window.screen.height/2) - 250 ;
var winWidt544x339 = (window.screen.width/2) - 330 ;

winparams544x339 += 'height=339,';
winparams544x339 += 'width=544,';
winparams544x339 += 'toolbar=0,';
winparams544x339 += 'menubar=0,';
winparams544x339 += 'directories=0,';
winparams544x339 += 'location=0,';
winparams544x339 += 'status=0,';
winparams544x339 += 'resizable=0,';
winparams544x339 += 'scrollbars=0,';
winparams544x339 += 'top=' + winHeight + ',';
winparams544x339 += 'left=' + winWidth + ',';

var winparams650x450 = '';
var winHeight650x450 = (window.screen.height/2) - 250 ;
var winWidt650x450 = (window.screen.width/2) - 330 ;

winparams650x450 += 'height=450,';
winparams650x450 += 'width=650,';
winparams650x450 += 'toolbar=0,';
winparams650x450 += 'menubar=0,';
winparams650x450 += 'directories=0,';
winparams650x450 += 'location=0,';
winparams650x450 += 'status=0,';
winparams650x450 += 'resizable=1,';
winparams650x450 += 'scrollbars=1,';
winparams650x450 += 'top=' + winHeight + ',';
winparams650x450 += 'left=' + winWidth + ',';

var winparams250x350 = '';
var winHeight250x350 = (window.screen.height/2) - 150 ;
var winWidt250x350 = (window.screen.width/2) - 200 ;

winparams250x350 += 'height=350,';
winparams250x350 += 'width=250,';
winparams250x350 += 'toolbar=0,';
winparams250x350 += 'menubar=0,';
winparams250x350 += 'directories=0,';
winparams250x350 += 'location=0,';
winparams250x350 += 'status=0,';
winparams250x350 += 'resizable=1,';
winparams250x350 += 'scrollbars=1,';
winparams250x350 += 'top=' + winHeight + ',';
winparams250x350 += 'left=' + winWidth + ',';


//////////////////////////////////////////////////////////////////
// FUNCTIONS

function getUnitListingPrice(count) {
    var price = 0;
    if(count <= 24) {
            price = count * 19.95;
    } else if(count <= 49) {
        price = count * 17.95;
    } else if(count <= 99) {
        price = count * 14.95;
    } else {
        price = count * 10.95;
    }
 
    if ((price > 0) || (price == "")) {
        return format_number(price, 2);
    } else {
        return "Please Call";
    }
}

function getResaleUnitListingPrice(count) {
    var price = 99.95 * count ; 
    if ((price > 0) || (price == "")) {
        return format_number(price, 2);
    } else {
        return "Please Call";
    }
}

/*
    revision: 1.2.0
    Authors: Buddhike de Silva
    Date: 22-Nov-2002 12:07 PM
    Notes: Optimized for best performance.
    usage: x = format_number(123.999, 2)
*/
function format_number(pnumber,decimals) {
    if (isNaN(pnumber)) { return 0};
    if (pnumber=='') { return 0};

    var snum = new String(pnumber);
    var sec = snum.split('.');
    var whole = parseFloat(sec[0]);
    var result = '';

    if(sec.length > 1) {
        var dec = new String(sec[1]);
        dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals)));
        dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals));
        var dot = dec.indexOf('.');
        if(dot == -1) {
            dec += '.';
            dot = dec.indexOf('.');
        }
        while(dec.length <= dot + decimals) { dec += '0'; }
        result = dec;
    } else {
        var dot;
        var dec = new String(whole);
        dec += '.';
        dot = dec.indexOf('.');
        while(dec.length <= dot + decimals) { dec += '0'; }
        result = dec;
    }
    return result;
}

function isValid(frm) {

    if (frm.invfirstname.value == "")
    {
    alert("Please enter a value for the \"First Name\" field.");    
    frm.invfirstname.focus();
    return false;
    }

    if (frm.invlastname.value == "")
    {
    alert("Please enter a value for the \"Last Name\" field.");    
    frm.invlastname.focus();
    return false;
    }

    var email=frm.invemail.value;
    if (email.indexOf(' ')==-1 
        && 0<email.indexOf('@')
        && email.indexOf('@')+1 < email.length
    ) 
     var checkEmail=0
    else checkEmail=1;

    if (checkEmail == '1')
    {
    alert("Please enter a valid email address.");    
    frm.invemail.focus();
    return false;
    }
    
    if (!frm.invauth.checked)
    {
    alert("To continue, you must acknowledge that the recipient is aware of this solicitation.\nYou will be unable to send the UFOC invitation unless you agree to the authorization statement.");    
    frm.invauth.focus();
    return false;
    }

}

function goClose() {
        window.close();
}

function over_effect(e,state){
    if (document.all) source4=event.srcElement
    else if (document.getElementById) source4=e.target
    if (source4.className=="menulines") source4.style.borderStyle=state
    else{
        while(source4.tagName!="TABLE"){
            source4=document.getElementById? source4.parentNode : source4.parentElement
            if (source4.className=="menulines") source4.style.borderStyle=state
        }
    }
}

function selectRegion() {
    var f = document.forms["matchmaker"];
    f.arg.value = "1";
    f.submit();
}

function Go() {
    return;
}

/*
* This function will not return until (at least)
* the specified number of milliseconds have passed.
* It does a busy-wait loop.
* stolen from http://www.faqts.com/knowledge_base/view.phtml/aid/1602/fid/143
*/
function busyWait(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}


function checkAssetPath(theForm)
{
    if (theForm.txtFileName.value == "")
    {
        alert('Please choose a file by clicking the "Browse..." button.');
        theForm.txtFileName.focus();
        return(false);
    }
    return(true);
}


function AreYouSure(page) {
var digo = '';
digo += 'Are you sure you want to do this?';

    if(confirm(digo)) {
        window.location.href = page;
    }
}


function popup( page , windowName , features ) {
    window.open( page , windowName , features )
}


function CheckResponse(theForm) {
    //only validate when status = Active
    if (theForm.opt[0].checked==false) { return true; }

    if (theForm.txtReplyToAddress.value == "")
    {
      alert("Please enter a value for the \"Reply-To Address\" field.");
      theForm.txtReplyToAddress.focus();
      return (false);
    }

    if (theForm.txtReplyToAddress.value.length > 150)
    {
      alert("Please enter at most 150 characters in the \"Reply-To Address\" field.");
      theForm.txtReplyToAddress.focus();
      return (false);
    }

    if (theForm.txtSubject.value == "")
    {
      alert("Please enter a value for the \"Subject\" field.");
      theForm.txtSubject.focus();
      return (false);
    }

    if (theForm.txtSubject.value.length > 50)
    {
      alert("Please enter at most 50 characters in the \"Subject\" field.");
      theForm.txtSubject.focus();
      return (false);
    }

    if (theForm.txtMessage.value == "")
    {
      alert("Please enter a value for the \"Message Text\" field.");
      theForm.txtMessage.focus();
      return (false);
    }

    if (theForm.txtMessage.value.length > 1000)
    {
      alert("Please enter at most 1000 characters in the \"Message Text\" field.");
      theForm.txtMessage.focus();
      return (false);
    }
    return (true);
}

function isDate(iYear, iMonth, iDay) {
   if (iDay == 31 
       && ( iMonth == 4
         || iMonth == 6
         || iMonth == 9
         || iMonth == 11 )
       ) {
      alert("Month "+iMonth+" Doesn't have 31 days");
      return false;
   }
      
   if (iMonth == 2) { // check for february 29th
        var bIsLeap = (iYear % 4 == 0 && (iYear % 100 != 0 || iYear % 400 == 0));
        if (iDay > 29 || (iDay==29 && !bIsLeap)) {
            alert("February " + iYear + " doesn't have " + iDay + " days");
            return false;
        }
   }

   return true;
}


function getSelectValue( selectBox ) {
   return selectBox.options[selectBox.selectedIndex].value;
}

function computeNetWorth(form)
{
var a = parseInt(form.HomeValue.value, 10) + parseInt(form.CarValue.value, 10);
var b = parseInt(form.SpecialValue.value, 10);
var c = parseInt(form.AccountValue.value, 10) + parseInt(form.RetirementValue.value, 10); 
var d = parseInt(form.LifeInsValue.value, 10) + parseInt(form.OtherValue.value, 10); 
form.AssetTotal.value = a + b + c + d;
if (form.AssetTotal.value == "NaN"){
form.AssetTotal.value = "No blanks in the form allowed!"
}
var e = parseInt(form.MortgageLoan.value, 10) + parseInt(form.CarLoan.value, 10) 
+ parseInt(form.CollegeLoan.value, 10);
var f = parseInt(form.OtherLoan.value, 10)  + parseInt(form.CreditCardLoan.value, 10);
form.LiabilityTotal.value = e + f;
if (form.LiabilityTotal.value == "NaN"){
form.LiabilityTotal.value = "No blanks in the form allowed!"
}
form.NetWorth.value = parseInt(form.AssetTotal.value, 10) - parseInt(form.LiabilityTotal.value, 10);
if (form.NetWorth.value == "NaN"){
form.NetWorth.value = "No blanks in the form allowed!"
}

}

function stripComma(id) {
  for (i = 0; i < id.value.length; i++) {
    ch = id.value.substring(i, i + 1);
    if ((ch == "$") || (ch == ",")) {
      id.value = id.value.substring(0,i)+id.value.substring(i+1,id.value.length)
      i=i-1
    }
  }
}

function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
self.name = "mainWin";
}

