// ///////////////////////////
// GENERAL WEBSITE FUNCTIONS...
	function $get(str) { return document.getElementById(str); }
	function openLink(screen,title,width,height){
		window_width = (width == null || width == '') ? 700 : width;
		window_height = (height == null || height == '') ? 460 : height;
		if (title = null){title = '_blank'}
		window.open(screen,title,'alwaysRaised=yes,width=' + window_width + ',height=' + window_height + ',location=no,menubar=yes,resizable=yes,titlebar=yes,toolbar=no,scrollbars=yes,left=20,top=20')
	}
	function openLinkMax(url,title,width,height){
		if ((width == null) || (width == '')){window_width = screen.availWidth - 70}
			else {window_width = width}
		if ((height == null) || (height == '')){window_height = screen.availHeight - 200}
			else {window_height = height}
		window.open(url, title, 'alwaysRaised=yes,width=' + window_width + ',height=' + window_height + ',location=no,menubar=yes,resizable=yes,titlebar=yes,toolbar=no,scrollbars=yes,left=20,top=30')
	}
	function CheckQS(){
		if (document.frm_QuickSearch.QSCriteria.value == 'Search by Street, PC# or MLS#')
			document.frm_QuickSearch.QSCriteria.value = '';	
		else if (document.frm_QuickSearch.QSCriteria.value.length == 0)
			document.frm_QuickSearch.QSCriteria.value = 'Search by Street, PC# or MLS#';
	}
	function sendTraffic(origin,destination){
		window.open('/sendtraffic.asp?ref_url=' + origin + '&red_url=' + destination)
	}
	function Chat(){openLink('http://messenger.providesupport.com/messenger/jtn.html','NRChat',600,500);}
	function openNationalSearch(){document.frm_NationalSearch.submit();}
	function PhotoGallery(mlsid,mlnum){window.open('/properties/gallery.asp?mlsid=' + mlsid + '&mlnum=' + mlnum)}
	function GuidedTour(toururl){
		window.open(toururl,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=642,height=437')
	}
	function VirtualTour(toururl){window.open(toururl)}
	function PrintFlyer(mlsid,mlnum){window.open('/properties/flyer.asp?mlsid=' + mlsid + '&mlnum=' + mlnum)}
	function CommunityInfo(zipcode){window.open('http://www.onboardnavigator.com/1.5/webcontent/obwc_results.aspx?aid=109&searchtype=1&datatype=1&state=ny&zip=' + zipcode)}
	function SchoolInfo(districtname){window.open('http://www.onboardnavigator.com/1.5/webcontent/obwc_results.aspx?aid=109&searchtype=1&datatype=2&state=ny&zip=' + districtname)}
	function NearbyEstablishments(zipcode){window.open('http://www.onboardnavigator.com/1.5/webcontent/obwc_results.aspx?aid=109&searchtype=1&datatype=3&state=ny&zip=' + zipcode)}
	
	// REMOVED UNTIL NEEDED -- JZ
	// function TVSCalc(){	window.open('/career/TVS/','TVSCalc','resizable=no,width=500,height=366,scrollbars=no')}
	// END REMOVAL

	function openCoupon(couponID) {
	    window.open('/homeservices/viewcoupon.asp?couponid=' + couponID, 'viewCoupon' + couponID, 'width=525,height=450')

	}

// END
// ///////////////////////////


// ///////////////////////////
// CONTACT FORMS...
	function CMARequest(agent){openLink('/forms/getform.asp?formid=10&pid=' + agent,'CMARequest',530,600);}
	function AgentRequest(){openLink('/forms/getform.asp?formid=4','AgentRequest',530,600);}
	function FLAgentRequest(){openLink('/forms/getform.asp?formid=38','AgentRequest',530,600);}
	function ContactAgent(agent,mlsid,mlnum){openLink('/forms/getform.asp?formid=1&pid=' + agent + '&mlsid=' + mlsid + '&mlnum=' + mlnum,'ContactAgent',530,600);}
	function GetNHAgent(){openLink('/forms/getform.asp?formid=6','FranchiseInfo',530,600)}
	function ContactNHAgent(agent,subid){openLink('/forms/getform.asp?formid=3&pid=' + agent + '&subid=' + subid,'ContactAgent',530,600);}
	function ScheduleAppt(agent,mlsid,mlnum){openLink('/forms/getform.asp?formid=7&mlsid=' + mlsid + '&mlnum=' + mlnum + '&pid=' + agent,'ScheduleAppt',530,600);}
	function ScheduleNHAppt(agent,subid){openLink('/forms/getform.asp?formid=9&pid=' + agent + '&subid=' + subid,'ScheduleAppt',530,600);}
	function GetPropInfo(mlsid,mlnum){openLink('/forms/getform.asp?formid=13&mlsid=' + mlsid + '&mlnum=' + mlnum,'GetPropInfo',530,600);}
	function GetPreQual(estmortgage){openLink('/forms/getform.asp?formid=16&estmortgage=' + estmortgage,'PreQual',530,600);}
	function ContactHSC(hsc){openLink('/forms/getform.asp?formid=30&employeeid=' + hsc,'ContactHSC',530,600);}
	function Email2AFriend(mlsid,mlnum){openLink('/forms/getform.asp?formid=28&mlsid=' + mlsid + '&mlnum=' + mlnum,'EmailToAFriend',530,600);}
	function SendTextMessage(agent,mlsid,mlnum){openLink('/forms/getform.asp?formid=37&pid=' + agent + '&mlsid=' + mlsid + '&mlnum=' + mlnum,'SendTM',530,600);}
	function ContactHUD(){openLink('/forms/getform.asp?formid=29','ContactForm',525,450)}
	function NationalReloForm(state){openLink('/forms/getform.asp?formid=26&state=' + state,'RELO',525,450)}
	function ContactCP(){openLink('/forms/getform.asp?formid=30','ContactUs',530,600)}
	function CPReg(){openLink('/forms/getform.asp?formid=34','CPReg',530,600)}
	function ContactCorporate(){openLink('/forms/getform.asp?formid=22','ContactUs',530,600)}
	function ContactStaff(empID){openLink('/forms/getform.asp?formid=33&empID=' + empID,'ContactStaff',530,600)}
	function ContactManager(agent){openLink('/forms/getform.asp?formid=39&pid=' + agent,'ContactManager',530,600)}
	function ContactWebmaster(){openLink('/forms/getform.asp?formid=14','Webmaster',530,600)}
	function CareerDayReg(){openLink('/forms/getform.asp?formid=15','CareerDayReg',530,600)}
	function ContactCC(){openLink('/forms/getform.asp?formid=23','ContactCC',530,600)}
	function WebsiteFeedback(){openLink('/forms/getform.asp?formid=41','WebsiteFeedback',530,600)}
	function AssessmentCheck(){openLink('/forms/getform.asp?formid=44','AssessmentCheck',530,600)}
	function RentalInfo(){openLink('/forms/getform.asp?formid=45','RentalInfo',530,600)}
	function FranchiseInfo(){openLink('/forms/getform.asp?formid=46','FranchiseInfo',530,600)}
// END
// ///////////////////////////


// ///////////////////////////
// PROPERTY COMPARE FEATURE
	var thecookie = document.cookie;
	var GLOBAL_CompareList = (getCookie("CompareList") == null) ? '' : getCookie("CompareList");	
	var GLOBAL_CompareCount = (getCookie("CompareCount") == null) ? 0 : parseInt(getCookie("CompareCount"));
	var GLOBAL_MaxCompare = 6;	//the maximum number of listings a user can check to compare
	
	function getCookie(name) {
		var index = thecookie.indexOf(name + "=");
		if (index == -1) return null;
		index = thecookie.indexOf("=", index) + 1; // first character
		var endstr = thecookie.indexOf(";", index);
		if (endstr == -1) endstr = thecookie.length; // last character
		return unescape(thecookie.substring(index, endstr));
	}
	
	function setCookie(name, value) {
	    document.cookie=name + "=" + escape(value) + ";";
	}
	
	function commitCompareList(){		
		setCookie("CompareList", GLOBAL_CompareList);
		setCookie("CompareCount", GLOBAL_CompareCount);
	}		
	
	function sendToCompare(){
		if (GLOBAL_CompareCount < 2)
			alert('Please select more than 1 property.');
		else {
			if (GLOBAL_CompareCount > 6)
				alert('Please select no more than 6 properties.');
			else
				window.location = "/properties/compare.asp?MLNUMList=" + GLOBAL_CompareList + "&CompareCount=" + GLOBAL_CompareCount;
		}
	}
	
	function compareClear() {
		GLOBAL_CompareList = "";
		GLOBAL_CompareCount = 0;		
		setCookie("CompareList","");
		setCookie("CompareCount","0");
	}
	
	function resetCompare(){
		compareClear();
		//for(i=0; i<document.frmCompare.elements.length; i++)
		//	if(document.frmCompare.elements[i].type=="checkbox")
		//		document.frmCompare.elements[i].checked=false;
		//}	
	}
	
	function addCompare(obj) {		
		if (obj.checked) {
			if (GLOBAL_CompareCount == GLOBAL_MaxCompare) {			
				obj.checked = false;
				alert('You have already chosen ' + GLOBAL_MaxCompare + ' properties.');
			}
			else {
				GLOBAL_CompareList = GLOBAL_CompareList + obj.value;
				GLOBAL_CompareCount = parseInt(GLOBAL_CompareCount) + 1;
			}
		}	
		else {
			GLOBAL_CompareCount = parseInt(GLOBAL_CompareCount) - 1
			GLOBAL_CompareList = GLOBAL_CompareList.replace(obj.value,"");
		}
		commitCompareList();
	}
// END PROPERTY COMPARE FEATURE
// ///////////////////////////

// BEGIN IE 5.5 & 6 MENU FIX
var hiding = false;
var cNav = '';
uHover = function() {
	if(navigator.userAgent.indexOf('MSIE') >= 0 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('MSIE')+5)) < 7 ) { 				
		if (!document.getElementsByTagName) return false;
		var uEls = $get("navNoth").getElementsByTagName("li");
		for (var i=0; i<uEls.length; i++) {		
			if(uEls[i].id != '') {
				uEls[i].onmouseover=function() { 
					$get('shim').style.display='none'; 
					hiding = false;
					cNav = this.id;
					var menus = $get("navNoth").getElementsByTagName("li");
					for (var i=0; i < menus.length; i++) {
						if(menus[i].className.indexOf('uhover') >= 0)
							menus[i].className = menus[i].className.replace(new RegExp(" uhover\\b"), "");	
					}
					if(this.id != "" && $get('shim').style.display != 'block') {
						this.className+=" uhover"; 
						var iframe = $get('shim'); 
						iframe.style.display = 'block';
						iframe.style.width = '142px';
						iframe.style.top = '100px';
						if(this.offsetParent)
							iframe.style.left = findLeft(this);
						var subs = this.getElementsByTagName("li");
						iframe.style.height = parseInt((subs.length * 24) + 2) + 'px';
					}
				}
				uEls[i].onmouseout=function() {
					cNav = '';
					if($get('shim').style.display != 'none') {
						hiding = true;
						setTimeout("hideShim('" + this.id + "')",50);	
					}
				}
			}
		}
		setTimeout('cleanup()', 500);
	}
}
function cleanup() {
	var menus = $get("navNoth").getElementsByTagName("li");
	for (var i=0; i < menus.length; i++) {
		if(menus[i].className.indexOf('uhover') >= 0 && menus[i].id != cNav)
			menus[i].className = menus[i].className.replace(new RegExp(" uhover\\b"), "");	
	}
	setTimeout('cleanup()', 500);
}
function hideShim(obj) {
	if(hiding) {
 		$get(obj).className = $get(obj).className.replace(new RegExp(" uhover\\b"), "");
		$get('shim').style.display='none'; 
	}
}
function findLeft(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		while (obj = obj.offsetParent) { curleft += obj.offsetLeft; }
	}
	return curleft + 15;
}
if (window.attachEvent) window.attachEvent("onload", uHover);
// END IE 5.5 & 6 MENU FIX
