/* Scrolls to the position of an element whose id is passed in via QueryString */
function scrollToPosition() {

	if (querystring('jumpTo') != '')
	{	
		var offsetTrail
		if (document.getElementById)
			offsetTrail = document.getElementById(querystring('jumpTo'));
		else
			offsetTrail = document.all.querystring('jumpTo');
			
		var ly = 0;
		while (offsetTrail)
		{	
			ly += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
	
		scrollTo(0, ly);
	}
}

 // querystring
// Call function by x = querystring("variable") returns variable=x

function querystring(key)
{
	var value = null;
	for (var i=0;i<querystring.keys.length;i++)
	{
		if (querystring.keys[i]==key)
		{
			value = querystring.values[i];
			break;
		}
	}
	return value;
}

querystring.keys = new Array();
querystring.values = new Array();

function querystring_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");

	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		querystring.keys[querystring.keys.length] = argname;
		querystring.values[querystring.values.length] = value;
		}
	}
}
querystring_Parse();

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function tvschedule() {
 theURL = "tvpopup/index.php";
 winName = "tvpopup";
 features = "scrollbars=yes,width=500,height=395'";
 window.open(theURL,winName,features);	
}

onLoad="MM_preloadImages('/images/nexthome_header_about_on.gif','/images/nexthome_header_selling_on.gif','/images/nexthome_header_buying_on.gif','/images/nexthome_header_open_on.gif','/images/nexthome_header_mortgages_on.gif','/images/nexthome_header_pocket_on.gif','/images/nexthome_header_video_on.gif','/images/nexthome_header_careers_on.gif','/images/nexthome_header_contact_on.gif')"

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function AddThousandsSeparator (tempNumber, separator)
{
    var counter = 0;
    var tempNumArray = tempNumber.split('');
    var tempNumFormatted = ''

    for (var i = tempNumber.length; i > 0; --i) {
        if (counter == 3) {
            tempNumFormatted = separator + tempNumFormatted;
            counter = 0;
        }
        tempNumFormatted = tempNumArray[i - 1] + tempNumFormatted;
        ++counter;
    }
    return tempNumFormatted;
}

function CalculateSavings ()
{
    document.calculator.commission.value = Math.round(.06 * Number(document.calculator.price.value.replace(',', '')));
    document.calculator.commission.nextSibling.nodeValue = AddThousandsSeparator(document.calculator.commission.value, ',');
    document.calculator.savings.nextSibling.nodeValue = AddThousandsSeparator(String(document.calculator.commission.value - 995), ',');
}

function CheckFormValues ()
{
    if (document.HomeSearchForm.SignNumber.value.length < 1 && document.HomeSearchForm.MLSNumber.value.length < 1 && document.HomeSearchForm.cityName.selectedIndex < 0) {
        alert("You must enter a Sign Number or an MLS number,\n or select a Region and City to continue");
    } else {
        SetFormAction();
    }
    return true;
}

function CheckFormValuesAdvance ()
{
    if (document.HomeSearchForm.SignNumber.value.length < 1 && document.HomeSearchForm.MLSNumber.value.length < 1 && document.HomeSearchForm.cityName1.selectedIndex < 0 && document.HomeSearchForm.zip.value.length < 1) {
        alert("You must enter a Sign Number, an MLS number or a zip code,\n or select a Region and City to continue");
    } else {
        SetFormAction();
    }
    return true;
}

function SetFormAction ()
{
    if (document.HomeSearchForm.SignNumber.value.length > 0 || document.HomeSearchForm.MLSNumber.value.length > 0) {
        document.HomeSearchForm.action = 'detail.php';
    } else {
        document.HomeSearchForm.action = 'list.php';
    }
    return true;
}

function CheckFormValues_hor ()
{
        
    if (document.HomeSearchForm.cityName.selectedIndex < 0) {
        alert("You must enter a Region and City to continue");
    } else {
		 SetFormAction_hor();
    }
    return true;
}

function SetFormAction_hor ()
{
    
        document.HomeSearchForm.action = 'list.php';
    
    return true;
}

function createSendToFriendWindow(propid)
{
    var xWin = window.open("emailpropinfo.php?propid="+propid,"window2","width=500,height=450,scrollbars,resizable");
}

function LLWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}