function handleValidation (s, e) {
		e.IsValid = checkFormat(s.regex,e.Value)
		//alert('returning true')
		//e.IsValid = true
}

var dateObj = "";
function setDateObj(dateInput){
	dateObj = dateInput;
}
function clearDateObj() {
  //in case user re-enters the same text twice (no onChange, so no new validation),
  //always re-format first, if we have a dateObj
  if (dateObj && dateObj != "") {
		dateObj.value = getFormattedDate(dateObj.value); 
  } 
	dateObj = ""
}
function handleDateValidation (s, e) {
		if (e.Value.length < 8) {
			e.IsValid = false;
		} else {
		    e.IsValid = checkFormat(s.regex,getFormattedDate(e.Value))
		}
		if (dateObj != "") {
		dateObj.value = getFormattedDate(e.Value)
		clearDateObj()
		}
}

function checkFormat(exprList, val) {
	var exprArray = exprList.split("~~")
	 for(i in exprArray) {
	 	 var re = new RegExp(exprArray[i]);
         if (!val.match(re)) {
           return false;
		 }
     }
    return true;
}

var quickSearchRefByWin = ""
var quickSearchRefToWin = ""
function openQuickSearchWindow(url, window_name) {
	//we don't want to reload the provider quicksearch page it it already exists
	
	if (window_name == "winQuickSearchRefBy") {
		if (quickSearchRefByWin != "") {
			if (quickSearchRefByWin.closed) quickSearchRefByWin = "";
		}
		
		if (quickSearchRefByWin == "") {
			quickSearchRefByWin = window.open(url, window_name, 'menubar=no,status=yes,location=no,toolbar=no,resizable=yes,scrollbars=yes,height=500,width=600');
			quickSearchRefByWin.focus();  
		} else {
			quickSearchRefByWin.focus();
		} 
	}
	else // window_name must be "winQuickSearchRefTo"
	{
		if (quickSearchRefToWin != "") {
			if (quickSearchRefToWin.closed) quickSearchRefToWin = "";
		}
		
		if (quickSearchRefToWin == "") {
			quickSearchRefToWin = window.open(url, window_name, 'menubar=no,status=yes,location=no,toolbar=no,resizable=yes,scrollbars=yes,height=500,width=600');
			quickSearchRefToWin.focus();
		} else {
			quickSearchRefToWin.focus();
		} 
	}
	
	
	
	
		
	
}


function openWindow(url, window_name) {
  //alert("openWindow is now executing...");
	if (window_name == "winQuickSearchRefBy" || window_name == "winQuickSearchRefTo") {
		openQuickSearchWindow(url, window_name);
	} else {
		myWindow = window.open(url, window_name, 'menubar=no,status=yes,location=no,toolbar=no,resizable=yes,scrollbars=yes,height=500,width=600')
		myWindow.focus()   
	}	
}

function openNonStandardWindow(url, window_name) {
		myWindow = window.open(url, window_name, 'menubar=no,status=no,location=no,toolbar=no,titlebar=no,resizable=yes,scrollbars=yes,height=600,width=800');
		myWindow.focus()
}

function limitTextLength(element, maxLength) {

if (element.value.length > maxLength)

element.value = element.value.substring(0, maxLength);

}
 
function SetProviderValue(ProviderNumControlID, ProviderNumValue, NPIControlID, NPIValue)
{
  //alert('In the method, with parameters of ' + NPIControlID + ' and ' + NPIValue);
		//Provider Number control
    for (var i = 0; i < document.forms[0].elements.length; i++)
    {
      if (document.forms[0].elements[i].name == ProviderNumControlID)
      {
        //alert('About to change the value from ' + document.forms[0].elements[i].value + ' to ' + newValue);
        document.forms[0].elements[i].value = ProviderNumValue;
       //return true;
      }
    }
    //NPI control
    for (var i = 0; i < document.forms[0].elements.length; i++)
    {
      if (document.forms[0].elements[i].name == NPIControlID)
      {
        document.forms[0].elements[i].value = NPIValue;
        __doPostBack(NPIControlID,NPIValue)
       return true;
      }      
    }    
   return false;
}

function turnOffAF(inputObj) { 
	inputObj.af = "false"
	return false;
}  // function

