function checkForm()
{
var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var digi = /^\d+$/;
var err= false;

var val = document.forma.fullname.value;
if(trims(val).length==0) {showErr("fullname");err=true;}
else hideErr("fullname");
val = document.forma.company.value;
if(trims(val).length==0) {showErr("company");err=true;}
else hideErr("company");
val=document.getElementById("phone1").value;
var val2=document.getElementById("phone2").value;
var val3=document.getElementById("phone3").value;
if(val.length!=3 || val2.length!=3 || val3.length!=4) {showErr("phone");err=true;}
else {
        if(!val.match(digi) || !val2.match(digi) ||!val3.match(digi)){showErr("phone");err=true;}
        else if(!clientPhoneCheck(val,val2,val3)){showErr("phone");err=true;}
        else{  
              hideErr("phone");
            }
        }
val = document.forma.email.value;
if(trims(val).length==0 || !val.match(emailFilter)) {showErr("email");err=true;}
else hideErr("email");

if(err) return false;
return true;
}

function checkFormOLD(){
var zipFormat=/^\d{5}$/;
var phoneFormat=/^\d{3}-\d{3}-\d{4}$/;
var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

   if(document.forma.fullname.value.length<1) {showErrMsg("You must enter your full name",40);return false;}
   if(document.forma.company.value.length<1) {showErrMsg("You must enter your company name",40);return false;}
   //if(document.forma.address.value.length<1) {showErrMsg("You must enter your addess",50);return false;}
  // if(document.forma.city.value.length<1) {showErrMsg("You must enter your city",50);return false;}
   if(document.forma.user_state.value.length<1) {showErrMsg("You must enter your state",40);return false;}
   //if(document.forma.zip.value.length<1) {showErrMsg("You must enter your zip area code",40);return false;}
   //else if(!document.forma.zip.value.match(zipFormat)){showErrMsg("The zip code format has to be XXXXX",40);return false;} 
   if(document.forma.phone.value.length<1) {showErrMsg("You must enter your phone number",40);return false;}
   else if(!document.forma.phone.value.match(phoneFormat)){showErrMsg("The phone format is XXX-XXX-XXXX",40);return false;} 
   if(document.forma.email.value.length<1) {showErrMsg("You must enter your email address",40);return false;}
   else if(!document.forma.email.value.match(emailFilter)){showErrMsg("The format of your email address is wrong",40);return false;} 
   //if(document.forma.email.value != document.forma.emailconf.value) {showErrMsg("The email addresses does not match",40);return false;} 
   //if(document.forma.businness.value.length<1) {showErrMsg(" Select a businness",70);return false;}

  
   document.forma.submit();
}

function showErrMsg(txt,left){
var pos=getContainerPosition();
var divE=document.createElement("div");
    divE.id="tempDiv";
    divE.style.position="absolute";
    divE.style.zIndex="100";
    divE.style.textAlign="center";
    divE.style.backgroundColor="yellow";
    divE.style.fontWeight="bold";
    divE.style.fontStyle="italic";
    divE.style.top=pos.top+300+"px";
    divE.style.right=pos.left+left+left+"px";
    divE.style.fontSize="1.2em";
    divE.innerHTML=txt;
    document.body.appendChild(divE); 
    setTimeout("hideErrMsg()",2000);   
}

function hideErrMsg(){
  if(document.getElementById("tempDiv")) document.body.removeChild(document.getElementById("tempDiv"));
}

function showErr(nam)
{
$("#"+nam+"lab").addClass("required");
var img = $("#"+nam+"lab").children("img")[0];
$(img).css("visibility","visible");
}

function hideErr(nam)
{
$("#"+nam+"lab").removeClass("required");
var img = $("#"+nam+"lab").children("img")[0];
$(img).css("visibility","hidden");
}

function getContainerPosition(){
var parent= document.getElementById("formContact");
var leftt=0;
var topp=0;
while(parent){
                    leftt+=parent.offsetLeft;
					topp+=parent.offsetTop;
					parent=parent.offsetParent;
			}
if(navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined"){
                    topp+=document.body.topMargin;
					leftt+=document.body.leftMargin;
					} 			
return {left:leftt,top:topp}
}

$(document).ready(function(e){initC();});

function initC()
{
$("#phone1").bind("keypress",function(e){return justDigit(e);});
$("#phone2").bind("keypress",function(e){return justDigit(e);});
$("#phone3").bind("keypress",function(e){return justDigit(e);});
}

function justDigit(evt){

var eve = evt ? evt : window.event;
var charCode = 0;

if(eve) charCode = eve.charCode ? eve.charCode : (eve.keyCode? eve.keyCode : (eve.which ? eve.which : 0)); 
//if(charCode == 44) return true;//allow ,
//if(charCode == 46) return true;//allow .
if(charCode > 31 && (charCode < 48 || charCode>57)) return false;

else return true;

}

function trims(txt){
try{
   var ttxt =txt.replace(/^\s+|\s+$/g,"");
   return ttxt;
   }catch(e){
              return txt;
  } 
}


function clientPhoneCheck(ph1,ph2,ph3)
{
  if(ph1=="000" || ph1=="111" || ph1=="222" || ph1=="555") return false;
  if(ph2=="000") return false;
  return true;
}
