var UrlParameters = "";

function onMouseOverEvent(Obj){
	Obj.style.cursor='pointer';
	if(onMouseOverEvent.arguments[1]){
		Obj.className=onMouseOverEvent.arguments[1];
	}
}
function onMouseOutEvent(Obj){
	Obj.style.cursor='';
	if(onMouseOutEvent.arguments[1]){
		Obj.className=onMouseOutEvent.arguments[1];
	}
}
function onClickEvent(Obj){
	return location.href=Obj;
}
function popUpWindow(url){
	if(popUpWindow.arguments[1]){
		window.open(url,"EventViewer","height=" + popUpWindow.arguments[1] + ",width=" + popUpWindow.arguments[2] +",'directories=no,resizable=no,scrollbars=yes,menubar=no,toolbar=no,top=0,left=0'")
	}
	else{
		window.open(url,"EventViewer","'height=700,width=600,resizable=no,scrollbars=yes,menubar=no,toolbar=no,top=0,left=0'")
	}
}
function CheckForm(FormName, Action){
	var d_form = document.getElementById(FormName).elements;

	for(var formCount=0;formCount<d_form.length;formCount++){
		// Only validate if required
		if(d_form[formCount].type!="hidden"){
			
			if( (d_form[formCount].id.indexOf("req__") != -1 || d_form[formCount].name.indexOf("req__") != -1) ){
				if(d_form[formCount].type.indexOf("radio") != -1 || d_form[formCount].type.indexOf("checkbox") != -1){

					// search for a checked field
					if(d_form[formCount].type.indexOf("radio") !== -1){
						RadioGroup = d_form[formCount].id.replace("req__","");
						RadioValid = false;
						while(d_form[formCount].name==RadioGroup){
							if(d_form[formCount].checked){
								if(UrlParameters == ""){
									UrlParameters = RadioGroup + "=" + escape(d_form[formCount].value);
								}
								else{
									UrlParameters += "&" + RadioGroup + "=" + escape(d_form[formCount].value);
								}
								RadioValid=true;
							}
							// check next field
							formCount++;
						}
						// checked break loop
						if(!RadioValid){
							alert("Please select a \"" + RadioGroup.replace(/[_]/g," ") + "\"");
							UrlParameters = "";
							return false;
						}
						// move back to current id
						formCount--;
					}
					else if(d_form[formCount].type.indexOf("checkbox") !== -1){
						CheckBoxGroup = d_form[formCount].id.replace("req__","")
						CheckBoxCount = 1;
						CheckBoxValid = false;
					
						while(d_form[formCount].name==(CheckBoxGroup+"_"+CheckBoxCount)){
							if(d_form[formCount].checked){
								if(d_form[formCount].value != ""){
									if(UrlParameters == ""){
										UrlParameters = (CheckBoxGroup+"_"+CheckBoxCount) + "=" + escape(d_form[formCount].value);
									}
									else{
										UrlParameters = UrlParameters + "&" + (CheckBoxGroup+"_"+CheckBoxCount) + "=" + escape(d_form[formCount].value);
									}
								}
								else{
									// search for check box value
									CheckBoxGroup_OtherAnswer = (CheckBoxGroup+"_"+CheckBoxCount);
									CheckBoxGroup_OtherAnswerCount = 1;
									CheckBoxGroup_OtherAnswerValid = false;
									if(d_form[(CheckBoxGroup_OtherAnswer+"_"+CheckBoxGroup_OtherAnswerCount+"_DO_NOT_INCLUDE")]){
										if(d_form[(CheckBoxGroup_OtherAnswer+"_"+CheckBoxGroup_OtherAnswerCount+"_DO_NOT_INCLUDE")].value!=""){
											if(UrlParameters == ""){
												UrlParameters = (CheckBoxGroup_OtherAnswer) + "=" + escape(d_form[(CheckBoxGroup_OtherAnswer+"_"+CheckBoxGroup_OtherAnswerCount+"_DO_NOT_INCLUDE")].value);
											}
											else{
												UrlParameters = UrlParameters + "&" + (CheckBoxGroup_OtherAnswer) + "=" + escape(d_form[(CheckBoxGroup_OtherAnswer+"_"+CheckBoxGroup_OtherAnswerCount+"_DO_NOT_INCLUDE")].value);
											}
											CheckBoxGroup_OtherAnswerValid = true;
										}
									}
									// missing value
									if(!CheckBoxGroup_OtherAnswerValid){
										alert("Please fill in the information for " + CheckBoxGroup);
										d_form[(CheckBoxGroup_OtherAnswer+"_"+CheckBoxGroup_OtherAnswerCount+"_DO_NOT_INCLUDE")].focus();
										UrlParameters = "";
										return false;
									}
								}
								CheckBoxValid = true;
							}
							// checke next field
							formCount++;
							CheckBoxCount++;
						}
						// missing value
						if(!CheckBoxValid){
							alert("Please select a " + CheckBoxGroup);
							UrlParameters = "";
							return false;
						}						
					}
				}
				else{
					if(d_form[formCount].value==""){
						alert("Please enter data for \"" + d_form[formCount].id.replace("req__","").replace(/[_]/g," ") + "\"");
						UrlParameters = "";
						return false;
					}
					else{
						if(UrlParameters == ""){
							UrlParameters = d_form[formCount].id.replace("req__","") + "=" + escape(d_form[formCount].value);
						}
						else{
							UrlParameters += "&" + d_form[formCount].id.replace("req__","") + "=" + escape(d_form[formCount].value);
						}
					}
				}
			}
			else if ( d_form[formCount].name.indexOf("DO_NOT_INCLUDE") == -1){
				if( d_form[formCount].type.indexOf("radio") != -1 || d_form[formCount].type.indexOf("checkbox") != -1 ){
					if(d_form[formCount].checked){
						if(UrlParameters == ""){
							UrlParameters = d_form[formCount].id + "=" + d_form[formCount].checked;
						}
						else{
							UrlParameters += "&" + d_form[formCount].id + "=" + d_form[formCount].checked;
						}
					}
				}
				else{				
					UrlParameters += (UrlParameters == "") ? d_form[formCount].id + "=" + escape(d_form[formCount].value) : "&" + d_form[formCount].id + "=" + escape(d_form[formCount].value);
				}
			}
		}
		else{
			// store hidden values
			UrlParameters += (UrlParameters == "") ? d_form[formCount].id + "=" + escape(d_form[formCount].value) : "&" + d_form[formCount].id + "=" + escape(d_form[formCount].value);
		}		
	}
	if(CheckForm.arguments[2]){
		if(CheckForm.arguments[2] == 'Prompt'){
			if(confirm("There were no errors on the form, are you sure you want to submit now?")){
				location.href = Action + "?" + UrlParameters;
				return false;
			}
			else{
				UrlParameters = "";	
			}
		}
		else{
			return true;
		}
	}
	else{
		location.href = Action + "?" + UrlParameters;
	}
	return false;
}
function ValidateForm(FormName){
	d_form = document.getElementById(FormName).elements;
	len = ValidateForm.arguments.length;
	for(i=1;i<len;i++){
		Obj = ValidateForm.arguments[i].split(';');
		ID = Obj[0];
		Type =  Obj[1].toUpperCase();
		ErrorMessage = "";
		switch(Type){
			case 'EMAIL': 
						IsValid = ValidateEmail(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Email Address.";
						break;
			case 'NUMERIC': 
						IsValid = IsNumeric(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Numeric Value.";
						break;
			case 'PHONE':
						IsValid = ValidatePhone_WithoutParaAreaCode(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Phone Number.";
						break; 
			case 'PHONEPARA':
						IsValid = ValidatePhone_WithParaAreaCode(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Phone Number.";
						break; 
			case 'DATE':
						IsValid = ValidateDate(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Date.";
						break; 
			case 'FOURDIGITYEAR':
						IsValid = ValidateFourDigitYear(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Four Digit Year.";
						break; 
			case 'TIME':
						IsValid = ValidateTime(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Time.";
						break; 
			case 'SSN':
						IsValid = ValidateSSN_Dashed(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Social Security.";
						break;
			case 'CURRENCY':
						IsValid = ValidateCurrency(d_form[ID].value);
						ErrorMessage = "Please Enter A Valid Currency (e.g. X.XX)";
						break;	
		}
		if(IsValid==false){
			alert(ErrorMessage);
			d_form[ID].focus();
			return false;
		}
	}
	return true;
}
function FormatForm(FormName){
	d_form = document.getElementById(FormName).elements;
	len = FormatForm.arguments.length;
	for(i=1;i<len;i++){
		Obj = FormatForm.arguments[i].split(';');
		ID = Obj[0];
		Type =  Obj[1].toUpperCase();
		switch(Type){
			case 'TEXT': 
						d_form[ID].value=Format_FormattedText(d_form[ID].value);
						break;
			case 'TEXTAREA': 
						d_form[ID].value=Format_TextArea(d_form[ID].value);
						break;
			case 'PHONE':
						d_form[ID].value = Format_PhoneNumber(d_form[ID].value);
						break; 
			case 'SSN':
						d_form[ID].value = Format_SSN_Dashed(d_form[ID].value);
						break;
		}
	}
	return true;	
}

