var type = "IE";	//Variable used to hold the browser name

function testbr()
{
  if (navigator.userAgent.indexOf("Opera")>=0)
  {
    // location.href="http://www.book-appointment.com/browser.html";
    // alert ("Opera");
  }
  else 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.book-appointment.com/browser.html";
  }		
}

//-------------------------------------------------

//detects the capabilities of the browser
function BrowserSniffer() 
{
  //if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";
  if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="MO";	  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 getElById ( obj_id )
{
  var el;
 
  if (type=="IE") 
  {
    el = document.all[obj_id]; 
  }
  if (type=="NN") {}
  if (type=="MO") 
  {
    el = document.getElementById(obj_id);
  }
  
  return el;
}

//-------------------------------------------------

function getFrameElById ( frame, obj_id )
{
  var el;
 
  if (type=="IE") 
  {
    el = frame.document.all[obj_id]; 
  }
  if (type=="NN") {}
  if (type=="MO") 
  {
    el = frame.document.getElementById(obj_id);
  }
  
  return el;
}

//-------------------------------------------------

function getRbCheckedValue ( radioObjects )
{
  var radioLength  = radioObjects.length;

  var rbValue; 
  for( var i = 0; i < radioLength; i++) 
  {
    if( radioObjects[i].checked ) 
    {
      rbValue = radioObjects[i].value;
    }
  }

  return rbValue;
}

//-------------------------------------------------

function getSelectedObjectId ( label ) 
{
  var rc;
  var frame = parent.frames["main"];
  if ( frame == undefined )
  {
    rc = "frame_undefined";
  }
  else
  { 
    var radioObjects = getFrameElById ( frame, "object_radio" );
    //alert ( "radioObjects=" + radioObjects );
    if ( radioObjects == undefined )
    { 
      rc = "radio_objects_undefined";
    }
    else
    {
      var id = getRbCheckedValue ( radioObjects );
      //alert ( "id=" + id );
      if ( id == undefined )
      { 
        alert ( "Please select " + label );
        rc= "radio_object_not_selected";
      }
      else
      {
         rc = id;
      }
    }
  }

  return rc;

}

//-------------------------------------------------

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 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;
}


//-------------------------------------------------

function goBack()
{
   history.go(-1);
}

//-------------------------------------------------

function goStepBack ( step )
{
   history.go ( step );
}

//-------------------------------------------------

function initOptionImg ( selId, keyWord )
{
  //alert ( selId + "," + document.images.length ); 
  for ( var i = 0; i < document.images.length; i++ )
  {
    var strId = document.images[i].id;
    //alert ( "strId=" + strId );
     
    if ( strId != undefined )
    { 
      if ( strId == selId )
      {
        document.images[i].src= "../common/images/flag.jpg";  
      }
      else if ( strId.indexOf (keyWord) >= 0 )
      {
        document.images[i].src= "../common/images/point.gif"; 
      }
    } 
  }
}

//-------------------------------------------------

function htmlPopUp (url,objId) 
{
  newWindow = window.open ( url, 'name', 'height=300,width=350,resizable=1,scrollbars=1' );

  var htmlEl   = getElById ( objId );
  var codeHtml = htmlEl.value;
  //alert ( objId + "," + htmlEl + "," + codeHtml);

  var newDoc = newWindow.document;
  newDoc.write(codeHtml);
 
  if ( window.focus ) 
  {
    newWindow.focus();
  }

  return false;
}

//-------------------------------------------------

