Drag From Title Bar
This looks kinda like a window or dialog box.
*/
var tempX = 0; //stores mouse x (horizontal) on movement
var tempY = 0; //stores mouse y (vertical) on movement
var active=false; //controls whether or not to drag on movement;
var active_el=false; //stores the current element id being dragged set to false on drop!
var beginX=tempX; //stores the starting left pixel location of the upper left corner of the element being dragged.
var beginY=tempY; //stores the starting top pixel location of the upper left corner of the element being dragged.
var Yoffset=tempY; //computed destination of the top pixel location for top left corner of the element being dragged.
var Xoffset=tempX; //computed destination of the left pixel location for top left corner of the element being dragged.
var highZ=900; //incremented to make the item picked up the highest in the z-index order. Puts selected element on top.
var IE = document.all?true:false //browser detection
if (!IE)
{
document.captureEvents(Event.MOUSEMOVE) //the mouse moved
document.captureEvents(Event.MOUSEUP) //the mouse button has been released
document.onmousemove = getMouseXY; //when the mouse moves call perform function getMouseXY();
document.onmouseup = dropIt; //when the mouse button has been released perform function dropIt();
} // NEXT 2 LINES ARE FOR ALL OTHER BROWSERS NOT I.E.
document.onmousemove = getMouseXY; //when the mouse moves call perform function getMouseXY();
document.onmouseup = dropIt; //when the mouse button has been released perform function dropIt();
// Captures the pointer's x and y coordinates called on mousemove.
// Summons dragIt()
// If the variable "active" is set to false then dragIt() will
// do nothing and the mouse movement is contued to be tracked.
function getMouseXY(e)
{
if (IE)
{
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
dragIt();
}
else
{
tempX = e.pageX
tempY = e.pageY
dragIt();
}
//make sure the mouse didn't leave the page.
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
return true
}
//When passed an element id from a span or div this will set it up to be dragged
function pickUP(el)
{
active_el=el; //set the name of the active element.
active=true; //turn on dragging.
document.getElementById(active_el).style.position='absolute'; //set the elements position attribute to absolute
document.getElementById(active_el).style.zIndex=highZ++; //lift it higher than the others
beginX=document.getElementById(active_el).style.left; //set the left pixal
beginY=document.getElementById(active_el).style.top; //set the top pixal
Xoffset= parseInt(tempX) - parseInt(beginX); //compute and store left offset
Yoffset= parseInt(tempY) - parseInt(beginY); //compute and store top offset
}
//Moves the element based on computed offset values from the pickUP function
function dragIt()
{
if(active==true) //is the active variable set to true?
{
var X=tempX - Xoffset; //compute new left pixal location of the upper left corner
var Y=tempY - Yoffset; //compute new top pixal location of the upper left corner
document.getElementById(active_el).style.left=X+'px'; //set new left pixal location of the upper left corner
document.getElementById(active_el).style.top=Y+'px'; //set new top pixal location of the upper left corner
}
}
//Deactivates dragging unsets the active element id.
function dropIt()
{
if(active)
{
active=false;
active_el=false;
}
}
function showCalc(price)
{
document.getElementById('calculator').style.visibility='visible';
document.getElementById('calculator').style.top=tempY+'px';
document.getElementById('calculator').style.left=tempX-100+'px';
document.mortgagecalc.LoanAmount.value=price;
document.mortgagecalc.AnnualRate.value=8;
document.mortgagecalc.Years.value=30;
MonthlyPayment()
}
function hideCalc()
{
document.getElementById('calculator').style.visibility='hidden';
}
function MonthlyPayment() {
LoanAmount = document.mortgagecalc.LoanAmount.value
AnnualRate = document.mortgagecalc.AnnualRate.value
Years = document.mortgagecalc.Years.value
MonthlyRate = AnnualRate / ( 12 * 100 )
Periods = Years * 12
Base = 1 + MonthlyRate
Exponent = -1 * Periods
MPayment = LoanAmount * ( MonthlyRate / ( 1 - Math.pow(Base,Exponent) ) )
Money = MPayment
Money = Money * 100
Money = Math.round(Money)
Money = Money / 100
TotalCost = MPayment * Periods
MoneyTC = TotalCost
MoneyTC = MoneyTC * 100
MoneyTC = Math.round(MoneyTC)
MoneyTC = MoneyTC / 100
document.mortgagecalc.Answer.value = "$" + Money
}
// -->