

// required dojo actions

//dojo.require("dojo.parser");
dojo.require("dijit.Dialog");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.Button");

// dojo.parser.parse(dojo.byId("logondialog"));

function isLoggedIn() {
	var userName = "";
	var cookies;
	if (document.cookie) {
		cookies = document.cookie.split(";")
		// alert("cookies: " + cookies.length);
		for (i = 0; i < cookies.length; i++) {
			// alert("cookie " + i + ": " + cookies[i]);
			var keyValue = cookies[i].split("=");
			keyValue[0] = keyValue[0].replace(/^ +/, "");
			if (keyValue[0] == "mojousn" && cookies.length >= 1) {
				userName = keyValue[1];
			}
		}
	}
	// alert("userName: '" + userName + "'");
	
	if(userName) {
		return ((userName != "") && (userName != "undefined")) ? true : false;
	} else {
		return false;
	}
}

function getCookieValue(key) {
	var value = "";
	var cookies;
	if(document.cookie) {
		cookies = document.cookie.split(";")
		for (i = 0; i < cookies.length; i++) {
			// alert("cookie " + i + ": " + cookies[i]);
			var keyValue = cookies[i].split("=");
			keyValue[0] = keyValue[0].replace(/^ +/, "");
			if (keyValue[0] == key && keyValue.length >= 1) {
				value = keyValue[1];
			}
		}
	}
	return value;
}

function isEmployer() {
	if(isLoggedIn()) {
		return (getCookieValue("mojorole") == "member")? false : true;
	} else {
		return false;
	}
}

function createLogonDialog() {
	return new dijit.Dialog(
			  { title: "You must be logged in as an employer to access the rates", 
					content: "" +
"					<table border=\"0\" width=\"220\">" + 
"					<tbody>" + 
"						<tr>" + 
"							<td colspan=\"2\" align=\"center\">" + 
"								<center>" + 
"									<font color=\"green\" face=\"arial\">" + 
"										<b>Sign	in with your username and password to continue.</b>" + 
"									</font>" + 
"								</center>" + 
"								<br>" + 
"							</td>" + 
"						</tr>" + 
"						<tr>" + 
"							<td><label for=\"username\">Username: </label></td>" + 
"							<td><input dojoType=\"dijit.form.TextBox\" type=\"text\" name=\"username\" id=\"username\" /></td>" + 
"						</tr><tr>" + 
"							<td><label for=\"password\">Password: </label></td>" + 
"							<td><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"password\" id=\"password\" /></td>" + 
"						</tr><tr>" + 
"							<td colspan=\"2\" align=\"center\"><button dojoType=\"dijit.form.Button\" type=\"submit\">OK</button> </td>" + 
"						</tr>" + 
"						<tr>" + 
"							<td colspan=\"2\" align=\"center\">" + 
"								<center>" + 
"									<table border=\"0\" width=\"480\">" + 
"										<tbody>" + 
"											<tr>" + 
"												<td align=\"center\">" + 
"													<font face=\"Arial\" size=\"+1\"><b>Not	Registered?</b></font>" + 
"													<p>" + 
"														<b>" + 
"															<font face=\"arial\">" + 
"																<a href=\"http://www.localhelpwanted.net/charlotte/cgi-bin/Jobs.cgi?type=member&amp;action=register\"><font color=\"#0000ff\" size=\"2\">Sign up now</font></a>" + 
"																<font size=\"2\"> registration is <font color=\"#ff0000\">FREE</font>!</font>" + 
"															</font>" + 
"														</b>" + 
"													</p>" + 
"												</td>" + 
"											</tr>" + 
"										</tbody>" + 
"									</table>" + 
"								</center>" + 
"							</td>" + 
"						</tr>" + 
"						<tr>" + 
"							<td colspan=\"2\">Why the hassle just to look up the rates? The" + 
"							reason is simple. We screen our employers to ensure that we only" + 
"							offer real jobs from quality companies like yours. Our surveys" + 
"							show that Jobseekers visit our sites because your real job listing is not" + 
"							lost in a bunch of scam jobs.</td>" + 
"						</tr>" + 
"					</tbody>" + 
"				</table>", 
					"class": "lhw",
					execute: submitLogin
				  });

}

function loginRequired(url) {
	  if(!isEmployer()) {
		  // alert("youtube:" + document.getElementById("youtube").style.display);
		  document.getElementById("youtube").style.display = "none";
		  document.getElementById("target_uri").value = url;
		  dijit.byId('logondialog').onBlur = dialogClose;
		  dijit.byId('logondialog').show();
		  // var foo = createLogonDialog();
		  // dojo.body().appendChild(foo.domNode); foo.startup(); foo.show();
	  } else {
		  document.location.href = url;
	  }
}

function submitLogin(args) {
	// alert("args: " + args.username + " / " + args.password + "\nuri: " + args.target_uri);
	document.location.href = "http://www.localhelpwanted.net/charlotte/cgi-bin/Jobs.cgi?type=member&action=login&step=final&request_uri=" + escape(args.target_uri) + "&username=" + args.username + "&password=" + args.password + "&submit=submit";
}

function dialogClose() {
	document.getElementById("youtube").style.display = "block";
}