function appInfoPopUp ( url, first_name, last_name, phone, email,
                        service_title, app_start_time, app_duration, app_date ) 
{
  newWindow = window.open ( url, 'name', 'height=300,width=350,resizable=1,scrollbars=1' );

  var newDoc = newWindow.document;
  newDoc.write ( '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><link rel="stylesheet" type="text/css" href="../../book_appointment.css"><body><center><table width="250"  class="border_css" cellspacing="2" cellpadding="2"><tr><td height="30" colspan="2" align="center" class="menu">Appointment Information</td></tr>' );

  newDoc.write ( '<tr class="text"><td>First Name:</td><td>' + first_name + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>Last Name:</td><td>' + last_name + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>Phone:</td><td>' + phone + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>Email:</td><td><a href="mailto:' + email + '" class="text">' + email +'</a></td></tr>' );
  newDoc.write ( '<tr class="text"><td>Service:</td><td>' + service_title + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>App date:</td><td>' + app_date + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>App start time:</td><td>' + app_start_time + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>App duration:</td><td>' + app_duration + '</td></tr>' );

  newDoc.write ( '</table><br><input type="button" class="menu" value="Close" onClick="window.close()"></center></body></html>' );
 
  if ( window.focus ) 
  {
    newWindow.focus();
  }

  return false;
}

//-------------------------------------------------

function appReservedInfoPopUp ( url, app_start_time, app_duration, app_date ) 
{
  newWindow = window.open ( url, 'name', 'height=300,width=350,resizable=1,scrollbars=1' );

  var newDoc = newWindow.document;
  newDoc.write ( '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><link rel="stylesheet" type="text/css" href="../../book_appointment.css"><body><center><table width="250"  class="border_css" cellspacing="2" cellpadding="2"><tr><td height="30" colspan="2" align="center" class="menu">Reserved Appointment Information</td></tr>' );

  newDoc.write ( '<tr class="text"><td>App date:</td><td>' + app_date + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>App start time:</td><td>' + app_start_time + '</td></tr>' );
  newDoc.write ( '<tr class="text"><td>App duration:</td><td>' + app_duration + '</td></tr>' );

  newDoc.write ( '</table><br><input type="button" class="menu" value="Close" onClick="window.close()"></center></body></html>' );
 
  if ( window.focus ) 
  {
    newWindow.focus();
  }

  return false;
}

//-------------------------------------------------

function selectOptionByValue ( selectName, value ) 
{
  var selectObject = getElById ( selectName );
  //alert ( selectObject + ", selectObject.length=" + selectObject.length + ", value=" + value );
  for ( var i = 0; i < selectObject.length; i++ ) 
  {
    //alert ( selectObject.options[i].value + "," + value );
    if ( selectObject.options[i].value == value ) 
    {
      selectObject.options[i].selected = true;
      break;
    }
  }
}

//-------------------------------------------------

//
// Function State/Province definition for 
// registration form
//
//-------------------------------------------------

usaStates = new Array();
canadaStates = new Array();
defaultStates = new Array();
ii = 0;
jj = 0;
kk = 0;

//-----------------------------

usaStates[ii] = "_Select one";
ii++;  
usaStates[ii] = "AK_ALASKA";
ii++;
usaStates[ii] = "AL_ALABAMA";
ii++;
usaStates[ii] = "AR_ARKANSAS";
ii++;
usaStates[ii] = "AZ_ARIZONA";
ii++;
usaStates[ii] = "CA_CALIFORNIA";
ii++;
usaStates[ii] = "CO_COLORADO";
ii++;
usaStates[ii] = "CT_CONNECTICUT";
ii++;
usaStates[ii] = "DC_DISTRICT OF COLUMBIA";
ii++;
usaStates[ii] = "DE_DELAWARE";
ii++;
usaStates[ii] = "FL_FLORIDA";
ii++;
usaStates[ii] = "GA_GEORGIA";
ii++;
usaStates[ii] = "GU_GUAM";
ii++;
usaStates[ii] = "HI_HAWAII";
ii++;
usaStates[ii] = "IA_IOWA";
ii++;
usaStates[ii] = "ID_IDAHO";
ii++;
usaStates[ii] = "IL_ILLINOIS";
ii++;
usaStates[ii] = "IN_INDIANA";
ii++;
usaStates[ii] = "KS_KANSAS";
ii++;
usaStates[ii] = "KY_KENTUCKY";
ii++;
usaStates[ii] = "LA_LOUISIANA";
ii++;
usaStates[ii] = "MA_MASSACHUSETTS";
ii++;
usaStates[ii] = "MD_MARYLAND";
ii++;
usaStates[ii] = "ME_MAINE";
ii++;
usaStates[ii] = "MI_MICHIGAN";
ii++;
usaStates[ii] = "MN_MINNESOTA"
ii++;
usaStates[ii] = "MO_MISSOURI";
ii++;
usaStates[ii] = "MS_MISSISSIPPI";
ii++;
usaStates[ii] = "MT_MONTANA";
ii++;
usaStates[ii] = "NC_NORTH CAROLINA";
ii++;
usaStates[ii] = "ND_NORTH DAKOTA";
ii++;
usaStates[ii] = "NE_NEBRASKA";
ii++;
usaStates[ii] = "NH_NEW HAMPSHIRE";
ii++;
usaStates[ii] = "NJ_NEW JERSEY";
ii++;
usaStates[ii] = "NM_NEW MEXICO";
ii++;
usaStates[ii] = "NV_NEVADA";
ii++;
usaStates[ii] = "NY_NEW YORK";
ii++;
usaStates[ii] = "OH_OHIO";
ii++;
usaStates[ii] = "OK_OKLAHOMA";
ii++;
usaStates[ii] = "OR_OREGON";
ii++;
usaStates[ii] = "PA_PENNSYLVANIA";
ii++;
usaStates[ii] = "PR_PUERTO RICO";
ii++;
usaStates[ii] = "RI_RHODE ISLAND";
ii++;
usaStates[ii] = "SC_SOUTH CAROLINA";
ii++;
usaStates[ii] = "SD_SOUTH DAKOTA";
ii++;
usaStates[ii] = "TN_TENNESSEE";
ii++;
usaStates[ii] = "TX_TEXAS";
ii++;
usaStates[ii] = "UT_UTAH";
ii++;
usaStates[ii] = "VA_VIRGINIA";
ii++;
usaStates[ii] = "VI_VIRGIN ISLANDS";
ii++;
usaStates[ii] = "VT_VERMONT";
ii++;
usaStates[ii] = "WA_WASHINGTON";
ii++;
usaStates[ii] = "WI_WISCONSIN";
ii++;
usaStates[ii] = "WV_WEST VIRGINIA";
ii++;
usaStates[ii] = "WY_WYOMING";
ii++;

//-----------------------------

canadaStates[jj] = "_Select one";
jj++;
canadaStates[jj] = "ALB_ALBERTA";
jj++;
canadaStates[jj] = "BC_BRITISH COLUMBIA";
jj++;
canadaStates[jj] = "MAN_MANITOBA";
jj++;
canadaStates[jj] = "NBR_NEW BRUNSWICK";
jj++;
canadaStates[jj] = "NFL_NEWFOUNDLAND";
jj++;
canadaStates[jj] = "NOS_NOVA SCOTIA";
jj++;
canadaStates[jj] = "NU_NUNAVUT";
jj++;
canadaStates[jj] = "NWT_NORTHWEST TERRITORIES";
jj++;
canadaStates[jj] = "ONT_ONTARIO";
jj++;
canadaStates[jj] = "PEI_PRINCE EDWARD ISLAND";
jj++;
canadaStates[jj] = "QUE_QUEBEC";
jj++;
canadaStates[jj] = "SAS_SASKATCHEWAN";
jj++;
canadaStates[jj] = "YUK_YUKON";
jj++;

//-----------------------------

defaultStates[kk] = "N/A_N/A";
kk++;

//-----------------------------

function displayStates ()
{
  // - function cleans option_list old values from previous choice of country
  //   and creates dynamically option_list new values in accordance with
  //   current choice of country 

  // option1 is selected country name
  // vec is states array pointed to static states array for particular country
  // iteSize is size of states array
  // option_list is options array of states
  // opt_size is size of options array of states from previous choice of country

  var vec;
  var iteSize = 0;
  var option_list;
  var opt_size = 0;

  // get selected country name
  var country_choice = getElById ( "country" );
  var state_choice   = getElById ( "state" );
  var index   = country_choice.selectedIndex;
  var option1 = country_choice.options[index].value;

  // clean old options
  opt_size = state_choice.options.length;
  for ( j = 0; j < opt_size; j++ ) 
  {
    state_choice.options[0] = null;
  }
  // associate option_list with options of "state" select object of html form
  option_list = state_choice.options;

  // init states array
  if ( option1 == "USA" )
  {
    iteSize = ii;
    vec = usaStates;
  } 
  else if ( option1 == "Canada" )
  {
    iteSize = jj;
    vec = canadaStates;
  } 
  else 
  {
    iteSize = kk;
    vec = defaultStates;
  }
  // dynamically create new option_list from static states array: XX_StateName
  // XX prefix is used as option value
  // StateName is used as option name
  for ( i = 0; i < iteSize; i++ ) 
  {
    var params = vec[i].split("_");
    var option = new Option(params[1], params[0]);
    option_list[i] = option;
  }
}

function selectStates ( country, state )
{
  var vec;
  var iteSize  = 0;

  // init states array
  if ( country == "USA" )
  {
    iteSize = ii;
    vec = usaStates;
  }
  else if ( country == "Canada" )
  {
    iteSize = jj;
    vec = canadaStates;
  } 
  else
  {
    iteSize = kk;
    vec = defaultStates;
  }

  var state_choice   = getElById ( "state" );

  for ( i = 0; i < iteSize; i++ ) 
  {
    var params = vec[i].split("_");
    var option = new Option(params[1], params[0]);
    state_choice.options[i] = option;
    //alert ( params[0] + ", " + state )
    if ( params[0] == state )
    {
      state_choice.options[i].selected = true;
    }
  }
}

// ---------------------------------------------------------
//
// Form validation functions
//
// ---------------------------------------------------------
 
var userType = "Returning";

function setUserType ( type )
{
  //alert (type);
  userType = type;
}

//-------------------------------------------------

function validateAuthForm ( theForm )
{
  //alert ("validateAuthForm()");

  if ( userType == "Returning" )
  {
    return validateReturningUser ( theForm );    
  }
  if ( userType == "FirstTime" )
  {
    return validateFirstTimeUser ( theForm );
  }
  
  return false;
 
} 

//-------------------------------------------------

function validateReturningUser ( theForm )
{
  if ( !isNotEmpty ( theForm.ru_user_name, "User Name" ) )
       return false;
 
  if ( !isNotEmpty ( theForm.ru_password, "Password" ) )
       return false;    
 
  return true;
} 

//-------------------------------------------------

function validateFirstTimeUser ( theForm, skipParam )
{
  if ( !isNotEmpty ( theForm.user_name, "User Name") )
       return false;
  if ( !isAlphaNumeric ( theForm.user_name, "User Name" ) )
       return false;

  if ( !isNotEmpty ( theForm.password, "Password") )
       return false;
  if ( !isAlphaNumeric ( theForm.password, "Password" ) )
       return false;

  //alert ( theForm.email.style.display );
  if ( skipParam != "SKIP_NON_EMPTY_VALID" )
  { 
    //alert ( "Check non empty field validation" );
    if ( theForm.email.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.email, "Email") )
           return false;
    }
    if ( theForm.address.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.address, "Address") )
           return false;
    }
    if ( theForm.city.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.city, "City") )
           return false;
    }
    if ( theForm.zip_code.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.zip_code, "Zip Code") )
           return false;
    } 
    if ( theForm.country.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.country, "Country") )
           return false;
    } 
    if ( theForm.state.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.state, "State/Province") )
           return false;
    } 
    if ( theForm.phone.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.phone, "Phone") )
           return false;
    } 
    if ( theForm.cell.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.cell, "Cell") )
           return false;
    } 
    if ( theForm.birth_year.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.birth_year,  "Year of Birth") )
           return false;
      if ( !isNotEmpty ( theForm.birth_month, "Month of Birth") )
           return false;
      if ( !isNotEmpty ( theForm.birth_day, "Day of Birth") )
           return false;
    }
    if ( theForm.gender.style.display == "block" )
    { 
      if ( !isNotEmpty ( theForm.gender, "Gender") )
           return false;
    }  
  }

  //alert ("Before validateFirstTimeUser1()");
  if ( !validateFirstTimeUser1 ( theForm ) )
       return false;

  return true;
} 

