<!--

// Auto-bookmark the website when the function is called.
function addToFavorites() {
	if (navigator.appName == 'Microsoft Internet Explorer' && parseInt(navigator.appVersion) >= 4) {
		window.external.AddFavorite('http://www.valvanorealty.com/', 'Valvano Real Estate Agency');
	}
}


// Auto-bookmark Script
var bookmarkurl="http://alvanorealty.com"
var bookmarktitle="Valvano Real Estate Agency"
function addbookmark(){
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}


// close pop-up image windows
function closeImageWindow() {
	if (ImageWindow != null && !ImageWindow.closed) ImageWindow.close();
}


// open a new, formatted image window
var ImageWindow = null;
function openImage(imageURL,imageTitle,imageWidth,imageHeight) {
	// check if window is open: then close
	closeImageWindow();

	// create an Image Window
	ImageWindow = openCenteredWindow('','ImageWindow'+imageWidth+'_'+imageHeight,imageWidth,imageHeight,'no');
	// write to, and format, ImageWindow
	ImageWindow.document.open();
	ImageWindow.document.write("<HTML><HEAD><TITLE>" + imageTitle + "</TITLE></HEAD><BODY BGCOLOR=black LEFTMARGIN=0 TOPMARGIN=0 onClick=\"window.close()\" STYLE=\"margin: 0px;\"><TABLE WIDTH=100% HEIGHT=100% CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN=CENTER VALIGN=MIDDLE><IMG SRC=\"" + imageURL + "\" BORDER=0></TD></TR></TABLE></BODY></HTML>");
	ImageWindow.document.close();
}


// open a content window (with consideration for screen size)
function openCenteredWindow(contentURL,contentTitle,contentWidth,contentHeight,scrollBars) {
	// center window on screen
	var winLeft = (screen.width - 1 - contentWidth) / 2;
	var winTop = (screen.height - 1 - contentHeight) / 2;

	if (winLeft < 0) {
		scrollBars = "yes";
		winLeft = 10;
		contentWidth = screen.width - 30;
	}
	if (winTop < 0) {
		scrollBars = "yes";
		winTop = 10;
		contentHeight = screen.height - 100;
	}

	var NewWindow = window.open(contentURL,contentTitle,'scrollbars='+scrollBars+',width='+contentWidth+',height='+contentHeight+',top='+winTop+',left='+winLeft+',screenX='+winLeft+',screenY='+winTop);
	NewWindow.focus();
	return NewWindow;
}


// Required Fields Script
function formCheck(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("realname", "email", "My telephone number");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("Your Name", "Your Email Address", "Your Telephone Number");
	//3) Enter dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}


//Popup Script
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=260,left = 490,top = 362');");
}


// Calculator Script
function bank(num)

{

   var1 = (num * 100) % 1;
   var2 = (num * 100) - var1;
   if (var1 > 0)
   {var2 += 1;}
   num = var2 / 100;
   return num;

}

function checkNumber(input, min, max, msg)

{

    msg = msg + " field has invalid data: " + input.value;
    var str = input.value;
    for (var i = 0; i < str.length; i++) {

        var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {

            alert(msg);
            return false;

        }

    }

    var num = 0 + str
    if (num < min || max < num) {

        alert(msg + " not in range [" + min + ".." + max + "]");
        return false;

    }

    input.value = str;
    return true;

}

function computeField(input)

{

    if (input.value != null && input.value.length != 0)

        input.value = "" + eval(input.value);

    computeForm(input.form);

}

function computeForm(form)

{

    if ((form.annum.value == null || form.annum.value.length == 0) ||

        (form.interest.value == null || form.interest.value.length == 0) ||
        (form.purchase.value == null || form.purchase.value.length == 0)) {
        return;

    }

    if ((form.down.value == null) || form.down.value.length == 0)

         {form.down.value = 0;}

    if (!checkNumber(form.annum, 1, 40, "# of years") ||

       !checkNumber(form.interest, .001, 99, "Interest") ||

        !checkNumber(form.purchase, 25, 100000000, "Purchase")) {
        form.payment.value = "Invalid";
        return;

    }

    var i = form.interest.value;
    if (i < 1.0)

      {

        i = i * 100;
        form.interest.value = i;

      }

    i = form.interest.value / 100;
    pow = 1 + (i/2);
    i = Math.pow(pow, 1/6) - 1;
    bot1 = (1 / (1 + i))
    bot2 = Math.pow(bot1, (form.annum.value * 12))
    form.payment.value = ((form.purchase.value - form.down.value)* i) / (1 - bot2);
    form.payment.value = bank(form.payment.value);

}

function clearForm(form)

{

    form.annum.value = "";
    form.interest.value = "";
    form.purchase.value = "";
    form.down.value = "";
    form.payment.value = "";

}

//-->