function fade(id){
	new Effect.Opacity(id, {from: 1, to: 0, duration: 3});
}
function zSwap(id){
	var div = document.getElementById(id);
	div.style.zIndex=4;
	var content = document.getElementById('content');
	content.style.zIndex=5;
}
function fadeTimer(id){// im not using this function right now because it was being called on body load and on initial page load the fade didnt happen fast enough so i just put the javascript in the body
	//var t=setTimeout(fade(id),5000);
	var t=setTimeout("fade('"+id+"')",4000);
	var t=setTimeout("zSwap('"+id+"')",6000);
}

function swapImage(id, newPic){
	var image = document.getElementById(id);
	image.src = newPic;
}

function updateCities(state,city) {
	if(state == ''){
		state = document.getElementById('state').value;
	}
  new Ajax.Updater('citySelect','admin/cityselect.php?s='+state+'&c='+city);
}

function selectCity(cityName){
	var searchString = 'value="'+ cityName +'"';
	var replaceString = 'value="'+ cityName +'" selected';
	var htmlString = document.getElementById('citySelect').innerHTML;
	var newHtmlString = htmlString.replace(searchString, replaceString); 
	document.getElementById('citySelect').innerHTML = newHtmlString;
}

function getHouseDetails(url) {
	var div = document.getElementById('houseDetails');
	div.style.top = document.documentElement.scrollTop+'px';
	new Ajax.Updater('houseDetails',url);
	new Effect.Appear('houseDetails', {duration: 2.0});

  
}
function closeDetailDiv(){
	var div = document.getElementById('houseDetails');
	new Effect.Fade('houseDetails', {duration: 2.0});
}

function openCloseDiv(id){
	var div = document.getElementById(id);
	var arrow = document.getElementById('criteriaArrow')
     if(div.style.display == 'none') { 
          new Effect.BlindDown(id); 
		  arrow.src = 'images/arrowDown.gif';
     }else { 
          new Effect.BlindUp(id); 
		  arrow.src = 'images/arrowRight.gif';
     }

}

function expandHouseDescription(){
	var div = document.getElementById('houseDescription');
	var button = document.getElementById('expandHouseDetailsLink');
	if(div.style.height == 'auto'){
		div.style.height = '50px';
		button.innerHTML = 'full description';
	}
	else{
		div.style.height = 'auto';
		button.innerHTML = 'close description';
	}
}

function showBidErrors(errors){
	var errorDiv = document.getElementById('bidErrors');
	var errorDisplay = document.getElementById('bidErrorsDisplay');
	//errorDisplay.innerHTML = errors;
	//errorDiv.innerHTML = ('TEST');
	errorDiv.style.top = document.documentElement.scrollTop+'px';
	new Effect.Appear('bidErrors', {duration: 2.0});
}

function closeBidErrors(){
	new Effect.Fade('bidErrors', {duration: 2.0});
}

function checkEmailForm(){
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var errorDiv = document.getElementById('emailError');
	if(name == '' || email == ''){
		errorDiv.innerHTML = '<span class="redText">You must enter your name and email so we can contact you when we find a rental that meets your needs. The phone number field is optional.</span>';
		return false;
	}
	else{
		return true;
	}
}

function selectCity(cityName){
	var searchString = 'value="'+ cityName +'"';
	var replaceString = 'value="'+ cityName +'" selected';
	var htmlString = document.getElementById('citySelect').innerHTML;
	var newHtmlString = htmlString.replace(searchString, replaceString); 
	document.getElementById('citySelect').innerHTML = newHtmlString;
}

function slider(div){
    var slideSteps = jQuery('.slideSteps');
    jQuery.each(slideSteps, function(a,b){
          if(b.id != 'slide_'+div){
              jQuery('#'+b.id).css('z-index','0');
              jQuery('#control_'+a).css('background-color','white');
          }
          else{
              jQuery('#'+b.id).css('z-index','100');
              jQuery('#control_'+a).css('background-color','#8BB336');
          }
    });
    jQuery('#slide_'+ div).slideDown(1000, function(){
            jQuery.each(slideSteps, function(a,b){
                if(b.id != 'slide_'+div && b.id != 'starter'){
                    jQuery('#'+b.id).css('display','none');
                }
            });
     });
}

function sliderVert(div){
    var slideSteps = jQuery('.slideStepsVert');
    jQuery.each(slideSteps, function(a,b){
          if(b.id != 'slide_'+div){
              jQuery('#'+b.id).css('z-index','0');
              jQuery('#control_'+a).css('background-color','white');
          }
          else{
              jQuery('#'+b.id).css('z-index','100');
              jQuery('#control_'+a).css('background-color','#8BB336');
          }
    });
    jQuery('#slide_'+ div).slideDown(1000, function(){
            jQuery.each(slideSteps, function(a,b){
                if(b.id != 'slide_'+div && b.id != 'starter'){
                    jQuery('#'+b.id).css('display','none');
                }
            });
     });
}

