/**
 * this is the main JS file for the web site
 */

// //////////////////////////////////////////////////////////////////
// Stats Tracking snippet:

var snippet = '<!--VISISTAT SNIPPET-->';
	snippet += '<SCRIPT TYPE="text/javascript">var DID=22051;</SCRIPT>';
	snippet += '<SCRIPT SRC="http://sniff.visistat.com/sniff.js" TYPE="text/javascript"></SCRIPT>';
	snippet += '<!-- End of VISISTAT SNIPPET-->';

document.write(snippet);

// //////////////////////////////////////////////////////////////////

var CookieHelper = {};

CookieHelper.currentCookieValues = null; // an array of cookie values - currentCookieValues['name'] = 'value';

// ...
CookieHelper.SetCookieValues = function()
{
	var c = document.cookie;
	var ccv = [];
	// all Pairs [Array] - name=value
	var p = c.split(";");
	for(var i=0; i<p.length; i++)
	{
		var nv = p[i].split("=");
		ccv[StringEncoder.Trim(nv[0])] = nv[1];
	}
	
	// transfer that data to the rightful owner:
	this.currentCookieValues = ccv;
};

// ...
CookieHelper.GetCookieByName = function(cName)
{
	if(this.currentCookieValues == null)
	{
		this.SetCookieValues();
	}
	return unescape(this.currentCookieValues[cName]);	
};

// Generic cookie setter, note no expire given, i.e sets a session cookie...
CookieHelper.SetSessionCookie = function(name, value)
{
	try
	{
	    this.currentCookieValues = null;
	    document.cookie = name + "=" + escape(value) + "; path=/";
	}
	catch(Error)
	{
        // do nothing...
	}
};

//sets a permanent cookie [10 years]...
CookieHelper.SetPermanentCookie = function(name, value)
{
	var expDate = new Date();
	var tenYearsFromNow = expDate.getTime() + (365 * 24 * 60 * 60 * 1000 * 10);
	expDate.setTime(tenYearsFromNow);
	
	this.currentCookieValues = null;
	document.cookie = name + "=" + value + "; path=/; expires=" + expDate.toGMTString();
};

// //////////////////////////////////////////////////////////////////

var StringEncoder = {};

// Removes leading whitespaces
StringEncoder.LTrim = function( value ) 
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
};

// Removes ending whitespaces
StringEncoder.RTrim = function( value ) 
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
};

// Removes leading and ending whitespaces
StringEncoder.Trim = function( value ) 
{
	return this.LTrim(this.RTrim(value));
};

// //////////////////////////////////////////////////////////////////

// ...
function Dimensions(width, height)
{
	this.width = width;
	this.height = height;
}

// //////////////////////////////////////////////////////////////////

var BrowserHelper = {};

// Returns an Object{ width, height }
BrowserHelper.GetWinSize = function() 
{
	var s = new Dimensions(0, 0);
	//var s = new Dimensions("X", "Y");
	if( typeof( window.innerWidth ) == "number" ) 
	{
		//Non-IE
		s = new Dimensions(window.innerWidth, window.innerHeight);
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		s = new Dimensions(document.documentElement.clientWidth, document.documentElement.clientHeight);
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		s = new Dimensions(document.body.clientWidth, document.body.clientHeight);
	}
	  
	return s;
};

// //////////////////////////////////////////////////////////////////

