dochref = document.location.href.substr(document.location.href.search('/')+2, 1000);
if(dochref.search('/') == -1){
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref;
} else {
	$thisurl = document.location.href.substr(0,document.location.href.search('/')+2) + dochref.substr(0,dochref.lastIndexOf('/'));
}

var xmlhttp;

function getXMLHttp()
{
  var xmllochttp;

  try
  {
    xmllochttp = new XMLHttpRequest();
  }
  catch(e)
  {
    try
    {
      xmllochttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmllochttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      { 
        alert("No support found for AJAX! Please upgrade your brower. We support Internet Explorer 6, Internet Explorer 7 and Firefox.")
        return false;
      }
    }
  }
  return xmllochttp;
}       


if (!xmlhttp) { 
  xmlhttp = getXMLHttp();
}

function myXMLHttpRequest ()
{
  var xmlhttplocal;
  try {
  	xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
  catch (e) {
	try {
	xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
	catch (E) {
	  xmlhttplocal = false;
	}
  }

  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
	try {
	  var xmlhttplocal = new XMLHttpRequest ();
	}
	catch (e) {
	  var xmlhttplocal = false;
	}
  }
  return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var xvotesString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function update_states(htmlid,country,statevarname,cityvarname,homestatevarname,homecityvarname,id)
{
	if (xmlhttp) 
	{
		url = $thisurl + "/dm_states.php";
		var mycontent = "draw=small&htmlid=" + htmlid + "&country_code=" + country + "&statevarname=" + statevarname + "&cityvarname=" + cityvarname + "&homecityvarname=" + homecityvarname + "&homestatevarname=" + homestatevarname + "&id=" + id;

		target2 = document.getElementById (htmlid);
		target2.innerHTML = "<br>Loading, please wait....";

		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();

		if (mnmxmlhttp) 
		{
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type','application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");

			target1 = document.getElementById ('emailto-' + htmlid);

			mnmxmlhttp[htmlid].onreadystatechange = function () 
			{
				if (mnmxmlhttp[htmlid].readyState == 4) 
				{
				    var tempSpan = document.createElement("SPAN");
				    document.body.appendChild(tempSpan);

				    tempSpan.innerHTML = mnmxmlhttp[htmlid].responseText;

					xvotesString[htmlid] = document.getElementById("states").innerHTML;
					xvotesString['cities'] = document.getElementById("cities").innerHTML;

					if (xvotesString[htmlid].match (errormatch)) 
					{
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} 
					else 
					{
						target2 = document.getElementById (htmlid);
						target3 = document.getElementById ('city_options');

						target2.innerHTML = xvotesString[htmlid] + '<img src="/templates/tmpl_extreemb/images/icons/warn.gif" class="form_warn_icon" style="display: none;" onmousemove="moveFloatDesc(event)" onmouseout="hideFloatDesc()" />';
						target3.innerHTML = xvotesString['cities']  + '<img src="/templates/tmpl_extreemb/images/icons/warn.gif" class="form_warn_icon" style="display: none;" onmousemove="moveFloatDesc(event)" onmouseout="hideFloatDesc()" />';
					}
					document.body.removeChild(tempSpan);
				}
			}
		}
	}
}

function update_cities(htmlid, state,statevarname,cityvarname,homestatevarname,homecityvarname,id)
{
	if (xmlhttp) {
		url = $thisurl + "/dm_states.php";
		var country = document.getElementById("country_select")[document.getElementById("country_select").selectedIndex].value;
		var metros_only = document.getElementById("metros_only") ? document.getElementById("metros_only").value : "false";
		mycontent = "draw=small&htmlid=" + htmlid + "&country_code=" + country + "&state_code=" + state + "&metros_only=" + metros_only + "&cityvarname=" + cityvarname + "&statevarname=" + statevarname + "&homecityvarname=" + homecityvarname + "&homestatevarname=" + homestatevarname + "&id=" + id;
		target2 = document.getElementById ( htmlid);
		target2.innerHTML = "<br>Loading, please wait....";		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');
			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
				    var tempSpan = document.createElement("SPAN");
				    document.body.appendChild(tempSpan);

				    tempSpan.innerHTML = mnmxmlhttp[htmlid].responseText;
				    
					xvotesString[htmlid] = document.getElementById("states").innerHTML;			
					xvotesString['cities'] = document.getElementById("cities").innerHTML;			
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} else {
						target3 = document.getElementById ('city_options');
						target3.innerHTML = xvotesString['cities'] + '<img src="/templates/tmpl_extreemb/images/icons/warn.gif" class="form_warn_icon" style="display: none;" onmousemove="moveFloatDesc(event)" onmouseout="hideFloatDesc()" />';
					}
					document.body.removeChild(tempSpan);
				}
			}
		}
	}
}
function update_homestates(htmlid, homecountry,statevarname,cityvarname,homestatevarname,homecityvarname,id)
{
	if (xmlhttp) {
		url = $thisurl + "/dm_states.php";
		var mycontent = "draw=small&htmlid=" + htmlid + "&homecountry_code=" + homecountry + "&cityvarname=" + cityvarname + "&statevarname=" + statevarname + "&homecityvarname=" + homecityvarname + "&homestatevarname=" + homestatevarname + "&id=" + id;
		target2 = document.getElementById ( htmlid);
		target2.innerHTML = "<br>Loading, please wait....";		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');

			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
				    var tempSpan = document.createElement("SPAN");
				    document.body.appendChild(tempSpan);
				    tempSpan.innerHTML = mnmxmlhttp[htmlid].responseText;
				    
					xvotesString[htmlid] = document.getElementById("homestates").innerHTML;			
					xvotesString['homecities'] = document.getElementById("homecities").innerHTML;			
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} else {
						target2 = document.getElementById (htmlid);
						target3 = document.getElementById ('homecity_options');
						target2.innerHTML = xvotesString[htmlid] + '<img src="/templates/tmpl_extreemb/images/icons/warn.gif" class="form_warn_icon" style="display: none;" onmousemove="moveFloatDesc(event)" onmouseout="hideFloatDesc()" />';
						target3.innerHTML = xvotesString['homecities'] + '<img src="/templates/tmpl_extreemb/images/icons/warn.gif" class="form_warn_icon" style="display: none;" onmousemove="moveFloatDesc(event)" onmouseout="hideFloatDesc()" />';
					}
					document.body.removeChild(tempSpan);
				}
			}
		}
	}
}