function advanceFocus(inputObj, evt) 
{ 
  if (evt.keyCode != 9) 
  {
    if (inputObj.af == "false") 
    {
	    inputObj.af="true"
    }
    else 
    {
			var elemArray = document.forms[0].elements;
			for (var i = 0; i < elemArray.length; i++) 
			{
				if (document.forms[0].elements[i].name == inputObj.name) 
				{
					if (inputObj.value.length == inputObj.maxLength)
					{
						++i;
						if (document.forms[0].elements[i].tagName == "FIELDSET") {
							//does not support focus call, so go to next element
							++i
						}
						document.forms[0].elements[i].focus();
						document.forms[0].elements[i].select();
						return true;
					} // if inputObj
				} // if document
			}  //for
    } //else
  } //if evt
  return false;
}  // function

function AutoTab(inputObj, nextElementId) {
  if (inputObj.value.length == inputObj.maxLength){
      document.getElementById(nextElementId).focus();
 }
} // autotab

function toggleElementDisplay(elmtId) {
var elmt = document.getElementById(elmtId)
  if (elmt.style.display=="none")
    elmt.style.display="inline";
  else
    elmt.style.display="none";
}

function toggleTableDetails(tableId) {
 var allTableData = document.all.tags("table");
 for (i=0; i<allTableData.length; i++) {
     if ( allTableData[i].id==tableId) {
        if (allTableData[i].style.display=="none")
           allTableData[i].style.display="inline";
        else
           allTableData[i].style.display="none";
     } //tableId
  } // for
} // function toggleTableDetails
// This function does not support standards: Use 'getElementById' instead of 'all'


function eiSSNToggleDetails(theTarget) { //This function is used in ssnEi usercontrol ascx
	var triggerOff = theTarget + "IsOn"
	var triggerOn = theTarget + "IsOff"
	var is_the_Target = theTarget + "Details"
	if (document.getElementById(is_the_Target).style.display=="none") {
		document.getElementById(is_the_Target).style.display="";		
		document.getElementById(triggerOff).style.display="";
		document.getElementById(triggerOn).style.display="none";
	}
	else {
		document.getElementById(is_the_Target).style.display="none";
		document.getElementById(triggerOff).style.display="none";
		document.getElementById(triggerOn).style.display="";
	}
}


function getFormattedDate(dateVal){
	var txtBoxVal = dateVal;
	var regExp1 = /-/g 
	txtBoxVal = txtBoxVal.replace(regExp1, "");
	
	var regExp2 = /\//g 
	txtBoxVal = txtBoxVal.replace(regExp2, "");
	
	if (txtBoxVal.length == 8 && !isNaN(txtBoxVal)) {
		if (txtBoxVal.substring(0,4) > 1231) {
		//entered format is yyyymmdd
		return txtBoxVal.substring(4,6) + "/" + txtBoxVal.substring(6,8) + "/" + txtBoxVal.substring(0,4);
		} else {
		//entered format is mmddyyyy
		return txtBoxVal.substring(0,2) + "/" + txtBoxVal.substring(2,4) + "/" + txtBoxVal.substring(4,8);
		}
	} 	
	return dateVal;	
}


function SetFormCntrlValue(controlId, newValue)
{
  //alert('In the method, with parameters of ' + controlId + ' and ' + newValue);
    for (var i = 0; i < document.forms[0].elements.length; i++)
    {
      if (document.forms[0].elements[i].name == controlId)
      {
        //alert('About to change the value from ' + document.forms[0].elements[i].value + ' to ' + newValue);
        document.forms[0].elements[i].value = newValue;
	
       return true;
      }
    }
   return false;
}


function pageForceSSL(forceSSL){
	if (forceSSL) {
		//alert("we have forceSSL");
		if ((self.location.href).indexOf("http://") == 0) {
			var regEx = /http:/;var loc = "" + self.location.href;
			location.replace(loc.replace(regEx, "https:"));
		} else {
			//alert("no forceSSL");
		}  
	}
}


function toggleDivContent(divID) {
	if (document.getElementById(divID).style.display=="none")
		document.getElementById(divID).style.display="block";
	else
		document.getElementById(divID).style.display="none";
}

function applyOverrideStyle(styleNameURL) {
	var styleString;
	styleString = "<link href='" + styleNameURL + "'  rel='stylesheet' type='text/css' media='screen' />";
	document.write(styleString);
}