//-------------------------------------------------

function validateFirstTimeUser1 ( theForm )
{
  if ( !isNotEmpty ( theForm.first_name, "First Name" ) )
       return false; 
  if ( !isValidName ( theForm.first_name, "First Name" ) )
       return false; 

  if ( !isNotEmpty ( theForm.last_name, "Last Name" ) )
       return false;
  if ( !isValidName ( theForm.last_name, "Last Name" ) )
       return false; 

  if ( !validEmail ( theForm.email, "Email Address") )
       return false;

  if ( !validPhone ( theForm.phone, "Phone Number") )
       return false;

  if ( !validPhone ( theForm.cell, "Cell Number") )
       return false;

  var bdEl   = getElById ( "birth_date" );
  bdEl.value = getBirthDate ();

  //alert ( bdEl.value );

  var tzEl = getElById ( "time_zone" );
  var si   = tzEl.selectedIndex;
  var so   = tzEl.options[si].value;
  //alert ( "tzEl.style.display=" + tzEl.style.display + ", tzEl.options[si].value=" + tzEl.options[si].value );
  
  if ( tzEl.style.display == "block" || tzEl.style.display == "" )
  {
    if ( so == "" )
    {
      alert ( 'Please select "Time Zone" field' );
      return false;
    }
  }

  return true;
} 

