// JavaScript Document
var prop = new Object();
	prop.address = '';
	prop.agent = '';
	prop.directory = '';
	prop.displayAgent = 'all';
	prop.offer = 'sale';		// used by property.htm to differentiate between sale & rent
	
var ourAgents = new Array();
	ourAgents[0] = 'lee';
	ourAgents[1] = 'howard';
	ourAgents[2] = 'liz';
	ourAgents[3] = 'webmaster';
	
var validSites = new Array();
	validSites[0] = 'blograbun.com';
	validSites[1] = 'buygeorgiamountainproperty.com';
	validSites[2] = 'howardsilvermanRealtor.com';
	validSites[3] = 'lakeburtononline.com';
	validSites[4] = 'lakerabunonline.com';
	validSites[5] = 'lakeseedonline.com';
	validSites[6] = 'rabuncountyonline.com';
	validSites[7] = 'rabunlakesonline.com';
	validSites[8] = 'rabunpropertyonline.com';
	validSites[9] = 'rabunrealtor.com';
	validSites[10] = 'sellrabun.com';
	validSites[11] = 'leesilvermanrealtor.com';
	
var displayAgent = 'all';
var myParent = '';			// used by ourEmail.htm
var mySite = document.URL;
var parentSite = '';

function parentValid() {
	mySite = document.URL;
	parentSite = parent.document.URL;
var numSites = validSites.length;
var s = parentSite.toLowerCase();
	for (var i = 0; i < numSites; i++) {
		if(myMatch(s, validSites[i])) {
			myParent = validSites[i];
			return true;
		}
	}
	return false;
}

function myMatch(m1, m2) {
var flg = false;
var i = 0;
var j = 0;
	while (i < m1.length) {
		j = 0;
		if(m2.charAt(j) == m1.charAt(i)) {
			flg = true;
			while (j < m2.length) {
				if(m2.charAt(j) != m1.charAt(i)) {
					flg = false;
					break;
				}
				i++;
				if(i >= m1.length) {
					j++;
					if(j != m2.length) flg = false;	
					return flg;
				}
				j++;
			}
			if (flg) return flg;
		} else {
			flg = false;	
		}
		i++;
	}
	return flg;
}

function getMySite() {
	return mySite;	
}

function getParentSite() {
	return parentSite;	
}

function callMail(whichAgent) {
var which = whichAgent + whichAgent.charAt(whichAgent.length-1);
var eObj = document.getElementById(which);	
	eObj.href = 'ourMail.htm?agent=' + whichAgent;
}

function callAHAH(url, postParam, pageElement, callMessage) {
	document.getElementById(pageElement).innerHTML = callMessage;
	try {
		req = new XMLHttpRequest();   // firefox
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");	// some versions of IE
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP"); // other versions of IE	
			} catch(e) {
				alert("Server error: " + e);
				req = false;	
			}
		}
	}
	req.onreadystatechange = function() {responseAHAH(pageElement);};
	req.open("POST", url, true);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Content-length", postParam.length);
	req.setRequestHeader("Connection", "close");
	req.send(postParam);
}

function responseAHAH(pageElement) {
	var output = '';
	if(req.readyState == 4) {
		if(req.status == 200) {
			output = req.responseText;
			document.getElementById(pageElement).innerHTML = output;
		}
	}
}

function getPropertyAgent(){
    return prop.agent;
}

function getDisplayAgent() {
	return prop.displayAgent;	
}

function getPropertyAddress(){
    return prop.address;
}

function getPropertyDirectory() {
	return prop.directory;	
}

function getPropertyOffer() {
	return prop.offer;	
}

// ------------------------------------------------------------------------
function resetTeam() {
	if (displayAgent != 'all') {
		for (var i = 0; i < ourAgents.length; i++) {
			if(ourAgents[i] != 'webmaster') {
				if (ourAgents[i] != displayAgent) {
					var s = ourAgents[i] + 'S';
					var myObj = document.getElementById(s);
					myObj.style.display = 'none';
				}
			}
		}
		var eObj = document.getElementById('single');
		eObj.innerHTML = 'Welcome!';
		eObj = document.getElementById('single1');
		eObj.innerHTML = 'me';
		eObj = document.getElementById('single2');
		eObj.innerHTML = 'my web site, click on my picture';
	}
}

// -----------------------------------------------------------------------
/*  WindowDoResize = function (){
var s = location.href;

	s += '?agent=' + getPropertyAgent() + '&theProperty=' + getPropertyAddress();
    location.replace(s);
}


window.onresize = WindowDoResize; // reset passed parameters after a resize; */


// -----------------------------------------------------------------------
// retrieve the string parameters from the URL and reset the above object variables

function myunescape (str) {  // this is needed by args_init, below
	str = '' + str;
	while (true)
	{
		var i = str . indexOf ('+');
		if (i < 0) break;
		str = str . substring (0, i) + ' ' + str . substring (i + 1, str . length);
	}
	return unescape (str);
}
// This function creates the args [] array and populates it with data
// found in the URL's search string:

function args_init () { // requires myunescape(), above
	args = new Array ();
	var argstring = window . location . search;
	if (argstring . charAt (0) != '?') return;
	argstring = argstring . substring (1, argstring . length);
//	argstring = switchColonToAmpersant(argstring);
	var argarray = argstring . split ('&');
	var singlearg;
	for (var i = 0; i < argarray . length; ++ i){
		singlearg = argarray [i] . split ('=');
		if (singlearg . length != 2) continue;
		var key = myunescape (singlearg [0]);
		var value = myunescape (singlearg [1]);
		args [key] = value;
	}
}

// Call the args_init () function to set up the args [] array:

    args_init ();
	
// retrieve listing address
	if (args['theProperty'] != undefined) {
		var aProperty = args['theProperty'];
		if(aProperty.length > 0) prop.address = aProperty;
	}
	if (args['offer'] != undefined) {
		var offer = args['offer'];
		if(offer.length > 0) prop.offer = offer;
	}
	if (args['agent'] != undefined) {
		aagent = args['agent'].toLowerCase();
		if(aagent.length > 0) {
			for (var i = 0; i < ourAgents.length; i++) {
				if ( aagent == ourAgents[i]) {
					displayAgent = aagent;
					prop.displayAgent = displayAgent;
				}
			}
		}
	}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

