var mouseClickDisabled = 0;

// Loads the page.
function Load()
{

	var images = new Array();
	var preloader = null;
	
	// Add any preload images here.
	pushOnToArray(images, "images/clients/CLIENTS_homebutton_svccallH.jpg");
	pushOnToArray(images, "images/clients/CLIENTS_homebutton_timechangesH.jpg");
	pushOnToArray(images, "images/clients/CLIENTS_homebutton_svccallR.jpg");
	pushOnToArray(images, "images/clients/CLIENTS_homebutton_timechangesR.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_aboutusH.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_historyH.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_ourteamH.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_careersH.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_distdiffH.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_aboutusR.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_historyR.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_ourteamR.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_careersR.jpg");
	pushOnToArray(images, "images/company/COMPANY_homebutton_distdiffR.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_homebutton_locationsH.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_homebutton_sendmessageH.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_homebutton_joinmailinglistH.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_homebutton_locationsR.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_homebutton_sendmessageR.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_homebutton_joinmailinglistR.jpg");
	pushOnToArray(images, "images/company/COMPANY_aboutusH.jpg");
	pushOnToArray(images, "images/company/COMPANY_historyH.jpg");
	pushOnToArray(images, "images/company/COMPANY_ourteamH.jpg");
	pushOnToArray(images, "images/company/COMPANY_careersH.jpg");
	pushOnToArray(images, "images/company/COMPANY_distdiffH.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_locationsH.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_sendmessageH.jpg");
	pushOnToArray(images, "images/contactus/CONTACTUS_joinmailinglistH.jpg");
	pushOnToArray(images, "images/services/SERVICES_homebutton_implementationH.jpg");
	pushOnToArray(images, "images/services/SERVICES_homebutton_supportH.jpg");
	pushOnToArray(images, "images/services/SERVICES_homebutton_trainingH.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_dataequipH.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_dataequipR.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_healthcareH.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_healthcareR.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_netsvcsH.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_netsvcsR.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_telephonyH.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_telephonyR.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_telesysH.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_telesysR.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_voicemailH.jpg");
	pushOnToArray(images, "images/solutions/SOLUTIONS_homebutton_voicemailR.jpg");
	pushOnToArray(images, "images/button_bar/button_company_up.jpg");
	pushOnToArray(images, "images/button_bar/button_services_up.jpg");
	pushOnToArray(images, "images/button_bar/button_clients_up.jpg");
	pushOnToArray(images, "images/button_bar/button_government_up.jpg");
	pushOnToArray(images, "images/button_bar/button_solutions_up.jpg");
	pushOnToArray(images, "images/button_bar/button_partners_up.jpg");
	pushOnToArray(images, "images/button_bar/button_testimonials_up.jpg");
	pushOnToArray(images, "images/button_bar/button_contact_up.jpg");
	pushOnToArray(images, "images/giveaway/giveaway_blackberry_7210H.jpg");
	pushOnToArray(images, "images/quote/quote_panel_buttonH.jpg");
	pushOnToArray(images, "images/body/body_printH.jpg");
	pushOnToArray(images, "images/body/body_closeH.jpg");

	// Perform the preload.
	for (var i = 0; i < images.length; i++)
	{
		preloader = new Image();
		preloader.src = images[i];
	}

	if (needsDropDowns == 1)
	{
		// Add handlers to the various popups.
		if (document.getElementById)
		{
			// Company popup.
			document.getElementById('companyPopup').onmouseover = ShowPopupHandler;
			document.getElementById('companyPopup').onmouseout = HidePopupHandler;
			
			// Services popup.
			document.getElementById('servicesPopup').onmouseover = ShowPopupHandler;
			document.getElementById('servicesPopup').onmouseout = HidePopupHandler;

			// Government popup.
			document.getElementById('governmentPopup').onmouseover = ShowPopupHandler;
			document.getElementById('governmentPopup').onmouseout = HidePopupHandler;
	
			// Solutions popup.
			document.getElementById('solutionsPopup').onmouseover = ShowPopupHandler;
			document.getElementById('solutionsPopup').onmouseout = HidePopupHandler;

			// Partners popup.
			document.getElementById('partnersPopup').onmouseover = ShowPopupHandler;
			document.getElementById('partnersPopup').onmouseout = HidePopupHandler;
	
			// Clients popup.
			document.getElementById('clientsPopup').onmouseover = ShowPopupHandler;
			document.getElementById('clientsPopup').onmouseout = HidePopupHandler;
	
			// Testimonials popup.
			document.getElementById('testimonialsPopup').onmouseover = ShowPopupHandler;
			document.getElementById('testimonialsPopup').onmouseout = HidePopupHandler;
	
			// Contact Us popup.
			document.getElementById('contactusPopup').onmouseover = ShowPopupHandler;
			document.getElementById('contactusPopup').onmouseout = HidePopupHandler;
			
		}
	}

}

