var isValid = true;
var focusObj = new Object();
var errStatus = false;
var errMsg = '<p class="ibm-ind-error ibm-error"><strong>If you do not want to provide us with the required information, please use the back button on your browser to return to the previous page.</strong></p><div class="ibm-rule ibm-error"><hr /></div>';
var errImg = '<img src="//www.ibm.com/i/v16/icons/error.gif" width="16" height="16" alt="" \/>';
//Verify common input field, such as text, select.
function isEmpty(oInput) {
	var oInput = '#' + oInput;
	jQuery(oInput).val(jQuery.trim(jQuery(oInput).val()));
	
	if (jQuery(oInput).val() == "") {
		jQuery(oInput).parents("p").children("label").addClass('ibm-error');
		jQuery(oInput).parents("p").children("span").append(errImg);
		isValid = false;
		if (focusObj == null){
			focusObj = jQuery(oInput);
		}
	} else {
		jQuery(oInput).parents("p").children("label").removeClass('ibm-error');			
	}
}
//Verify Checkbox and Radio button
function isChecked(oInput) {	
	if (jQuery("input[id^='"+oInput+"']:checked").length == 0) {
		jQuery("input[id^='"+oInput+"']").parents("span").parents("fieldset").children("legend").css('color','#F00');
		jQuery("input[id^='"+oInput+"']").parents("span").parents("fieldset").children("span").append(errImg);
		isValid = false;
		if (focusObj == null){
			focusObj = jQuery(oInput);
		}
	} else {
		jQuery("input[id^='"+oInput+"']").parents("span").parents("fieldset").children("legend").css('color','#000');
	}
}
//Verify Email address
function isEmail(oInput) {
	var reEmail = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/;
	var oInput = '#' + oInput;
	jQuery(oInput).val(jQuery.trim(jQuery(oInput).val()));
	
	if (jQuery(oInput).val() == "" || !reEmail.test(jQuery(oInput).val())) {
		jQuery(oInput).parents("p").children("label").addClass('ibm-error');
		jQuery(oInput).parents("p").children("span").append(errImg);
		isValid = false;
		if (focusObj == null){
			focusObj = jQuery(oInput);
		}
	} else {
		jQuery(oInput).parents("p").children("label").removeClass('ibm-error');
	}
}
//Verify number
function isNumber(oInput) {
	var reNumber=/[0-9\(\)-]+/;
	var oInput = '#' + oInput;
	jQuery(oInput).val(jQuery.trim(jQuery(oInput).val()));
	
	if (jQuery(oInput).val() == "" || !reNumber.test(jQuery(oInput).val())) {
		jQuery(oInput).parents("p").children("label").addClass('ibm-error');
		jQuery(oInput).parents("p").children("span").append(errImg);
		isValid = false;
		if (focusObj == null){
			focusObj = jQuery(oInput);
		}
	} else {
		jQuery(oInput).parents("p").children("label").removeClass('ibm-error');
	}
}
function beforeVerify() {
	focusObj = null;
	jQuery("img[src$='//www.ibm.com/i/v16/icons/error.gif']").remove();
}
function afterVerify(oForm) {
	if (focusObj != null) {
		focusObj.focus();
	}
	
	if (isValid) {
		jQuery('p').remove('.ibm-error');
		jQuery('div').remove('.ibm-error');
		return true;
	} else {
		if (errStatus == false) {
			oForm.prepend(errMsg);
			errStatus = true;
		}
		isValid = true;	
		return false;
	}
}
