var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
if(location.href.indexOf('/atlanticsecuritysystems.com/') != -1 ){
	var rootdomain="http://"+window.location.hostname+"/atlanticsecuritysystems.com/"
}else{
	var rootdomain="http://"+window.location.hostname+"/"
}
var bustcacheparameter=""
var xmlHttp
var vertStartPos = 0;
var showErrors = 1;
var lastPageSave = 1;
var startSearch = 'Begin search here...';

function loading(area){
	var iconArea = document.getElementById(area);
	//controlPanel.innerHTML = '';
	
	div = document.createElement('div');
	//div.className = 'onLoad';

	div.id = 'loadingDiv';
if(area == 'newsletterPanel'){
	div.style.position = 'relative';
	div.style.top = '0px';
	div.style.left = '25px';
}else{
	div.style.position = 'absolute';
	div.style.top = vertStartPos + 600 +'px';
	div.style.left = '50%';
}
	div.style.height = '400px';
	div.align = 'center';
	img = document.createElement('img');
	img.src = rootdomain + 'RootImages/onLoad.gif';
	div.appendChild(img);
	iconArea.appendChild(div);
}

function GetXmlHttpObject(){
var xmlHttp=null;
	try{  // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer
	try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
  }
return xmlHttp;
}

function $(element) {
    return document.getElementById(element);
}

function cleanValue(value){
	var cleanValue = value.replace(/&/g,'||');
	return cleanValue;
}

function logosHeight(){
	if($('logosMenu')){
		$('logosMenu').style.height = $('contentRow').scrollHeight+20+'px';
	}
}

function changeImg(img){
	$('defaultImg').src = img;	
}

function sendMail(){
var form = document.thisForm;
$('nameWarning').style.display = 'none';
$('emailWarning').style.display = 'none';
$('phoneWarning').style.display = 'none';
$('commentsWarning').style.display = 'none';
$('emailPanelWarning').style.display = 'none';

if(form.txtName.value == ''){	$('nameWarning').style.display = '';return false;}
if(form.txtEmail.value == ''){ $('emailWarning').style.display = '';$('emailWarning').innerHTML = ' - Please insert your email';return false;}
if(validate(form.txtEmail.value,'email') == false){$('emailWarning').style.display = '';$('emailWarning').innerHTML = ' - Please insert a valid email';return false;}
if(form.txtPhone.value == ''){ $('phoneWarning').style.display = '';return false;}
if(form.txtComments.value == ''){	$('commentsWarning').style.display = '';return false;}

var url=rootdomain+"RootIncludes/phpScript.php?req=contact-us.php";
for (i = 0; i < form.elements.length; i++) {
	var elName = form.elements[i].name;
	var elValue = cleanValue(form.elements[i].value);		
	url=url+"&"+elName+"="+elValue;
} //end for(

url=url+"&sid="+Math.random();

	if(!document.getElementById('loadingDiv')){loading('emailPanel');}
//	alert('url: '+url);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){sendMailRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function sendMailRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if(document.getElementById('loadingDiv')){document.getElementById('loadingDiv').parentNode.removeChild(document.getElementById('loadingDiv'));}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			$('emailPanel').innerHTML = '<div class="warningText">Your email has been sent successfully.<br>Thank you for your comments.  We will be in touch with you, shortly.</div>'
		}else{
			$('emailPanelWarning').style.display = '';
			$('emailPanelWarning').innerHTML = '<div class="warningText">Unfortunately, your email was not sent.<br>There appears to be a problem with this form.  Please contact us using the information above.</div>'			
		}

	}
}
function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}
function validate(aStr, type) {
/*------ Function to check inputs ------*/
	var expr = "";
	switch (type){
	case "date" : expr = /^[0-2]{0,1}([1-9]|30|31)\/0{0,1}([0-9]|11|12)\/[0-9]{4,4}$/; break;
	case "email" : expr = /^(.)+@{1,1}((.)+\.(.)+)+$/; break;
	case "integer" : expr = /^[0-9]*$/; break;
	case "decimal" : expr = /^[0-9]*\.{0,1}[0-9]*$/; break;
	case "username" : expr = /^([a-z]|[A-Z]|[0-9])*$/; break;
	case "password" : expr = /^([a-z]|[A-Z]|[0-9])*$/; break;
	case "string" : expr = /^([a-z]|[A-Z]|[ ]|[.])*$/; break;
	case "phonenumber" : expr = /^([0-9]|[ ]|[+]|[-])*$/; break;
	}
	if(expr != "")
		return expr.test(Trim(aStr));
	else
		return false;
}

function showBckGroundDim(){
	var bckGroundDim = document.createElement('div');
	bckGroundDim.className = 'bckGroundDim';
	bckGroundDim.id = 'bckGroundDim';
	document.getElementById('pageFooter').appendChild(bckGroundDim);
}

