			function emailIsValid(email){return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9]{1,25}\.)+[a-z]{2,4}$/i).test(email);}
			// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
			function checkInternationalPhone(strPhone){
				var bracket=3
				
				strPhone=trim(strPhone)
				//alert(strPhone.indexOf("("))
				if(strPhone.indexOf("+")>1) return false
				if(strPhone.indexOf("-")!=-1)bracket=bracket+1
				if(strPhone.indexOf("(")!=0 && strPhone.indexOf("(")>bracket)return false
				var brchr=strPhone.indexOf("(")
				//alert(strPhone.charAt(brchr+2));
				//if(strPhone.indexOf("(")!=0 && strPhone.charAt(brchr+4)!=")")return false
				//if(strPhone.indexOf("(")==0 && strPhone.indexOf(")")!=-4)return false
				s=stripCharsInBag(strPhone,validWorldPhoneChars);
				return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
			}
			function sendMail(s){
				
				if(s == 1){
					var name = $('#sname');
					var email = $('#semail');
					var phone = $('#sphone');
					var text = $('#stext');
					
					$('.sinput').css('border', '1px solid #87888A');

				}else{
					var name = $('#name');
					var email = $('#email');
					var phone = $('#phone');
					var text = $('#text');
					
					$('.input').css('border', '1px solid #87888A');
				}
				var errors = 0;
				if(name.val() == ''){
					errors++;
					name.css('border', '1px solid red');
				}
				if(email.val() == ''){
					errors++;
					email.css('border', '1px solid red');
				}else if(!emailIsValid(email.val())){
					errors++;
					email.css('border', '1px solid red');
				}
				if(phone.val() == ''){
					errors++;
					phone.css('border', '1px solid red');
				}else if(checkInternationalPhone(phone.val())==false){
					errors++;
					phone.css('border', '1px solid red');
				
				}
				if(text.val() == ''){
					errors++;
					text.css('border', '1px solid red');
				}
				//errors++;
				if(errors == 0){
				
					if(s == 1){
						$('#sajax').show();
						var data = "name="+name.val()+"&email="+email.val()+"&phone="+phone.val()+"&text="+text.val()+"&s=true";
						$('#sformDiv').fadeTo(500, 0.2);
					}else{
						$('#ajax').show();
						var data = "name="+name.val()+"&email="+email.val()+"&phone="+phone.val()+"&text="+text.val();
						$('#formDiv').fadeTo(500, 0.2);
					}
					$.ajax({
					   type: "POST",
					   url: "/smail.php",
					   data: data,
					   success: function(msg){
							if(msg == 'true'){
								if(s == 1){
									$('#sajax').hide();
									$('#sformDiv').hide();
									$('#sajaxSuccess').show();
								}else{
									$('#mailText').hide();
									$('#ajax').hide();
									$('#formDiv').hide();
									$('#ajaxSuccess').show();
								}
							}else{
								if(s == 1){
									$('#sajax').hide();
									$('#formDiv').fadeTo(500, 1, function (){
										$('#sajaxFaild').show();
									});
								}else{
									$('#sajax').hide();
									$('#sformDiv').fadeTo(500, 1, function (){
										$('#sajaxFaild').show();
									});
								}
							}
					   },
					   error: function (){
							if(s == 1){
									$('#sajax').hide();
									$('#formDiv').fadeTo(500, 1, function (){
										$('#sajaxFaild').show();
									});
								}else{
									$('#sajax').hide();
									$('#sformDiv').fadeTo(500, 1, function (){
										$('#sajaxFaild').show();
									});
								}
					   }
					});
					
				}
	}

