/*
	11/18/2005
	kristine manzano
*/

function focusOn(formName, elemName) {
	var elem = document.forms[formName].elements[elemName];
	elem.focus( );
	elem.select( );
}

// validates MIN 
function checkMIN(objName) {
	var strNum = objName.value;
	pattern =/^(\+?63|0)?(\(?(9\d\d)\)?)(-| )?(\d{3})(-| )?(\d{4})$/g;
	var hasMatch = strNum.match(pattern);	
	if (!hasMatch)	{
		alert("Please enter a valid Mobile Number.");
		setTimeout("focusOn('" + objName.form.name + "', '" + objName.name + "')", 0);
		return false;
	}
	else {
		var strCleanNum = strNum;

		var chrStart=strNum.charAt(0);
		
		if (chrStart == '(') {
		strCleanNum = strNum.replace('((', '(');
		strCleanNum = strNum.replace('))', ')');
		strCleanNum = strNum.replace(pattern, '$2'+'$5'+'-'+'$7');
		objName.value=strCleanNum;
		
		}

		else {
		strCleanNum = strNum.replace(pattern, '('+'$2'+')'+'$5'+'-'+'$7');
		objName.value=strCleanNum;

		}
	}
	
}

// validates Telephone # 
function checkTel(objName) {
	var strTel = objName.value;
	pattern =/^([2-9]\d{2})(-| )?(\d{4})$/g;
	
	var hasMatch = strTel.match(pattern);	
	if (!hasMatch)	{
		alert("Please enter a valid Telephone Number.");
		setTimeout("focusOn('" + objName.form.name + "', '" + objName.name + "')", 0);
		return false;
	}
	else {
		var strCleanNum = strTel;

		strCleanNum = strTel.replace(pattern, '$1'+'-'+'$3');
		objName.value=strCleanNum;
				
		return true;
	}
	
}

//verify if either Mobile No or Tel # has something
function checkTelInfo(aspxForm) {
	
	var intindex = aspxForm.txtMobileNo.value.length + aspxForm.txtHomePhone.value.length + aspxForm.txtOfficePhone.value.length;	
	if (intindex == 0)	{
		alert("Please enter value for either Mobile No. or Home Phone No. or Office Phone No.");
		aspxForm.txtMobileNo.focus();
		return false;
	}
	
	else {
		
		return true;
	}
}

//validate form
function validateForm(aspxForm) {
	if (checkTelInfo(aspxForm) == false) {
		return false;
	}
	
	else {
		return true;
	}
}