﻿function MortgageCalc(price)
{
    var minWidth = 338;
    var minHeight = 242;

    price = price.replace("$", "").replace(/,/g, "");
    // remove trailing .00
    var CentsRgex = /\.00$/;
    if (CentsRgex.test(price)) 
    {
        price = price.replace(CentsRgex, '');
    }

    //alert(price);
    
    var URL = "/reno/widgets/mortgagecalc/mortgagecalc.aspx?price=" + price;


    ShowDialog(URL, minWidth, minHeight, function() {
        //Automatically calculate on load
        MC.calculateMortgage();
    });
    
    $("#MC-AskPrice").keyup(function(e)
    {
        $("#MC-AskPrice").val(MC.formatCurrency($("#MC-AskPrice").val().replace(/[\.\,\+]+/g, "")));
    });
    

}

function FlashClickToCall(encodedPhone)
{
    var minWidth = 300;
    var minHeight = 125;

    var URL = "/reno/widgets/video/featuredagent/clicktocall.aspx?n=" + escape(encodedPhone);

    ShowDialog(URL, minWidth, minHeight);
}

function EmailAgent(id, idType, reportData)
{
//	var idType = "idlisting";
//	
//	if (altIdType != undefined)
//	{
//		idType = altIdType;
//	}
    var minWidth = 338;
    var minHeight = 267;
	
    var URL = "/reno/widgets/emailagent/emailagent.aspx?" + idType + "=" + id + 
				"&reportData=" + escape(reportData) +
				"&referrer=" + escape(window.location.href);

    ShowDialog(URL, minWidth, minHeight, function() {
        $("#agent_form").validate({
            rules: {
                email_agent_user_name: { required: true },
                email_agent_user_email: { required: true, email: true },
                email_agent_user_message: { required: true }
            }
        });
    });
}

function EmailFriend(message) 
{
    var minWidth = 338;
    var minHeight = 467;

    URL = window.location.href + "/email-friend?message=" + message; // path is suffix of SEO URL

    // window.location.href = URL;

    ShowDialog(URL, minWidth, minHeight, function() {

        // create custom validator that matches
        // comma-separated email addresses
        jQuery.validator.addMethod("emails", function(value, element) {
        return this.optional(element) || /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(\s*[,]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*(\s*([,])?\s*)?$/.test(value);
        }, "Invalid email address(es)");


        $("#friend_form").validate({
            rules: {
                email_friend_user_name: { required: true },
                email_friend_user_email: { required: true, email: true },
                email_friend_email: { required: true, emails: true }
            }
        });
    });
}

function SendToCell(message) 
{
    var minWidth = 358;
    var minHeight = 417;

    URL = window.location.href + "/send-cell?message=" + message // path is suffix of SEO URL

    ShowDialog(URL, minWidth, minHeight, function() {
        $("#sendtocell_form").validate({
            rules: {
                sendtocell_phone123: { required: true, number: true },
                sendtocell_phone456: { required: true, number: true },
                sendtocell_phone7890: { required: true, number: true },
                sendtocell_to_email: { required: true }
            },
            groups: {
                tel: "sendtocell_phone123 sendtocell_phone456 sendtocell_phone7890"
            },
            messages: {
                sendtocell_to_email: "Select a cell carrier"
            },
            errorPlacement: function(error, element) {
                if (element[0] == $("#sendtocell_to_email")[0]) {
                    $("#sendtocell_to_email").parent().append(error);
                }
                else {
                    $("#sendtocell_phone").append(error);
                }
            }
        });
    });
}


function VideoOnDemand(ID)
{
    var minWidth = 320;
    var minHeight = 320;

    var URL = "/reno/widgets/video/videoondemand/videoondemandframe.aspx?IdListing=" + ID;
	//window.location.href = URL;
    ShowDialog(URL, minWidth, minHeight);
}


