var switchTo5x=true;
var fontsize = 13;
var savedFontSize = 13;

function setFontSize() {
	if (savedFontSize)
	{
		savedFontSize = Get_Cookie("FontSize");
		if (parseInt(savedFontSize)) fontsize = savedFontSize;
		el = document.getElementsByTagName("body");
		if (el)
		{
			try
			{
				el[0].style.fontSize = fontsize + "px";	
			}
			catch (ex)
			{
				;
			}
			
		}
	}
}

function changeFontSize(direction) {
	el = document.getElementsByTagName("body");
	if (direction == 0)
	{
		el[0].style.fontSize = "13px";
		fontsize = 13;
	} else {
		if (fontsize >= 19 && direction > 0) return true;
		if (fontsize <= 11 && direction < 0) return true;
		fontsize = parseInt(fontsize) + parseInt(direction); 
		el[0].style.fontSize = fontsize + "px";
	}
	direction = 1 - direction;
	Set_Cookie("FontSize", fontsize, 1);
}

function alert2(msg, title) {
	txt = "<div class='alert'>";
	if (title)
	{
		txt += "<div class='title'>" + title + "</div>";
	}
	txt += "<div class='message'>" + msg + "</div>";
	message2(txt);
}

function alert3(msg) {
	showOverlay();
	box("<div>"+'<div class="login-close" style="text-align: right"> <a href="#" onclick="return false"><img style="position: relative; top: 24px; left: -3px;" src="images/icon_delte_up.gif" alt="close" name="closepop"  border="0" id="closepop" onmouseover="MM_swapImage(\'closepop\',\'\',\'images/icon_delte_over.gif\',1)" onmouseout="MM_swapImgRestore()" onclick="closeWait()" /></a></div>'+ "<div class='msgalert' style='-moz-border-radius: 0.6em;	-webkit-border-radius: 0.6em;	border-radius: 0.6em; border: 2px solid #26a7df; padding: 0px;'>" + msg+"</div></div>");
}

$(document).ready(function () {
		setFontSize();
		$("#Search").focus(function () {$("#Search").attr("class", "active")});
		$("#Search").blur(function () {if (!$("#Search").val()) $("#Search").attr("class", "")});
	});

function showGroup(obj) {
	$("#map img").css("opacity", "0");
	$(obj).css("opacity", "1");
	$('#map').css('background-image', 'url(images/homebg2.png)');
}

function hideGroup(obj) {
	$("#map img").css("opacity", "0");
	$('#map').css('background-image', 'url(images/homebg1.png)');
}

var sliderLeft = 0;
var sliderCount = 4;
var slideInterval;
var slideTimer = 150;
var slideDirection = 0;
var slideStep = 0;
var slideSteps = 0;
var stepDuration = 10;
var slideLength = 0; //pixels

function slideLeft() {
	if (sliderLeft>=-100) return false;
	slideDirection = 1;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
}

function slideRight() {
	slideDirection = -1;
	el = document.getElementById("slider");
	slideLength = el.offsetWidth * -1 + 990;
	if (sliderLeft <= slideLength) return false;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
	
}

function slide() {
	slideStep ++;
	if (slideStep > slideSteps)
	{
		slideStep = 0;
		clearInterval(slideInterval);
		return true;
	}
	increment = Math.abs(855) / slideSteps;
	el=document.getElementById('slider'); 
	sliderLeft = sliderLeft + increment * slideDirection;
	el.style.marginLeft= sliderLeft + 'px';
	
}


function enableTab(id, pages) {
	for (i=1; i<=pages ;i++ )
	{
		if (i==id) continue;
		$("#page" + i).css("display", "none");
		$("#tab" + i).removeClass("active")
	}
	$("#page" + id).css("display", "block");
	$("#tab" + id).addClass("active")
	return true;
}

function highlight(obj) {
	$(obj).addClass("active");
}

function unhighlight(obj) {
	$(obj).removeClass("active");
}

var currentMode;
function searchCondos(mode) {
	if (!mode) mode = currentMode;
	if (!mode) mode = getQueryVariable("mode");
	if (!mode) mode = "community";
	currentMode = mode;
	criteria = "";
	criteria = $("#price").val() + "|" + $("#sqft").val();
	txt = [];
	el = document.getElementsByName("Bedrooms");
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("Bathrooms");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("Occupancy");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("City");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");
//	alert(mode);
	url = "index.php?s=main&o=get-results&criteria=" + criteria + "&mode=" + mode;
//	wait();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_searchCondos;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _searchCondos() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		$("#results").html(getXMLNode(ret));
	}
}



