
		

NS4 = (document.layers) ? true : false
IE4 = (document.all) ? true : false

function ValidatePhone(p1) {
	
	var keycode;
	var strName = navigator.appName;

	if (NS4) keycode = e.which;
	else if (IE4) keycode = window.event.keyCode;
	else if (docom) keycode = e.keyCode;
		
	var blnValidKey = false;
	if ((keycode != 8) && (keycode != 46) && (keycode != 37) && (keycode != 39)) {
		blnValidKey = true;
	}
	
	
	if (blnValidKey == true) {
		var phoneChar = new RegExp("[^0-9a-z\-]", "g");
		p = p1.value;
		p = p.replace(phoneChar, '');    
			
		if (p.length < 4) {
			pp1 = p.substring(0, 3);
			pp2 = p.substring(4, p.length);
			if (pp1.indexOf('-') > -1) {
				pp1 = pp1.replace('-', '');
			}
			p = pp1 + pp2;
		}
		
		if (p.length > 2) {
			if (p.indexOf('-') != 3) {
				pp1 = p.substring(0, 3);
				pp2 = p.substring(4, p.length)
				p = pp1 + '-' + pp2;


			}
		}

		if ((p.length > 4)) {
			pp1 = '';
			pp2 = '';
			pp3 = '';
			pp1 = p.substring(0, 4);
			pp2 = p.substring(4, 7);
			pp3 = p.substring(7, p.length);
			
			
			if (pp2.indexOf('-') > -1) {
				pp2 = pp2.replace('-', '');
			}
			//alert(pp1 + ' : ' + pp2 + ' : ' + pp3)
			p = pp1 + pp2 + pp3;
		}
		
		if (p.length > 6) {
			if (p.indexOf('-') != 7) {
				pp1 = p.substring(0, 7);
				pp2 = p.substring(8, p.length)
				p = pp1 + '-' + pp2;


			}
		}
		if ((p.length > 7)) {
			pp1 = '';
			pp2 = '';
			pp3 = '';
			pp1 = p.substring(0, 8);
			pp2 = p.substring(8, p.length);
			
			if (pp2.indexOf('-') > -1) {
				pp2 = pp2.replace('-', '');
			}
			//alert(pp1 + ' : ' + pp2)
			p = pp1 + pp2;
		}
		
		p1.value = p;
		
	}
}

		
		