var LC = {}; // Local Constants

	LC.PopUpAttributes = "location=no,menubar=no,title=no,scrollbars=no,resizable=no,width=900,height=680,left=0,top=0";
	LC.ClipAttributes = "location=no,menubar=no,title=no,scrollbars=no,statusbar=no,resizable=no,width=900,height=539,left=0,top=0";

	LC.CookieNames = {
		"Sales" : "sales"
	};

	LC.Section = {
		
		"Home" : {
			"Name" : "Home",
			"Pages" : 
			[
				{
					"Name" : "Home",
					"URL" : "default.htm"
				}
			]
		},
		
		"AboutUs" : {
			"Name" : "About Us",
			"Pages" : 
			[
				{
					"Name" : "History",
					"URL" : "About_History.htm"
				},
				{
					"Name" : "Mission Statement",
					"URL" : "About_Mission.htm"
				},
				{
					"Name" : "Founder's Message",
					"URL" : "About_Management.htm"
				}
			]
		},
		
		"Products" : {
			"Name" : "Products & Services",
			"Pages" : 
			[
				{
					"Name" : "Accendo<sup><small>&#174;</small></sup>",
					"URL" : "PS_Accendo.htm"
				},
				{
					"Name" : "Accendo Assets&#153;",
					"URL" : "PS_Assets.htm"
				},
				{
					"Name" : "Accendo Incidents&#153;",
					"URL" : "PS_Incidents.htm"
				},
				{
					"Name" : "Accendo Issues&#153;",
					"URL" : "PS_Issues.htm"
				},
				// NOTE: When this gets uncommented, don't forget to fix the index in 'PS_Services.htm' and 'PS_Services_Integration.htm' !!!
				//{
				//	"Name" : "Inventory",
				//	"URL" : "PS_Inventory.htm"
				//},
				{
					"Name" : "Services",
					"URL" : "PS_Services.htm"
				}
			]
		},
		
		"Industries" : {
			"Name" : "Industries",
			"Pages" : 
			[
				{
					"Name" : "Industries",
					"URL" : "Industries.htm"
				},
				{
					"Name" : "Office Management",
					"URL" : "Industries_OfficeMT.htm"
				},
				{
					"Name" : "Shopping Centers",
					"URL" : "Industries_ShoppingCenter.htm"
				},
				{
					"Name" : "Municipalities and BIDs",
					"URL" : "Industries_BIDs.htm"
				},
				{
					"Name" : "Manufacturing",
					"URL" : "Industries_Manufacturing.htm"
				},
				{
					"Name" : "Hospitality",
					"URL" : "Industries_Hospitality.htm"
				},
				{
					"Name" : "Education",
					"URL" : "Industries_Education.htm"
				},
				{
					"Name" : "Security, Safety and Emergency Preparedness",
					"URL" : "Industries_Security.htm"
				},
				{
					"Name" : "Other",
					"URL" : "Industries_Other.htm"
				}
			]
		},
		
		"Resources" : {
			"Name" : "Resources",
			"Pages" : 
			[
				{
					"Name" : "Resources",
					"URL" : "Resources.htm"
				}
			]
		},
		
		"ContactUs" : {
			"Name" : "Contact Us",
			"Pages" : 
			[
				{
					"Name" : "Contact Us",
					"URL" : "About_Contact.htm"
				}
			]
		},
		
		"Logon" : {
			"Name" : "Client Logon",
			"Pages" : []
		}
	};

// //////////////////////////////////////////////////////////////////
// check for campaign association:

var CAMPAIGN_COOKIE = "";

function GetCampaignInfo()
{
	var s = "";
	var x = "";
	
	// check to see of the address contains the key:
	x = document.location.search;
	
	//alert(x);
	
	x = x.substring(1, x.length).toLowerCase(); // remove "?" from the query string...
	if(x == "mt")
	{
		s = "MT";
	} 
	else if(x == "sf")
	{
		s = "SF";
	}
	else
	{
		// let's examine the query string - the only thing we expect is 'pcm=mt' or 'pcm=sf'
		var a = x.split("=");
		if(a[0] == "pcm")
		{
			if(a[1] == "mt")
			{
				s = "MT";
			} 
			else if(a[1] == "sf")
			{
				s = "SF";
			}
		}		
	}
	
	if (s != "") 
	{
		CookieHelper.SetSessionCookie(LC.CookieNames.Sales, s);
	}
	else
	{
		// read the cookie:
		var salesC = CookieHelper.GetCookieByName(LC.CookieNames.Sales);
		if(salesC === undefined || salesC == "undefined")
		{
		}	
		else
		{
			s = salesC;
		}	
	}
		
	//alert("s = ." + s + ".");
	
	CAMPAIGN_COOKIE = s;
}

