var openWindow;
//------------------------------------------------------------------------------------------------------------------------------
function resetWindow()
{
	top.window.moveTo(0,0); 
	 top.window.resizeTo(screen.availWidth,screen.availHeight); 
	 if (top.window.outerHeight < window.screen.availHeight || top.window.outerWidth < window.screen.availWidth){ 
		top.window.outerHeight = top.screen.availHeight; 
		top.window.outerWidth = top.screen.availWidth; 
	} 
}
//------------------------------------------------------------------------------------------------------------------------------
function showModallessWindow(pURL,pFacilityName,pTitle,pExport,pHeight,pWidth,pHasScrollBars)
{
	var strWindowWidth = pWidth;
	var strWindowHeight = pHeight;
	var strURL = pURL;
	var strLeft = window.screen.availWidth;
	var strTop = window.screen.availHeight;
	
	strLeft = ( (strLeft - strWindowWidth) / 2);
	strTop = ( (strTop - strWindowHeight) / 2);
	strURL =  strURL + "&strFacilityName=" + pFacilityName + "&strPageTitle=" + pTitle + "&strExportButton="+ pExport;
	
	if(openWindow){
		if(!openWindow.close()){
			openWindow.close();
		}
	}
openWindow = window.open(''+strURL+'',"","top="+strTop+",left="+strLeft+",height="+strWindowHeight+",width="+strWindowWidth+",status=0,resizeable=0,scrollbars="+pHasScrollBars+",toolbar=0");
}
//------------------------------------------------------------------------------------------------------------------------------
function showModallessWindow2(pURL,pHeight,pWidth,pHasScrollBars)
{
	var strWindowWidth = pWidth;
	var strWindowHeight = pHeight;
	var strURL = pURL;
	var strLeft = window.screen.availWidth;
	var strTop = window.screen.availHeight;
	
	strLeft = ( (strLeft - strWindowWidth) / 2);
	strTop = ( (strTop - strWindowHeight) / 2);
		
	if(openWindow){
		if(!openWindow.close()){
			openWindow.close();
		}
	}
openWindow = window.open(''+strURL+'',"","top="+strTop+",left="+strLeft+",height="+strWindowHeight+",width="+strWindowWidth+",status=0,resizeable=0,scrollbars="+pHasScrollBars+",toolbar=0");
}
//------------------------------------------------------------------------------------------------------------------------------
function GotoFacility(pURL)
{
	window.opener.document.location.href = pURL;
	window.opener.focus();
	window.close();
}
//------------------------------------------------------------------------------------------------------------------------------
function ShowPhiladelphiaDaughter(pURL,pHeight,pWidth,pHasScrollBars)
{
	var strWindowWidth = pWidth;
	var strWindowHeight = pHeight;
	var strURL = pURL;
	var strLeft = window.screen.availWidth;
	var strTop = window.screen.availHeight;
	
	strLeft = ( (strLeft - strWindowWidth) / 2);
	strTop = ( (strTop - strWindowHeight) / 2);
		
	if(openWindow){
		if(!openWindow.close()){
			openWindow.close();
		}
	}
openWindow = window.open(''+strURL+'',"","top="+strTop+",left="+strLeft+",height="+strWindowHeight+",width="+strWindowWidth+",status=0,resizeable=0,scrollbars="+pHasScrollBars+",toolbar=0");
}
//------------------------------------------------------------------------------------------------------------------------------
function doHourglass()
{
  //document.body.style.cursor = '../images/dinosaur.ani';
  document.body.style.cursor = 'wait';
}
//------------------------------------------------------------------------------------------------------------------------------
function ShowWarningMessage(pMessage)
{
	if(!confirm(pMessage)){
		return false
	}
	return true
}
//------------------------------------------------------------------------------------------------------------------------------
function ShowExportWarningMessage(pMessage,pImageName)
{
	if(!confirm(pMessage)){
		return false
	}
	document.getElementById('DaughterTop1_imgExport').src =  "../images/imgProcessingData.gif";
	setTimeout('SetImage()',2000);
	showModallessWindow("../zipcodes/zip_ZipCodeExport.aspx?","","","",50,225,0)
	return true
}
function SetImage()
{
	document.getElementById('DaughterTop1_imgExport').src =  "../images/view_in_excel_button.gif";
}
//------------------------------------------------------------------------------------------------------------------------------
function Rollover(pObject, pClassName)
{
	pObject.classname = pClassName;
}
//------------------------------------------------------------------------------------------------------------------------------
function RolloverLargeImage(pArrayNumber)
{
	document.images['imgLargePic'].src=img[pArrayNumber].src;
}
//------------------------------------------------------------------------------------------------------------------------------
function PrintPage()
{
	var exists = eval(document.getElementById("divNoPrint"));
	if(exists){
		document.getElementById("divNoPrint").className='noprint';
		document.getElementById("DaughterTop1_lnkPrintPage").style.visibility='hidden';
		window.print();
		document.getElementById("DaughterTop1_lnkPrintPage").style.visibility='visible';
		document.getElementById("divNoPrint").className='';
	}
	else{
		document.getElementById("DaughterTop1_lnkPrintPage").style.visibility='hidden';
		window.print();
		document.getElementById("DaughterTop1_lnkPrintPage").style.visibility='visible';
	}
}
//------------------------------------------------------------------------------------------------------------------------------
function PrintBid()
{
	var exists = eval(document.getElementById("divNoPrint"));
	if(exists){
		document.getElementById("divNoPrint").className='noprint';
		window.print();
		document.getElementById("divNoPrint").className='labelnormal';
	}
}
//------------------------------------------------------------------------------------------------------------------------------
function ClearListBox(pField)
{
	//remove from the listbox 
	if(pField.options.length != 0){
		//make sure they are double-clicking on a real list item and not just the box
		pField.selectedIndex = -1
	}
}
//------------------------------------------------------------------------------------------------------------------------------
function AutoComplete(dropdownlist,caseSensitive) 
{
	// check the keypressBuffer attribute is defined on the dropdownlist
	var undefined; 
	if (dropdownlist.keypressBuffer == undefined) { 
		dropdownlist.keypressBuffer = ''; 
	} 
	
	// get the key that was pressed 
	var key = String.fromCharCode(window.event.keyCode); 
	dropdownlist.keypressBuffer += key;
	if (!caseSensitive) {
		// convert buffer to lowercase
		dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
	}
	
	// find if it is the start of any of the options 
	var optionsLength = dropdownlist.options.length; 
	for (var n=0; n < optionsLength; n++) { 
		var optionText = dropdownlist.options[n].text; 
		if (!caseSensitive) {
			optionText = optionText.toLowerCase();
		}
		if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { 
			dropdownlist.selectedIndex = n; 
			return false; // cancel the default behavior since we have selected our own value 
		} 
	} 
	// reset initial key to be inline with default behavior 
	dropdownlist.keypressBuffer = key; 
	return true; // give default behavior 
} 
//------------------------------------------------------------------------------------------------------------------------------
function ClearListBox(pField)
{
	//remove from the listbox 
	if(pField.options.length != 0){
		//make sure they are double-clicking on a real list item and not just the box
		pField.selectedIndex = -1
	}
}
//------------------------------------------------------------------------------------------------------------------------------
function SetItems(pField1, pField2)
{
	//this function is needed because we build the chosen listboxes on the client side
	//therefore, we need to select all of the items so that they get pushed to the server side
	var intItemCounter;
	
	//for prime specialties
	for(intItemCounter=0;(intItemCounter < pField1.options.length);++intItemCounter){
		pField1.options[intItemCounter].selected = true
	}
	
	//ffor sub specialties
	for(intItemCounter=0;(intItemCounter < pField2.options.length);++intItemCounter){
		pField2.options[intItemCounter].selected = true
	}
}
//------------------------------------------------------------------------------------------------------------------------------
function SelectSpecialty(pPickerField,pChosenField)
{
	//function takes the chosen specialty and moves it to the "chosen" listbox
	var objListBoxOption;
	var blnAddOption = true;
	var intChosenFieldCounter;
	var intNextAvailablePosition;
	var intValue = pPickerField.options[pPickerField.selectedIndex].value;
	var strText = pPickerField.options[pPickerField.selectedIndex].text;
	
	//loop thru the "chosen" listbox to make sure that value was not already selected
	for(intChosenFieldCounter=0;(intChosenFieldCounter < pChosenField.options.length); ++intChosenFieldCounter){
		if (pChosenField.options[intChosenFieldCounter].value == intValue){
			blnAddOption = false;
			return;
		}
	}
	
	//only add the option if it isn't already in the "chosen" listbox
	if(blnAddOption == true){
		//only take the first 25 characters because of horizontal limitations
		if (strText.length > 25){
			strText = strText.substring(0,25) + "...";
		}
	
		//new functionality that will look if Primary Care Physician was chosen, 
		//and if so, select 4 specialties to go with it (IMs, GPs, FPs) values of (048,033,029), respectively
		if (strText == 'Primary Care Physician'){
			var strTextArray = new Array(3)
			var strValueArray = new Array(3)
			
			strTextArray[0] = "General Practice"
			strValueArray[0] = 338
			
			strTextArray[1] = "Family Practice"
			strValueArray[1] = 334
			
			strTextArray[2] = "Internal Medicine"
			strValueArray[2] = 353
			
			for(var intCounter=0;(intCounter <3);intCounter++){
				//load the new object into the next available slot in the listbox
				objListBoxOption = new Option(strTextArray[intCounter],strValueArray[intCounter]);
				intNextAvailablePosition = pChosenField.options.length;
				pChosenField.options[intNextAvailablePosition] = objListBoxOption;
				pChosenField.style.visibility  = "visible"
			}
		}
		
		//load the new object into the next available slot in the listbox
		objListBoxOption = new Option(strText,intValue);
		intNextAvailablePosition = pChosenField.options.length;
		pChosenField.options[intNextAvailablePosition] = objListBoxOption;
		pChosenField.style.visibility  = "visible"
		
		//first check for the presence of the radius boxes.  if true, then remove their values and hide
		var exists = eval(document.getElementById("txtChosenMedZip"));
		if(exists){
			if(document.Form1.listChosenMedLocations.style.visibility == "visible"){
				document.Form1.txtChosenMedZip.value = "";
				document.Form1.txtChosenMedMiles.value = "";
				document.Form1.txtChosenMedZip.style.visibility = "hidden";
				document.Form1.txtChosenMedMiles.style.visibility = "hidden";
				document.getElementById("btnClear").style.visibility = "hidden";
			}
		}
		
		//first check for the presence of the radius boxes.  if true, then remove their values and hide
		var exists = eval(document.getElementById("txtChosenConsumerZip"));
		if(exists){
			if(document.Form1.listChosenConsumerLocations.style.visibility == "visible"){
				document.Form1.txtChosenConsumerZip.value = "";
				document.Form1.txtChosenConsumerMiles.value = "";
				document.Form1.txtChosenConsumerZip.style.visibility = "hidden";
				document.Form1.txtChosenConsumerMiles.style.visibility = "hidden";
				document.getElementById("btnClear").style.visibility = "hidden";
			}
		}
		
			//first check for the presence of the radius boxes.  if true, then remove their values and hide
		var exists = eval(document.getElementById("txtChosenBusZip"));
		if(exists){
			if(document.Form1.listChosenBusLocations.style.visibility == "visible"){
				document.Form1.txtChosenBusZip.value = "";
				document.Form1.txtChosenBusMiles.value = "";
				document.Form1.txtChosenBusZip.style.visibility = "hidden";
				document.Form1.txtChosenBusMiles.style.visibility = "hidden";
				document.getElementById("btnClear").style.visibility = "hidden";
			}
		}
		
		
	}
}
//------------------------------------------------------------------------------------------------------------------------------
function DeselectSpecialty(pField)
{
	//remove from the listbox 
	if(pField.options.length != 0){
		//make sure they are double-clicking on a real list item and not just the box
		if(pField.selectedIndex >= 0){
			pField.options[pField.selectedIndex] = null;
			if(pField.options.length <= 0)
				pField.style.visibility  = "hidden"
		}
	}
}
//------------------------------------------------------------------------------------------------------------------------------
function RankOrder2(pGroup1,pGroup2, pGroup3)
{
    var intGroup1Value;
    var intGroup2Value;
    var intGroup3Value;
    var elGroup1 =  document.Form1[pGroup1];
    var elGroup2 =  document.Form1[pGroup2];
    var elGroup3 =  document.Form1[pGroup3];
    var len1 = elGroup1.length;
    var len2 = elGroup2.length;
    var len3 = elGroup3.length;  

    //first start with the group that was checked
    for(i=0; i<=len1-1; i++)
    {
        if (elGroup1[i].checked) {
            intGroup1Value = i;
            break; 
        }
    }

    //next start with the 2nd group
    for (i=0; i<=len2-1; i++){
         if (i != intGroup1Value) {
            elGroup2[i].checked = true;
            intGroup2Value = i;
            break; 
         }
    }
   
    //finally go with the 3rd group
    for (i=0; i<=len2-1; i++){
         if ((i != intGroup1Value) && (i != intGroup2Value) ) {
            elGroup3[i].checked = true;
            break; 
        }
    }   
}
//------------------------------------------------------------------------------------------------------------------------------
function RankOrder(pGroup1,pGroup2, pGroup3)
{
    if(document.Form1[pGroup2].checked == true || document.Form1[pGroup3].checked == true){
       alert("You are attempting to select a rank that already belongs to another city.\nPlease change that city's ranking first.");
       document.Form1[pGroup1].checked = false;
       return;
   }
    document.Form1[pGroup1].checked = true;
}
//------------------------------------------------------------------------------------------------------------------------------
function checkNumeric(allowDecimal)  {
    if ((event.keyCode == 189 || event.keyCode == 109) || (event.keyCode >= 48 && event.keyCode <= 57)) { 
        return true; 
    }
    else if (allowDecimal && event.keyCode == 46) {
        return true;
    }
    else {   
        return false;
    }
}
//------------------------------------------------------------------------------------------------------------------------------
function clearInputs() {
    for (var c=0; c <= document.form1.elements.length-1; c++) {
        if (document.form1.elements[c].type == 'checkbox') {
            document.form1.elements[c].checked = false;
        }
        else if (document.form1.elements[c].type == 'text' || document.form1.elements[c].type == 'textarea') {
            document.form1.elements[c].value = '';
        }  
        else if (document.form1.elements[c].type == 'select-multiple') {
            document.form1.elements[c].selectedIndex = -1;
        }  
        else if (document.form1.elements[c].type == 'select-one') {
            document.form1.elements[c].selectedIndex = 0;
        }  
    }
    if (document.getElementById('lblBadZip')) {
        document.getElementById('lblBadZip').style.display = 'none';
    }  
    return false; 
}
//------------------------------------------------------------------------------------------------------------------------------
function confirmCriteria(){
var l
    l = document.getElementById('spPS').innerHTML.length;
    l += document.getElementById('spRA').innerHTML.length;
    l += document.getElementById('spEM').innerHTML.length;
    l += document.getElementById('spTC').innerHTML.length;
    l += document.getElementById('spRA').innerHTML.length;
    l += document.getElementById('spMD').innerHTML.length;
    l += document.getElementById('spCH').innerHTML.length;
    l += document.getElementById('spAU').innerHTML.length;
    l += document.getElementById('spTS').innerHTML.length;
    l += document.getElementById('spHS').innerHTML.length;
    l += document.getElementById('spTR').innerHTML.length;
    l += document.getElementById('spGM').innerHTML.length;
    l += document.getElementById('spGR').innerHTML.length;
    l += document.getElementById('spBP').innerHTML.length;
    l += document.getElementById('spFD').innerHTML.length;
    l += document.getElementById('spPT').innerHTML.length;
    l += document.getElementById('spFN').innerHTML.length;
    l += document.getElementById('spHC').innerHTML.length;
   if (l == 0){
        alert('No criteria has been selected.');
        return false;
   }
   else{
        document.body.style.cursor = "wait"; 
        return true;
   }  
}
//------------------------------------------------------------------------------------------------------------------------------
 function ClipBoard(pCellID,pAnchorID) 
{
    document.getElementById("txtHoldText").innerText = document.getElementById(pCellID).innerText;
    Copied = document.getElementById("txtHoldText").createTextRange();
    Copied.execCommand("RemoveFormat");
    Copied.execCommand("Copy");
    document.getElementById(pAnchorID).title = "Great job.  You just copied this URL to your clipboard.  Now go paste it."; 
   document.getElementById(pAnchorID).style.color = "darkorange"; 
}
//------------------------------------------------------------------------------------------------------------------------------
function ResetDefaultText(pFrom,pTo)
{
  document.getElementById(pTo).value = document.getElementById(pFrom).value.replace(/<br>/gi,"\n");
}