var focusSwitch = false;
//used in all pages with a rental search function

// no longer pre-populating the search field
/*function setFormValue(string,elementName,obj,elementType) {
var startPos = string.indexOf(elementName + "=");
if (startPos > -1) {
startPos = startPos + elementName.length + 1;
var endPos = string.indexOf("&",startPos);
if (endPos == -1) endPos = string.length;
var elementValue = unescape(string.substring(startPos,endPos));
if (elementType == "text" || elementType == "password") obj.value = elementValue;
if (elementType == "select") obj.selectedIndex = parseInt(elementValue);
}
}

function getValues(string) {
if(document.f.city.value=='' && document.f.state.selectedIndex==0) {
setFormValue(string,"city",document.f.city,"text");
setFormValue(string,"state",document.f.state,"select");
}
}
*/

function setup() {
setupsearch();
var myLogin = GetCookie("pfr");
changeLoginType(myLogin);
}

function setup2() {
var myLogin = GetCookie("pfr");
changeLoginType(myLogin);
}

function setupsearch() {
//var lastSearch = GetCookie("lastSearch");
//if (lastSearch) getValues(lastSearch);
if (focusSwitch) return;
else {
  document.f.elements[0].focus();
  focusSwitch = true;
}
}


function submitform(f) {
x = f.state;
y = f.city;
while(''+y.value.charAt(y.value.length-1)==' ')
y.value=y.value.substring(0,y.value.length-1);
if (y.value=='') {
alert("Please enter a city");
y.focus();
return false;
}
if (x.value=='') {
alert("Please select a state")
x.focus();
return false;
}
/*var today = new Date();
var expires = new Date(today.getTime() + (56 * 86400000));
var cStr = "city="+f.city.value+"&state="+f.state.selectedIndex;
SetCookie("lastSearch",cStr,expires);
return true;
*/
}




//for use by all pages requiring a popup window

function getAttributes(type) {
var width;
var height;
var options;
var attributes;

if (type=="RentalsHelp") {
width="630";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,z-lock=0";
} 

	
else if (type=="RentalsPreview"){

width="630";
height="500";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1,z-lock=0";
} 

else if (type=="RentalsContent"){
width="630";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1,z-lock=0";
} 

else if (type=="RentalsVTour"){
width="510";
height="510";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=1,toolbar=0,z-lock=0";
} 

else if (type=="RentalsFloorplan"){
width="450";
height="490";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,z-lock=0";
}
	
else if (type=="RentalsNotice"){
width="610";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,z-lock=0";
}

else if (type=="RentalsTip"){
width="450";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,z-lock=0";
} 
	
else if (type.indexOf("OldTour")>=0){
width="550";
height="469";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0,z-lock=0";
} 

else if (type.indexOf("Tour")>=0){
width="700";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0,z-lock=0";
} 

else if (type=="RentalsForm"){
width="630";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1,z-lock=0"
}

else if (type=="CyberSpot"){
width="300";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1,z-lock=0"
} 
	
else {
width="630";
height="400";
options="alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=1,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=1,z-lock=0";
}
	
attributes="width="+width+",height="+height+","+options;
return attributes;
}

function windowPopup(myLink, windowName){
var attributes=getAttributes(windowName);
var myWin=window.open(myLink.href,windowName,attributes);
myWin.focus();
}






function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0) date.setTime (date.getTime() - skew);
}

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; 
}
return null;
}

function SetCookie (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
if (GetCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}





function validateLogin(f) {
  x = f.username;
  y = f.pword;
  if (x.value=='') {
    alert("Please enter your user name")
    x.focus();
    return false;
  }
  if (y.value=='') {
    alert("Please enter your password")
    y.focus();
    return false;
  }
    return true;
}








function changeLoginType(targetType) {

  if (targetType == "renter") document.loginf.pfr[0].click();

  else if (targetType == "owner") document.loginf.pfr[1].click();

  else return false;

}



function login(f) {

  if (validateLogin(f)) {

    today = new Date();

    expires = new Date(today.getTime() + (56 * 86400000));

    lStr = whichType(f.pfr);

    SetCookie("pfr",lStr,expires);

   } else return false;

}



function whichType(radioBtn) {

  var pfr = "";

  var loginTypeIndex = "";

  for (var i=0; i < radioBtn.length; i++) {

    if (radioBtn[i].checked) loginTypeIndex = i;

  } 

  if (loginTypeIndex == 0) pfr = "renter";

  else if (loginTypeIndex == 1) pfr = "owner";

  else pfr = "renter";

  return pfr;

}
