function GetPartnerName()
{
	return GetURLParam('partner');
}

function GetPageName()
{
	return GetURLParam('page');
}


function GetURLParam(param)
{
	var name_length;
	var name_index;
	var end_index;
	var name = "";
	var params;

	name_index = document.URL.indexOf('?' + param + '=', 0);
	if (name_index == -1)
	{
		name_index = document.URL.indexOf('&' + param + '=', 0);
	}
	if (name_index != -1)
	{
		name_index = name_index + param.length + 2;
		name_end = document.URL.indexOf('&', name_index);
		if (name_end == -1)
		{
			name_length = document.URL.length - name_index;
		}
		else
		{
			name_length = name_end - name_index;
		}
		name = document.URL.substr(name_index, name_length);
	}
	return name;
}

// Determine whether to do a zipcode search or city/state
//     zipcode overrides city/state
function clearcityNav(){
	if(document.qs.cityNav.value == "City")
		{
			document.qs.cityNav.value = "";
		}
	}
	
function clearzipNav(){
	if(document.qs.zipNav.value == "Zip")
		{
			document.qs.zipNav.value = "";
		}
	}
function deterLoadNav()
{

theNavCity = window.document.qs.cityNav.value;
theNavState =
window.document.qs.state.options[window.document.qs.state.selectedIndex].value;
theNavZip = window.document.qs.zipNav.value;
theNavZip = escape(theNavZip);
Rent_Minimum = window.document.qs.Rent_Minimum.value;
Rent_Maximum = window.document.qs.Rent_Maximum.value;

  if (theNavZip != "Zip" && theNavState == "")
  {  
       return loadNavZS();
	   
  }
  else if ( theNavState != "")
  {

       return loadNavQS();
  }
  
  else
  {
    alert("Please enter a \"city and state\" or \"zipcode\".");
    return false;
  }
  
  

}


function loadNavQS(w)
{
var theNavCity;
var theNavState;
var radius;
var bool; 
var partner = GetPartnerName();

theNavCity = window.document.qs.cityNav.value;

	if (theNavCity == "City")
		{
			theNavCity = "";
		}
	
theNavState = window.document.qs.state.options[window.document.qs.state.selectedIndex].value;
radius = window.document.qs.rad.options[window.document.qs.rad.selectedIndex].value;
Rent_Minimum = window.document.qs.Rent_Minimum.value;
Rent_Maximum = window.document.qs.Rent_Maximum.value;
bedrooms = window.document.qs.bedrooms.options[window.document.qs.bedrooms.selectedIndex].value;
	if(radius == '5' || radius == '10' || radius == '20') {
		if(theNavCity == ""){
		alert("Please enter a City");
		document.qs.cityNav.focus();
		return false;
		}
	}
	if(bedrooms == 'studio')
 {

 bedrooms1 = '&studio=0';
 }
 
 else if(bedrooms == 'onebdrm')
 {

 bedrooms1 = '&onebdrm=0';
 }

 else if(bedrooms == 'twobdrm')
 {

 bedrooms1 = '&twobdrm=0';
 }
 
 else  if(bedrooms == 'threebdrm')
 {

 bedrooms1 = '&threebdrm=0';
 }
 else 
 {
 bedrooms1 = ''
 }

 if(Rent_Minimum == "" || Rent_Maximum == "")
    {
      alert ('Rent fields cannot be empty');
       return false;
    }

	else if(!IsNumeric(Rent_Minimum))
    {
	   alert ('Rent fields should have numeric values only');	  
	   document.qs.Rent_Minimum.focus();       
       document.qs.Rent_Minimum.value=0;

       return false;
    }
   
	else if(!IsNumeric(Rent_Maximum))
    {
	   alert ('Rent fields should have numeric values only');	  
	   document.qs.Rent_Maximum.focus();       
       document.qs.Rent_Maximum.value=99999;

       return false;
    }
	
	
bool = validateForm(theNavState);
 if (bool == "n")
{
  return false;
}

else
{

theNavCity = escape(theNavCity);

  var qString;
 if(document.qs.rad.value == '5' || document.qs.rad.value == '10' || document.qs.rad.value == '20'){
	qString = "/Results.aspx?page=results&stype=city&city=" + theNavCity + "&state=" + theNavState  + "&rad=" + radius + "&prvg=5" + "&Rent_Minimum=" + Rent_Minimum + "&Rent_Maximum=" + Rent_Maximum + bedrooms1;
	}
	
  else if (document.qs.rad.value == '0' && document.qs.bedrooms.value == '0' && document.qs.Rent_Minimum.value == '0' && document.qs.Rent_Maximum.value == '99999'){
		qString = "/Rent.aspx?page=rent&stype=city&city=" + theNavCity + "&state=" + theNavState;
	}	
	
  else {

	
	qString = "/Results.aspx?page=results&stype=city&city=" + theNavCity + "&state=" + theNavState + "&prvg=5" + "&Rent_Minimum=" + Rent_Minimum + "&Rent_Maximum=" + Rent_Maximum + bedrooms1;
	}
			if(partner!='' && partner !='magazine')
      {
        qString += "&partner=" + partner
    }
	
	window.document.location = qString;
	
  return false;
}

}

