﻿<!-- This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
<!-- Revised script : http://www.kodyaz.com -->

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
    phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object){
    phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) {
    if(e){
        e = e
    } 
    else {
        e = window.event
    }
    
    if(e.which){
        var keycode = e.which
    } 
    else {
        var keycode = e.keyCode
    }

    ParseForNumber1(object)

    if(keycode >= 48){
        ValidatePhone(object)
    }
}

function backspacerDOWN(object,e) {
    if(e){
        e = e
    } 
    else {
        e = window.event
    }
    
    if(e.which){
        var keycode = e.which
    } 
    else {
        var keycode = e.keyCode
    }
    
    ParseForNumber2(object)
}

function GetCursorPosition(){

var t1 = phonevalue1;
var t2 = phonevalue2;
var bool = false
for (i=0; i<t1.length; i++)
    {
        if (t1.substring(i,1) != t2.substring(i,1)) {
            if(!bool) {
                cursorposition=i
                bool=true
            }
        }
    }
}

function ValidatePhone(object){

var p = phonevalue1

p = p.replace(/[^\d]*/gi,"")

if (p.length < 3) {
    object.value=p
} 

else if(p.length==3){
    pp=p;
    d4=p.indexOf('(')
    d5=p.indexOf(')')
    
    if(d4==-1){
    pp="("+pp;
}
    if(d5==-1){
        pp=pp+")";
    }
    object.value = pp;
} 
else if(p.length>3 && p.length < 7){
    p ="(" + p;
    l30=p.length;
    p30=p.substring(0,4);
    p30=p30+")"

    p31=p.substring(4,l30);
    pp=p30+p31;

    object.value = pp;

} 
else if(p.length >= 7){
    p ="(" + p;
    l30=p.length;
    p30=p.substring(0,4);
    p30=p30+")"

    p31=p.substring(4,l30);
    pp=p30+p31;

    l40 = pp.length;
    p40 = pp.substring(0,8);
    p40 = p40 + "-"

    p41 = pp.substring(8,l40);
    ppp = p40 + p41;

    object.value = ppp.substring(0, maxphonelength);
}

GetCursorPosition()

if(cursorposition >= 0){
if (cursorposition == 0) {
cursorposition = 2
} else if (cursorposition <= 2) {
cursorposition = cursorposition + 1
} else if (cursorposition <= 5) {
cursorposition = cursorposition + 2
} else if (cursorposition == 6) {
cursorposition = cursorposition + 2
} else if (cursorposition == 7) {
cursorposition = cursorposition + 4
e1=object.value.indexOf(')')
e2=object.value.indexOf('-')
if (e1>-1 && e2>-1){
if (e2-e1 == 4) {
cursorposition = cursorposition - 1
}
}
} else if (cursorposition < 11) {
cursorposition = cursorposition + 3
} else if (cursorposition == 11) {
cursorposition = cursorposition + 1
} else if (cursorposition >= 12) {
cursorposition = cursorposition
}

var txtRange = object.createTextRange();
txtRange.moveStart( "character", cursorposition);
txtRange.moveEnd( "character", cursorposition - object.value.length);
txtRange.select();
}

}

function ParseChar(sStr, sChar)
{
if (sChar.length == null)
{
zChar = new Array(sChar);
}
else zChar = sChar;

for (i=0; i<zChar.length; i++)
{
sNewStr = "";

var iStart = 0;
var iEnd = sStr.indexOf(sChar[i]);

while (iEnd != -1)
{
sNewStr += sStr.substring(iStart, iEnd);
iStart = iEnd + 1;
iEnd = sStr.indexOf(sChar[i], iStart);
}
sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

sStr = sNewStr;
}

return sNewStr;
}

function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=750,height=500');");
}

