<!-- hide JS code
function validInput(myform)  // validate user input
{
   var form_name=myform.name; 
   var rgroup=myform.Seen;
         var msg="Please tell us if you have been seen at Upstate before by choosing Yes or No.:";  
         if (!validRadio(rgroup,msg))
           {
             rgroup[0].focus(); 
             return false;
           }       


   if (isBlank(myform.realname.value))    // first name valid?
     {
            alert("Please enter patient's name:");
            myform.realname.focus();
            return false;
     }

      var app_msg="For making an appointment, please enter either your phone number or your email address.";
      if (!validateEMailOrPhone(myform,app_msg)) // either name or Phone valid?
      {
        return false
      }


    var msg="Please select department/section:";
         if (!validateSelect(myform.DeptName,msg))  // Department  selected?
          {
           return false
          }


   if (isBlank(myform.Message.value))    // first name valid?
     {
            alert("Please enter your message:");
            myform.Message.focus();
            return false;
     }

   return true; 
}
function isBlank(testStr) // check if a field is blank
{
  
  if (testStr.length == 0)                     // nothing entered?
    return true
  for (var i = 0; i <= testStr.length-1; i++)  // all spaces?
    if (testStr.charAt(i) != " ")
      return false
  return true 
}


function isPhone(phone) // check if a field is blank
{
  
  if (!phone.match(/\d{3}-\d{3}-\d{4}/))                     // 123-456-7890
  {
     return false;
  }else{
     return true;
  } 
}

function validateSelect(item,msg) //check if a selection is valid, working properly
{
     if (item.selectedIndex==0) //check if only the first item on the list is selected which starts with "Select..."
          {
             alert(msg); 
             item.focus();
             return false; 
          }
     return true;   
}   

function validRadio(radiogroup,msg)
{
    var itemchecked=false;
    for (var j=0; j<radiogroup.length; j++){
            if (radiogroup[j].checked){
                itemchecked=true;
                break
            }
     }
     if(!itemchecked) { // if nothing is checked for Seen radio button
//      alert("Please choose an answer for "+el[i].name+".");
        alert(msg)   
        return false;
     }
     return true;
}

function validateEMailOrPhone(form,msg) // check if either email or phone field is valid 
  {
  if ((isBlank(form.email.value)&&isBlank(form.Phone.value)))                       // both email & phone blank?
    { 
      alert(msg)
      return false
    }
  else if (!isBlank(form.email.value)){ // check if email is in valid form
    var email=form.email.value
    var atsignPos = email.indexOf("@", 0)     // check for @
    if (atsignPos == -1)  
     {
     alert("Please enter a valid email address. A valid email address should be in the form of emailname@somewhere.com")
     return false
     }
    if (email.indexOf(".", atsignPos) == -1)  // check for . after @      
     {
     alert("Enter a valid email domain after the @, please!")
     return false
     }
    return true
  }
  return true
}

// for ajax
function createRequestObject(){
        var request_o; //declare the variable to hold the object.
        var browser = navigator.appName; //find the browser name
        if(browser == "Microsoft Internet Explorer"){
                /* Create the object using MSIE's method */
                request_o = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
                /* Create the object using other browser's method */
                request_o = new XMLHttpRequest();
        }
        return request_o; //return the object
}

/* You can get more specific with version information by using 
        parseInt(navigator.appVersion)
        Which will extract an integer value containing the version 
        of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 
/* Function called to get the expert list in question form */
function get_info(id){
        /* Create the request. The first argument to the open function is the method (POST/GET),
                and the second argument is the url... 
                document contains references to all items on the page
                We can reference document.form_category_select.select_category_select and we will               
                be referencing the dropdown list. The selectedIndex property will give us the 
                index of the selected item. 
        */
/*        alert("ID="+id);*/
        http.open('get', '/gch/providers/include/get_system.php?system_id=' + id);
        /* Define a function to call once a response has been received. This will be our
                handleProductCategories function that we define below. */
        http.onreadystatechange = handleSystemInfo; 
        /* Send the data. We use something other than null when we are sending using the POST
                method. */
        http.send(null);
}

/* Function called to handle the list that was returned from physician/qform.php file.. */
function handleSystemInfo(){
        /* Make sure that the transaction has finished. The XMLHttpRequest object 
                has a property called readyState with several states:
                0: Uninitialized
                1: Loading
                2: Loaded
                3: Interactive
                4: Finished */
        if(http.readyState == 4){ //Finished loading the response
                /* We have got the response from the server-side script,
                        let's see just what it was. using the responseText property of 
                        the XMLHttpRequest object. */
                var response = http.responseText;
                /* And now we want to change the product_categories <div> content.
                        we do this using an ability to get/change the content of a page element 
                        that we can find: innerHTML. */
                document.getElementById('info_block').innerHTML = response;
        }
}

sfHover = function() {
	var sfEls = document.getElementById("bodynav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
	sfEls = document.getElementById("nonbodynav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// end JS hide -->

