// vars & consts
var SIDE_BAR_STYLE_SELECTED = 'sideBarSelected'; //'text-decoration:none; padding:2px 0 2px 10px; display:block; background-color:#fff; color:#da5c00 !important; font-weight:bold;'; //'border-top:1px solid #e0e1e1';

var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

/*---------------------------------------------------------------------*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*---------------------------------------------------------------------*/
// set header nav bar images based on that page we are in
function setHeaderNavBar() {
	var obj = null;
	if (sPage == "index.shtml") {
		obj = window.document.getElementById("imgHome");
		obj.src = "images/layout/nav-home-on.gif";
	}
	if (sPage.indexOf("products") != -1) {
		obj = window.document.getElementById("imgProducts");
		obj.src = "images/layout/nav-products-on.gif";
	}
	if (sPage.indexOf("services") != -1) {
		obj = window.document.getElementById("imgServices");
		obj.src = "images/layout/nav-services-on.gif";
	}
	if (sPage.indexOf("customers") != -1) {
		obj = window.document.getElementById("imgCustomers");
		obj.src = "images/layout/nav-customers-on.gif";
	}
	if (sPage.indexOf("resources") != -1) {
		obj = window.document.getElementById("imgResources");
		obj.src = "images/layout/nav-resources-on.gif";
	}
	if (sPage == "about-us.shtml") {
		obj = window.document.getElementById("imgCompany");
		obj.src = "images/layout/nav-company-on.gif";
	}
	if (sPage == "videos.shtml") {
		obj = window.document.getElementById("imgVideos");
		obj.src = "images/layout/nav-videos-on.gif";
	}	
}

