
function sendAction( actionURL ){
	document.form2.action = actionURL;
	document.form2.submit();
}

function validateParticipant( actionSuccess, manFields, showFields ){
	var error_message = "<br>";
	var email_error = "";
	var numeric_error = "";
	var email = document.getElementById("email").value;
	var ctr = 0;
	var ctr_num = 0;
	var ctr_num = 0;var ctr_track = 0;
	var ctr_radio = 0;
	
	var arrNewMan = new Array();
	var arrNewShow = new Array();
	var arrMan = manFields.split(", ");
	var arrShow = showFields.split(", ");
	
	var arr2str = "";
	var arr2strshow = "";
	var arrValue = "";
	
	for( c = 0; c < arrMan.length; c++ ){
		arrValue = arrMan[c].replace("{", "").replace("}", "").split("=")[0];
		arrNewMan[c] = arrValue;
	}
	
	for( d = 0; d < arrShow.length; d++ ){
		if( arrShow[d].split("=")[1] == 1 ){
			arrValue = arrShow[d].replace("{", "").replace("}", "").split("=")[0];
			arrNewShow[d] = arrValue;
		}
	}
	
	arr2str = arrNewMan.toString();
	arr2strshow = arrNewShow.toString();
	
	for( a = 0; a < document.getElementsByTagName("input").length; a++ ){
		if( document.getElementsByTagName("input")[a].type == "radio" ){
			ctr_radio++;
			if( document.getElementsByTagName("input")[a].checked == true && document.getElementsByTagName("input")[a].value == "Yes" ){
				ctr_track++;
			}
		}
	}
	
	//if( ctr_radio != 0 ){
	//	if( ctr_track == 0 ){
	//		error_message += "Please select at least one track you want to attend. <br>";
	//	}
	//}
	//About You
	if( arr2str.search("firstName") >= 0 && arr2strshow.search("firstName") >= 0 ){
		if( validateBlankValue('firstName') ){
			ctr++;
			error_message += "First Name";
		}
	}
	
	if( arr2str.search("lastName") >= 0 && arr2strshow.search("lastName") >= 0 ){
		if( validateBlankValue('lastName') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;	
			error_message += "Last Name";
		}
	}
	
	if( arr2str.search("email") >= 0 && arr2strshow.search("email") >= 0 ){
		if( validateBlankValue('email') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;	
			error_message += "Email";
		} else if( email.match("@") == null ){
			email_error += "Please input a valid email address. ";
		}
	}
	
	if( arr2str.search("phone") >= 0 && arr2strshow.search("phone") >= 0 ){
		if( validateBlankValue('phone') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;	
			error_message += "Phone";
		} else if( validateNumeric("phone") ) {
			if( ctr_num >= 1 ) numeric_error += ", ";
			ctr_num++;
			numeric_error += "Phone";
		}
	}
	
	if( arr2str.search("mobile") >= 0 && arr2strshow.search("mobile") >= 0 ){
		if( validateBlankValue('mobile') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;	
			error_message += "Mobile";
		} else if( validateNumeric("mobile") ) {
			if( ctr_num >= 1 ) numeric_error += ", ";
			ctr_num++;
			numeric_error += "Mobile";
		}
	}
	
	//About Your Company
	if( arr2str.search("companyName") >= 0 && arr2strshow.search("companyName") >= 0 ){
		if( validateBlankValue('companyName') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;
			error_message += "Company Name";
		}
	}
	if( arr2str.search("jobTitle") >= 0 && arr2strshow.search("jobTitle") >= 0 ){
		if( validateBlankValue('jobTitle') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;
			error_message += "Job Title";
		}
	}
	
	
	if( arr2str.search("employee") >= 0 && arr2strshow.search("employee") >= 0 ){
		if( validateBlankValue('employee') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;
			error_message += "Employee";
		}
	}

	if( arr2str.search("industrial") >= 0 && arr2strshow.search("industrial") >= 0 ){
		if( validateBlankValue('industrial') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;
			error_message += "Industry";
		}
	}
	
	//Additional Information
	if( arr2str.search("houseNo") >= 0 && arr2strshow.search("houseNo") >= 0 ){
		if( !validateBlankValue('houseNo') && validateNumeric("houseNo") ) {
			if( ctr_num >= 1 ) numeric_error += ", ";
			ctr_num++;
			numeric_error += "House Number"
		}
	}
	
	if( arr2str.search("unitNo") >= 0 && arr2strshow.search("unitNo") >= 0 ){
		if( !validateBlankValue('unitNo') && validateNumeric("unitNo") ) {
			if( ctr_num >= 1 ) numeric_error += ", ";
			ctr_num++;
			numeric_error += "Unit Number"
		}
	}
	
	if( arr2str.search("postal") >= 0 && arr2strshow.search("postal") >= 0 ){
		if( validateBlankValue('postal') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;
			error_message += "Postal Code";
		} else if( validateNumeric("postal") ) {
			if( ctr_num >= 1 ) numeric_error += ", ";
			ctr_num++;
			numeric_error += "Postal"
		}
	}
	
	if( arr2str.search("department") >= 0 && arr2strshow.search("department") >= 0 ){
		if( validateBlankValue('department') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;
			error_message += "Department";
		}
	}
	
	if( arr2str.search("decision") >= 0 && arr2strshow.search("decision") >= 0 ){
		if( validateBlankValue('decision') ){
			if( ctr >= 1 ) error_message += ", ";
			ctr++;
			error_message += "Decision";
		}
	}
	
	if( error_message != "<br>" ){
		if( ctr > 1 ){
			error_message += " are required.";
		} else if( ctr == 1 ) {
			error_message += " is required.";
		}
		
		if( numeric_error != "" ){
			error_message += "<br>" + numeric_error + " should be a number only.";
		}
		
		if( email_error != "" ){
			error_message += "<br>" + email_error;
		}
		
		printErrorMessage( error_message );
	} else {
		if( document.getElementById("agreedreceive").checked == true ){
			document.getElementById("agreedreceive").value = 1;
		} else {
			document.getElementById("agreedreceive").value = 0;
		}
		if( document.getElementById("agreedreceive_e-news").checked == true ){
			document.getElementById("agreedreceive_e-news").value = 1;
		} else {
			document.getElementById("agreedreceive_e-news").value = 0;
		}
		sendAction( actionSuccess + "&agreedreceive=" + document.getElementById("agreedreceive").value+"&agreedreceive_e-news=" + document.getElementById("agreedreceive_e-news").value );
	}
}

function unHide(){
	var frmDef = document.getElementById("uploadType");
	for( a = 0; a < frmDef.length; a++ ){
		if( frmDef.options[a].selected == true ){
			if(frmDef.options[a].value == 'upload'){
				//document.location.href = "upload_photo.jsp";
				document.form2.action = "upload_photo.jsp";
				document.form2.submit();
			} else {
				document.getElementById("external").style.display = "block";
			}
		}
	}
}


function unHide2(){
	var frmDef = document.getElementById("uploadType");
	for( a = 0; a < frmDef.length; a++ ){
		if( frmDef.options[a].selected == true ){
			if(frmDef.options[a].value == 'external'){
				//document.location.href = "posteventwriteup.jsp";
				document.form2.action = "posteventwriteup.jsp";
				document.form2.submit();
			}
		}
	}
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) 
field.value = field.value.substring(0, maxlimit);
else
cntfield.value = maxlimit - field.value.length;
}
