
function updateImg(imgName, sType)
{
	//var imgName = event.srcElement.id;
	switch (sType) {
		case "Over" :
			window.document.getElementById(imgName).src = eval(imgName + "_over.src");
			break;
		case "Out" :
			window.document.getElementById(imgName).src = eval(imgName + ".src");
			break;
		case "Down" :
			window.document.getElementById(imgName).src = eval(imgName + "_down.src");
			break;
		case "Up" :
			window.document.getElementById(imgName).src = eval(imgName + "_up.src");
			break;
	}
}

function updateImg2(oImg, sType)
{
	var imgName = oImg.name; 
	//alert (imgName); 
	//split on : to get the image name 
	
	var aryImg = imgName.split(":"); 
	
	//var imgName = event.srcElement.id;
	switch (sType) {
		case "Over" :
			oImg.src = eval(aryImg[1] + "_i_over.src");
			break;
		case "Out" :
			oImg.src = eval(aryImg[1] + "_i.src");
			break;
		case "Down" :
			oImg.src = eval(aryImg[1] + "_i_down.src");
			break;
		case "Up" :
			oImg.src = eval(aryImg[1] + "_i_up.src");
			break;
	}
}

function required(sFieldName) {
	var sField = window.document.getElementById(sFieldName);

	if (sField == null) {
		alert(sFieldName + " field is not found"); 
		return false; 
	}

	if (sField.value.length == 0) 
		return false;
	else 
		return true; 
}

function selectRequired(sFieldName) {
	var sField = window.document.getElementById(sFieldName);

	if (sField == null) {
		alert(sFieldName + " field is not found"); 
		return false; 
	}
		
	if (sField.selectedIndex == 0) 
		return false;
	else 
		return true; 
}

function radioCheckedRequired(sFieldName)
{
	var sField = window.document.getElementsByName(sFieldName);
	var bSelected;
	bSelected=false;
	if (sField == null) {
		alert(sFieldName + " field is not found"); 
		return false; 
	}
	
	for(var i=0; i < sField.length; i++){
		if(sField.item(i).checked==true){
			bSelected = true;
			break;
		}
	}
	return bSelected; 
}

function checkDate(monthList, dayList, yearList)
{
	var bChar = "";

	var oMonth = document.getElementById(monthList);
	var oDay = document.getElementById(dayList);
	var oYear = document.getElementById(yearList); 
	
	if (oMonth == null) {
		alert("CheckDate Failed to find element: " + monthList);
		return false; 
	}
	if (oDay == null) {
		alert("CheckDate Failed to find element: " + dayList);
		return false; 
	}
	if (oYear == null) {
		alert("CheckDate Failed to find element: " + yearList);
		return false; 
	}
	
	var month = oMonth.options[oMonth.selectedIndex].value; 
	var day = oDay.options[oDay.selectedIndex].value;
	var year = oYear.options[oYear.selectedIndex].value; 
	
	if (month.length = 3) {
		bChar = month.substring(2, 3)
		month = month.substring(0, 2) 
	}
	
	if (month==9 || month==4 || month==6 || month==11)
	{
		oDay.options.length=30 + 1;
	}
	else
	{
		if (month==2)
		{
			if (year % 4==0 || (year % 100 !=0 && year % 400==0))
			{
				oDay.options.length=29 + 1;
			}
			else
			{
				oDay.options.length=28 + 1;
			}
		}
		else
		{
		oDay.options.length = 31 + 1;
		}
	}
	
	for (x=1; x < oDay.options.length; x++)
	{
		if (x < 10)
		{
			oDay.options[x].value = '0' + String(x) + bChar;
			oDay.options[x].text = '0' + String(x);
		}
		else
		{
			oDay.options[x].value=x + bChar;
			oDay.options[x].text=x;
		}
	}
}

function validateTextBoxDate(sMonth, sDay, sYear) {
	/*
	function will return 
		** 0 if date is valid and complete. 
		** 1 if date is valid (blank) 
		** 2 if date is partially filled in but invalid 
	*/
	
	var oMonth = document.getElementById(sMonth);
	var oDay = document.getElementById(sDay); 
	var oYear = document.getElementById(sYear); 
	if ((oMonth.value.length > 0) || (oDay.value.length > 0) || (oYear.value.length > 0)) {
		//something has been selected, make sure that everything is selected 
		if ((oMonth.value.length == 0) || (oMonth.value.length == 0) || (oMonth.value.length == 0)) {
			//something is not selected, return false!  
			return 2;
		}
		else {
			//everything has been selected, this is good. 
			return 0; 
		}
	}
	else {
		//nothing has been selected, return true 
		return 1; 	
	}


}

