/***************************************
* JavaScript function to validate US phone number:
*
* (c) 2003 Peter Kionga-Kamau, http://www.pmkmedia.com
* No restrictions have been placed on the use of this code
*
* Updated Friday Jan 9 2004 to optionally ignore the area code:
*
* Input: a single string parameter and an optional boolean variable (default=true)
* Output: boolean true(1) or false(0)
*
* The function will return true for any alphanumeric string with the following
* sequence of characters:  any number of spaces [optional], a single  open parentheses [optional], any number o
* spaces [optional], 3 digits (area  code), any number of spaces [optional], a  single close parentheses [optio
* dash [optional], any number of spaces  [optional], 3 digits, any number of spaces  [optional], a single dash
* number of spaces [optional], 4 digits, any  number of spaces [optional].
**************************************/

function check_usphone(phonenumber)
{
//alert('HEY ,'+phonenumber+' !');
if (((phonenumber.match(/^[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-]{0,1}[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null)
    && (phonenumber.match(/^[ ]*[0-9]{3,3}[ ]*[-]{0,1}[ ]*[0-9]{4,4}[ ]*$/)==null))) {
    return false;
}
//alert('TRUE ,'+phonenumber+'!');
return true;
}
        
/***********************************
*   Function Used to verify the email address that was entered
***********************************/

function  checkit_email()
{
    var cellcol = /yellow/i;
    var re2 = /none/i;
    box_email = document.form.email;
    answer_email =  box_email.value.search(re2);
    if ( answer_email > -1){
        box_email.style.background = "white";
        return (true);
    }
    answer_email =  box_email.style.background.search(cellcol)
//    alert ('HEY THERE THE CAT and the Filddle, email ' + box_email.value + ' !');
//    if ((focused) || ( who_set=="email") ){
        if( (!check_email(box_email.value)) ){// && (answer_email == -1) ) {
            alert("Invalid email detected.The format should be  yyy@xxxx.aa");
//            focused=false;
//            who_set ="email";
            box_email.style.background = "yellow";
//            box_email.focus()        
//            setTimeout("box_email.focus();",0);
//            return false;
        }
        answer = box_email.style.background.search(cellcol);
//        alert ('Hey ' + answer + ' ~ ' + box_email.style.background + ' !');
        if( (check_email(box_email.value))&& (answer > -1)  ) {
//          alert ('Thank you');
//            focused=true;
//            who_set ="";
            box_email.style.background = "white";
        }
//    }
}

/***********************************
*   Function Used to call ther verification routine to check email and phone number formats
***********************************/
function checkit_phone()
{
    var cellcol = /yellow/i;
    var re2 = /none/i;
    box_phone = document.form.phone;
    answer_phone =  box_phone.value.search(re2);
//    alert ('HEY THERE THE CAT and the Filddle, phone '+ answer  +'  !' + box_phone.value + '!!');
//   alert ('value ' + check_usphone(box_phone.value) + ' colour: ' + box_phone.style.background + ' ! ');
//   if ( box_phone.value == 'None') {
//    if ( box_phone.value.seach(re2)>0){
    if ( answer_phone >-1){
        box_phone.style.background = "white";
        return true;
    }
//    if ((focused) || ( who_set=="phone") ){
        if ( (!check_usphone(box_phone.value)) ){// && (box_phone.style.background.search(cellcol))==-1 ) {
            alert ('The format for the phone number must be (123) 123-4567');
//            focused=false;
//            who_set ="phone";
            box_phone.style.background = "yellow";
//            box.focus;
//            setTimeout("box_phone.focus();",0);
        }
        if(  (check_usphone(box_phone.value)) && (box_phone.style.background.search(cellcol))>-1 ) {
//            alert ('Thank you');
//            focused=true;
//            who_set ="";
            box_phone.style.background = "white";
        }
//    }                                        

}

/***********************************
*       Function Used to Email Verification. Written by PerlScriptsJavaScripts.com
***********************************/


function check_email(e) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
    
    for(i=0; i < e.length ;i++){
        if(ok.indexOf(e.charAt(i))<0){ 
            return (false);
        }       
    } 
    
    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);            
        } 
    }
}
/***********************************
*
*       Function Used to Check all cells. Written by PerlScriptsJavaScripts.com
*
***********************************/

function checkit_org()
{ 
    var cellcol = /yellow/i;
    box_org = document.form.organization;
//    alert ('HEY THERE THE CAT and the Filddle, org ' + box_org.style.background.search(cellcol) + ' !');
//    if ((focused) ||  (who_set=="organization")  ){
        if (( !box_org.value) ){// && (box_org.style.background.search(cellcol))==-1 ) {
            alert ('This cell is empty, An Organization\'s name is required');
//            focused=false;
//            who_set ="organization";
            box_org.style.background = "yellow";
//            box_org.focus();
//            setTimeout("box_org.focus();",0);          
      }
        if( (box_org.value) ){// && (box_org.style.background.search(cellcol))>-1 ) {
//            alert ('Thank you');
//            focused=true;
//            who_set ="";
            box_org.style.background = "white";
        }
//    }
}
