function activeForm(obj,obj2) {
	// Collapse all of the div forms
	collapseForm();

	// Turn the one on that was selected
	document.getElementById(obj).style.display = '';
	document.getElementById(obj2).style.background = 'url(/images/state-search-tab-on.jpg)';
}

function collapseForm(){
	divList = "hs1,hs2,hs3";
	divList2 = "hsn1,hsn2,hsn3";
	divArray = divList.split(",");
	divArray2 = divList2.split(",");

	// Loop over fields and turn them all off
	for(i=0;i<divArray.length; i++){
		document.getElementById(divArray[i]).style.display = 'none';
	}
	
	// Loop over fields and turn them all off
	for(i=0;i<divArray2.length; i++){
		document.getElementById(divArray2[i]).style.background = 'url(/images/state-search-tab-off.jpg)';
	}
}

function toggleDiv(divid){
    if(document.getElementById(divid).style.display == 'none'){
      document.getElementById(divid).style.display = 'block';
    }else{
      document.getElementById(divid).style.display = 'none';
    }
  }
  
function ClearMe(Id,msg) {
	if (document.getElementById(Id).value == msg)
		document.getElementById(Id).value = "";
	return;
}

function ResetMe(Id,msg) {
	if (document.getElementById(Id).value.length == 0)
		document.getElementById(Id).value = msg;
	return;
}

function setDepart(date){
	document.getElementById("depart").value = document.getElementById("date").value;
}

function wait(msecs){
	var start = new Date().getTime();
	var cur = start
	while(cur - start < msecs){
		cur = new Date().getTime();
	}
} 

function resetSearch(){
	window.location.href='search.htm?newSearch=1';
}

function setRemoveVisable(id1,id2){
	document.getElementById(id1).style.display = 'none';
	document.getElementById(id2).style.display = 'block';
	return;
}

function viewMore(id1,id2){
	document.getElementById(id1).style.display = 'none';
	document.getElementById(id2).style.display = 'block';
	return;
}

function toggleview(element1) {
   var element1 = document.getElementById(element1);

   if (element1.style.display == 'block' || element1.style.display == '')
      element1.style.display = 'none';
   else
      element1.style.display = 'block';

   return;
}

function removeItem(str) {
	window.location.href = '/vacation-rentals/search-result.htm?removeSearch=' + str;
}

function addItem(str){
	window.location.href = '/vacation-rentals/search-result.htm?addSearch=' + str;
}

function goTo(str){
	window.location.href = str;
}


function getToday(){
	var Date1 = new Date();
	// Setting date parts
	m = new String(Date1.getMonth() + 1);
	d = new String(Date1.getDate());
	y = new String(Date1.getFullYear());

	// Add leading zeros to month and date if required
	if ( d.length == 1 ) d = "0" + d; 	
	if ( m.length == 1 ) m = "0" + m;
	// Formatting Date
	var newDate = m + '/' + d + '/' + y;

	return newDate;
}

function checkDate(id){
	var today = new Date();
	var inDate = new Date(Date.parse(document.getElementById(id).value));
	
	if (inDate < today){
		alert('You must select a date grater than today.');
		document.getElementById(id).value = getToday();
		return false;
	}
}

function checkArriveDepart(){
	var arrive = new Date(Date.parse(document.getElementById("arrive").value));
	var depart = new Date(Date.parse(document.getElementById("depart").value));
	
	if (depart <= arrive){
		alert('You must select a departure date grater than your arrival date.');
		document.getElementById("depart").value = document.getElementById("arrive").value;
	}
}

function checkKeyword(){
	var keyword = document.getElementById('keyword').value;
	
	if (keyword == 'Destination/Keyword' || keyword.length() == 0) {
		alert('You must enter a destination or keyword for the system to search for available listings.');
		return false;
	}
	return true;
}

function setExpandCollapse(id,expand,collapse) {
	if (document.getElementById(id).className == 'collapsed') {
		document.getElementById(id).style.height = expand; /* IE Hack because it does not understand auto */
		document.getElementById(id).className = "expanded";
	} else {
		document.getElementById(id).style.height = collapse;/* IE Hack because it does not understand auto */
		document.getElementById(id).className = "collapsed";
		
	}	
}

function toggleStatus(id){
	 	var image = document.getElementById(id).src;
		if (image.match("statusExpand.gif") )
			document.getElementById(id).src = image.replace("statusExpand.gif", "statusCollapse.gif");
		else
			document.getElementById(id).src = image.replace("statusCollapse.gif", "statusExpand.gif");
	 }

function geturl(addr) {  
	var r = $.ajax({type: 'GET',  url: addr,  async: false }).responseText;  
    return r;  
}