function BuildEmailIFrame()
{
	var divW = 526;
	var divH = 460;
	var o = 2;
	
	var a = "<div";
		a += " id='divEmail'";
		a += " style='	display:none;";
		a += "			overflow:hidden;";
		a += "			position:absolute;";
		a += "			top:0px;";
		a += " 			left:0px;";
		a += " 			width:" + divW + "px;";
		a += " 			height:" + divH + "px;";
		a += " 			border: 1px solid #666666;";
		a += " 			z-index: 100000;";
		a += " 		'";
		a += ">";
		a += "<table cellpadding='0' cellspacing='0' width='100%'>";
		a += "<tr>";
		a += "<td>";
		a += "<iframe id='ifEmail' width='" + (divW-o) + "' height='" + (divH-o) + "' src='blank.htm'></iframe>";
		a += "</td>";
		a += "</tr>";
		a += "";
		a += "</table>";
		a += "</div>";
		
	document.write(a);
}

function BuildVideoIFrame()
{
	var divW = 100;
	var divH = 100;
	var offset = 2;
	
	var a = "<div";
		a += " id='divVideo'";
		a += " style='	display:none;";
		a += "			overflow:hidden;";
		a += "			position:absolute;";
		a += "			top:0px;";
		a += " 			left:0px;";
		a += " 			width:" + divW + "px;";
		a += " 			height:" + divH + "px;";
		a += " 			border: 1px solid #666666;";
		a += " 			z-index: 10000;";
		a += " 		'";
		a += ">";
		a += "<table cellpadding='0' cellspacing='0' width='100%'>";
		a += "<tr>";
		a += "<td>";
		a += "<iframe id='ifVideo' width='" + (divW-offset) + "' height='" + (divH-offset) + "' src='blank.htm'></iframe>";
		a += "</td>";
		a += "</tr>";
		a += "";
		a += "</table>";
		a += "</div>";
		
	document.write(a);
}

GetCampaignInfo();
BuildEmailIFrame();
BuildVideoIFrame();
	
// //////////////////////////////////////////////////////////////////
	
// ...
function init()
{
	resize();
}

// ...
function resize()
{
	var dims = BrowserHelper.GetWinSize();

	// reposition email Iframe:
	var emd = document.getElementById("divEmail");
	if(emd != null)
	{
		var divW = parseInt(emd.style.width);
		var divH = parseInt(emd.style.height);
		var pTop = (dims.height - divH)/2;
		var pLeft = (dims.width - divW)/2;
		emd.style.top = pTop + "px";
		emd.style.left = pLeft + "px";
	}	
}

// Writes the HTML for the 'contact me' link...
function GetContactMeLink(infoAbout, linkText, titleText)
{
	var s = CAMPAIGN_COOKIE;
	
	var b = "";
	b += "Please contact me as soon as possible with more information about " + infoAbout + ".";
	//b += "<br /><br />My industry is:";
	//b += "<br /><br />My phone number is:";
	
	var ts = "font-size:12px;"; // text style...
	
	var t = "";
	if(s != "")
	{
		t = "[" + s + "]";
	}
	
	var l = "";
	
		// for direct e-mail:
		l += "<a title='Click here to contact us via e-mail...'";
		l += " href='mailto:info" + s + "@sfwllc.com";
		l += "?Subject=Contact me... " + t;
		l += "&Body=" + b;
		l += "'";
		l += "style='" + ts + "'>";
		l += "<img src='images/contactMeSoon.gif' border='0' align='absbottom' />";
		if(linkText.length > 0)
		{
			l += "E-mail us";
		}
		l += "</a>";
		
		if(linkText.length > 0)
		{
			l += "&#160;";
		}
		l += "&#160;";

		// for e-mail form:
		l += "<a title='" + titleText + "'";
		l += " href=\"javascript:ExecuteContactMe('" + infoAbout + "', '" + s + "')\"";
		l += "style='" + ts + "'>";
		l += "<img src='images/info.gif' border='0' align='absbottom' />";
		l += linkText;
		l += "</a>";
	
	document.write(l);
}