function update_homecities(htmlid, homestate,statevarname,cityvarname,homestatevarname,homecityvarname,id)
{
	if (xmlhttp) {
		url = $thisurl + "/dm_states.php";
		var homecountry = document.getElementById("homecountry_select")[document.getElementById("homecountry_select").selectedIndex].value;
		var metros_only = document.getElementById("metros_only") ? document.getElementById("metros_only").value : "false";
		mycontent = "draw=small&htmlid=" + htmlid + "&homecountry_code=" + homecountry + "&homestate_code=" + homestate + "&metros_only=" + metros_only + "&cityvarname=" + cityvarname + "&statevarname=" + statevarname + "&homecityvarname=" + homecityvarname + "&homestatevarname=" + homestatevarname + "&id=" + id;
		target2 = document.getElementById ( htmlid);
		target2.innerHTML = "<br>Loading, please wait....";		
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');
			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
				    var tempSpan = document.createElement("SPAN");
				    document.body.appendChild(tempSpan);
				    tempSpan.innerHTML = mnmxmlhttp[htmlid].responseText;
				    
					xvotesString[htmlid] = document.getElementById("homestates").innerHTML;			
					xvotesString['homecities'] = document.getElementById("homecities").innerHTML;			
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);						
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];						
					} else {
						target3 = document.getElementById ('homecity_options');
						target3.innerHTML = xvotesString['homecities'] + '<img src="/templates/tmpl_extreemb/images/icons/warn.gif" class="form_warn_icon" style="display: none;" onmousemove="moveFloatDesc(event)" onmouseout="hideFloatDesc()" />';
					}
					document.body.removeChild(tempSpan);
				}
			}
		}
	}
}

