	function getStarted(form){
		 document.getStartedForm.submit();
	}

	function addStates(form){
		 document.form.submit();
	}

	function checkAll( id, pID ) {
		   $( "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked'));
	}

var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){ return; }
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1); },DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c); }, 0);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1); },DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1); },DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  if (d < 1) {
	  c.style.height = currh + (dist * d) + 'px'; 
	  c.style.opacity = 0;
	  c.style.filter = 'alpha(opacity=0)';
  } else {
	  c.style.height = currh + (dist * d) + 'px'; 
	  c.style.opacity = currh / c.maxh;
	  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  }

  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

function selectAllChkBox(source) {
	  checkboxes = document.getElementsByName('market');
	  for(var i in checkboxes)
	    checkboxes[i].checked = source.checked;
	}

function SetAllCheckBoxes(FormName, FieldName, CheckValue) {
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	
		el.style.display = 'block';
	}
	else {
		el.style.display = 'none';
		}
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}

function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);	
}

function setStateInfoRetrievalPause(state_name) {
	alert("setStateInfoRetrievalPause().state: " + state_name);
	runImg = new Image();
	runImg.src = "../images/ajax-loader.gif";
//	document.getElementById("retrievalMessageBox").innerHTML = "Retrieving Listings ...";
//	document.getElementById("retrievingImg").height = 16;
//	document.getElementById("retrievingImg").width = 16;
//	document.getElementById("retrievingImg").src = runImg.src;
}


function getStateInfoById(state_id) {
	alert("getStateInfoById().state_id: " + state_id);
	url = "/franinfo/portal/ajax/state";
	query = "state_id=" + encodeURIComponent(state_id);
	ajax = new AJAXInteraction(url, query, retrieveStateInfoCallback);
	setTimeout(function(){ajax.doGet();}, 1000);
	return true;
}

function newgetStateInfoById(state_id) {
	alert("getStateInfoById().state_id: " + state_id);
	asynchGet("/franinfo/portal/ajax/state?state_id=" + encodeURIComponent(state_id));
	return true;
}



function retrieveStateInfoCallback(responseXML) {
	alert("retrieveStateInfoCallback().responseXML: " + responseXML);

	status = responseXML.getElementsByTagName("status");
	alert("responseXML.status: " + status);

	if ( success == "true") {
		alert("bueno ...");
//		var state_name = responseXML.getElementsByTagName("state_name");
//		document.getElementById("stateName").innerHTML = state_name;
//		document.getElementById("stateName").style = "stateName";
//		retrievalString = "<p><input type='checkbox' name='market' id='market0' value='0' />&nbsp;&nbsp;Birmingham</p>";
//		document.getElementById("chkBox").innerHTML = retrievalString;
	} else {
		alert("no bueno ... ");
	}
}

var portletReq;

function asynchGet(updateURL){
    if (window.XMLHttpRequest) {
        portletReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        portletReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    portletReq.onreadystatechange = processReqChange;
    portletReq.open("GET", updateURL, true);
    portletReq.send(null);
}

function processReqChange() {
    if (portletReq.readyState == 4) {
    	alert("caca ..." + portletReq.responseText);
        if (portletReq.status == 200) {
        	alert("bueno ..." + portletReq.responseText);
        }
    }
}

function AJAXInteraction(url, query, callback) {
	var req = init();
	var n = query.length;
	
	req.onreadystatechange = function() { processRequest(req); };

	function init() {
		var httpRequest = null;
		if (window.XMLHttpRequest) {
				httpRequest = new XMLHttpRequest();
			if (httpRequest.overrideMimeType) {
				httpRequest.overrideMimeType('text/xml');
			}
			} else if (window.ActiveXObject) {
				try {
					httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
				try {
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) { }
			}
		}
		if (!httpRequest) {
			return false;
		} else {
			return httpRequest;
		}
	}

	function processRequest () {
		try {
			if (req.readyState == 4) {
				if (req.status == 200) {
					alert('to Callback');
					alert(req.responseText);
					callback(req.responseText);
				} else {
					alert('There is a issue with the request: ' + req.status);
				}
			}
		} catch(e) {
			alert('ProcessRequest Caught Exception: ' +  e.description);
		}
	}

	this.doChklstValidate = function() {
		req.open("POST", url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.setRequestHeader('Content-length', n);
		req.setRequestHeader('Connection', 'close');
		req.send(query);
	};

	this.doGet = function() {
		url = url + "?" + query;
		alert("AJAXInteraction().URL: " + url);
		req.open("GET", url, true);
		req.send(null);
	};

	this.doPost = function() {
		req.open('POST', url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.setRequestHeader('Content-length', n);
		req.setRequestHeader('Connection', 'close');
		req.send(query);
	};
}