// Push an element into an array.
function pushOnToArray(array, value)
{
	array[array.length] = value;
}

//Click on a News article in the footer layer and pop up a window
function winopen(filenamewtoken,winWidth,winHeight,whichwindow) {
		closechild(); 
	 	if (document.all) {	
			var xMax = screen.width, yMax = screen.height;
	    } else {
			if (document.layers) {
				var xMax = window.outerWidth, yMax = window.outerHeight;
	        } else { var xMax = 640, yMax=480; }
		}
		var xOffset = (xMax - winWidth)/2, yOffset = ((yMax - winHeight)/2) - 30;
		//Whichwindow == 1 -- No Scrolls, no Menu
		//Whichwindow == 2 -- Scrolls, no Menu
		//Whichwindow == 3 -- Scrolls, Menu
		//Whichwindow == 4 -- No Scrolls, Menu
		if (whichwindow == 1) {
			PopupAuxWindow = window.open(filenamewtoken,'PopupAuxWindow', 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
		} else if (whichwindow == 2) {
			PopupAuxWindow = window.open(filenamewtoken,'PopupAuxWindow', 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
		} else if (whichwindow == 4) {
			PopupAuxWindow = window.open(filenamewtoken,'PopupAuxWindow', 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=no,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
		} else {
			PopupAuxWindow = window.open(filenamewtoken,'PopupAuxWindow', 'screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,hotkeys=no,resizable=no,width='+winWidth+',height='+winHeight+'');
		}
		if (!PopupAuxWindow.opener) { PopupAuxWindow.opener = self; } 
	}

	var PopupAuxWindow = '';
	function closechild() {
		if (PopupAuxWindow && PopupAuxWindow.open && !PopupAuxWindow.closed) { PopupAuxWindow.close(); }
	}

//rollover image functions
function MM_swapImgRestore() {
   if (mouseClickDisabled == 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) { 
  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() { 
   if (mouseClickDisabled == 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];}
   }
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
  mouseClickDisabled = 1;
}

//THE DROPDOWN MENU FUNCTIONS
function ToggleWindowElement(element, inDisplay)
{
	switch (element.type)
	{
		case 'select-one':
			element.style.visibility = inDisplay;		
			break;
	}
}

// Blurs the element.
function BlurElement(element)
{
	element.blur();
}

// Renders the form for popups.
function PrepareFormForPopups(form, displayMode)
{
	var i;
	
	// Iterate and act on the form.
	for (i = 0; i < form.elements.length; i++)
	{
		// Selectively hide certain elements.
		ToggleWindowElement(form.elements[i], displayMode);
		
		// Blur the element.
		if (displayMode == 'hidden') BlurElement(form.elements[i]);
	}
}

// Show the popup.
function ShowPopup(id)
{
	// Test capabilities.
	if (!document.getElementById) return false;
	if (!document.getElementById(id)) return false;
	
	// Set visibility.
	document.getElementById(id).style.visibility = "visible";
	
	// Test form capabilities.
	if (!document.forms) return false;
	if (!document.forms[0]) return false;
	
	// Show the form.
	if (!PrepareFormForPopups(document.forms[0], 'hidden')) return false;
	
	return true;
}

// Hide the popup.
function HidePopup(id)
{
	// Test capabilities.
	if (!document.getElementById) return false;
	if (!document.getElementById(id)) return false;
	
	// Set visibility.;
	document.getElementById(id).style.visibility = "hidden";
	
	// Test form capabilities.
	if (!document.forms) return false;
	if (!document.forms[0]) return false;
	
	// Show the form.
	if (!PrepareFormForPopups(document.forms[0], 'visible')) return false;
	
	return true;
}

// Shows the popup from inside the popup.
function ShowPopupHandler(mouseEvent)
{
	this.style.visibility = 'visible';
	
	// Test form capabilities.
	if (!document.forms) return false;
	if (!document.forms[0]) return false;
	
	// Show the form.
	if (!PrepareFormForPopups(document.forms[0], 'hidden')) return false;
}

// Hides the popup from the popup.
function HidePopupHandler(mouseEvent)
{
	var target;
	var relatedTarget;
	var trace = "";
	
	// Get the event.
	if (!mouseEvent) mouseEvent = window.event;
		
	// Get the target.
	target = (mouseEvent.srcElement ? mouseEvent.srcElement : mouseEvent.target);
		
	// If the target is not a DIV mouseout, return false.
	if (target != this) 
	{
		//alert('Not a DIV mouseout');
		return;
	}
	
	// Get the related target.
	relatedTarget = (mouseEvent.toElement ? mouseEvent.toElement : mouseEvent.relatedTarget);
	
	// Iterate through and verify.
	while (relatedTarget != this && relatedTarget.nodeName.toUpperCase() != 'BODY')
	{
		trace += relatedTarget.nodeName + '\n';
		relatedTarget = relatedTarget.parentNode;
	}
	
	// If we are still inside the target, return false.
	if (relatedTarget == this) 
	{
		//alert('Inside the target.');
		return;
	}
	
	// Hide the popup.
	this.style.visibility = 'hidden';
	
	// Test form capabilities.
	if (!document.forms) return false;
	if (!document.forms[0]) return false;
	
	// Show the form.
	if (!PrepareFormForPopups(document.forms[0], 'visible')) return false;
}

function printSpecial()
{
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the print section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);		
		if (gAutoPrint)
		{
			//Detect IE5.5+
			var version=0 
			if (navigator.appVersion.indexOf("MSIE")!=-1){
			temp=navigator.appVersion.split("MSIE")
			version=parseFloat(temp[1])
			}

			
			if ((version >= 5.5) || (navigator.appName=="Netscape"&&parseFloat(navigator.appVersion)>=4.7))
			{
 				printWin.print();
			}
			else
			{
				alert("Please use your browser's print functionality to print this document.");
			}
		}
		printWin.document.close();
			
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}


// Validates the form, prompts with a message if the values are invalid.
function validateForm(inForm)
{
	var errorString = "";
	var errorOccurred = false;
	
	// Prep the error string.
	errorString = errorString + "The following errors occurred:\n\n";
	
	// Iterate through form elements looking for required flag.
	for (var i = 0; i < inForm.elements.length; i++)
	{
		// Check for elements that are required.
		if (inForm.elements[i].required)
		{
			// Check the value.
			if (inForm.elements[i].value == '')
			{
				// An error did occur, flag it.
				errorOccurred = true;
				
				// Add the message to the error string.
				if (inForm.elements[i].message != '')
				{
					errorString = errorString + "• " + inForm.elements[i].message + "\n";
				}					
				else
				{
					// Output a default error for the field.
					errorString = errorString + "• There is a missing field.\n";
				}
			}
		}
	}
	
	// Finish the error string.
	errorString = errorString + '\nPlease correct these errors and re-submit this form.';
	
	// If an error occurred, show the message.
	if (errorOccurred == true) alert(errorString);
	
	// Return true if no error occurred.
	return !errorOccurred;
}

//this validates the form across ALL browsers (NOV 4, 2004)
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.title; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors+'\nPlease correct these errors and re-submit this form.');
  document.MM_returnValue = (errors == '');
}