function ExecuteContactMe(infoAbout, campaignID)
{
	var emd = document.getElementById("divEmail");
	var emif = document.getElementById("ifEmail");
	if (emd != null && emif != null) 
	{
		window.scrollTo(0, 0);
		//var ifs = "emailForm.htm";
		var ifs = "SfwSupport/AdditionalInfoEmail.aspx";
		    ifs += "?" + encodeURIComponent(infoAbout);
			ifs += "&" + campaignID; // cid = campaign ID...
 			ifs += "";
		emif.src = ifs;
		emd.style.display = "";
	}
}

function CloseEmail()
{
	var emd = document.getElementById("divEmail");
	var emif = document.getElementById("ifEmail");
	if (emd != null && emif != null) 
	{
		emd.style.display = "none";
		emif.src = "blank.htm";
	}
}

// ///////////////////////////////

// NOTE: MERGE THIS CODE WITH THE CODE FOR E_MAIL IFRAME !!!

function ExecuteShowVideo(videoURL, videoWidth, videoHeight)
{
	var div = document.getElementById("divVideo");
	var iFrame = document.getElementById("ifVideo");
	if (div != null && iFrame != null) 
	{
 	    var dims = BrowserHelper.GetWinSize();
   	    var vMargin = 65;
    	var hMargin = 30;
    	var offset = 2;
    	var divWidth = videoWidth + hMargin;
    	var divHeight = videoHeight + vMargin

		window.scrollTo(0, 0);
		
		div.style.width = divWidth + "px";
		div.style.height = divHeight + "px";

        iFrame.setAttribute("width", videoWidth + hMargin - offset);
        iFrame.setAttribute("height", videoHeight + vMargin - offset);

		iFrame.src = videoURL;
		div.style.display = "";

	
		var pTop = (dims.height - divHeight)/2;
		var pLeft = (dims.width - divWidth)/2;
		div.style.top = pTop + "px";
		div.style.left = pLeft + "px";
	}
}

function CloseVideo()
{
	var div = document.getElementById("divVideo");
	var iFrame = document.getElementById("ifVideo");
	if (div != null && iFrame != null) 
	{
		div.style.display = "none";
		iFrame.src = "blank.htm";
	}
}


// ///////////////////////////////

// Writes the HTML for the 'details' link...
function GetDetailsLink(url, linkText, titleText, removeImageBool)
{	
	var l = "<a href='" + url + "' title='" + titleText + "' style='font-size:12px; font-weight:bold;'>";
	if(!removeImageBool)
	{
		l += "<img src='images/seeDetails.gif' border='0' align='absbottom' />";
	}
	l += linkText;
	l += "</a>";
	
	document.write(l);
}

// changes the appearance of a nav cell(tdRef):
function highlightNav(overBool, tdRef)
{
	if(tdRef !== null)
	{
		if(overBool)
		{
			tdRef.style.fontWeight = "bold";
			tdRef.style.color = "#666699";
			tdRef.style.backgroundImage = "url(images/navBG-002.gif)";			
		}
		else
		{
			tdRef.style.fontWeight = "normal";
			tdRef.style.color = "#999999";
			tdRef.style.backgroundImage = "url(images/navBG-001.gif)";			
		}		
	}
}

