
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
    var inputs = document.getElementsByTagName("input");
    for (var i=0; i<inputs.length; i++){
        // test to see if the hint span exists first
        if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
            // the span exists!  on focus, show the hint
            inputs[i].onfocus = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
            }
            // when the cursor moves away from the field, hide the hint
            inputs[i].onblur = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "none";
            }
        }
    }
    // repeat the same tests as above for selects
    var selects = document.getElementsByTagName("select");
    for (var k=0; k<selects.length; k++){
        if (selects[k].parentNode.getElementsByTagName("span")[0]) {
            selects[k].onfocus = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
            }
            selects[k].onblur = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "none";
            }
        }
    }
}
addLoadEvent(prepareInputsForHints);
//-------------------------------------------------------------------------------------------------------//
function varifyform()
  {
     if(document.getElementById('firstname').value=="")
      {
         alert('Please insert your name.');
         document.getElementById('firstname').focus();
         return false;
      }
     var text=document.getElementById('firstname').value;
     for ( c=0; c < text.length; c ++ )
      {
        alpha = (text.charCodeAt(c)>=65 && text.charCodeAt(c)<=90) || (text.charCodeAt(c)>=97 && text.charCodeAt(c)<=122 ) || text.charCodeAt(c)==32
        if ( !alpha )
         {
           alert('Sorry, invalid name.\nType alphanumeric character (a-z) only.');
           document.getElementById('firstname').select();
           return false;
         }
      }
     if(document.getElementById('email').value=="")
      {
         alert('Please insert your e-mail.');
         document.getElementById('email').focus();
         return false;
      } 
     var errMsg,pos;
     errMsg = '';
     pos = document.getElementById('email').value.indexOf("@")
     if (pos == -1)
      {
         alert("Sorry, invalid e-mail id.");
         document.getElementById('email').select();
         return false;
      }
     else if (document.getElementById('email').value.lastIndexOf(".") < pos)
      {
         alert("Sorry, invalid e-mail id.");
         document.getElementById('email').select();
         return false;
      }
     if(document.getElementById('company').value=="")
      {
         alert('Please insert company name.');
         document.getElementById('company').focus();
         return false;
      }
     if(document.getElementById('designation').value=="")
      {
         alert('Please insert your designation.');
         document.getElementById('designation').focus();
         return false;
      }        
     if(document.getElementById('phone').value=="")
      {
         alert('Please insert phone number.');
         document.getElementById('phone').focus();
         return false;
      }   
     if(isNaN(document.getElementById('phone').value) == true)
      {
         alert("Sorry, invalid phone number.\nOnly numbers between 0-9.");
         document.getElementById('phone').select();
         return false;
      }
     if(document.getElementById('message').value=="")
      {
         alert('Please insert your message');
         document.getElementById('message').focus();
         return false;
      }
     else
      {
         return true;
      }
  }

