//<!--
//alert ("Validation Functions Included");
function isValidFileType()
{
	try
	{
	oElement		= window.event.srcElement;
	strAccepted		= oElement.getAttribute("acceptedContent");
	oPlaceholder	= oElement.previousSibling;
	oValue			= oElement.value;
	iAttributes		= oElement.attributes.length
	strFileType		= oValue.slice(oValue.lastIndexOf('.')+1,oValue.length);
		
	if (strAccepted.indexOf(strFileType.toLowerCase())==-1)
	{
		oReplacement	= document.createElement("input")
		oReplacement.attachEvent("onchange",isValidFileType)
		oReplacement.setAttribute("acceptedContent",strAccepted);
		oReplacement.type="file";
		for (index=0;index < iAttributes-1;index++)
		{ 
			if ((oElement.attributes(index).value) != (oReplacement.attributes(index).value))
			{
			oReplacement.setAttribute(oElement.attributes(index).name,oElement.attributes(index).value)
			}
		}
		oElement.removeNode(true);
		oPlaceholder.insertAdjacentElement("afterEnd", oReplacement );
		if(confirm('The file you have selected does not appear to be of the correct type.\n Files with the following extensions are acceptable\n\n'+ strAccepted +'\n\nClick OK to select a different file or Cancel to return to the page'))
			{
			var strExec = 'document.getElementById(\'' + oElement.id + '\').click();';
			window.setTimeout(strExec,1);
			}		
		}
	}
	catch(Err)
	{
	handleError(Err);
	}
}



function isValidDate(oDate)
{
var dteDate;
var day, year, month;
day = document.getElementById(oDate +'_dd').value;
month = document.getElementById(oDate +'_mm').value-1;
year = document.getElementById(oDate +'_yy').value;
dteDate=new Date(year,month,day);

//alert(year +' '+ month +' '+ day)
setSelect(oDate +'_dd',dteDate.getDate());
setSelect(oDate +'_mm',dteDate.getMonth()+1);
setSelect(oDate +'_yy',dteDate.getFullYear());
//alert(year +' '+ month +' '+ day)
}