function validateForm(st)
{
var daState = st;

if (daState == "")
{
	alert("Please Select a State from the menu")
	return("n");
}

else
{
return("y");
}
}
//NxB
function loadNavZS()
{
	var theNavZip;
	var bool;
	var partner = GetPartnerName();

	Rent_Minimum = window.document.qs.Rent_Minimum.value;
Rent_Maximum = window.document.qs.Rent_Maximum.value;
bedrooms = window.document.qs.bedrooms.options[window.document.qs.bedrooms.selectedIndex].value;
if(bedrooms == 'studio')
 {

 bedrooms1 = '&studio=0';
 }
 
 else if(bedrooms == 'onebdrm')
 {

 bedrooms1 = '&onebdrm=0';
 }

 else if(bedrooms == 'twobdrm')
 {

 bedrooms1 = '&twobdrm=0';
 }
 
 else  if(bedrooms == 'threebdrm')
 {

 bedrooms1 = '&threebdrm=0';
 }
 else 
 {
 bedrooms1 = ''
 }

 if(Rent_Minimum == "" || Rent_Maximum == "")
    {
      alert ('Rent fields cannot be empty');
       return false;
    }

	else if(!IsNumeric(Rent_Minimum))
    {
	   alert ('Rent fields should have numeric values only');	  
	   document.qs.Rent_Minimum.focus();       
       document.qs.Rent_Minimum.value=0;

       return false;
    }
   
	else if(!IsNumeric(Rent_Maximum))
    {
	   alert ('Rent fields should have numeric values only');	  
	   document.qs.Rent_Maximum.focus();       
       document.qs.Rent_Maximum.value=99999;

       return false;
    }
   


 

	theNavZip = document.qs.zipNav.value;
	
	theNavZip = escape(theNavZip);

	if(theNavZip != "Zip" && theNavZip.length < 5 || theNavZip.length > 5)
	{
		alert("Please enter a 5 digit zip code");
		document.qs.zipNav.focus();
		return false;
	}
	
	
	var qString;
	if(document.qs.rad.value == '5' || document.qs.rad.value == '10' || document.qs.rad.value == '20'){
      qString  = "/Results.aspx?page=results&stype=zip&zip=" + theNavZip + "&rad=" + document.qs.rad.value + "&prvg=5" + "&Rent_Minimum=" + Rent_Minimum + "&Rent_Maximum=" + Rent_Maximum + bedrooms1;
	}
	
	else{
	  qString = "/Results.aspx?page=results&stype=zip&zip=" + theNavZip + "&prvpg=5" + "&Rent_Minimum=" + Rent_Minimum + "&Rent_Maximum=" + Rent_Maximum + bedrooms1;
	  }
	  		  if(partner!='' && partner!='magazine') {
          qString += "&partner=" + partner
        }

	window.document.location = qString;
	return false;
}



function ValidateZip(WebSearchFrm)
{
   if(WebSearchFrm.txtZipCode.value == "") 
   { 
      alert('Missing ZIP information. Please enter a ZIP code to post a listing') 
      WebSearchFrm.txtZipCode.focus(); 
      return false; 
   } 
 
 
   if (!IsNumeric(WebSearchFrm.txtZipCode.value)) 
   { 
      alert('Please enter only numbers in the Zip Code') 
      WebSearchFrm.txtZipCode.focus(); 
      return false; 
      } 
 
 return true;
}
function Form_Validation(WebSearchFrm)
 {
 	 if (WebSearchFrm.txtContactEmail.value == "")
  {
    alert("Please enter a value for the Email field.");
    WebSearchFrm.txtContactEmail.focus();
    return (false);
  }

  var checkOK = "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&#402;&#352;&#338;&#353;&#339;&#376;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789-@. \t\r\n\f";
  var checkStr = WebSearchFrm.txtContactEmail.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit, whitespace and \"@.\" characters in the Contact Email field.");
    WebSearchFrm.txtContactEmail.focus();
    return (false);
  }

  if (!(IsEmailValid(WebSearchFrm.txtContactEmail)))
  		return(false);

	

return true;
 
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function IsEmailValid(ElemName)
{
var EmailOk  = true;
var Temp     = ElemName;
var AtSym    = Temp.value.indexOf('@');
var Period   = Temp.value.lastIndexOf('.');
var Space    = Temp.value.indexOf(' ');
var Length   = Temp.value.length - 1;   // Array is from 0 to length-1
if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
      EmailOk = false;
      alert('Please enter a valid e-mail address!');
      Temp.focus();
   }
return EmailOk;
}

//~NxB
//-->