function validateForContinueButton(what) { // validates radio buttons in scheduler and enables continue button
	// see if any radios are checked
	switch(what) {
		case 'select_service': // not used
		case 'select_staff': // not used
			var scheduler_wrapper=document.getElementById('scheduler');
			var inputs = scheduler_wrapper.getElementsByTagName("input");
			var continueOk=false;
			for(var a = 0; a < inputs.length; a++) {
				if (inputs[a].type=='radio' && inputs[a].checked==true) continueOk=true;
			}
			var continueButton=document.getElementById('scheduler_continue_button');
			continueButton.disabled=(continueOk?false:true);
			break;
		case 'cust_info':
			try {
				// continue button
				var split=requiredCustFields.split('|');
				var err=0;
				for(i = 0; i < split.length; i++){
					var eachField=document.getElementById(split[i]);
					if (eachField.value=='') err++;
				}
				var continueOk=(err>0?false:true);
				var continueButton=document.getElementById('scheduler_continue_button');
				continueButton.disabled=(continueOk?false:true);
				// sign in button
				var loginEmail=document.getElementById('login_email');
				var loginPswd=document.getElementById('login_pswd');
				var signinButton=document.getElementById('cust_login_button');
				signinButton.disabled=((loginEmail.value!='' && loginPswd.value!='')?false:true);
			} catch(e) {
			
			}
			break;
	}
}

function getPswd() { // validates 'forgot password' in scheduler
	var email=document.getElementById('login_email');
	if (email.value=='') {
		email.setAttribute('class', 'missing'); 
		alert('Please enter your email address and click this link again.');
	} else {
		document.getElementById('forgot_pswd').value=true;
		document.forms.signin_form.submit();
	}
}

function setStylizedRadios(where,value) {
	if (where=='date_filters') {
		var wrapper=top.frames['JobsFrame'].document.getElementById('date_wrapper');
	}
	var radios=wrapper.getElementsByTagName('input');
	var spans=wrapper.getElementsByTagName('span');
	var len = radios.length;
	for(i=0;i<len;i++) {
		if (radios[i].type=="radio") {
			if (radios[i].value==value) {
				radios[i].checked=true;
				spans[i].style.backgroundPosition='0px -50px';
			} else {
				radios[i].checked=false;
				spans[i].style.backgroundPosition='0px 0px';
			}
		}
	}
}

function checkForTOS() {
	var tos=document.getElementById('agree_tos').checked;
	if (tos) {
		document.forms.scheduler_form.submit();
	} else {
		var wrapper=document.getElementById('i_agree_wrapper');
		wrapper.style.border="2px solid red";
		wrapper.style.padding="5px";
		wrapper.style.backgroundColor="#FFDAB9";
		wrapper.style.color="#000000";
		wrapper.style.fontWeight="bold";
		alert('Please accept the Terms of Service by checking the checkbox.');
	}
}

function showAndCenterPopup(div,w,h,fromIframe) {
	//jumpTo('top',fromIframe);
	// hide any open popups
	hideAllDivsInContainer("editorOverlay",fromIframe);

	// show overlay
	var overlay = (fromIframe?parent.document.getElementById("editorOverlay"):document.getElementById("editorOverlay"));
	overlay.style.display = 'block';

	// show popup
	var popUp = (fromIframe?parent.document.getElementById(div):document.getElementById(div));
	var windowW=parent.getVisibleWidthHeight('w');
	var windowH=parent.getVisibleWidthHeight('h');
	//popUp.style.top = (windowH-h)/2 + "px";
	//popUp.style.left = (windowW-w)/2 + "px";
	popUp.style.width = w + "px";
	popUp.style.height = h + "px";
	popUp.style.visibility = "visible";
	popUp.style.marginLeft = "-" + w/2 + "px";
	popUp.style.marginTop = "-" + h/2 + "px";
}

function hideAllDivsInContainer(container,fromIframe) {
	// hide all divs in container
	var container_div;
	var location=(fromIframe?'top':'window');
	if (window.document.all) { // IE
		container_div = eval(location+".document.all." + container + "");
	} else if (document.layers) { // NN
		container_div = eval(location+".document.all." + container + "");
	} else if (!document.all && document.getElementById) { // MO
		container_div = eval(location+".document.getElementById('" + container + "')");
	} else if (navigator.userAgent.indexOf("Opera")!=-1&& document.getElementById) { // OP
		container_div = eval(location+".document.getElementById('" + container + "')");
	} else {
		alert("Your browser does not support this feature. Please upgrade to the latest browser version.");
		return;
	}

	var divList = container_div.getElementsByTagName("div");
	for(var a = 0; a < divList.length; a++) {
		divList[a].style.display = "none";
	}

}