function filterSpotlight(obj, idx) {
	$(".spotlight .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	$(".slide-cell").each(function () {x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[2]) == parseInt(idx)) $(this).css("display", "block"); else $(this).css("display", "none"); });
	return false;
}

function filterInventory(obj, idx) {
	$("#movetoday .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	$("#movetoday .spotlight-content").each(function () {x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[1]) == parseInt(idx)) $(this).css("display", "block"); else $(this).css("display", "none"); });
	return false;
}

function filterFinances(obj, idx) {
	$("#finances .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	$("#finances .spotlight-content").each(function () {x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[1]) == parseInt(idx)) $(this).css("display", "block"); else $(this).css("display", "none"); });
	return false;
}

function showMenu(obj) {
	$(obj).find("ul").css("display", "block");
}

function hideMenu(obj) {
	$(obj).find("ul").css("display", "none");
}

function showTags(e) {
	$("#divTags").css("display", "block");
	x = getCenter(400, 600);
	$("#divTags").css("top", x.y);
	$("#divTags").css("left", x.x);

//	$("#divTags").css("top", e.pageY);
//	$("#divTags").css("left", e.pageX);

}
function updateTags() {
	el = document.getElementsByTagName("input");
	url = "index.php?o=update-tags&tags=";
	for (i=0; i< el.length ; i++ )
	{
		if (el[i].id.substr(0,3) == "Tag")
		{
			if (el[i].checked) url += el[i].value + ";";
		}
	}
	window.location = url;
}

function resetTags() {
	url = "index.php?o=reset-tags";
	window.location = url;
}

function closeTags() {
	$("#divTags").css("display", "none");
}

function updateCategories() {
	el = document.getElementsByTagName("input");
	url = "index.php?o=update-categories&categories=";
	for (i=0; i< el.length ; i++ )
	{
		if (el[i].id.substr(0,8) == "category")
		{
			if (el[i].checked) url += el[i].value + ";";
		}
	}
	window.location = url;
}

var jobID = "";
var tokenID = "";
function showH2HApply(jobno, token) {
	jobID = jobno;
	tokenID = token;
	setTimeout(_showH2HApply, 500);
	alert2("<center>You are now accessing our secure job application platform. Please wait while the application is loading ... <br><br><img src='images/progressbar_microsoft.gif'></center>");

}

function _showH2HApply() {
	txt = "<div style='width: 1000px; height: 460px; padding: 40px 10px; '><div style='float: left; width: 179px; overflow: hidden;'>Select job type:<br><br><a class='lblue' href='http://h2h.smartsimple.com/Recruitment/rm_jobs.jsp?token=HwQMUh4dYlhe' target='frmExt' >Recruitment Professionals</a><br><a class='lblue' href='http://h2h.smartsimple.com/Recruitment/rm_jobs.jsp?token=Hw8JUh4dYlhe' target='frmExt' >HR Professionals</a><br><a class='lblue' href='http://h2h.smartsimple.com/Recruitment/rm_jobs.jsp?token=HwoLUh4dYlhe' target='frmExt' >Supply Chain Professionals</a><br><a class='lblue' href='http://h2h.smartsimple.com/Recruitment/rm_jobs.jsp?token=Hw8GUh4dYlhe' target='frmExt'>IT/Other Professionals</a></div><div style='float: left; width: 1x; overflow: hidden; border-left: 1px solid #26a7df; margin-top: 0px; height: 400px;'></div><div style='float: left; margin-left: 15px; width: 800px; overflow: hidden;'><div style='float: left; width: 800px; overflow: hidden;'><iframe name='frmExt' id='frmExt' width='800' height='460' frameborder='0' src='http://h2h.smartsimple.com/Recruitment/rm_jobdetails.jsp?token="+tokenID+"&jobid="+jobID+"'></iframe></div></div>";
	alert3(txt);
}

function loadFrame(frameID) {
	var tokens = ["HwQMUh4dYlhe", "Hw8JUh4dYlhe", "HwoLUh4dYlhe", "Hw8GUh4dYlhe"];
	window.open("h2h.smartsimple.com/Recruitment/rm_jobs.jsp?token=HwQMUh4dYlhe");
}

function showProfile(jobno, token) {
showH2HApply(jobno, token);
return true;
	$("#divProfile").css("display", "block");
	x = getCenter(600, 600);
	$("#divProfile").css("top", x.y);
	$("#divProfile").css("left", x.x);
}

function closeProfile() {
	$("#divProfile").css("display", "none");

}

function showLogin() {
	showH2HApply();
	return true;
	$("#divLogin").css("display", "block");
	x = getCenter(600, 600);
	$("#divLogin").css("top", x.y);
	$("#divLogin").css("left", x.x);
}

function closeLogin() {
	$("#divLogin").css("display", "none");
}

function doLogin() {
	
	el1 = document.getElementById('Username');
	el2 = document.getElementById('Pwd');
	if (el1.value == '' || el2.value == '')
	{
		alert("Please enter your username and password!");
		return false;
	}

	url = "index.php?o=ajaxlogin&username="+ el1.value + "&password=" + md5(el2.value);
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_frmLogin_validate;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	return false;
}

function _frmLogin_validate() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;

	x=response.getElementsByTagName("login_error");
	try
	{
		err = x[0].firstChild.data;
	}
	catch (ex)
	{
		err = "";
	}
	if (err != "" && err != "no")
	{
		alert(err);
//		el1 = document.getElementById('Username'); el1.value = "";
		el2 = document.getElementById('Password'); el2.value = "";
		return false;
	} else {
		window.location = "index.php?o=profile";
	}	
  }
}

function showForgot(err) {
	setOpacity(10) ;
	id = createAlert("divForgot", "Retrieve Password");
	el = document.getElementById(id);
	txt = "";
	if (err != '')
	{
		txt += "<p style='color: #ff3300; font-weight: bold;'>" + err + "</p>";
	}
	txt += "<p style='width: 250px;'>Please enter your email address in the field below and hit the retrieve button. If your email is found in the database, your password will be emailed to you.</p>";
	txt += "Email address: <input type='text' name='txtEmail' id='txtEmail' value=''> <input type='button' value='retrieve' onclick='sendPassword();'>";
	el.innerHTML = txt;
	centerElement("divForgot");
}

function sendPassword() {
	el=document.getElementById("txtEmail");
	url = "index2.php?n=Users&o=send_password&email=" + encodeURI(el.value);
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_sendPassword;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
}

function _sendPassword() {
  if(checkReadyState(xmlhttp)) {
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;

		x=response.getElementsByTagName("result");
		res = getXMLNode(x);
		closeAlert("divForgot");
		if (res == "ok")
		{
			setOpacity(10) ;
			id = createAlert("divForgotConfirmation", "Retrieve Password");
			el = document.getElementById(id);
			el.innerHTML = "<center>Your password has been emailed to you</center>";
			centerElement("divForgotConfirmation");
		} else {
			showForgot("Email not found");
		}
  }
}
function createProfile() {
	$("#createProfile").submit();
}

var savedFields = [];
function saveField(obj) {
	if (!savedFields[obj.id]) savedFields[obj.id] = obj.value;
	if (savedFields[obj.id] == obj.value)
	{
		obj.value = "";
	}
}

function restoreField(obj) {
	if (!obj.value && savedFields[obj.id])
	{
		obj.value = savedFields[obj.id];
	}
}

function updateJobs() {
	url = "index.php?o=opportunities&catid=" + $("#CategoryID").val() + "&cityid=" + $("#LocationID").val() + "&typeid=" + $("#JobTypeID").val() + "&keywords=" + $("#Keywords").val();
	window.location = url;

}

sloganOpacity = 100; sloganInterval = "";
matrixOpacity = 0; matrixInterval = "";
function startFading() {
	setTimeout(_startFading, 2000);
}

function _startFading() {
	sloganInterval = setInterval(fadeSlogan, 20);
}

function fadeSlogan() {
	sloganOpacity -= 5;
	el = document.getElementById("slogan");
	if (sloganOpacity < 0)
	{
		opacity(el, 0);
		sloganOpacity = 0;
		el = document.getElementById("map");
		el.style.display = "block";
		matrixInterval = setInterval(fadeinMatrix, 20);
		clearInterval(sloganInterval);

	} else {
		opacity(el, sloganOpacity);
	}
}

var matrixOpacity = 0;
function fadeinMatrix() {
	el = document.getElementById("map");
	matrixOpacity += 5;
	opacity(el, matrixOpacity);
	if (matrixOpacity >= 100)
	{
		clearInterval(matrixInterval);
	}
}


function submitForm(frmid, frmdata) {
	errors = "";
	for (i=0; i<frmdata.length ; i++ )
	{
		
		if ($("#" + frmdata[i].id).val() == frmdata[i].val) $("#" + frmdata[i].id).val("");
		if (!$("#" + frmdata[i].id).val() && frmdata[i].msg)
		{
			errors += frmdata[i].msg + "<br>";
		}
	}

	if (errors)
	{
		alert2(errors);
		for (i=0; i<frmdata.length ; i++ ) {
			if (!$("#" + frmdata[i].id).val() && frmdata[i].val) $("#" + frmdata[i].id).val(frmdata[i].val);
		}
		return false;
	} else {
		url = $("#" + frmid).attr("action");
		for (i=0; i<frmdata.length ; i++ ) {
			url += "&" + frmdata[i].id + "=" + $("#" + frmdata[i].id).val();
		}
		initObj();
		if (xmlhttp!=null) {
		  xmlhttp.onreadystatechange=_submitForm;
		  xmlhttp.open("GET",url,true);
		  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
		  xmlhttp.send(null);
		}
		return false;
	}

}


function _submitForm() {
  if(checkReadyState(xmlhttp)) {
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;

		x=response.getElementsByTagName("msg");
		ret = getXMLNode(x);
		alert2(ret);
  }
}


function loadMonths(obj) {
	for (i=0; i<obj.length ;i++ )
	{
		$("#blogMonthsInner" + obj.options[i].value).css("display", "none");
	}
	$("#blogMonthsInner" + $(obj).val()).css("display", "block");
}

function loadMonth(y, m) {
	window.location = "index.php?o=blog&year=" + y + "&month=" + m;
}

function loadTags(tagid) {
	window.location = "index.php?o=blog&tag=" + tagid;
}



function showClientLogin() {
	txt = "<div style='padding: 40px 100px'><h3>CLIENT LOGIN</h3>";
	txt += '<table cellspacing="0" cellpadding="8"><tr><td>Username: </td><td><input type="text" name="portalUsername" id="portalUsername" value="Email *" onfocus="saveField(this)" onblur="restoreField(this)"></td></tr>';
	txt += '<tr><td>Password: </td><td><input type="password" name="portalPwd" id="portalPwd" value="Password" onfocus="saveField(this)" onblur="restoreField(this)"></td></tr>';
	txt += '<tr><td colspan="2" style="padding-top: 20px;"><a href="#" onclick="doClientLogin(); return false;"><h3>SUBMIT</h3></a></td></tr>';
	txt += '</div>';
	alert3(txt);

}

function doClientLogin() {
	
	el1 = document.getElementById('portalUsername');
	el2 = document.getElementById('portalPwd');
	if (el1.value == '' || el2.value == '')
	{
		alert("Please enter your username and password!");
		return false;
	}

	url = "index.php?o=portal-login&username="+ el1.value + "&password=" + md5(el2.value);
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_frmClientLogin_validate;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	return false;
}

function _frmClientLogin_validate() {
  if(checkReadyState(xmlhttp)) {
	var response = xmlhttp.responseXML.documentElement;
	response.normalize;

	x=response.getElementsByTagName("login_error");
	try
	{
		err = x[0].firstChild.data;
	}
	catch (ex)
	{
		err = "";
	}
	if (err != "" && err != "no")
	{
		alert(err);
//		el1 = document.getElementById('Username'); el1.value = "";
		el2 = document.getElementById('Password'); el2.value = "";
		return false;
	} else {
		window.location = "index.php?o=portal";
	}	
  }
}

function showPortalFiles() {
	url = "index.php?o=portal-files";
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_showPortalFiles;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	return false;

}

function _showPortalFiles() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
	txt = "<div class='alert'>";
	txt += "<div class='message'>" + getXMLNode(ret) + "</div></div>";

		showOverlay();

	box("<div>"+'<div class="login-close" style="text-align: right"> <a href="#" onclick="return false"><img style="position: relative; top: 24px; left: -3px;" src="images/icon_delte_up.gif" alt="close" name="closepop"  border="0" id="closepop" onmouseover="MM_swapImage(\'closepop\',\'\',\'images/icon_delte_over.gif\',1)" onmouseout="MM_swapImgRestore()" onclick="closeWait()" /></a></div>'+ "<div class='msgalert' style='width: 660px; -moz-border-radius: 0.6em;	-webkit-border-radius: 0.6em;	border-radius: 0.6em; border: 2px solid #ff7000; background-color: #ff7000; color: #fff; padding: 0px;'>" +"<div style=' text-align: center; line-height: 150%;'><b>"+txt+"</b></div></div></div>");

	}

}

function blogPost() {

	url = "index.php?o=blog-post&subject=" + encode($("#blogSubject").val()) + "&message=" + encode($("#blogMessage").val());
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_blogPost;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	return false;

}

function _blogPost() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		$("#all-comments").html($("#all-comments").html() + getXMLNode(ret));


	}

}

