﻿

//<!--
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
//-->

function el(id)
{
    return document.getElementById(id);
}


function cancelEvent(e)
{
   event.cancelBubble = true;
   event.returnValue = false;
   return false;
}
//-->
function showImage(URL)
{
return window.open("/showImage.asp?image="+URL,"","toolbar=no,resizeable=no");
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function shouldRedirect(URL) 
{
if (confirm("This page is currently set to redirect to '" + URL +"'.\n\nThis has been overridden because you are currently administering the site and have permission to change this setting.\n\n You can either follow the redirect (choose 'OK') or you can stay on this page (choose 'Cancel'). \n\n To change the current redirect setting, choose cancel then enter the metadata panel from the menu bar and change the page alias."))
{
location.href=URL;
}
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}



function swapClass (id,newClass)
{
document.getElementById(id).className  = newClass;
}


function getRidOfundefined(value)
{
if (value == undefined)
{
return '';
}
else
{
return value; 
}
}

//<!--
//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 replaceT(obj){
var newO=document.createElement('input');
newO.setAttribute('type','password');
newO.setAttribute('name',obj.getAttribute('name'));
newO.setAttribute('class',obj.getAttribute('class'));
newO.setAttribute('id',obj.getAttribute('id'));
obj.parentNode.replaceChild(newO,obj);
setTimeout("document.getElementById('"+newO.getAttribute('id')+"').focus();", 10);
}

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)
{
 // alert(selectID);
  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, "");
  
}
//-->