function showPopup(which,redirect_to,primary_domain) {
	var popUpFrame = document.getElementById("PopupFrame");
	var w=400;
	var h=450;
	switch(which) {
		case 'create_account':
			popUpFrame.src="https://www."+primary_domain+"/create_account";
			w=600;
			h=450;
			popUpFrame.style.height='424px';
			break;
		case 'customer_support':
			popUpFrame.src="/customer_support";
			w=600;
			h=350;
			popUpFrame.style.height='324px';
			break;
		case 'empoyee_login':
			popUpFrame.src="https://www."+primary_domain+"/manage?from_popup=true&redirect_to="+redirect_to;
			w=320;
			h=220;
			popUpFrame.style.height='194px';
			break;
		case 'find_companies':
			popUpFrame.src="/find_companies";
			w=700;
			h=450;
			popUpFrame.style.height='424px';
			break;
		case 'my_account':
			popUpFrame.src="https://www."+primary_domain+"/myaccount?from_popup=true&redirect_to="+redirect_to;
			w=600;
			h=450;
			popUpFrame.style.height='424px';
			break;
		case 'privacy':
			popUpFrame.src="/privacy";
			w=600;
			h=450;
			popUpFrame.style.height='424px';
			break;
		case 'terms':
			popUpFrame.src="/terms";
			w=600;
			h=450;
			popUpFrame.style.height='424px';
			break;
		case 'affiliate':
			popUpFrame.src="/affiliate";
			w=600;
			h=450;
			popUpFrame.style.height='424px';
			//document.getElementById("header_popup").style.display='none';
			//document.getElementById("PopupFrame").style.height='450px';
			break;
	}
	showAndCenterPopup('div_popup',w,h,false);
}

function jumpTo(anchor,fromIframe) {
	var location=(fromIframe?'parent.':'');
	var anchorYPos=0;
	if (anchor!="top") {
		var theAnchor=document.getElementById(anchor);
		anchorYPos=getYPos(theAnchor)-10;
	}
	eval(location+"window.scroll(0,anchorYPos)");
}

function getYPos(obj) {
	var ypos = 0;
	if(obj.offsetParent) {
		while(1) {
			ypos += obj.offsetTop;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	} else if(obj.y) {
		ypos += obj.y;
	}
	return ypos;
}

function getVisibleWidthHeight(which) {//which=w or h; returns integer
	var result=0;
	var type=(which=='w'? 'Width' : 'Height' );
	if (typeof(window.innerHeight)=='number') { // all other browsers
		result=eval('window.inner'+type);
	} else if (document.documentElement&&document.documentElement.clientHeight) { // IE 6+
		result=eval('document.documentElement.client'+type);
	} else if (document.body&&document.body.clientHeight) { // IE 4+
		result=eval('document.body.client'+type);
	}
	return result;
}

function hidePopup(div) {
	// hides popup opened by showAndCenterPopup()
	var popUp = document.getElementById(div);
	popUp.style.visibility = "hidden";
	// hide overlay
	var overlay = document.getElementById("editorOverlay");
	overlay.style.display = 'none';
}

function closePopupAndRefresh(where) {
	parent.window.location='/'+where;
}

function closeWindow() {
	var popUpFrame = top.document.getElementById("PopupFrame");
	popUpFrame.src="/admin/popups/popup_blank.php";
	top.hidePopup('div_popup');
	window.close();
}

function hideWebPopup() {
	var popUpFrame = top.document.getElementById("PopupFrame");
	popUpFrame.src="/admin/popups/popup_blank.php";
	top.hidePopup('div_popup');
	//window.close();
}

function createAccount(primary_domain) {
	showPopup('create_account','',primary_domain);
	document.forms.start_new_acct_form.submit();
}

function locationMsg(val) {
	var msg='city,state OR address,city,state OR zip';
	var searchFld = document.getElementById("search_city_state");
	if (val==msg) {
		searchFld.value='';
		searchFld.setAttribute("class", "");
	} else if (val=='') {
		searchFld.value=msg;
		searchFld.setAttribute("class", "hint");
	} else {
		searchFld.setAttribute("class", "");
	}
}

function findCompanies(primary_domain) {
	// validate
	var location=document.getElementById('search_city_state').value;
	if (location=='' || location=='city,state OR address,city,state OR zip' ) {
		alert('Please enter a location.');
		return;
	}
	// submit
	showPopup('find_companies','',primary_domain);
	document.forms.find_companies_form.submit();
}

function toggleDiv(id,center) {
	var the_div;
	if (window.document.all) { // IE
		the_div = eval("window.document.all." + id + ".style");
	} else if (document.layers) { // NN
		the_div = eval("window.document.all." + id + "");
	} else if (!document.all && document.getElementById) { // MO
		the_div = eval("window.document.getElementById('" + id + "').style");
	} else if (navigator.userAgent.indexOf("Opera")!=-1&& document.getElementById) { // OP
		the_div = eval("window.document.getElementById('" + id + "').style");
	} else {
		alert("Your browser does not support this feature.");
		return;
	}

	if (the_div.display == "block") {
		the_div.display = "none";
	} else {
		if (center) {
			var w=document.getElementById(id).offsetWidth;
			var h=document.getElementById(id).offsetHeight;
			var windowW=this.getVisibleWidthHeight('w');
			var windowH=this.getVisibleWidthHeight('h');
			the_div.position = "fixed";
			the_div.top = (windowH-h)/2 + "px";
			the_div.left = (windowW-w)/2 + "px";
		}
		the_div.display = "block";
	}
}

function getRadioValue(radioObj) {
	for (var i=0;i<radioObj.length;i++) {
		if (radioObj[i].checked) return radioObj[i].value;
	}
	return '';
}
