var type = "IE";	//Variable used to hold the browser name

function testbr()
{

if (navigator.userAgent.indexOf("Opera")>=0)
	{
		 location.href="http://www.be-in-time.com/main_common/browser.html";
	}
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ))
	{
	 //var params = navigator.appVersion.split(";");
	 //var params1 = params[2].split(")");
	 //alert("Your browser:        " + navigator.appName + "\nBrowser version:   " + params[1] + "\nWindows version: " + params1[0] + "\n\n          Your system is ready to use \n WEB-BASED APPOINTMENT SCHEDULER");
	} 
else 
	{
	 if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 5 ))
		{
		 //alert("Your browser:        " + " Netscape / Mozilla" + "\nBrowser version:   " + "NN7+ or MO1.4+" +  "\n\n          Your system is ready to use \n WEB-BASED APPOINTMENT SCHEDULER");
	 	}
	 else
		 location.href="http://www.be-in-time.com/main_common/browser.html";
	}		
}

//detects the capabilities of the browser
function BrowserSniffer() {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";	//Opera
	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";													//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";						//Mozila e.g. Netscape 6 upwards
	else type = "IE";
      //alert( "type:" + type); 
}

// Check whether IE4 or later.
var MS = navigator.appVersion.indexOf("MSIE");
window.isIE4 = (MS > 0) &&
               (parseInt(navigator.appVersion.substring(MS + 5, MS + 6)) 
               >= 4);

function lead0(val) {
  // Add leading 0s when necessary.
  return (val < 10) ? "0" + val.toString() : val;
}

function buildTime() {
  var time = new Date();
  var ampm = "AM";
  var h = time.getHours();
  // Fix military time and determine ampm.
  if (h >=12) {
    ampm = " PM";
  }
  if (h >12) {
    h = h - 12;
  }

  return lead0(h) + ":" + lead0(time.getMinutes()) + ":" +
               lead0(time.getSeconds()) + " " + ampm;
  
}

function buildDayOfWeek() {
  var dw = new Date();
  var ddw = dw.getDay();
  if (ddw == 0) mm = "Sunday";
  if (ddw == 1) mm = "Monday";
  if (ddw == 2) mm = "Tuesday";
  if (ddw == 3) mm = "Wednesday";
  if (ddw == 4) mm = "Thursday";
  if (ddw == 5) mm = "Friday";
  if (ddw == 6) mm = "Saturday";

  return mm;
}

function buildDate() {
  var d = new Date();
  var dd = d.getDate();
  var mm = d.getMonth();
  if (mm == 0)  mm = "Jan";
  if (mm == 1)  mm = "Feb";
  if (mm == 2)  mm = "Mar";
  if (mm == 3)  mm = "Apr";
  if (mm == 4)  mm = "May";
  if (mm == 5)  mm = "Jun";
  if (mm == 6)  mm = "Jul";
  if (mm == 7)  mm = "Aug";
  if (mm == 8)  mm = "Sep";
  if (mm == 9)  mm = "Oct";
  if (mm == 10) mm = "Nov";
  if (mm == 11) mm = "Dec";
  var yy = d.getFullYear();

  return mm + " " + dd + ", " + yy;
}

// Puts the contents of buildTime into the layer id
// Works with all browsers except Opera
function tick2id(id) {
	if (type=="IE") {
		document.all[id].innerHTML = buildTime();
	}
	if (type=="NN") { 
		document.layers[id].document.open();
		document.layers[id].document.write(buildTime());
		document.layers[id].document.close();
	}
	if (type=="MO") {
		document.getElementById(id).innerHTML = buildTime();
	}
}

function mytick2id()
{
  // 'clock' is id of div tag representing html clock
  tick2id('clock')  
  setTimeout("mytick2id()", 999)
  return
}

// Puts the contents of buildTime into the text input element
// to avoid second oscillation in netscape div/span
// Works with all browsers except Opera
function tick2text() {
	if (type=="IE") {
                document.all.clock.value = buildTime();  
	}
	if (type=="NN") { 
                document.clock.visibility='show'
                document.clock.document.open();
                document.clock.document.write('<center>'+ buildTime() +'</center>');
                document.clock.document.close();
	}
	if (type=="MO") {
                document.getElementById("clock").value = buildTime();
	}
}

function mytick2text()
{
  tick2text()  
  setTimeout("mytick2text()", 999)
  return
}

// -----------------------------------------------

// these are functions of form fields validation

// -----------------------------------------------

function checkTextareaLength(formField, fieldLabel)
{
  var result = true;

  if(formField.value.length > 3000)
  {
     alert('Number of characters for the "' + fieldLabel +'" field exceeds max: 3,000');
     formField.focus();
     result = false;
  }

  return result;    
}

function validRequired(formField, fieldLabel)
{
  var result = true;
	
  if (formField.value == "")
  {
     alert('Please enter a value for the "' + fieldLabel +'" field');
     formField.focus();
     result = false;
  }
	
  return result;
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validEmail(formField,fieldLabel)
{
  var result = true;

  if (!validRequired(formField,fieldLabel))
     result = false;
	
  if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
  {
     alert("Please enter a complete email address in the form: yourname@yourdomain.com");
     formField.focus();
     result = false;
  }
   
  return result;
}

function allDigits(str)
{
  return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
  var result = true;

  // Note: doesn't use regular expressions to avoid early Mac browser bugs	
  for (var i=0;i<str.length;i++)
  if (charset.indexOf(str.substr(i,1))<0)
  {
    result = false;
    alert("Use only digits for Phone");
    break;
  }
	
  return result;
}
// -----------------------------------------------