function validateContactForm() {
    if (document.getElementById("_ctl0_ContentPlaceHolder1_txtfirst_name").value=="")
      {
                 alert("First Name is a required Field.  Please provide your first name.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtfirst_name").focus();
                 return false;
      }
      if (document.getElementById("_ctl0_ContentPlaceHolder1_txtlast_name").value=="")
      {
                 alert("Last Name is a required Field.  Please provide your last name.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtlast_name").focus();
                 return false;
      }
      if (document.getElementById("_ctl0_ContentPlaceHolder1_txtcompany_name").value=="")
      {
                 alert("Company Name is a required Field.  Please provide your company name.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtcompany_name").focus();
                 return false;
      }
      if (document.getElementById("_ctl0_ContentPlaceHolder1_txtAddress1").value=="")
      {
                 alert("Address is a required Field.  Please provide your address.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtAddress1").focus();
                 return false;
      }
      if (document.getElementById("_ctl0_ContentPlaceHolder1_txtCity").value=="")
      {
                 alert("City is a required Field.  Please provide your city.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtCity").focus();
                 return false;
      }
       if (document.getElementById("_ctl0_ContentPlaceHolder1_ddState_province").options[document.getElementById("_ctl0_ContentPlaceHolder1_ddState_province").selectedIndex].value == "")
      {
                 alert("State/Province is a required Field.  Please provide your state/province name.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_ddState_province").focus();
                 return false;
      }

      if (document.getElementById("_ctl0_ContentPlaceHolder1_txtzip_code").value=="")
      {
                 alert("ZIP/Postal Code is a required Field.  Please provide your zip/postal code.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtzip_code").focus();
                 return false;
      }
      if(document.getElementById("_ctl0_ContentPlaceHolder1_txtEmail").value=="")
      {
                 alert("Email is a required field. Please provide a valid email address.");
                document.getElementById("_ctl0_ContentPlaceHolder1_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("_ctl0_ContentPlaceHolder1_txtEmail").value;
     var matchArray = emailid.match(emailPat);
     if (matchArray == null)
    {
               alert("Email is a required field. Please provide a valid email address.");
               document.getElementById("_ctl0_ContentPlaceHolder1_txtEmail").focus();
               return false;
    }
    if(document.getElementById("_ctl0_ContentPlaceHolder1_txtMessage").value=="")
      {
                 alert("Message is a required field. Please provide a message.");
                document.getElementById("_ctl0_ContentPlaceHolder1_txtMessage").focus();
                return false;
      }
      
    if(document.getElementById("_ctl0_ContentPlaceHolder1_rblHuman_0").checked==true)
      {
                alert('Please select "I\'m a human"');
                document.getElementById("_ctl0_ContentPlaceHolder1_rblHuman_0").focus();
                return false;
      }
//      if (document.getElementById("txtCaptchaResponse").value=="")
//      {
//                 alert("Please type the text from the image before submitting.");
//                 document.getElementById("txtCaptchaResponse").focus();
//                 return false;
//      }
//      if (document.getElementById("txtCaptchaResponse").value!= )
//      {
//                 alert("Please type the text from the image before submitting.");
//                 document.getElementById("txtCaptchaResponse").focus();
//                 return false;
//      }
//     alert("Your message to the TII Informatixhas been submitted.  Thank you.");
//     document.forms[0].reset()
     return true;
}

function resetContactForm(frm) {
    if (confirm("Are you sure you want to clear form?")) {
        document.forms[0].reset();
    }
}



function validateResumeForm() {
      if (document.getElementById("_ctl0_ContentPlaceHolder1_txtname").value=="")
      {
                 alert("Name is a required Field.  Please provide your name.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtname").focus();
                 return false;
      }
      if(document.getElementById("_ctl0_ContentPlaceHolder1_txtemail").value=="")
      {
                 alert("Email is a required field. Please provide a valid email address.");
                document.getElementById("_ctl0_ContentPlaceHolder1_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("_ctl0_ContentPlaceHolder1_txtemail").value;
     var matchArray = emailid.match(emailPat);
     if (matchArray == null)
       {
               alert("Email is a required field. Please provide a valid email address.");
               document.getElementById("_ctl0_ContentPlaceHolder1_txtemail").focus();
               return false;
       }
      if (document.getElementById("_ctl0_ContentPlaceHolder1_txtpostition").value=="")
      {
                 alert("Position is a required Field.  Please provide the position you are interested in.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_txtpostition").focus();
                 return false;
      }
      if (document.getElementById("_ctl0_ContentPlaceHolder1_fileUpload").value=="")
      {
                 alert("File is a required Field.  Please use the 'Browse' button to upload your resume to send to TII Informatix.");
                 document.getElementById("_ctl0_ContentPlaceHolder1_fileUpload").focus();
                 return false;
      }
      if (document.getElementById("_ctl0_ContentPlaceHolder1_fileUpload").value!=="") 
      {
            var strFileName;
            var strLast4;
            var strLast5;
            strFileName = document.getElementById("_ctl0_ContentPlaceHolder1_fileUpload").value;
    //        alert(strFileName);
            strLast4 = Right(strFileName, 4);
            strLast5 = Right(strFileName, 5);
    //        alert(strLast4);
            if (strLast4 !== ".doc")
            {
                if (strLast4 !== ".pdf")
                {
                    if (strLast5 !== ".docx")
                    {
                        alert("Invalid File Type, you may only upload a file with the following extensions (.doc, .pdf, .docx).  example filename: myresume.doc");
                return false;
                    }    
                }
            }
      }  
     alert("Thank you, your message has been sent to the TII Informatix Group.");
//     document.forms[0].reset();
     return true;
}


function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }


function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
