function parseDate(d){
	var monthTxt = d.split('-')[1];
	var month = 0;
	switch (monthTxt) {
		case "Jan":	month = 0;	break;
		case "Feb":	month = 1;	break;
		case "Mar":	month = 2;	break;
		case "Apr":	month = 3;	break;
		case "May":	month = 4;	break;
		case "Jun":	month = 5;	break;
		case "Jul":	month = 6;	break;
		case "Aug":	month = 7;	break;
		case "Sep":	month = 8;	break;
		case "Oct":	month = 9;	break;
		case "Nov":	month = 10;	break;
		case "Dec":	month = 11;	break;
	}
	return new Date(d.split('-')[2], month, d.split('-')[0]);
}

function getMonthFromDate(monthInt){
	var months = ["January ","February ","March ","April ","May ","June ","July ","August ","September ", "October ","November ","December "];
	return months[monthInt];
}

function getDayOfWeek(dayInt, short){
	if(short == null){
		short = false;	
	}
	if(short){
		var weekday=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
	}else{
		var weekday=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
	}
	return weekday[dayInt]	
}

function zeroPad(num,count){
	var numZeropad = num + '';
	while(numZeropad.length < count) {
		numZeropad = "0" + numZeropad;
	}
	return numZeropad;
}
function getValueFromUrl(urlString, varName, alt){
	if(urlString.indexOf("?") != -1){
		if(alt != null){
			var tempUrlArr = urlString.substring(urlString.indexOf("?"),urlString.length).split("&");
		}else{
			var tempUrlArr = urlString.split("?")[1].split("&");
		}
		for(i=0;i<tempUrlArr.length;i++){
			if(tempUrlArr[i].indexOf(varName + "=") != -1){
				return	tempUrlArr[i].split("=")[1];
			}			
		}
	}
	return "";
}

function setupAreaItems(){         
	if(window.location.href.search(/\/area\//i) != -1){
		$j('.searchMapInner').css('display', 'block');
		if($$('.pagination').length>0){
			$$('.pagination')[0].setStyle('display', 'none');
		}
		$$(".itemGroup").each(function (el,i){
			if(el.innerHTML.indexOf("No items found.")!=-1){
				el.style.height = "0px";
				el.style.marginBottom = "0px";
			}
		});
		if(window.location.href.indexOf("#") != -1){
			var itemNum = window.location.href.split("#")[1];
			$$(".itemGroup a").each(function (el,i){
				var aName = el.getAttribute("name");
				if(aName == itemNum){
					el.parentNode.parentNode.style.height = "auto";
					el.parentNode.parentNode.style.marginBottom = "15px";
				}
			});
		}
		if($$(".featuredlistings")[0].innerHTML.indexOf("No items found") != -1){
			$$(".featuredlistings")[0].style.display = "none";
		}
		var allHidden = 1;
		$$(".itemGroup").each(function (el,i){
			if(el.style.height != "0px" && el.style.height != "0"){
				allHidden = 0;
			}
		});
		if(allHidden == 1){
			$$("#results h2").each(function(el, i){
				el.style.display = "none";
			});
		}
		$$(".itemGroup").each(function (el,i){
			if(el.innerHTML.indexOf("No items found.")!=-1){
				el.innerHTML = el.innerHTML.replace(/No items found\./gi, "We will have inventory for this property soon. Please visit other properties on our site to find the vacation place of your dreams.");
			}
		});
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else{
		var expires = "";
	}
	var cookieVal = name+"="+value+expires+"; path=/";
	document.cookie = cookieVal
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length).replace(/<br>/gi, "\n");
	}
	return "";
}

function inspect(obj, maxLevels, level){
	var str = '', type, msg;

	if(level == null)  level = 0;
	if(maxLevels == null) maxLevels = 99;
	if(maxLevels < 1)     
		return '<font color="red">Error: Levels number must be > 0</font>';
	if(obj == null)
	return '<font color="red">Error: Object <b>NULL</b></font>';
	str += '<ul>';
	for(property in obj){
		try{
			type =  typeof(obj[property]);
			  str += '<li>(' + type + ') ' + property + ((obj[property]==null)?(': <b>null</b>'):((type=='object')?(''):(': '+obj[property]))) + '</li>';
			if((type == 'object') && (obj[property] != null) && (level+1 < maxLevels))
			str += inspect(obj[property], maxLevels, level+1);
		}catch(err){
			if(typeof(err) == 'string') msg = err;
			else if(err.message)
				msg = err.message;
			else if(err.description)
				msg = err.description;
			else 
				msg = 'Unknown';
			str += '<li><font color="red">(Error) ' + property + ': ' + msg +'</font></li>';
	  }
	}
	str += '</ul>';
	return str;
}

