// JavaScript Document

function pcswat_HideSubMenus () {
  var subMenus=new Array ("hideSubMenusLayer","ourServicesMenuWrapper");
  for (i=0;i<subMenus.length;i++)
  {
    var obj, m=subMenus[i];
    if ((obj=MM_findObj(m))!=null) obj.style.visibility="hidden";
    if ((obj=MM_findObj(m+"Shadow"))!=null) obj.style.visibility="hidden";
  }
}

function pcswat_ShowSubMenu (m) {
  pcswat_HideSubMenus();
  var obj;
  if ((obj=MM_findObj(m))!=null) obj.style.visibility="visible";
  if ((obj=MM_findObj(m+"Shadow"))!=null) obj.style.visibility="visible";
  if ((obj=MM_findObj("hideSubMenusLayer"))!=null) obj.style.visibility="visible";
}

function pcswat_NoSpamEmail(obj)
{
  var username=obj.getAttribute("username");
  var domain=obj.getAttribute("domain");
  var s=username;
  s+=String.fromCharCode(64);
  s+=domain;
  obj.href="mailto:"+s;
}

function pcswat_Valid (input, type)
{
	switch (type) { case 'required': return (input.value != ''); break;	default: return true; }
}

function pcswat_ValidateForm(form)
{
	var errors = '';
	var autoSelect;
	for (var id in validation)
	{
		var label = validation[id][1];
		var requirements = validation[id][2];
		if (requirements.length > 0)
		{
			if (!pcswat_Valid (form.elements[id], requirements[0]))
			{
				errors += ('\n- ' + label + ': ' + requirements[0]);
				if ((!autoSelect) && (requirements[1] != ''))
				{
					autoSelect = form.elements[id];
					autoSelect.select();
				}
			}
		}
	}

	if (errors == '')
	{
		return confirm('You are about to submit the assessment form. Click OK to submit or CANCEL to return to the form.');
	}
	else
	{
		alert('Please fill in the following required fields\nbefore submitting this form:\n' + errors);
		return false;
	}
}

function pcswat_NumDaysInMonth(selectedMonth,selectedYear)
{
	var dateObj = new Date (selectedYear, selectedMonth-1, 1);
	var monthVar = dateObj.getMonth();
	var timeObj = dateObj.getTime() + 2332800000; // 28th day
	var nextMonth = false;
	var dayCount = 28;
	while (nextMonth != true)
	{
		timeObj += 86400000; // Add a day
		dateObj.setTime(timeObj);
		var newMonthVar = dateObj.getMonth();
		if (newMonthVar != monthVar)
		  nextMonth = true;
		else
		  dayCount++;
	}
	if (dayCount > 31)
	  dayCount = 31;
	return dayCount;
}

function pcswat_ForceHTTPS()
{
	var loc = document.location.toString();
	var index = loc.indexOf(":");
	var url = loc.substring(index,loc.length);
	if (index == "4")
	{
		var secureUrl = "https" + url;
		document.location.replace(secureUrl); // get rid of current page in history
		document.location.href = secureUrl;
	}
	return true;
}

function pcswat_ForceHTTP()
{
	var loc = document.location.toString();
	var index = loc.indexOf(":");
	var url = loc.substring(index,loc.length);
	if (index == "5")
	{
		var secureUrl = "http" + url;
		document.location.replace(secureUrl); // get rid of current page in history
		document.location.href = secureUrl;
	}
	return true;
}