/*
* Define our DIVs
*/
var statediv = "StateDiv";
var citydiv = "CityDiv";
var cityid = "";
var statename = "";
/* 
* Setup prototypes
*/
WPgrab.prototype.grab = WPgrab;
WPgrab.prototype.process = wpprocess;
WPgrab.prototype.cat = "state"; // city or state
WPgrab.prototype.statediv = statediv;
WPgrab.prototype.citydiv = citydiv;

/*
* Empty constructor
*/
function WPgrab() {}

/*
* Process request
* @params category (optional) stateid (required if city request)
*/
function wpprocess(category,stateid,cityid,statename)
{
	var cat = "";
	if(!category || category == "") {
		cat = this.cat;
	} else {
		cat = category;
	}
		
	if(this.citydiv == "" || this.statediv == "") {
		alert("Please set your DIVS!");
		return false;
	}
	
	if(document.getElementById(this.statediv) == "undefined") {
		alert("Check your DIV");
		return false;
	}
	if(document.getElementById(this.citydiv) == "undefined") {
		alert("Check your DIV");
		return false;
	}

	var div = this.statediv;
	if(cat == 'city') div = this.citydiv;

	requestUri = "cat="+cat+"&stid="+stateid+"&statediv="+this.statediv+"&citydiv="+this.citydiv+"&cityid="+cityid+"&statename="+statename;
	$("#"+div).load("/wp-content/plugins/dropdowns/wpGrab.php?"+requestUri);
}