//-------------------------------------------------

function getBirthDate ()
{
  var byEl  = getElById ( "birth_year" );
  var bmEl  = getElById ( "birth_month" );
  var bdEl  = getElById ( "birth_day" );

  var index = byEl.selectedIndex;
  var year  = byEl.options[index].value;

  index = bmEl.selectedIndex;
  var month = bmEl.options[index].value;

  index = bdEl.selectedIndex;
  var day = bdEl.options[index].value;

  var bDate = year + "-" + month + "-" + day;

  return bDate;

}

//-------------------------------------------------

function isNotEmpty ( formField, fieldLabel )
{
  var result = true;

  if ( formField.value == "" )
  {
     alert ( 'Please enter a value for the "' + fieldLabel +'" field' );
     formField.focus();
     result = false;
  }
  else
  {
    var trimmed = trimStr ( formField.value );
    if ( trimmed.length == 0 )
    {
      alert ( 'Only blanks in 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 ( formField.value != "" && ((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 validDecimal ( formField, fieldLabel )
{
  var result = true;
  //alert ( formField + ", " + fieldLabel );
	 
  if ( formField != undefined && !inValidCharSet (formField.value,"0123456789.") )
  {
     alert("Please enter valid " + fieldLabel );
     formField.focus();
     result = false;
  }
   
  return result;
}

//-------------------------------------------------

function validPhone ( formField, fieldLabel )
{
  var result = true;
  //alert ( formField + ", " + fieldLabel );
	 
  if ( formField != undefined && !inValidCharSet (formField.value,"0123456789-") )
  {
     alert("Please enter valid " + fieldLabel );
     formField.focus();
     result = false;
  }
   
  return result;
}

//-------------------------------------------------
 
function allDigits ( str )
{
  //alert ("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++)
  {
    //alert (str.substr(i,1));
    if (charset.indexOf(str.substr(i,1))<0)
    {
      result = false;
      break;
    }
  }
	
  return result;
}

//-------------------------------------------------

function validTextAreaMaxLength ( formField, maxLength, fieldLabel )
{
  var result = true;
	
  if ( formField.value.length > maxLength )
  {
     alert ( 'Number of characters for the "' + fieldLabel +'" field exceeds max: ' + maxLength );

     formField.focus();
     result = false;
  }
	
  return result;
}
 
//-------------------------------------------------

function trimStr ( str )
{
  var trimmed = str.replace(/^\s+|\s+$/g, '');

  return trimmed;
}

//-------------------------------------------------
//
// Header menu functions
//
//-------------------------------------------------

function initMenu ( el, color )
{
  //alert("A=" + el.id);
  var row  = getElById ( "menu_tr" );
  var tds  = row.getElementsByTagName('td');
  var size = tds.length;
  //alert("size=" + size);
  for ( var i = 0; i < size; i++ )
  {
    //alert ( tds[i].style.borderBottom );
    tds[i].style.borderLeft   = "0px solid " + color;  
    tds[i].style.borderRight  = "0px solid " + color;  
    tds[i].style.borderTop    = "0px solid " + color; 
    tds[i].style.borderBottom = "2px solid " + color; 
  }

  el.style.borderLeft   = "2px solid " + color;  
  el.style.borderRight  = "2px solid " + color;  
  el.style.borderTop    = "2px solid " + color; 
  el.style.borderBottom = "0px solid " + color;  
}

//-------------------------------------------------

function setStartPos ( obj_id )
{
  var el = getElById ( obj_id );

  el.style.left = -320;
}

//-------------------------------------------------
 
function move ( obj_id, coord )
{
  var i;
  var j;
  var function_call;

  var el = getElById ( obj_id );
         
  //alert(el.innerHTML + parseInt(el.style.left));
  j = parseInt ( el.style.left );
  if ( j == -180 )
  {  
    j = j + 180;
  } 
  //alert("j=" + j);
 
  i = ( coord - j );
  //alert("i=" + i);
  if ( i <= 25 ) 
  {
    el.style.left = coord;
    return 0;
  }
 
  el.style.left = parseInt ( el.style.left ) + parseInt ( i/2 );
  //alert(el.innerHTML + parseInt(el.style.left));
 
  function_call = "move('" + obj_id + "'," + coord + ")";
  setTimeout ( function_call, 50 );
 
}	  

//-------------------------------------------------

function showObject ( show, name )
{
  //alert("showObject()"); 
 
  var object = getElById ( name );
  if ( show == "yes" )
  {
    object.style.display = "block";
  }
  else
  {
    object.style.display = "none";
  }
 
  //return true;
}

//-------------------------------------------------

function requestPriceCalculation ( url, month_payment, year_payment,
                                   locations_number, staff_number, action, homeUrl )
{
 
  newWindow = window.open ( url, 'name', 'height=350,width=400,resizable=1,scrollbars=1' );
 
  var newDoc = newWindow.document;
  newDoc.write ( '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><link rel="stylesheet" type="text/css" href="' + homeUrl + '/book_appointment.css"><body><center><table width="350"  class="border_css" cellspacing="2" cellpadding="2"><tr><td height="30" colspan="2" align="center" class="menu">WWW.book-appointment.com Service<br> Price Calculation</td></tr>' );
 
  newDoc.write ( '<tr><td height="10" colspan="2"></td></tr><tr><td colspan="2" class="text" align="center"><font class="warning_text">*</font> Indicates a required field</td></tr><tr><td colspan="2" height="10"></td></tr>' );
 
  newDoc.write ( '<form name="requestPrice" method="post" action="' + action + '">' );
 
  newDoc.write ( '<tr class="text"><td>Locations Number: <font class="warning_text">*</font></td><td><input type="text" name="locations_number" size="20" maxlength="20" value="' + locations_number +'"></td></tr>' );
 
  newDoc.write ( '<tr class="text"><td>Staff Member Number: <font class="warning_text">*</font></td><td><input type="text" name="staff_number" size="20" maxlength="20" value="' + staff_number + '"></td></tr>' );

  newDoc.write ( '<tr class="text"><td>Calculated Monthly Price:</td><td>' + month_payment + '</td></tr>' );

  newDoc.write ( '<tr class="text"><td>Calculated Annual Price:</td><td>' + year_payment + '</td></tr>' );
 
  newDoc.write ( '<tr class="text"><td height="40" colspan="2" align="center"><input type="submit" value="Submit" class="menu"></td></tr>' );
 
  newDoc.write ( '</form></table><br><br><br><input type="button" class="menu" value="Close Window" onClick="window.close()"></center></body></html>' );
 
  if ( window.focus ) 
  {
    newWindow.focus();
  }
 
  return false;
 
}

//-------------------------------------------------

function htmlValidatorHelp ( url, fieldName, homeUrl )
{
  //alert ("htmlValidatorHelp");

  var newWindow = window.open ( url, 'name', 'height=540,width=400,resizable=1,scrollbars=1' );
  var newDoc = newWindow.document;
  newDoc.write ( '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><link rel="stylesheet" type="text/css" href="' + homeUrl + '/book_appointment.css"><body><center><table width="300"  class="border_css" cellspacing="2" cellpadding="2"><tr><td height="30" align="center" class="menu">Help Corner</td></tr>' );
 
  newDoc.write ( '<tr><td height="10"></td></tr><tr><td align="center" class="text">You have 2 format options to fill the field<br><font class="warning_text"> "' + fieldName +'"</font></td></tr><tr><td height="10"></td></tr>' );
 
  newDoc.write ( '<tr><td class="text"><li>Use the regular text description</li></td></tr>' );
  newDoc.write ( '<tr><td class="text"><li>Use the html format</li></td></tr><tr><td height="10"></td></tr>' );
  newDoc.write ( '<tr><td class="text">We validate your html code. Please be sure:</td></tr><tr><td height="10"></td></tr>' );
  newDoc.write ( '<tr><td class="text">1. All opened html tags should be closed</td></tr>' );
  newDoc.write ( '<tr><td class="text">Examples:<br>&lt;table&gt;&lt;/table&gt;<br>&lt;img&gt;&lt;/img&gt; or &lt;img/&gt;<br>&#60;br&gt;&lt;/br&gt; or &lt;br/&gt;</td></tr><tr><td height="10"></td></tr>' );
  newDoc.write ( '<tr><td class="text">2. The following tags should be excluded from your code:</td></tr>' );
  newDoc.write ( '<tr><td class="text">&lt;iframe&gt;<br>&lt;frame&gt;<br>&lt;script&gt;</td></tr><tr><td height="10"></td></tr>' );
  newDoc.write ( '<tr><td class="text">3. Single quotes should be excluded from your code</td></tr><tr><td height="10"></td></tr>' );

  newDoc.write ( '<tr><td class="text">4. Value of parameter should be taken into the double quotes</td></tr>' );
  newDoc.write ( '<tr><td class="text">Example:<br>width="100%"<br>border="1"</td></tr><tr><td height="10"></td></tr>' );
  
  newDoc.write ( '</table><br><br><br><input type="button" class="menu" value="Close Window" onClick="window.close()"></center></body></html>' );
 
 

  if ( window.focus ) 
  {
    newWindow.focus();
  }
 
  return false;
 
}

//-------------------------------------------------

function userTypeHelp ( url )
{
  //alert ("userTypeHelp");

  var newWindow = window.open ( url, 'name', 'height=780,width=780,resizable=1,scrollbars=1' );
  var newDoc = newWindow.document;
  newDoc.write ( '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Book Appointment</title><link rel="stylesheet" type="text/css" href="../../book_appointment.css"></head><body class="body_css"><center><table width="700" class="border_css" cellspacing="0" cellpadding="0"><tr><td height="25" class="menu" align="center">Help Corner</td></tr><tr><td height="15"></td></tr><tr><td class="title" align="center">User Access Type Description</td></tr><tr><td height="15" ></td></tr><tr><td align="center"><table width="700" border="1" bordercolor="#ffffff" cellspacing="0" cellpadding="2"><tr><td width="20%" class="title">&nbsp;</td><td width="20%" class="title" align="center">Headquaters Admin</td><td width="20%" class="title" align="center">Location Admin</td><td width="20%" class="title" align="center">Staff Member</td><td width="20%" class="title" align="center">View Appointments Only User</td></tr><tr><td class="title" valign="top">Appointments</td><td class="text" valign="top"><li>All locations are visible</li><li>All staff members are visible</li><li>User can Add/Read/Update/Delete appointments</li></td><td class="text" valign="top"><li>Locations associated with user are visible</li><li>All staff members associated with user locations are visible</li><li>User can Add/Read/Update/Delete appointments</li></td><td class="text" valign="top"><li>Locations associated with user are visible</li><li>User himself is visible</li><li>User can Add/Read/Update/Delete appointments</li></td><td class="text" valign="top"><li>Locations associated with user are visible</li><li>User himself is visible</li><li>User can Read appointments</li><li>User can Update appointment status</li></td></tr><tr><td class="title" valign="top">Office</td><td class="text" valign="top"><li>User has full access and permissions</li></td><td class="text" valign="top"><li>User can Read/Update his locations</li><li>All staff members associated with user locations are visible except Head Office Admin</li><li>User can Add/Read/Update/Delete staff members, their working hours and reserved days</li><li>Services button is disable</li><li>Settings button is disable</li><li>Payment button is disable</li></td><td class="text" valign="top"><li>Office tab is disable</li></td><td class="text" valign="top"><li>Office tab is disable</li></td></tr><tr><td class="title" valign="top">Clients</td><td class="text" valign="top"><li>User has full access and permissions</li></td><td class="text" valign="top"><li>User has full access and permissions</li></td><td class="text" valign="top"><li>User has full access and permissions</li></td><td class="text" valign="top"><li>User can Read clients and their appointments and meetings</li></td></tr><tr><td class="title" valign="top">Client View</td><td class="text" valign="top"><li>User has full access and permissions</li></td><td class="text" valign="top"><li>Client View tab is disable</li></td><td class="text" valign="top"><li>Client View tab is disable</li></td><td class="text" valign="top"><li>Client View tab is disable</li></td></tr><tr><td class="title" valign="top">Reports</td><td class="text" valign="top"><li>All locations are visible</li><li>User can create report for all staff members</li></td><td class="text" valign="top"><li>Locations associated with user are visible</li><li>User can create report for all staff members associated with user locations</li></td><td class="text" valign="top"><li>Locations associated with user are visible</li><li>User can create his own report only</li></td><td class="text" valign="top"><li>Locations associated with user are visible</li><li>User can create his own report only</li></td></tr><tr><td class="title" valign="top">Meetings</td><td class="text" valign="top"><li>All locations are visible</li><li>All staff members are visible</li><li>User can Add/Read/Update/Delete meetings</li><li>User can Add/Read/Update/Delete meeting categories</li><li>User can Subscribe/Update meeting clients</li></td><td class="text" valign="top"><li>Locations associated with user are visible</li><li>User can Add/Read/Update/Delete meetings</li><li>User can Add/Read/Update/Delete meeting categories</li><li>User can Subscribe/Update meeting clients</li></td><td class="text" valign="top"><li>User can Read meetings associated with user location</li><li>User can Read meeting categories</li><li>User can Subscribe/Update meeting clients</li></td><td class="text" valign="top"><li>User can Read meetings associated with user location</li><li>User can Read meeting categories</li><li>User can Read clients subscribed to meeting</li></td></tr></table></td> </tr><tr><td height="15" ></td></tr></table><br><br><input type="button" class="menu" value="Close Window" onClick="window.close()"><br><br></center></body></html>');

  if ( window.focus ) 
  {
    newWindow.focus();
  }
 
  return false;
 
}

//-------------------------------------------------

function isUrl ( s ) 
{
  var regexp = /[hH][tT][tT][pP]:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2,3}$/;
  //alert ( regexp.test(s) );
  return regexp.test ( s );

}

//-------------------------------------------------

function isValidName ( formField, fieldLabel )
{
  //alert ("isValidName");
  var result = true;

  formField.value = trimStr ( formField.value );

  var regexp = /^([A-Za-z-]+)$/;

  if ( !regexp.test ( formField.value ) )
  {
     alert ( 'Please use letters for the "' + fieldLabel +'" field' );
     formField.focus();
     result = false;
  }
	
  return result;
}

//-------------------------------------------------

function isAlphaNumeric ( formField, fieldLabel )
{
  //alert ("isAlphaNumeric");
  var result = true;

  var regexp = /^([a-zA-Z0-9_-]+)$/;

  if ( !regexp.test ( formField.value ) )
  {
     alert ( 'Please use letters and numbers for the "' + fieldLabel +'" field' );
     formField.focus();
     result = false;
  }
	
  return result;
}

//-------------------------------------------------

function isNotSpecialChars ( formField, fieldLabel )
{
  //alert ("isNotSpecialChars");
  var result = true;

  var regexp = /^([\s\/\.,:a-zA-Z0-9_-]*)$/;

  if ( !regexp.test ( formField.value ) )
  {
     alert ( 'Please do not use special chars for the "' + fieldLabel +'" field' );
     formField.focus();
     result = false;
  }
	
  return result;
}

//-------------------------------------------------

function printWindow ( url, height, width )
{
  var params = "height=" + height + ",width=" + width + ",resizable=1,scrollbars=1,menubar=no,location=no, toolbar=yes,status=no";
  var newWindow = window.open ( url, 'name', params );

  if ( window.focus ) 
  {
    newWindow.focus();
  }
 
  return false;
 
}

//-------------------------------------------------

function timeZoneHelp ( url )
{
  //alert ("timeZoneHelp");

  var newWindow = window.open ( url, 'name', 'height=400,width=400,resizable=1,scrollbars=1' );
  var newDoc = newWindow.document;
  newDoc.write ( '<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><link rel="stylesheet" type="text/css" href="../../book_appointment.css"><body><center><table width="300"  class="border_css" cellspacing="2" cellpadding="2"><tr><td height="30" align="center" class="menu">Help Corner</td></tr>' );
 
  newDoc.write ( '<tr><td class="text">"Time Zone" option allows your clients to see your office current time.</td></tr>' );
  
  newDoc.write ( '<tr><td class="text">If you have world wide clients please set up the following options to allow your clients to see office hours and appointment time in their local time:</td></tr>' );

  newDoc.write ( '<tr><td class="text"><li>Select your office time zone on Office/Location page</li></td></tr>' );
  newDoc.write ( '<tr><td class="text"><li>Add time zone field to client registration form on Client/Settings page</li></td></tr>' );
  newDoc.write ( '<tr><td class="text"><li>Set Client Authentication to “yes” on Client/Settings page</li></td></tr>' );

  newDoc.write ( '</table><br><br><br><input type="button" class="menu" value="Close Window" onClick="window.close()"></center></body></html>' );
 
  if ( window.focus ) 
  {
    newWindow.focus();
  }
 
  return false;
 
}

//-------------------------------------------------

var newW=null;
var img=null;
var aw=null;
var ah=null;
function OpenImgWindow(imageName,alt,posLeft,posTop,aw,ah) 
{
  img=new Image()
  img.src=imageName
 
  if (aw == null)
    w=img.width + 10;
  else
    w=aw + 10; 
 
  if (ah == null)
    h=img.height + 55;
  else
    h=ah + 55;
 
  if (posLeft == null)
    posLeft=200
  if (posTop == null)
    posTop=100
  if(newW != null) 
    if(!newW.closed) 
      newW.close()
  newW= window.open("","newW","width="+w+",height="+h+",left="+posLeft+",top="+posTop)
  newW.document.open()
  newW.document.writeln('<html><title>'+alt+'</title><body bgcolor="#E1E5F0" leftmargin="5" topmargin="5" marginheight="5" marginwidth="5"><center>') 
  newW.document.writeln('<img src='+imageName+' alt='+alt+'>') //' width='+w+' height='+h+
  newW.document.writeln('<br><a href="' + 'javascript:window.close()"' + '><font face="Verdana, Arial" size="1" color="#000000">Close window</font></a>' )
  newW.document.write('</center></body></html>')
  newW.document.close()
  img=null
  newW.focus()

}

//-------------------------------------------------

