var pop = false; // to pop or not to pop
var focusOnPop = false;

function PopOff() { pop = false; }

window.onload = window_onload;
window.onunload = window_onunload;

function window_onload() {
	//document.getElementById("CcfForm").onsubmit = form_onsubmit;

	var args = getArgs();

	if (!args.popunder) {
		if (document.getElementById("txtFirstName")) { focusField(document.getElementById("txtFirstName"), focusOnPop); }
	}

	// No exit pop on any clicked links
	var anc = document.getElementsByTagName("a");
	for (i = 0; i < anc.length; i++) {
		if (anc.item(i).getAttribute("href")) anc.item(i).onclick = PopOff;
	}
}

function window_onunload() {
	if (pop) {
		popup = window.open("popups/NoTime/", "hppop", "width=400,height=650,left=20,top=20");
		if (window.focus) popup.focus();
	}
}

function form_onsubmit() {
	var b = document.getElementById("btnSubmit1");
	b.disabled = true;

	if (validateForm(this)) {
		PopOff();
		return true;
	}

	b.disabled = false;
	return false;
}

function OnFocus(elementId, defaultText) {
	if (document.getElementById(elementId).value == defaultText) {
		document.getElementById(elementId).className = "normal";
		document.getElementById(elementId).value = "";
	}
}

function OnBlur(elementId, defaultText) {
	var textValue = document.getElementById(elementId).value;

	if (textValue == defaultText || textValue.length == 0) {
		document.getElementById(elementId).className = "watermark";
		document.getElementById(elementId).value = defaultText;
	}
	else
		document.getElementById(elementId).className = "normal";
}

function getArgs() {
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for (var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0, pos);
		var value = pairs[i].substring(pos + 1);
		args[argname] = unescape(value);
	}
	return args;
}