//<script>
/*
'********************************************************************* 
' Name:  inc_formchek.js
' Class:  
' Created date: 5/21/2003
' Created by:   Megan Birch
' Purpose:      JavaScript Library for validation
' Inputs:
' Outputs:
' Notes:     
' History:
'	5/21/2003 Megan Birch
'		checkAlpha(theField)							Check that theField.value is an Alpha character
'		checkRange(theField, theField2, numberType)		Check that theField.value is less than theField2.value
'		checkLongDates(theField)						Check that theField.value is a proper date.
'		checkNumeric(theField, numberType [,eok])		Check that the entered value is numeric
'	7/31/2003 Keiji Ikuta
'		isPhoneNumber(value)
'		isLongDate(value)
'		CountCheckBoxChecked(strFieldName)
'
*/

// Check that string theField.value is Alphabetic. Return Alert if not.
function checkAlpha (theField,blnAllowCommas)
{   
	var arrValues = new Array();
	if(blnAllowCommas == 'True')
	{
		arrValues = theField.value.split(",");
	}
	else
		arrValues[0] = theField.value
	for(var i=0; i<arrValues.length; i++)
	{
	
		if (!isAlphabetic(arrValues[i])) 
		   return warnInvalid(theField, iAlpha);
		//else return true;
	}
	return true;
}

// Check that string theField.value is Numeric (1 = int, 2 = float). Return Alert if not.
function checkNumeric(theField, numberType, emptyOK)
{
   //check if this is a field that allows
   //comma-separated values.
 //  if(commaSep == true) 
   //{
	//	var splitValues = theField.value.split(",");
		
		
  // }  
   switch(numberType)
   {
	case 1: //int
		if (!isInteger(theField.value)) 
			return warnInvalid(theField, iInt);
		break;
	
	case 2: //float allowed
		if(!isFloat(theField.value))
			return warnInvalid(theField, iFloat);
		break;
		
	default:
		return true
   }
    
    return true;
}



//this function returns false if theField is greater than theField2.
// numberType
//		1 = int
//		2 = float
//		3 = date
function checkRange(theField, theField2, numberType)
{
	switch(numberType)
	{
	 case 1: //int
		if (parseInt(theField.value) > parseInt(theField2.value))
			return warnInvalid(theField2, iRange);
		break;
		
	 case 2: //float
		if (parseFloat(theField.value) > parseFloat(theField2.value))
			return warnInvalid(theField2, iRange);
		break;
		
	 case 3: //date
		var newdate;
		var newdate2;
		newdate = new Date(theField.value);
		newdate2 = new Date(theField2.value);
 
		if(newdate > newdate2)
			return warnInvalid(theField2, iRange);
		break;
	
	 default:
		return true;
	}
	
}



// Check that string theField.value is proper date (mm/dd/yy). Return Alert if not.
function checkLongDate(theField)
{
	var arrDate;
	var month;
	var day;
	var year;
	if (theField.value != "")
	{
		arrDate = reformatDate(theField.value);
		month = arrDate[0];
		day = arrDate[1];
		year = arrDate[2];
	
		if (!isYear(year)) return warnInvalid (theField, iYear);
		if (!isMonth(month)) return warnInvalid (theField, iMonth);
		if (!isDay(day)) 
		   return warnInvalid (theField, iDay);
		if (isDate (year, month, day))
		   return true;
		alert (iDatePrefix + " date " + iDateSuffix)
		return false
	}
	else
		return true;
	
}


//takes in date (mm/dd/yy) and breaks it out into month date year
function reformatDate (value)
{
	var date;
	
	//replace "-" with "/"
	date = value
	date = date.replace(/-/g,"/");
	date = date.split("/");

	return date;
}



// Get checked value from radio button.

function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    return radio[i].value
}



function selectcheck(selector)
{
	if(selector.selectedIndex==0)
		for(count=1;count<selector.options.length;count++)
			selector.options[count].selected=false;
	else
		selector.options[0].selected=false;
}




/*
'********************************************************************* 
' Name:  isLongDate
' Created date: 7/25/2003 
' Created by:   Keiji Ikuta
' Purpose:      
' Inputs:
' Outputs:
' Notes:     
' Update date:
' Update by:
'********************************************************************* 
*/
function isLongDate(value)
{
	var arrDate;
	var month;
	var day;
	var year;
	if(value != "")
	{
		arrDate = reformatDate(value);
		month = arrDate[0];
		day = arrDate[1];
		year = arrDate[2];
	
		if (!isYear(year)) return false;
		if (!isMonth(month)) return false;
		if (!isDay(day)) 
		   return false;
		if (isDate (year, month, day))
		   return true;
		return false
	}
	else
		return true;
	
}


/*
'********************************************************************* 
' Name:  isTime
' Created date: 8/5/2003 
' Created by:   Keiji Ikuta
' Purpose:      
' Inputs:
' Outputs:
' Notes:     
' Update date:
' Update by:
'********************************************************************* 
*/
function isTime(value)
{
	var arrTime;
	var hh,mm,ss;
	if(value != "")
	{
		try
		{
			arrTime = value.split(":");
			if(arrTime.length<2) return false;
			hh = parseInt(arrTime[0]);
			mm = parseInt(arrTime[1]);
	
			if (!isPositiveInteger(hh) || hh<0 || hh>=24) return false;
			if (!isPositiveInteger(mm) || mm<0 || mm>60) return false;

			ss = parseInt(arrTime[2])
			if (!isPositiveInteger(ss) || ss<0 || ss>60) return false; 
		}
		catch(e)
		{
			return false;
		}
	}
	return true;
}