// changes the appearance of a nav cell(tdRef):
function highlightSubNav(overBool, tdRef)
{
	if(tdRef !== null)
	{
		if(overBool)
		{
			tdRef.style.fontWeight = "bold";
			tdRef.style.color = "#666699";
			//tdRef.style.backgroundImage = "url(images/navBG-002.gif)";			
		}
		else
		{
			tdRef.style.fontWeight = "normal";
			tdRef.style.color = "#999999";
			//tdRef.style.backgroundImage = "url(images/navBG-001.gif)";			
		}		
	}
}

// takes the user to the desired page(url):
function gotoUrl(url)
{
	document.location = url;
}

// Opens the Accendo main window:
function clientLogon()
{
	// Redirect them to the secure site
	//var myHostName = window.location.hostname;
	//var wWidth = eval(parseInt(screen.availWidth)-9);
	//var wHeight = eval(parseInt(screen.availHeight)-47);
	//accendoWin = window.open("https://" + myHostName + "/main/Logon/Logon.aspx","Accendo","width=" + wWidth + ",height=" + wHeight + ",status=yes,resizable=yes,scrollbars=yes,top=0,left=0");
	//accendoWin.focus();	
	
	//document.location = "http://" + window.location.hostname + "/main/";	
	document.location = "http://" + window.location.hostname + "/accendo/";	
}

// ...
function buildMainNav(section)
{
	var sn = "navigation"; // style name

	var s = '';
	s += '<table cellpadding="0" cellspacing="0" width="100%">';
	s += '<tr>';

	s += buildNavSection("10%", sn, (section == LC.Section.Home), "gotoUrl('" + LC.Section.Home.Pages[0].URL + "')", LC.Section.Home.Name, true, false);
	s += buildNavSection("14%", sn, (section == LC.Section.AboutUs), "gotoUrl('" + LC.Section.AboutUs.Pages[0].URL + "')", LC.Section.AboutUs.Name, true, false);
	s += buildNavSection("20%", sn, (section == LC.Section.Products), "gotoUrl('" + LC.Section.Products.Pages[0].URL + "')", LC.Section.Products.Name, true, false);
	s += buildNavSection("14%", sn, (section == LC.Section.Industries), "gotoUrl('" + LC.Section.Industries.Pages[0].URL + "')", LC.Section.Industries.Name, true, false);
	s += buildNavSection("14%", sn, (section == LC.Section.Resources), "gotoUrl('" + LC.Section.Resources.Pages[0].URL + "')", LC.Section.Resources.Name, true, false);
	s += buildNavSection("14%", sn, (section == LC.Section.ContactUs), "gotoUrl('" + LC.Section.ContactUs.Pages[0].URL + "')", LC.Section.ContactUs.Name, true, false);
	s += buildNavSection("12%", sn, (section == LC.Section.Logon), "clientLogon()", LC.Section.Logon.Name, false, false);
	
	s += '</tr>';
	s += '</table>';
	
	document.write(s);
}

// ...
function buildSubNav(section, pageIndex)
{
	var sn = "subNavigation"; // style name
	var nop = section.Pages.length; // number of pages
	var cw = parseInt(100/nop); 
	
	//alert("cw = " + cw);

	var s = '';
	s += '<table cellpadding="0" cellspacing="0" width="100%">';
	s += '<tr>';
	
	for(var i=0; i<nop; i++)
	{
		s += buildNavSection(cw + "%", sn, (i == pageIndex), "gotoUrl('" + section.Pages[i].URL + "')", section.Pages[i].Name, true, true);
	}
	
	s += '</tr>';
	s += '</table>';
	
	document.write(s);
}

