function getRegionUrl () {
	
	pathArray = window.location.pathname.split( '/' );
	if (pathArray.length >= 3) {
		return '/' + pathArray[1] + '/' + pathArray[2];
	}
	else {
		return '';
	}
	
	
}

/* 1 = add, 0 = remove */

function add_to_notepad (tradesmenID, extra) {
	regionUrl = getRegionUrl ();
	
	$("#mini-notepad-contents").load(
		regionUrl+'/ajax/notepad.php', 
		{'tradesmenID': tradesmenID, action: 1}, 
		change_notepad_action(tradesmenID, 1, extra)
	);

}

function remove_from_notepad (tradesmenID, extra) {
	
	regionUrl = getRegionUrl ();
	
	$("#mini-notepad-contents").load(
		regionUrl+'/ajax/notepad.php', 
		{'tradesmenID': tradesmenID, action: 0}, 
		change_notepad_action(tradesmenID, 0, extra)
	);
}

function remove_from_notepad_entire (tradesmenID, extra) {
	
	regionUrl = getRegionUrl ();
	
	$("#mini-notepad-contents").load(
		regionUrl+'/ajax/notepad.php', 
		{'tradesmenID': tradesmenID, action: 0}, 
		do_remove_from_notepad(tradesmenID, 1, extra)
	);
}

function change_notepad_action (tradesmenID, changeAction, extra) {
    
    extraStr = extra?(",\""+extra+"\""):"";
    if(!extra) extra = '';

	linkContainer = document.getElementById("no"+tradesmenID);

	if (changeAction == 1) {
		linkContainer.removeAttribute("class");
		linkContainer.setAttribute("class", "notepad-option-remove"+extra);
		linkContainer.setAttribute("className", "notepad-option-remove"+extra);
		linkContainer.innerHTML = "<strong style=\"color: green;\">Saved to notepad</strong><br /> <span class=\"small\"> <a href=\""+regionUrl+"/notepad.php\">View notepad</a> | <a href='javascript:remove_from_notepad("+tradesmenID+extraStr+")'>Remove</a></span>";
	}
	else if (changeAction == 0){
		linkContainer.removeAttribute("class");
		linkContainer.setAttribute("class", "notepad-option-add"+extra);
		linkContainer.setAttribute("className", "notepad-option-add"+extra);
		linkContainer.innerHTML = "<span>Removed from notepad</span><br /> <span class=\"small\"><a href='javascript:add_to_notepad("+tradesmenID+extraStr+")'>Save to notepad</a></span>";
	}

}

function do_remove_from_notepad (tradesmenID, cycle) {

	notepaditemcontainer = document.getElementById("n"+tradesmenID);
	
	if (cycle == 1) {
		notepaditemcontainer.innerHTML = "<strong style=\"color: green;\">Removed from notepad</strong>";
		setTimeout("do_remove_from_notepad("+tradesmenID+",2)",1808);
	}
	else {
		var notepad = document.getElementById('notepadcontainer');
  		notepad.removeChild(notepaditemcontainer);
	}

}