/*
'********************************************************************* 
' Name:  isLongDate
' Created date: 7/31/2003 
' Created by:   Keiji Ikuta
' Purpose:      
' Inputs:
' Outputs:
' Notes:     
' Update date:
' Update by:
'********************************************************************* 
*/
function isPhoneNumber(value)
{
	var rc=true;
	if(value!="")
	{
		var aVal=value.split('-');
		if(aVal.length==3)
		{
			if( !(aVal[0].length==3 && isPositiveInteger(aVal[0])) ) rc=false;
			if( !(aVal[1].length==3 && isPositiveInteger(aVal[1])) ) rc=false;
			if( !(aVal[2].length==4 && isPositiveInteger(aVal[2])) ) rc=false;
		}
		else
		{
			rc=false;	
		}
	}
	return rc;
}




/*
'********************************************************************* 
' Name:  CountCheckBoxChecked
' Created date: 8/1/2003 
' Created by:   Keiji Ikuta
' Purpose:      Count how muany check box is checked.
' Inputs:
' Outputs:
' Notes:     
' Update date:
' Update by:
'********************************************************************* 
*/
function CountCheckBoxChecked(strFieldName)
{
	var e2,k;
	var iChecked=0;
	e2=document.getElementsByName(strFieldName);
	for(k=0;k<e2.length;k++){
		if(e2[k].checked){
			//chkedItems=chkedItems+","+e2[k].value;
			iChecked++;
		}
	}//for k
	return iChecked;
}

/*
'********************************************************************* 
' Name:			GetMSXmlHttp
' Created date: 5/28/10
' Created by:   Tim French
' Purpose:      Adds Functionality for getting Reference to XMLHTTPRequest
'				Across multiple browsers. 
' Inputs:
' Outputs:
' Notes: for RCOM-52; Supports ClearForm 

'********************************************************************* 
*/
// Subfunction. Supports GetMSXmlHttp
function CreateXmlHttp(clsid)
{
    var xmlHttp = null;
    try
    {
        xmlHttp = new ActiveXObject(clsid);
        lastclsid = clsid;
        return xmlHttp;
    }
    catch (e) { }
}
function GetMSXmlHttp()
{
    var xmlHttp = null;
    var clsids = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0",
                 "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0",
                 "Msxml2.XMLHTTP.2.6", "Microsoft.XMLHTTP.1.0",
                 "Microsoft.XMLHTTP.1", "Microsoft.XMLHTTP"];
    for (var i = 0; i < clsids.length && xmlHttp == null; i++)
    {
        xmlHttp = CreateXmlHttp(clsids[i]);
    }
    return xmlHttp;
}

/*
'********************************************************************* 
' Name:			ClearForm
' Created date: 8/11/2003
' Created by:   Jason Olson
' Purpose:      Clear all form elements and restore to original values.
'				For multiple selects, just reset to the first option.
' Inputs:
' Outputs:
' Notes:     
' Update date: 5/28/10
' Update by: Tim French
' Notes: RCOM-52: clear state box first
'********************************************************************* 
*/
function ClearForm(form)
{
    // Added: RCOM-52
    // clear Session First
    var oReq = null;
    if (!window.XMLHttpRequest)
    {
        // Old Microsoft
        oReq = GetMSXmlHttp();
    }
    else
    {
        oReq = new XMLHttpRequest();
    }
    oReq.open("POST", "../include/inc_form_Clear.asp", false);
    oReq.send();
    var i = oReq.status;
    if (oReq.status != 200)
        alert("XMLHttpRequest Error:" + oReq.status + "(" + oReq.statusText + ")");

    // Clear State for Quick Search by removing url parameters
    var url = window.location.toString().split("?"); //RCOM-62 DavB adjusted url for location
    window.location = url[0];
    return;  
    // end of ADD for RCOM-52
    // REMOVED, RCOM-52
//    
//    // Cycle through the rest    
//	for (var i = 0; i < form.elements.length; i++)
//	{
//		var curElement = form.elements[i];
//        
//		// uncheck all checkboxes
//		if (curElement.type == "checkbox")
//		{
//			curElement.checked = false;
//		}
//		
//		// clear all textboxes
//		if (curElement.type == "text" || curElement.type == "textarea")
//		{
//			curElement.value = "";
//		}
//		
//		// reset option lists
//		if (curElement.type == "select-one" || curElement.type == "select-multiple")
//		{
//			for (var j = 0; j < curElement.options.length; j++)
//			{
//				curElement.options[j].selected = false;
//			}
//			curElement.options[0].selected = true;
//		}
//		
//		// reset radio buttons
//		if (curElement.type == "radio")
//		{
//			for (var j = 0; j < curElement.length; j++)
//			{
//				curElement[j].checked = false;
//			}
//		}
//	}
}


// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}
