/* <![CDATA[ */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
//*************************************************************
function attachEventListener(target,eventType,functionRef,capture){
	if(target==null){return}
	if (typeof(target.attachEvent) != "undefined") {
		//Man, I hate IE
		var functionString=eventType+functionRef;
		target["e"+functionString]=functionRef;
		target[functionString]=function(event){
			if(typeof event=='undefined'){
				event=window.event;
			}
			target["e"+functionString](event);
		};
		target.attachEvent("on"+eventType,target[functionString]);
	} else if (typeof target.addEventListener != "undefined") {
		target.addEventListener(eventType,functionRef,capture);
	}
}
//*************************************************************
String.prototype.ucFirst = function () {
   return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}
//*************************************************************
function cancelEvent(event){
	if (event.cancelable){
		event.preventDefault();// DOM style
	}
	event.returnValue=false;//IE
}
//*************************************************************
function getEventTarget(event){
	var targetElement=null;
	if(typeof event.target!="undefined"){
		targetElement=event.target;
	}else{
		targetElement=event.srcElement;
	}
	while(targetElement.nodeType==3 && targetElement.parentNode!=null){
		targetElement=targetElement.parentNode;
	}
	return targetElement;
}
//*************************************************************
function switchFieldset(whichfieldset){
	var fieldsets=document.getElementsByTagName('fieldset');
	for(var i=0; fieldsets.length>i; i++){
		if(fieldsets[i].className=='submit'){continue;}
		fieldsets[i].style.display='none';
	}
	document.getElementById(whichfieldset).style.display='';
	var buttons=document.getElementById('login_btns').getElementsByTagName('input');
	for(var i=0; buttons.length>i; i++){
		//buttons[i].removeAttribute('disabled');
		buttons[i].style.color='black';
	}
	//document.getElementById(whichfieldset+'_btn').setAttribute('disabled','disabled');	
	document.getElementById(whichfieldset+'_btn').style.color='gray';	
}
//*************************************************************
function limitText(limitField, limitNum) {
	// Limits a text field to specified length. truncates the rest
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}
//*************************************************************
function addSelectValidate(){
	    var check_input = document.getElementsByTagName('select');
	    var input_count = check_input.length;
	    for(var i=0; i<input_count; i++){
	        if(true == check_input[i].defaultselected || -1 == check_input[i].className.search(/ ?required/g )){continue}
	        attachEventListener(check_input[i],"blur",validateField,false);
	    }
	}
//*************************************************************	
addLoadEvent(addSelectValidate);
//*************************************************************	
function addInputValidate(){
	    var check_input = document.getElementsByTagName('input');
	    var input_count = check_input.length;
	    for(var i=0; i<input_count; i++){
	        if('text'!=check_input[i].type && 'password'!=check_input[i].type || -1 == check_input[i].className.search(/ ?required/g )){continue}
	        attachEventListener(check_input[i],"blur",validateField,false);
	    }
	}
//*************************************************************	
addLoadEvent(addInputValidate);
//*************************************************************	
function validateField(event){
	    var target = getEventTarget(event);
	    var targetLabel = target.previousSibling.previousSibling;
	    var errorMsgSpan = target.nextSibling.nextSibling;
	    if( true == validateValue(target)){
	        errorMsgSpan.innerHTML='* Required';
	        errorMsgSpan.className=errorMsgSpan.className.replace(/errorMsgRequired/g , '' );
	    }else{
	        errorMsgSpan.innerHTML=targetLabel.innerHTML+' is a required field.';
	        errorMsgSpan.className=errorMsgSpan.className+' errorMsgRequired';
	    }
	}
//*************************************************************	
function validateValue(target) {
	    //check for blank
	    if(''==target.value){return false;}
	    return true;
	}
//*************************************************************	
function addFormValidate(){
	    var forms = document.forms;
	    var forms_length = forms.length;
	    for(var i=0; i<forms_length; i++){
	        thisform = this;
	        attachEventListener(forms[i],"submit",validateForm,true);
	    }
	}
//*************************************************************	
addLoadEvent(addFormValidate);
//*************************************************************	
function validateForm(event){
	    var thisform = getEventTarget(event);
	    var stopSubmit=false;
	    for(var i=0; i<thisform.length; i++){
	        if('input' != thisform[i].nodeName.toLowerCase() || -1 == thisform[i].className.search(/ ?required/g )){continue;}
	        if(false == validateValue(thisform[i])){
	            var errorMsgSpan = thisform[i].nextSibling.nextSibling;
	            var targetLabel = thisform[i].previousSibling.previousSibling;
	            errorMsgSpan.className=errorMsgSpan.className+' errorMsgRequired';
	            errorMsgSpan.innerHTML=targetLabel.innerHTML+' is a required field.';
	            stopSubmit=true;
	        }
	    }
	    //if( true == stopSubmit){displayProblemIndicator();}
	    if( true == stopSubmit){cancelEvent(event);}
	}
//*************************************************************
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
//*************************************************************
function validateUsername(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address for the username.";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
//*************************************************************
function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\s_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.";
    } else if ((fld.value.length < 1) || (fld.value.length > 20)) {
        error = "The password is the wrong length.";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.";
        fld.style.background = 'Yellow';
	//} else if (!((fld.value.search(/[a-zA-Z]+/)==-1) || ((fld.value.search(/[0-9]+/)==-1)))) {
    //} else if (!((fld.value.search(/[a-zA-Z]+/)) && (fld.value.search(/[0-9]+/)))) {
	} else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}

//*************************************************************
function validateLogin(theForm) {
	var reason = "";

 	reason += validateUsername(theForm.username);
  	reason += validatePassword(theForm.password);
	
  if (reason != "") {
    alert ("Some fields need correction: " + reason + "");
    return false;
  }
  theForm.validuser.value = "Y"
  return true;

}
//*************************************************************
function chkpassmatch() {
	var passfld1 = document.getElementById("password").value;
	var passfld2 = document.getElementById("validpass").value;
	
	if (passfld1 == passfld2) {
		document.myprofile.submit();
		return true;
	} else {
	alert("Please check your spelling and verify again.");
	return false;
	}
}
//*************************************************************
function verifyPassword() {	
	document.getElementById("verifypass").style.display = "block";
	document.getElementById("changepass").type = "hidden";
}
//*************************************************************
function slideBox(linknum) {
	var itemset1 = document.getElementById("contentbox1");
	var itemset2 = document.getElementById("contentbox2");
	var itemset3 = document.getElementById("contentbox3");
	var itemset4 = document.getElementById("contentbox4");
	
	if (linknum == "1" && itemset1.style.display == "none") {
		itemset1.style.display = "block";
	} else if (linknum == "1" && itemset1.style.display == "block") {
		itemset1.style.display = "none";
	}

	if (linknum == "2" && itemset2.style.display == "none") {
		itemset2.style.display = "block";
	} else if (linknum == "2" && itemset2.style.display == "block") {
		itemset2.style.display = "none";
	}
	
	if (linknum == "3" && itemset3.style.display == "none") {
		itemset3.style.display = "block";
	} else if (linknum == "3" && itemset3.style.display == "block") {
		itemset3.style.display = "none";
	}
	
	if (linknum == "4" && itemset4.style.display == "none") {
		itemset4.style.display = "block";
	} else if (linknum == "4" && itemset4.style.display == "block") {
		itemset4.style.display = "none";
	}

}

function resetPage(chkupdflag) {
	if (chkupdflag == "Y") {
	alert("Thank you for the update. Please click OK to see your new status.");
	window.location.href = "member_login.php";
	}
}
	
/* ]]> */