function popBox(type){
if(type == 'serviceMap' && !$('serviceMap')){
	var serviceMapIcon = document.getElementById('serviceMapIcon');
	var serviceMap = document.createElement('img');	
	serviceMap.id = 'serviceMap';
	serviceMap.src = rootdomain+'RootImages/template/service_map.jpg';
	serviceMap.className = 'serviceMap';
	serviceMap.onclick = function (){return popBox('serviceMapIcon');};
	serviceMapIcon.appendChild(serviceMap);
	$('newletterImgDiv').style.display = 'none';
}else if(type == 'serviceMap' && $('serviceMap')){
//	var serviceMapIcon = document.getElementById('serviceMapIcon');
//	var bckGroundDim = top.document.getElementById('bckGroundDim');		
	document.getElementById(type).parentNode.removeChild(document.getElementById(type));
//	pageFooter.removeChild(bckGroundDim);
	$('newletterImgDiv').style.display = '';
	return;
}else{
//	var pageFooter = document.getElementById('pageFooter');
//	showBckGroundDim();	
//	var bckGroundDim = document.getElementById('bckGroundDim');
//	var popBox = document.createElement('div');	
//	popBox.className = 'popBox';
//	popBox.id = 'popBox';
//	pageFooter.appendChild(popBox);
//
//	var xBox = document.createElement('div');	
//	xBox.className = 'xBox';
//	xBox.innerHTML = 'X';
//	xBox.id = 'xBoxId'
//	xBox.onclick = function (){return popBoxRemove(type);};
//	popBox.appendChild(xBox);
//
//	var popBoxContent = document.createElement('div');	
//	popBoxContent.id = 'popBoxContent';
//	popBox.appendChild(popBoxContent);
//
}

//	var iframe = document.createElement('iframe');
//	if(type == 'serviceMap'){
//		iframe.src = rootdomain+'RootIncludes/serviceMap.php';
//	}

//	iframe.frameBorder = '0';
//	iframe.scrolling = 'no';
//	iframe.style.overflowY = 'hidden'; 
//	iframe.style.overflowX = 'hidden'; 
//	iframe.style.textAlign = 'center';
//	//iframe.setAttribute('align','center');
////	iframe.style.height = '400px';
//	iframe.width = '100%';	
////	iframe.style.overflow = 'auto';		
//	iframe.id="iframe";	
//	popBoxContent.appendChild(iframe);
}

function iframeHeight(){
	var popBoxHeight = top.document.getElementById('popBox').scrollHeight;
	var newHeight = top.document.getElementById('iframe').contentWindow.document.body.scrollHeight+40;
//	var newHeight = top.document.getElementById('iframe').contentWindow.document.body.offsetHeight+40;	
	top.document.getElementById('iframe').style.height = newHeight+'px';
//	alert(newHeight);
}

function popBoxRemove(itemBox){
	var serviceMapIcon = document.getElementById('serviceMapIcon');
//	var bckGroundDim = top.document.getElementById('bckGroundDim');		
	var serviceMap = document.getElementById(itemBox);
	serviceMapIcon.removeChild(serviceMap);
//	pageFooter.removeChild(bckGroundDim);
	$('newletterImgDiv').style.display = '';
}

function clearValue(id,origValue){
	if(document.getElementById('emailWarning')){
		document.getElementById('emailWarning').style.innerHTML = '';
		document.getElementById('emailWarning').style.display = 'none';
	}
	if(document.getElementById(id).value == origValue){document.getElementById(id).value = '';}
	return;
}
function ifEmpty(id,origValue){
	if(document.getElementById(id) && document.getElementById(id).value == ''){document.getElementById(id).value = origValue;}
	return;
}

function keyPress(type,mode,Id,e){
//alert('type: '+type+' mode: '+mode+' Id: '+Id);

var key;
	 if(window.event)
		  key = window.event.keyCode;     //IE
	 else
		  key = e.which;     //firefox
	if (key == 13){
		if(type == 'newsletter'){	
			fnValidateNewsletter();
		}
	}
}


function fnValidateNewsletter(){
	document.getElementById('emailWarning').style.display = 'none';
	document.getElementById('emailWarning').innerHTML = '';
	if(document.getElementById('email').value == ''){
		document.getElementById('emailWarning').style.display = '';
		document.getElementById('emailWarning').innerHTML = 'Be sure to enter your email address.';
		return false; 
	}
	if (validate(Trim(document.getElementById('email').value), "email") == false) {
		document.getElementById('emailWarning').style.display = '';
		document.getElementById('emailWarning').style.height = '25px';
		document.getElementById('emailWarning').innerHTML = 'Be sure to enter a valid email address.';
		return false;
	}

	if(!$('loadingDiv')){loading('newsletterPanel');}
	var url=rootdomain+"RootIncludes/phpScript.php?req=newsletter.php&email=" + $('email').value + "&sid="+Math.random();
	//	alert('url: '+url);

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){  alert ("Your browser does not support AJAX!");  return;  } 
	xmlHttp.onreadystatechange=function(){fnValidateNewsletterRsp()};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	

}


function fnValidateNewsletterRsp(){
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
		if($('loadingDiv')){$('loadingDiv').parentNode.removeChild($('loadingDiv'));}
//		alert(xmlHttp.responseText);
		var theGoods = xmlHttp.responseText.split('|');
		if(theGoods[0] == 1){
			$('emailWarning').style.display = '';
			$('emailWarning').innerHTML = 'Your email has been added successfully<br>'+theGoods[1];
			$('email').value = 'email address';
		}else{
			$('emailWarning').style.display = '';
			$('emailWarning').innerHTML = 'There appears to be a problem with this form.  Please <a style="color:#FF0000;text-decoration:underline;" href="'+rootdomain+'contact-us.php">contact us</a>.</div>'			
		}

	}
}
