var ListingRow = function (actions, double_click, emp) {
	this.actions = actions;
	this.double_click = double_click;
	this.emp = emp;
}

ListingRow.prototype.buildJSString = function(js_code) {
	var temp = "";
	for(var k in this.emp) {
		if (typeof(this.emp[k])!="function") {
			temp = this.emp[k].replace("'", "\\'");
			js_code = js_code.replace(k, "'"+temp+"'");
		}
	}
	return js_code;
}

ListingRow.prototype.buildEMPString = function() {
	emp_str = "";
	amp = "";
	temp = "";
	for(var k in this.emp) {
		if (typeof(this.emp[k])!="function") {
			temp = this.emp[k].replace("'", "\\'");
			emp_str += amp+k+"="+temp;
			amp = "&";
		}
	}
	return emp_str
}

ListingRow.prototype.showRCM = function(x_loc, y_loc, prefix, adjust_rcm) {
	
	innerhtml = "<table cellpadding=0 cellspacing=0 border=0 class=right-click-menu>";
	onmouseover=" onMouseOver=\"this.className='right-click-menu-row-on'\" ";
	onmouseout=" onMouseOut=\"this.className='right-click-menu-row'\" ";
	list_actions = eval(prefix+"_actions");
	for(i=0; i<this.actions.length; i++) {
		if(list_actions[this.actions[i]].indexOf("javascript:") != -1) {
			click_action = this.buildJSString(list_actions[this.actions[i]].substr(11+list_actions[this.actions[i]].indexOf("javascript:")));
		}
		else {
			click_action = "window.location.href = '"+list_actions[this.actions[i]];
			emp_str = this.buildEMPString();
			if(emp_str.length > 0) {
				if(list_actions[this.actions[i]].indexOf("?") == -1)
					click_action += '?';
				else
					click_action += '&';
			}
			click_action+=emp_str+"'";
			
		}
		onclick=" onClick=\"document.getElementById('"+prefix+"_right_click_menu').style.visibility='hidden'; "+click_action+";\"";
		name_html = ((this.double_click==this.actions[i])?"<b>":"")+this.actions[i]+((this.double_click==this.actions[i])?"</b>":"");
		innerhtml += "<tr class=right-click-menu-row "+onmouseover+onclick+onmouseout+"><td nowrap>"+name_html+"</td></tr>";
	}
	for(var k in this.rcm) {
		if(typeof(this.rcm[k])!="string")	{		// Things like Mootools and EXTJS modify JS arrays
			continue;
		}
		
		if(this.rcm[k].indexOf("javascript:") != -1) {
			click_action = this.buildJSString(this.rcm[k].substr(11+this.rcm[k].indexOf("javascript:")));
		}
		else {
			click_action = "window.location.href = '"+this.rcm[k];
			emp_str = this.buildEMPString();
			if(emp_str.length > 0) {
				if(this.rcm[k].indexOf("?") == -1)
					click_action += '?';
				else
					click_action += '&';
			}
			click_action+=emp_str+"'";
			
		}
		onclick=" onClick=\"document.getElementById('"+prefix+"_right_click_menu').style.visibility='hidden'; "+click_action+";\"";
		innerhtml += "<tr class=right-click-menu-row "+onmouseover+onclick+onmouseout+"><td nowrap>"+k+"</td></tr>";
	}
	innerhtml += "</table>";
	rcm = document.getElementById(prefix+"_right_click_menu");
	
	// If Ext is being used, go ahead and use its positioning capabilities, as the old way seems to result in incorrect placement sometimes
	if(typeof(Ext)!="undefined" && Ext!=null)	{
		var el = Ext.get(rcm);
		el.setXY([x_loc, y_loc]);
	}
	else	{
		if (is_ie && adjust_rcm) {
			var new_elem = rcm.parentNode;
			while (typeof(new_elem)!="undefined" && new_elem) {
				if(new_elem.nodeName == 'DIV') { 
					y_loc -= new_elem.offsetTop;
				}
				new_elem = new_elem.parentNode;
			}
		}
		
		rcm.style.left=x_loc;
		rcm.style.top=y_loc;
	}
	
	rcm.innerHTML=innerhtml;
	rcm.style.zIndex = 1000;
	rcm.style.visibility="visible";
}

ListingRow.prototype.doubleClick = function(prefix) {
	if(this.double_click!=0&&this.double_click!='0')
		this.doAction(this.double_click, prefix);
}

ListingRow.prototype.doAction = function(act_name, prefix) {
	has_action = false;
	for(i=0; i<this.actions.length; i++) {
		if(this.actions[i] == act_name) {
			has_action = true;
			break;
		}
	}
	if(has_action) {
		list_actions = eval(prefix+"_actions");
		act = list_actions[act_name];
		if(act.indexOf("javascript:") != -1)
			click_action = this.buildJSString(act.substr(11+act.indexOf("javascript:")));
		else {
			click_action = "window.location.href = '"+act;
			emp_str = this.buildEMPString();
			if(emp_str.length > 0) {
				if(act.indexOf("?") == -1)
					click_action += '?';
				else
					click_action += '&';
			}
			click_action+=emp_str+"'";
			
		}
		
			//click_action = "window.location.href = '"+act+this.buildEMPString()+"'";
		eval(click_action);
	}
	else {
		alert("This action cannot be performed on this item.");
	}
}


