// checks web browser information
var user_agent      = navigator.userAgent.toLowerCase();
var app_version     = navigator.appVersion.toLowerCase();
var is_ie           = 0;
var is_firefox      = 0;
var is_safari       = 0;
var is_other        = 0;
var browser_version = 0;
var browser_name    = '';
if(user_agent.indexOf('msie') != -1){
	is_ie = 1;
	browser_version = parseFloat(app_version.split("msie")[1]);
	browser_name = 'ie';
} else if(user_agent.indexOf('firefox') != -1){
	is_firefox = 1;
	browser_name = 'firefox';
} else if(user_agent.indexOf('safari') != -1){
	is_safari = 1;
	browser_name = 'safari';
} else {
	is_other = 1;
}
if(!is_ie && browser_name){
	browser_version = parseFloat(user_agent.split(browser_name + "/")[1])
}

// popup window function
function newwin(url, w, h, wn){
	var win_features = "status=0,scrollbars=1,resizable=1,toolbar=0,location=0,";
	if(!wn) wn = "Find Local Agents - Popup";
	if(!w)  w  = screen.width - 200;
	if(!h)  h  = screen.height - 200;
	var newwindow = window.open(url, wn, win_features + "width=" + w + ",height=" + h);
	newwindow.focus();
}

// trim extra white spaces
function trimWS(s){
	s = s.replace(/^\s*/, "");
	return s.replace(/\s*$/, "");
}

// strip out special characters
function stripSpecialChars(data){
	return data.replace(/[\.,]/g, "");
}

//  remove spaces and change the casing to all uppercase
function changeCase(data){
	return data.replace(/\s/g, "").toUpperCase();
}

// check if variable is "undefined"
function isUndefined(variable){
	if(typeof(variable) == undefined || typeof(variable) == "undefined" || variable == NaN) return true;
	else false;
}

// check if object is "null"
function isNull(obj){
	return (obj == null);
}

// check if object is "undefined" or "null"
function isUndefinedNull(obj){
	return (isUndefined(obj) || isNull(obj));
}

// parse object for particular tag
function parseForTagName(tName, oArray, bFindFirst){
	var bFindFirst = (bFindFirst == null) ? false : bFindFirst;
	var bItemFound = false;
	var tmpArray = new Array();
	var loopObject = function(_tName, _oArray){
		for(var x in _oArray){
			if(x == _tName){
				tmpArray.push(_oArray[x]);
				bItemFound = true;
			}
			if(typeof(_oArray[x]) == 'object'){
				if(!bFindFirst || (bFindFirst && !bItemFound)) loopObject(_tName, _oArray[x]);
			}
		}
	}
	loopObject(tName, oArray);
	if(!bItemFound) return null;
	else if(tmpArray.length == 1) return tmpArray[0];
	else return tmpArray;
}

// create custom event listener
function addCustomLoadFunction(event_name, function_name){
	if(window.addEventListener){
		window.addEventListener(event_name, function_name, false);
	} else if(window.attachEvent){
		//ie browser
		window.attachEvent("on" + event_name, function_name);
	}
}

// create AJAX request object
function makeAjaxRequest(){
	try{
		request = new XMLHttpRequest();
	} catch (tryMS){
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (otherMS){
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed){
				request = null;
			}
		}
	}
	return request;
}

var RecaptchaOptions = {theme:'clean'};