function validate(oForm,verbose){
index=0;
var message='';
var loop=1;
var Style;
var validForm=true;
var validField=false;
var oTest;
var nElements=oForm.elements.length;
var formfeedback=oForm.getAttribute("feedback");
while(index<nElements){
oTest=oForm.elements[index];
type=oTest.type;
customScript=oTest.getAttribute("customScript");
name=oTest.getAttribute("name");
field=oTest.value;
fieldfeedback=oTest.getAttribute("feedback");
max=oTest.getAttribute("max");
min=oTest.getAttribute("min");
vtype=oTest.getAttribute("vtype");
vname=oTest.getAttribute("vname");
dField=oTest.getAttribute("dfield");
dValue=oTest.getAttribute("dvalue");
mandatory=oTest.getAttribute("mandatory");
warning=oTest.getAttribute("warning");
validCustom=true;
validFormat=true;
validRange=true;
validChars=true;
validMandatory=true;
validSelect=true;
validRadio=true;
if(customScript!=null){
validCustom=(eval(customScript))}
else{
validCustom='true';
if(dField!=null){
var dVal=eval("document.getElementById('"+dField+"')")
if(dVal.type=='radio'||dVal.type=='select-one'||dVal.type=='checkbox'){
var dStatus =(dValue=='true') 
if(dVal.status==dStatus)
mandatory='true'
else
mandatory='false'}		
else{
if(!isEmpty(dVal.value))
mandatory='true'
else
mandatory='false'}}
switch(type){
case'password':
case'text':
case'textarea':
if(!isEmpty(field))	{
validChars=true;
switch(vtype){
case'text':
field=field.replace(/"/g,"`");
validFormat=true;
break;
case'numeric':
validFormat = (field.search(/^([-|+]){0,1}(\d){0,}(\.){0,1}(\d){0,}$/) !=-1);
break;
case'email':
validFormat=(field.search(/\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1);
break;
default:
validformat = true
break;
}			
switch(vtype){
case'numeric':
if(min!=null){
if(field.length<min){
validRange=false;
msgRange="\nIt is smaller then the minimum allowed value of "+min+"."}}
if(max!=null){
if(field.length>max){
validRange=false;
msgRange="\nIt is larger then the maximum allowed value of "+max+"."}}	
default:
if(min!=null){
if(field.length<min){
validRange=false;
msgRange="\nIt is smaller then the minimum allowed size of "+min+"."}}
if(max!=null){
if(field.length>max){
validRange=false;
msgRange="\nIt is larger then the maximum allowed size of "+max+"." }}}}		
else{
if(mandatory=='true')
validMandatory=false;}	
break;	
case'checkbox':
case'radio':
validRadio=false;
while(index<nElements){
oTest=oForm.elements[index];
if(oTest.name!=name){
index--
break;}
if(mandatory=='true')
validRadio=(validRadio||oTest.status);
else{
validRadio=true
validMandatory=true}
index++}
break;
case'hidden':		
case'button':		
break;
case'select-one':
if((oTest.selectedIndex==-1)||(oTest.value==''))
{
if(mandatory=='true')
validMandatory=false;
else
validMandatory=true;
}
else
validMandatory=true;
break;
default:
break;}}
validField=((validCustom=='true')&&validFormat&&validRange&&validChars&&validMandatory&&validRadio)
if(!validField){
if(formfeedback!='none'||fieldfeedback!=null){
message+='\nYou have not correctly filled in the '+vname+' field.'
if(!validChars)
//message+="\nIt contains invalid characters."
if(!validFormat)
message+="\n'+vname+' is not in the correct format."
if(!validRange)
//message+=msgRange
if(!validRadio)
//message+="\nDoes not have a value selected."
if(!validMandatory)
//message+="\n'+vname+' is a required field and does not appear to contain a value."
if(validCustom!='true')
message+=validCustom}}
if(!validField)
Style='#C8005D';
else
Style='';
switch(type){
case'select-one':
if(oTest.parentElement.tagName!='SPAN'){
var oMySelect=oTest;
var oNewSpan=document.createElement("SPAN");
oMySelect.parentElement.insertBefore(oNewSpan,oMySelect);
var oClone=oMySelect.cloneNode(true);
oNewSpan.insertAdjacentElement("afterbegin",oClone);
oMySelect.removeNode(true);
oClone.selectedIndex =oMySelect.selectedIndex;}
else
oNewSpan=oTest.parentElement
if(!validField)
oNewSpan.style.border="2px solid "+Style;
else
oNewSpan.style.border="none"
break;
default:
oForm.elements[index].style.borderColor=Style;
break;}
validForm=(validForm&&(validField||(warning=='true')))
if((formfeedback=='incremental'||fieldfeedback=='incremental')&&!validField)
break;
index++}
//if(!verbose)
//return true;
if(validForm)
return validForm;
else{
if(formfeedback!='none'||fieldfeedback=='incremental'){
message+='\nPlease correct the appropriate entries and resubmit.'
alert(message)}
return validForm;}}
function isEmpty(str){
if(str.length==0){
return true;}
if(str.search(/\S/)==-1){
return true;}
return false;}


function handleError(Err)
{
alert('An Error Occurred - \n\n' + Err.description)
}



function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
} 


function setSelect(selectID,strValue)
{
 
  var select =  document.getElementById(selectID);
  
  for(var index=0; index<select.options.length;index++)
    {
        if(select.options[index].value == strValue)
        {
        //alert('option:'+select.options[index].value);
        select.selectedIndex = index;
        }
    } 
}

function stripHTML(oldString) {

  return oldString.replace(/<&#91;^>&#93;*>/g, "");
  
}
//-->
