﻿function SubmitFormAgt() {

    var zip = document.getElementById('txtZipCodeAgt');
    
    if (zip != null) {
		if (!zip.value.match(/^\d\d\d\d\d$/)) {
			zip.className = 'invalidfields';
			alert('Invalid ZIP format.');
			return;
		}
		pic1 = new Image(1, 1); pic1.src = "/clicktrack.aspx?type=trackpartnerclick&url=" + location.href + "&serviceProv=USRealEstate.com";
        window.open('http://www.usrealestate.com/find_agent.asp?z=' + zip.value +'&search_type=direct_zip');
    }
}

function ChangePointerAgt(ctr) {
    ctr.style.cursor = 'hand';
}

function HideDhtmlAgt() {
    document.getElementById('DhtmlDivAgt').style.visibility = 'hidden';
}

function CreateFormAgt() {
    var html = "";
    html += "<div class='sb_agent'>";
    html += "	<div class='sb_a_top'><!-- --></div>";
    html += "	<div class='sb_a_inner'>";
    html += "		<h5>Find a Realtor</h5>";
    html += "       <p><label for='hezp'>Enter Zip Code:</label></p>";
    html += "       <p><input type='text' maxlength='5' class='txtStyle' id='txtZipCodeAgt' />&nbsp;<span id='Span4' onclick='ShowZipFinderAgt(this)' class='js_field_zipfinder'>Zip Finder</span></p>";
    html += "		<p class='btn_'><img src='http://www.relocation.com/files/buttons/button_submit.jpg' onclick='SubmitFormAgt()' onmouseover='ChangePointerAgt(this)'  /></p>";
    html += "   </div>";
    html += "	<div class='sb_a_bot'><!-- --></div>";
    html += "</div>";

    document.write(html);
    HideDhtmlAgt();
}

document.write('<div id="DhtmlDivAgt" class="js_form_zipfinder"><div class="jsf_close"><span onclick="HideDhtmlAgt()">Close</span></div><div class="jsf_iframe"><iframe src="/MiscPages/ZipCodeFinder.aspx?FromJS=true&ParentDest=Agt" id="iFrameZipFinder" frameborder="0" scrolling="no" width="250" height="250"></iframe></div></div>');
function ShowZipFinderAgt(obj) {
    findPositionAgt(obj, "DhtmlDivAgt");
}

function findPositionAgt(oElement, dhtmlDivAgt) {
    oDiv = document.getElementById(dhtmlDivAgt);
    if (typeof (oElement.offsetParent) != 'undefined') {
        for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
            posX += oElement.offsetLeft;
            posY += oElement.offsetTop;
        }
        oDiv.style.top = posY;
        if (dhtmlDivAgt == 'DhtmlDivAgt') {
            oDiv.style.top = posY - 70 + 'px';
        }

        oDiv.style.left = posX + 55 + 'px';
    }
    else {
        oDiv.style.top = oElement.y + 'px';
        oDiv.style.left = oElement.x + 'px';
    }
    oDiv.style.visibility = 'visible';
}

function SetZipOfParentAgt(zipCode) {

    var zip = document.getElementById('txtZipCodeAgt');
    if (zip != null) {
        zip.value = zipCode;
    }

    HideDhtmlAgt();
}