function validateDate(sMonth, sDay, sYear) {
	/*
	function will return 
		** 0 if date is valid and complete. 
		** 1 if date is valid (blank) 
		** 2 if date is partially filled in but invalid 
	*/
	
	var oMonth = document.getElementById(sMonth);
	var oDay = document.getElementById(sDay); 
	var oYear = document.getElementById(sYear); 
	if ((oMonth.selectedIndex != 0) || (oDay.selectedIndex != 0) || (oYear.selectedIndex != 0)) {
		//something has been selected, make sure that everything is selected 
		if ((oMonth.selectedIndex == 0) || (oDay.selectedIndex == 0) || (oYear.selectedIndex == 0)) {
			//something is not selected, return false!  
			return 2;
		}
		else {
			//everything has been selected, this is good. 
			return 0; 
		}
	}
	else {
		//nothing has been selected, return true 
		return 1; 	
	}
}

function validateMonthYear(sMonth, sYear) {
	/*
	function will return 
		** 0 if date is valid and complete. 
		** 1 if date is valid (blank) 
		** 2 if date is partially filled in but invalid 
	*/
	
	var oMonth = document.getElementById(sMonth);
	//var oDay = document.getElementById(sDay); 
	var oYear = document.getElementById(sYear); 
	
	//|| (oDay.selectedIndex != 0)
	//|| (oDay.selectedIndex == 0)
	
	if ((oMonth.selectedIndex != 0) || (oYear.selectedIndex != 0)) {
		//something has been selected, make sure that everything is selected 
		if ((oMonth.selectedIndex == 0) || (oYear.selectedIndex == 0)) {
			//something is not selected, return false!  
			return 2;
		}
		else {
			//everything has been selected, this is good. 
			return 0; 
		}
	}
	else {
		//nothing has been selected, return true 
		return 1; 	
	}
}

function validateNumber(sTextbox) {
	var oItem = document.getElementById(sTextbox); 
	if (oItem == null) 
		alert("Item not found: " + sTextbox) 
		
	var sValue = oItem.value;
	for (var i = 0; i < sValue.length; i++) { 
		if (isNaN(parseInt(sValue.charAt(i)))) { 
			return false;
		}
	}
	return true; 
}

