﻿
//page init (for striped, gradient back)
function bginit() {
    var bd = document.getElementById('divBodyMain');
    var bht = bd.offsetHeight + 10;
    var cHeight = getHt();

    if ((bht + 200) < cHeight) {
        bd.style.height = (cHeight - 200).toString() + 'px';
        bht = bd.offsetHeight + 10;
    }

    bd.style.backgroundImage = "URL('/Images/BuildImage.aspx?imgType=Body&O=Vertical&H=" + bht.toString() + "&SC=F2ECC4&FC=F2E079')";
    document.getElementById('divFooterMain').style.backgroundImage = "URL('/Images/BuildImage.aspx?imgType=Footer')";
}

//gradient back generator
function getGradient(obj, startColor, finishColor) {
    var ht = obj.offsetHeight + 10;
    document.getElementById('heightTester').style.backgroundImage = "URL('ImageReturn.aspx?O=Vertical&H=" + ht.toString() + "&SC=" + startColor + "&FC=" + finishColor + "')";

}

function getHt() {
    var myHeight = 0;
    if (typeof (window.innerWidth) == 'number') //non-ie
        myHeight = window.innerHeight;
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) //ie6 scm
        myHeight = document.documentElement.clientHeight;
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) //ie4 compat.
        myHeight = document.body.clientHeight;

    return myHeight;
}


function WatermarkFocus(txtElem, strWatermark) {
    if (txtElem.value == strWatermark) {
        txtElem.style.color = "#000000";
        txtElem.value = '';
    }
}

function WatermarkBlur(txtElem, strWatermark) {
    if (txtElem.value == '') {
        txtElem.style.color = "#666666";
        txtElem.value = strWatermark;
    }
}


//zip code validation (and submission - right now to foreclosures)
function TrimString(sInString) {
    sInString = sInString.replace(/^\s+/g, ""); // strip leading
    return sInString.replace(/\s+$/g, ""); // strip trailing
}
function zipCheck(strValue) {
    var objRegExp = /(^\d{5}$)/;
    return objRegExp.test(strValue);
}
function zipsubmit_foreclosure(zipfield, err) {
    document.getElementById(zipfield).value = TrimString(document.getElementById(zipfield).value)
    if (zipCheck(document.getElementById(zipfield).value)) {
        window.open('http://fsbocom.foreclosure.com/search.html?zip=' + document.getElementById(zipfield).value);
    }
    else 
    {
        document.getElementById(err).innerText = "Please enter a valid zip code.";
        document.getElementById(err).style.display = 'block';
    }
    return false;
}

function zipsubmit_seller(zipfield, err) 
{
    var ret = false;
    document.getElementById(zipfield).value = TrimString(document.getElementById(zipfield).value)

    if (zipCheck(document.getElementById(zipfield).value)) {
        ret = true;
    }
    else 
    {
        document.getElementById(err).innerText = "Please enter a valid zip or postal code.";
        document.getElementById(err).style.display = 'block';
    }
    
    return ret;
}

//-------------------------------------------------------------------
var popupsCounter = 0;

function popupHelp(objName, helptext)
{
    var divIdName = 'popupHelp_' + objName;
    
    if(document.getElementById(divIdName))
    {
        document.getElementById('popupHelp_' + objName).style.display = 'block';
    }
    else
    {
        var z = 9000;
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id',divIdName);
        
        newdiv.style.fontFamily = 'Verdana, Geneva, Lucida, Arial, Helvetica, sans-serif';
        newdiv.style.fontSize = '8pt';
        newdiv.style.color = '#666666';
        newdiv.style.textDecoration = 'none';
        newdiv.style.fontWeight = 'bold';
        newdiv.innerHTML = helptext;
	    newdiv.style.display = "block";
	    newdiv.style.position = "absolute";
	    newdiv.style.borderTop = "solid 1px #666666";
	    newdiv.style.borderLeft = "solid 1px #666666";
	    newdiv.style.borderBottom = "double 2px #333333";
	    newdiv.style.borderRight = "double 2px #333333";
	    newdiv.style.backgroundColor = "#eeeeee";
	    newdiv.style.padding = "4px";
        newdiv.style.zIndex = (z + popupsCounter).toString();
    	

	    var placement = findPos(document.getElementById(objName));

	    newdiv.style.left = (placement[0] + 20).toString() + "px";
	    newdiv.style.top = (placement[1]).toString() + "px";
    	
	    document.body.appendChild(newdiv);
	    popupsCounter++;
	}
}

function hidePopup(objName) 
{
    document.getElementById('popupHelp_' + objName).style.display = 'none';
}

function findPos(obj) {

	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ajaxRequest() {
    var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
    if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
        for (var i = 0; i < activexmodes.length; i++) {
            try {
                return new ActiveXObject(activexmodes[i])
            }
            catch (e) {
                //suppress error
            }
        }
    }
    else if (window.XMLHttpRequest) // if Mozilla, Safari etc
        return new XMLHttpRequest()
    else
        return false
}