﻿/*Validate phone number javascirpt*/
/**
* DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/

// 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 = 12;
*/
/*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)
    if (strPhone.indexOf("+") > 1) return false
    if (strPhone.indexOf("-") != -1) bracket = bracket + 1
    if (strPhone.indexOf("(") != -1 && strPhone.indexOf("(") > bracket) return false
    var brchr = strPhone.indexOf("(");
    if (strPhone.indexOf("(") != -1 && strPhone.charAt(brchr + 2) != ")") return false
    if (strPhone.indexOf("(") == -1 && strPhone.indexOf(")") != -1) return false
    s = stripCharsInBag(strPhone, validWorldPhoneChars);
    return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}*/

/*function ValidateForm() {
    var Phone = document.getElementById('txtPhone');

    if ((Phone.value == null) || (Phone.value == "")) {
        alert("Please Enter your Phone Number");
        Phone.focus();
        return false;
    }
    if (checkInternationalPhone(Phone.value) == false) {
        alert("Please Enter a Valid Phone Number");
        Phone.value = "";
        Phone.focus();
        return false
    }
    return true
}*/


/*
    Vatidate javascript for relevant field
*/

function validate(str) {

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(str) == false) {
        return false;
    }
}

function submitQC1(e) {
    try {
        var k = window.event ? event.keyCode : e.keyCode;
        if (k == 13) {
            if (verify1()) {
                //if(ValidateForm())
                //{
                    document.frmQuickContact.submit();
                    
                //}
                //else 
                    //return false;
            }
            else
                return false;
        }
    }
    catch (e) { alert(e); return false; }
}
function submitQC2(e) {
    try {

        if (verify1()) {
            //if (ValidateForm())
            //{
                document.getElementById('frmQuickContact').submit();
             //}
             //else
                //return false;
        }
        else
            return false;

    }
    catch (e) { alert(e); return false; }
}
function verify1() {
    var themessage = "You are required to complete the following fields: ";
    var nm = document.getElementById('txtName').value;
    var phone = document.getElementById('txtPhone').value;
    var email = document.getElementById('txtEmail').value;
    var contact = document.getElementById('txtCompany').value;
    var comments = document.getElementById('txtComment').value;
    var res = true;
    if ((nm.value == '') && (email.value == '') && (comments.value == '') && (phone.value == '') && (contact.value == '')) {
        alert("First Fill All Details...");
        document.form1.txtname.focus();
        return false;
    }
    else {
        if (nm.value == '') {
            alert("Name Field can not be blank");
            document.getElementById('txtEmail').focus();
            return false;
        }

        var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
        var emailid = document.getElementById('txtEmail').value;
        var matcharray = emailid.match(emailPat);
        if (matcharray == null) {
            alert("Email Address seems incorrect. Please Try Again.");
            document.getElementById('txtEmail').focus();
            return false;
        }

        if (comments.value == '') {
            alert("Requirement Field can not be blank...");
            document.getElementById('txtComment').focus();
            return false;
        }
        if (contact.value == '') {
            alert("Requirement Field can not be blank...");
            document.getElementById('txtCompany').focus();
            return false;
        }
        var check = true;
        var value = document.getElementById('txtPhone').value;

        for (var i = 0; i < phone.length; ++i) {
            var new_key = value.charAt(i);
            if (((new_key < '0') || (new_key > '9')) && !(new_key == '')) {
                check = false;
                alert("Phone Number Not Valid...");
                document.getElementById('txtPhone').focus();
                return false;
            }
        }
    }
    alert("Mail Send Successfully...");
    return true;
    /*if (nm.length <= 1) {
        themessage = themessage + " - Name";
        res = false;
    }
    if (phone.length <= 1) {
        themessage = themessage + " - Phone";
        res = false;
    }
    if (email.length <= 1) {
        themessage = themessage + " -  Email";
        res = false;
    }
    if (email.length > 1) {
        if (validate(email) == false) {
            themessage = themessage + " -  Email in proper format";
            res = false;
        }
    }
    if (contact.length <= 1) {
        themessage = themessage + " -  Company Address";
        res = false;
    }
    if (comments.length <= 1) {
        themessage = themessage + " -  Comments";
        res = false;
    }
    if (res) {
        return true;
    }
    else {
        alert(themessage);
        //nm.focus();
        return false;
    }*/
}
function thankyou() {
    var themessage = "Thank you.";
    alert(themessage);
    return true;
}
       