function oneCheckBox(sCheckBox, oCurCheckBox)
{
	var oCheckboxes = document.getElementsByName(sCheckBox) 
	//alert(oCheckboxes.length); 
	var i;
	if(oCheckboxes.length > 1){
		if(oCurCheckBox.checked == true){
			for(i = 0; i < oCheckboxes.length; i++) {
				oCheckboxes[i].checked=false;
			}
			oCurCheckBox.checked=true;
		}
	}
}
function isEmail2(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
function runtimeNumValidation(oBox, sText, iLen, sNext) {

	/*
	This function will validate that the box is going to be numeric 
	in the runtime.  The length will have to be validated during the 
	submit function.  
	input arguments:  
	**  oBox - box which triggered this event 
	**  sText - text which is to be displayed to the user as to which box 
				must be numeric 
	** iLen	- Length the box is supposed to be; will move to the next field when 
				the length reached iLen 
	** sNext - field which is to be moved to when the length is correct.  
	*/

	if (validateNumber(oBox.id) != true) {
		alert(sText + " must be numeric"); 
		if (isNaN(parseInt(oBox.value))) 
			oBox.value = "" 
		else
			oBox.value = parseInt(oBox.value); 

		oBox.focus(); 
	}
	else {
		if ((oBox.value.length == iLen) && (sNext != null)) {
			//it is time to move to the next box 
			document.getElementById(sNext).focus() 
		}
	}
}


function validateLength(sName, iLen) {
	var oText = document.getElementById(sName)
	if (oText == null) 
		alert("unable to validate Length " + sName) 
		
	if ((oText.value.length == 0) || (oText.value.length == iLen))
		return true; 
	else 
		return false; 
}

function validatePhone(sAC, sExc, sPh, sExt) {
	/*
	function will return 
		** 0 if phone is valid and complete. 
		** 1 if phone is valid (blank) 
		** 2 if phone is partially filled in but invalid 
	*/
	var sReturn = 0;
	var bPartial = false; 
	var oAC = document.getElementById(sAC);
	var oExc = document.getElementById(sExc); 
	var oPh = document.getElementById(sPh);
	var oExt
	if (sExt == null) 
		oExt = null;
	else
		oExt = document.getElementById(sExt); 
	
	if (oAC == null) {
		alert(sAC + " field is not found"); 
		return false; 
	}
		
	//if nothing was entered, phone is valid? 
	if ((oAC.value.length != 0) || (oExc.value.length != 0) || (oPh.value.length != 0)) {
		//something was entered
		bPartial = true; 
	}
	else {
		if (oExt != null) {
			//there is an extention, check it's length 
			if (oExt.value.length != 0) 
				bPartial = true; 
			else {
				//nothing was entered in the first three phone numbers and the 
				//	extention is blank as well 
				sReturn = 1; 
			}
		}
		else {
			//nothing was entered in phone and extention is null 
			sReturn = 1; 
		}
	}
	
	//if something was entered, make sure all three are entered. 
	if (bPartial == true) {
		//check all three to ensure that they are all complete. 
		if ((oAC.value.length == 3) && (oExc.value.length == 3) && (oPh.value.length == 4)) {
			//phone is entered and complete 
			sReturn = 0;
		}
		else {
			//phone is partially entered, but lengths are not corret.  
			sReturn = 2;
		}
	}
	
	//return value to calling function 
	return sReturn; 
}

function validateSocial(s1, s2, s3) {
	/*
	function will return 
		** 0 if social is valid and complete. 
		** 1 if social is valid (blank) 
		** 2 if social is partially filled in but invalid 
	*/
	var sReturn = 0;
	var bPartial = false; 
	var oS1 = document.getElementById(s1);
	var oS2 = document.getElementById(s2); 
	var oS3 = document.getElementById(s3);
		
	
	if ((oS1 != null) && (oS2 != null) && (oS3 != null)) {
		//if nothing was entered, ssn is valid? 
		if ((oS1.value.length != 0) || (oS2.value.length != 0) || (oS3.value.length != 0)) {
			//something was entered; check to ensure that everything was entered and the correct len 
			if ((oS1.value.length == 3) && (oS2.value.length == 2) && (oS3.value.length == 4)) {
				//values are all correct lengths!  return 0 
				return 0;
			}
			else {
				//values aren't correct lengths, return 2 
				return 2;
			} 
		}
		else {
			//nothing was entered; return 1
			return 1; 
		}
	}
	else {
		// there are no ssn textboxes; return 1 
		return 1; 
	}
}

function validateAddress(sStreet, sAppt, sCity, sState, sZip, sZip4, bReq) {
	var oStreet = document.getElementById(sStreet);
	if (sAppt != null) 
		var oAppt = document.getElementById(sAppt); 
	var oCity = document.getElementById(sCity);
	var oState = document.getElementById(sState);
	var oZip = document.getElementById(sZip); 
	if (sZip4 != null) 
		var oZip4 = document.getElementById(sZip4)
	
	if ((oStreet.value.length != 0) || (oCity.value.length != 0) || 
			(oState.value != "") || (oZip.value.length != 0) || 
			((oAppt != null)?(oAppt.value.length != 0):false) ||
			((oZip4 != null)?(oZip4.value.length != 0):false)) {
		//something is filled in, validate that address is complete. 
		
		if ((oStreet.value.length == 0) || (oCity.value.length == 0) ||
			(oState.value == "") || (oZip.value.length == 0)){
			//something is missing
			return "address is invalid"
		}
		else {
			//everything is complete. 
			return ""; 
		}
	}
	else {
		//nothing is filled in, check if address is required!  
		if (bReq == true) {
			return "address is required"
		}
		else {
			return "" 
		}
	}
}

function limitEntry(e, allow) // e contains the Javascript Event (the key that was pressed), allowable characters is the list of characters that are allowed - duh.
{
	var key;
	var keychar;

	// The following accounts for differences in browser implementation
	// IE 4.0 isn't quite slick enough to recognize the event, so we have to assign it
	if (window.event)
		key = window.event.keyCode;
	else { 
		if (e)
			key = e.which;
		else
			return true;
	}
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();

	// control keys -- Unicode characters (13=RETURN;) 
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
	return true;

	// allowable characters
	else if (((allow).indexOf(keychar) > -1))
		return true;
	else
		return false;
}

function ChangeImageDisplay(oImageObject, sImageName)
{
	oImageObject.src=sImageName;

}

function checkLanguage() {
	var oLangSel = document.getElementById("LangCode");
	var oLangTable = document.getElementById("tdLanguage");
	var oLanguage = document.getElementById("PriLang");
	
	if ((oLangTable != null) && (oLangSel != null)){ 
		if (oLangSel.value == "ZZ") {
			oLangTable.style.display = "inline"; 
		}
		else {
			oLangTable.style.display = "none"; 
			oLanguage.value = ""; 
		}
	} 
}

function printFunctions() {
	self.focus();
	window.print(); 
}

function preventBackspace(e, oElement) {
	if (e == null) 
		e = window.event; 

    if (document.layers)
        Key = e.which;
    else {
		Key = e.keyCode; 
    }
    //oDebug.innerHTML += "<br>Keyhandler2! ASCII-value: " + Key;
    //oDebug.innerHTML += "<br>Element: " + oElement.id;
    
    //if (Key != 0)
    //    alert("Keyhandler2! ASCII-value: " + Key);
    //if (oSelected != null) 
	//	oDebug.innerHTML += "<br>oSelected: " + oSelected.id;
	//else
	//	oDebug.innerHTML += "<br>oSelected is null ";
     
	if ((Key == 8) && (oSelected == null)) {
        // try to cancel the backspace
        e.cancelBubble = true;
        e.returnValue = false;
        oSelected = null; 
        return false;
    }
    
    oSelected = null;
}

function allowBackspace(e, oElement) {
	if (e == null) 
		e = window.event; 

	if (document.layers)
        Key = e.which;
    else {
		Key = e.keyCode;
    }
    
    if (Key != 0) {
		//alert("Key pressed handler3! ASCII-value: " + Key);
        //e.cancelBubble = true;
        oSelected = oElement; 
    }
}

function validateZip(oZip, sText, iLen, sNext, sCity, sState, sSavCity, sFrame) {

	/*
	This function will call a page to perform a lookup based on the value which 
	was entered in the zip code table to populate the boxes passed in by city and 
	state.  
	input arguments:  
	**  oBox - box which triggered this event 
	**  sText - text which is to be displayed to the user as to which box 
				must be numeric 
	** iLen	- Length the box is supposed to be; will move to the next field when 
				the length reached iLen 
	** sNext - field which is to be moved to when the length is correct.  
	** sCity - field which is to have the city value populated in from the called 
			page. 
	** sState - select which is to have the state value selected after page processing 
			is complete. 
	*/

	var sWidth = 450;
	var sHeight = 200;

	runtimeNumValidation(oZip, sText, iLen, sNext);
	//alert(oZip.value.length); 
	if (oZip.value.length == iLen) {
		var oCity = document.getElementById(sCity);
		var oState = document.getElementById(sState);
		var oFrame = window.frames[sFrame];

		//alert(oFrame.document.location.href); 
		
		//var sURL = "../Include/SelectedCity.aspx?ZipCode=" + oZip.value + "&StateBox=" + sState + "&CityBox=" + sCity + "&SavCity=" + sSavCity;
		var sURL = "../Include/SelectedCity.asp?ZipCode=" + oZip.value + "&StateBox=" + sState + "&CityBox=" + sCity;

		//alert(sURL); 
				
		//oFrame.document.location.href = sURL; 
		
		var popUp = window.open(sURL, "chooseState", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=' + sWidth + ',height=' + sHeight);
		popUp.moveTo((window.screen.availWidth - sWidth) / 2, (window.screen.availHeight - sHeight) / 2)
		window.screen.availHeight 
		popUp.focus();
	}
}

function SearchPCPInformation(sPlanName)
{
	var sUrl;
	var sWidth = window.screen.availWidth ;
	var sHeight = window.screen.availHeight;
	var sFunction

	var str1 = "SELECT"
	var s = sPlanName.indexOf(str1);
	 
	
	if( s > 0){
		sUrl="http://provdirectory.tufts-health.com/main?req=public&amp;fn=ProvSearch&amp;redirect=0&amp;srchType=1&amp;appType=pubsrch&amp;inpPlan=SLN";
	}
	else{
		sUrl="http://provdirectory.tufts-health.com/main?req=public&amp;fn=ProvSearch&amp;redirect=0&amp;srchType=1&amp;appType=pubsrch";
	}

		
		sFunction = "height=" + sWidth 
		sFunction += ", width=" + sHeight
		sFunction += ", status=yes, toolbar=no, menubar=no "
		sFunction += ", location=no, scrollbars=yes, resizable=yes "
	

	var popUp = window.open(sUrl, "FindPCPName", sFunction);
	//popUp.moveTo((window.screen.availWidth - sWidth) / 2, (window.screen.availHeight - sHeight) / 2)
	//window.screen.availHeight 
	//popUp.focus();


}