// ...
function buildIndustriesSubNav()
{
	var s = "";
	
	//s += "Commercial Properties";
	//s += "|";
	s += '<a href="Industries_OfficeMT.htm" style="font-size:smaller;" >Office Management</a>';
	s += ' | ';
	s += '<a href="Industries_ShoppingCenter.htm" style="font-size:smaller;" >Shopping Centers</a>';
	s += ' | ';
	s += '<a href="Industries_BIDs.htm" style="font-size:smaller;" >Municipalities and BIDs</a>';
	//s += ' | ';
	//s += 'Healthcare';
	s += '<br />';
	s += '<a href="Industries_Manufacturing.htm" style="font-size:smaller;" >Manufacturing</a>';
	s += ' | ';
	s += '<a href="Industries_Hospitality.htm" style="font-size:smaller;" >Hospitality</a>';
	s += ' | ';
	s += '<a href="Industries_Education.htm" style="font-size:smaller;" >Education</a>';
	s += ' | ';
	s += '<a href="Industries_Security.htm" style="font-size:smaller;" >Security, Safety & Emergency Preparedness</a>';
	s += ' | ';
	s += '<a href="Industries_Other.htm" style="font-size:smaller;" >Other</a>';
						
	document.write(s);
}

// Builds an individual nav cell:
function buildNavSection(cellWidth, styleName, isOn, clickHandler, text, borderBool, isSub)
{	
	s = '<td width="' + cellWidth + '"';
	if(isOn)
	{
		s += ' class="' + styleName + 'ON"';
		s += ' onclick="' + clickHandler + '"';
	}
	else
	{
		var hlf = "highlightNav"; if(isSub) hlf = "highlightSubNav";

		s += ' class="' + styleName + 'OFF"';
		s += ' onmouseover="' + hlf + '(true, this);"';
		s += ' onmouseout="' + hlf + '(false, this);"';
		s += ' onclick="' + clickHandler + '"';
	}
	if(borderBool && !isSub)
	{
		s += ' style="border-right: 1px solid #DDDDDD; height:22px"';
	}
	s += '>';
	s += text;
	s += '</td>';
	
	return s;
}

function doCopyright()
{
	var c = '<table cellpadding="0" cellspacing="0" width="100%">';
	c += '<tr>';
	c += '<td id="copyright" align="center">';
	c += "&#169; ";
	c += new Date().getYear();
	c += ' SFW LLC.  All rights reserved.';
	c += '</td>';
	c += '</tr>';
	c += '</table>';
	c += '';
	
	document.write(c);
}


// //////////////////////////////////////////////////////////////////
// Image Pop Up Handling:

var picWin = null;

function showLargePic(s, i, tt)
{
	var t = encodeURIComponent(tt);
	picWin = window.open("imgPopUp.htm?section=" + s + "&index=" + i + "&text=" + t + "", "xxx", LC.PopUpAttributes);
}

var clipWin = null;

function showClip(s)
{
	clipWin = window.open("clips/" + s + "/page-0.htm", "yyy", LC.ClipAttributes);
}

function showPDF(url)
{
	picWin = window.open(url, "zzz", "");
}

// //////////////////////////////////////////////////////////////////
		
/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html


*****/


window.addEventListener ? window.addEventListener("load", so_init, false) : window.attachEvent("onload", so_init);

var imgs = [], zInterval = null, current=0, pause=false;
var delay = 5;
var fadeInterval = delay * 1000;
function so_init() 
{
	var wrapper = document.getElementById("imageContainer");
	
	if(wrapper !== null)
	{
		delay = parseInt(wrapper.getAttribute("delay"), 10);
		fadeInterval = delay * 1000;
		
		imgs = wrapper.getElementsByTagName("img");
		
		for(i=1; i<imgs.length; i++) 
		{
			imgs[i].xOpacity = 0;
		}
		imgs[0].style.display = "block";
		imgs[0].xOpacity = 0.99;
		
		setTimeout(so_xfade, fadeInterval);
	}
}

function so_xfade() 
{
	//alert("so_xfade");
	
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1] ? current+1 : 0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity -= 0.05; 
	nOpacity += 0.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) 
	{
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade, fadeInterval);
	}
	else 
	{
		setTimeout(so_xfade, 50);
	}
	
	function setOpacity(obj) 
	{
		if(obj.xOpacity > 0.99) 
		{
			obj.xOpacity = 0.99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}				
			





























