function make_phone(obj)
{

	if(navigator.userAgent.indexOf( "Safari" ) < 0)
	{

	    if (obj.value == "") return;

	    var phone = new String (obj.value);

	    phone = phone.substring(0,14);

	    if (phone.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
	    {

	        if (phone.match (".[0-9]{2}.[0-9]{3}-[0-9]{4}|" + ".[0-9].[0-9]{3}-[0-9]{4}|" +
	            ".[0-9]{3}.[0-9]{2}-[0-9]{4}|" + ".[0-9]{3}.[0-9]-[0-9]{4}") == null)
	        {

	            var phoneNumeric = phoneChar = "", i;
	            for (i=0;i<phone.length;i++)
	            {
	                phoneChar = phone.substr (i,1);
	                if (!isNaN (phoneChar) && (phoneChar != " ")) phoneNumeric = phoneNumeric + phoneChar;
	            }

	            phone = "";
	            for (i=0;i<phoneNumeric.length;i++)
	            {
	                if (i == 0) phone = phone + "(";
	                if (i == 3) phone = phone + ") ";
	                if (i == 6) phone = phone + "-";
	                phone = phone + phoneNumeric.substr (i,1)
	            }
	        }
	    }
	    else
	    {
	        phone = "(" + phone.substring (1,4) + ") " + phone.substring (5,8) + "-" + phone.substring(9,13);
	    }
	    if (phone != obj.value) obj.value = phone;
	}

}

function show_numeric(event)
{
	 if (!event) {event = window.event;}
        var k = event.keyCode;

        if ((k < 48 || (k > 57 && k < 96) || k > 105) && k != 8 && k != 9 && k != 46)
           if (event.preventDefault)
            event.preventDefault()
           else
            event.returnValue= false
           return false
}

function isValidEmail (email, strict)
{
	 if ( !strict ) email = email.replace(/^\s+|\s+$/g, '');
	 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function send(id,snd,name,phone,email,notes)
{
	var errs='';
	if(name==''||phone==''||email=='')
		errs+='Please specify fields marked with *\n';
	if(!isValidEmail(email))
		errs+='Please correct email\n';


	if(errs!='')
	{
		alert(errs);
		return false;
	}
	document.getElementById(snd).disabled='disabled';
	jQuery("#"+id).html('Please wait...');

	jQuery.ajax({
   				type: "POST",
   				url: "/ajax.php",
   				data: "name="+name+"&phone="+phone+"&email="+email+"&notes="+notes+"&rand=" + Math.random(),
   				success: function(data){
     				jQuery("#"+id).html(data);
     				document.getElementById(snd).disabled='';
     				jQuery.unblockUI();
   				}
 			});
}