/*---------------------------------------------------------------------*/
// set products side nav bar images based on that page we are in
function setProductNavBar() {
	var obj = null;

	if (sPage == "products.shtml") {
		obj = window.document.getElementById("aOverview");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-propertyware.shtml") {
		obj = window.document.getElementById("aPw");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-properties.shtml") {
		obj = window.document.getElementById("aProperties");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-lease.shtml") {
		obj = window.document.getElementById("aLease");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-money-in.shtml") {
		obj = window.document.getElementById("aMoneyIn");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-money-out.shtml") {
		obj = window.document.getElementById("aMoneyOut");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-grp-collb.shtml") {
		obj = window.document.getElementById("aGrpCollab");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-analytics.shtml") {
		obj = window.document.getElementById("aAnalytics");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-quickbooks.shtml") {
		obj = window.document.getElementById("aQuickBooks");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-marketing.shtml") {
		obj = window.document.getElementById("aMarketing");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-maintenance.shtml") {
		obj = window.document.getElementById("aMaintenance");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-management.shtml") {
		obj = window.document.getElementById("aManagement");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-website.shtml") {
		obj = window.document.getElementById("aWebsite");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-compare.shtml") {
		obj = window.document.getElementById("aCompare");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-security.shtml") {
		obj = window.document.getElementById("aSecurity");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-why-pw.shtml") {
		obj = window.document.getElementById("aWhy");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "products-faq.shtml") {
		obj = window.document.getElementById("aFAQ");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
}

/*---------------------------------------------------------------------*/
// set company side nav bar images based on that page we are in
function setCompanyNavBar() {
	var obj = null;

	if (sPage == "about-us.shtml") {
		obj = window.document.getElementById("aAboutUs");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "contact-information.shtml") {
		obj = window.document.getElementById("aContactInfo");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "team.shtml") {
		obj = window.document.getElementById("aTeam");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "manifesto.shtml") {
		obj = window.document.getElementById("aManifesto");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "press-releases.shtml") {
		obj = window.document.getElementById("aPress");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "news.shtml") {
		obj = window.document.getElementById("aNews");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "careers.shtml") {
		obj = window.document.getElementById("aCareers");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
}

/*---------------------------------------------------------------------*/
// set services side nav bar images based on that page we are in
function setServicesNavBar() {
	var obj = null;

	if (sPage == "services-pro-services.shtml") {
		obj = window.document.getElementById("aOverview");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "services-training.shtml") {
		obj = window.document.getElementById("aTraining");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "services-support.shtml") {
		obj = window.document.getElementById("aSupport");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
	if (sPage == "services-webinars.shtml") {
		obj = window.document.getElementById("aWebinars");
		obj.className = SIDE_BAR_STYLE_SELECTED;
	}
}


/*---------------------------------------------------------------------*/
// set header small nav bar images based on that page we are in
function setSmallHeaderBar() {
	var obj = null;

	if (sPage == "email-this-page.shtml") {
		obj = window.document.getElementById("imgHome");
		obj.src = "images/layout/nav-home-on2.gif";
	}
	if (sPage == "products-manual.shtml") {
		obj = window.document.getElementById("imgManual");
		obj.src = "images/layout/nav-manual-on.gif";
	}
	if (sPage == "videos.shtml") {
		obj = window.document.getElementById("imgVideos");
		obj.src = "images/layout/nav-videos-on.gif";
	}
	if (sPage == "forum.shtml") {
		obj = window.document.getElementById("imgForum");
		obj.src = "images/layout/nav-forum-on.gif";
	}
	if (sPage == "products-faq.shtml") {
		obj = window.document.getElementById("imgFAQs");
		obj.src = "images/layout/nav-faqs-on.gif";
	}
}

/*---------------------------------------------------------------------*/
// we use a wrapper name for the pages
// so that if the file name is changed
// it does not affect the functionality
// of the javascript
function getFileNameFromPageName(pageName) {
	if (pageName == "home")			return "index.shtml";
	if (pageName == "products")		return "products.shtml";
	if (pageName == "services")		return "services-pro-services.shtml";
	if (pageName == "customers")	return "customers.shtml";
	if (pageName == "resources")	return "landlord-resources.shtml";
	if (pageName == "company")		return "about-us.shtml";
	if (pageName == "login")		return "login.jsp";
	if (pageName == "smallHome")	return "index.shtml";
	if (pageName == "smallManual")	return "products-manual.shtml";
	if (pageName == "smallVideos")	return "videos.shtml";
	if (pageName == "smallForum")	return "forum.shtml";
	if (pageName == "smallFAQs")	return "products-faq.shtml";
}

/*---------------------------------------------------------------------*/
// first checks if the page we are is the same 
// the the image in question, if it is
// it ignores the swap since we don't want rollover behavior
//  
// Params:
//
// pageName: name of the page. I.e.: home
// imgObj: image object to change 
// imgPath: path to the new image to use
function setImage(pageName, imgObjName, imgPath) {
	var fileName = getFileNameFromPageName(pageName);
//alert(pageName);
//alert(fileName);
//alert(imgObjName);
//alert(imgPath);
	if (sPage != fileName) {	
		MM_swapImage(imgObjName,'',imgPath,1)
	}
}

/********
 * Pop-up Window
********/

var curPopupWindow = null;

function openWindow(url, winName, width, height, center, winType) {

   var xposition = 75; // Postions the window vertically in px
   var yposition = 75; // Postions the window horizontally in px
   var location, menubar, resizable, scrollbars, status, titlebar;

   if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
       xposition = (screen.width - 800) / 2;
       yposition = (screen.height - 600) / 2;
   } 
   
   if (winType == "1") {           // winType 1 is for regular popup windows
      location=0;
      menubar=0;
      resizable=0;
      scrollbars=1;
      status=0;
      titlebar=1;
   } else if (winType == "2") {   // winType 2 is for Quick Tour like popups
      location=0;
      menubar=0;
      resizable=0;
      scrollbars=0;
      status=0;
      titlebar=1;
   } else if (winType == "3") {   // winType 3 is for footer like popups
      location=0;
      menubar=0;
      resizable=0;
      scrollbars=0;
      status=0;
      titlebar=0;
   } else {                       // if no arg is passed for winType
      location=0;
      menubar=0;
      resizable=0;
      scrollbars=0;
      status=0;
      titlebar=0;
   } 
   
   // Features to specify for a new window
   args = "width=" + width + ","
   + "height=" + height + ","
   + "location=" + location + ","
   + "menubar=" + menubar + ","
   + "resizable=" + resizable + ","
   + "scrollbars=" + scrollbars + ","
   + "status=" + status + ","
   + "titlebar=" + titlebar + ","
   + "toolbar=0,"
   + "hotkeys=0,"
   + "screenx=" + xposition + ","  //NN Only
   + "screeny=" + yposition + ","  //NN Only
   + "left=" + xposition + ","     //IE Only
   + "top=" + yposition;           //IE Only
   
	// Performs the opening of the window (and closing of a window already opened for that page).
	if (curPopupWindow != null) {
		curPopupWindow.close();
	}
	curPopupWindow = window.open(url, winName, args, false);
	curPopupWindow.focus();
}


/********
 * Opens a URL location in the parent window of a popup
********/

function switchWindows(url) {
   parent.opener.location.href = url; 
}

/********
 * Close tour window and bring up signup screen(s)
********/

function switchAndClose(url) {
   top.opener.location.href=url;    
   top.close();
   top.opener.focus();
}

/********
 * Takes a Select option value and loads it into a higher level frame
********/

function goto_URL(object) {
   parent.frames[0].location.replace(object.options[object.selectedIndex].value);
}

/********
 * Takes a Select option value and loads reloads the URL in the current window
********/

function goto_URL_2(object) {
   location.replace(object.options[object.selectedIndex].value);
}

/****************
Empty Field Validation
********************/
function isEmpty(val) {
   if ((val.length==0) ||(val==null)) {
      return true;
   }
   else { return false; }
}

/****************
Valid Email
********************/
function isValidEmail(email) {
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (emailFilter.test(email)) { 
		return false;
	}
	return true;
}

/****************
Valid Phone
********************/
function isValidPhone(phone) {
	if (phone.match(/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/) == null) 
		return false; 
	return true; 
}

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);
	}
	return null;
}

/****************
Pop Up Window
********************/

function popUp(url){
	var x, y;
	var popupWidth = 500, popupHeight = 450;
	if(!document.all) {
		x = window.screenX + 400 - (popupWidth/2);
		y = window.screenY + 300 - (popupHeight/2);
	} else {
		x = window.screenLeft + 400 - (popupWidth/2);
		y = window.screenTop + 300 - (popupHeight/2);   
		y = y - 65    //IE does not include the top bars of the window in the screenTop value. 
	}
	y = y - 16;       //account for the top bar of the popup
	var popupWin = window.open(url, "win", 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+popupWidth+',height='+popupHeight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	popupWin.focus();
}

/****************
Email This Page
********************/
function emailThisPage() {
	window.open('http://www.propertyware.com/pw/marketing/email_page.do?action=Default&url='+document.location.href, 'popupwindow', 'width=520,height=600');
	return false;
}

