function mtcSubmitForm(obj) {
     
    //alert("test");
    
    var getstr = "?";
    var targetstr = "";
    var checkCookie;
   
    if (document.getElementById('UseCookie') == null )
    {
        checkCookie = "";
    }
    else
    {
        if ( document.getElementById('UseCookie').value == "true" )
        {
               checkCookie = document.getElementById('UseCookie').value;
        }
        else
        {
            checkCookie = "";
        }
    }
    
try {

        getstr += mtc1001s(obj);
      //  targetstr = mtc1000s(obj);
        if (checkCookie ) {
            mtc1005(obj);
        }
      //  obj.action = targetstr + getstr;
//alert("action: " + obj.action); 
      //  obj.action = "http://localhost:3845/HostedForms/mtcContactReg.aspx" + getstr;
        obj.submit(); 
}
catch(er)
{
     //alert("error: " + er);
    //if(er=="EmailInvalid") 
    //alert("Error! Email Address is Required");
    //if(er == "ReqEmpty") 
    //alert("Error! A Required Field is Empty"); 
//if(er == "PhoneInvalid") 
    //alert("Error! A Required Field is Empty"); 
}
}

function mtc1000s(obj) {    
    var targetstr = ((location.protocol=='http:')?'http:':'https:') + "//"
  //   alert( targetstr);
  //   alert( document.getElementById('MTC_GROUP').value);
  //   alert( document.getElementById('MTC_ID').value);
  //   alert( document.getElementById('MTC_KEY').value);
  //   alert( document.getElementById('MTC_SERVER').value);
  //   targetstr += document.getElementById('MTC_SERVER').value + "/Data/" + document.getElementById('MTC_GROUP').value + "/" + document.getElementById('MTC_ID').value + "/" + document.getElementById('MTC_KEY').value + "/mtcContactReg.aspx";
   //alert( targetstr);
    return targetstr;
}
   
function mtc1001s(obj) {
      var getstr = "";       
      var children = obj.childNodes; 
      for (var i=0; i<children.length; i++) {                    
            getstr = getstr + mtc1002s(children[i])
            getstr = getstr + mtc1001s(children[i])                     
      }     
    
    return getstr
}
   
function mtc1002s(obj) {

    var getstr = ""

if ((obj.tagName == "INPUT") && !((document.getElementById("noEmailVal").value == "yes")&&(obj.name == "EmailAddress"))) {
    if ( !mtc1004b(obj) ) {
        throw "ReqEmpty";
    }
        if (obj.type == "text") {
if (obj.name == "FirstName") { 
        if (!mtc1009b(obj)) {
         throw "InvalidName";
        }
    }  

if (obj.name == "LastName") { 
        if (!mtc1009c(obj)) {
         throw "InvalidName";
        }
    }

if (obj.name == "Company") { 
        if (!CompCheck(obj)) {
         throw "InvalidCompanyName";
        }
    } 

if ((obj.name == "EmailAddress") && (document.getElementById("noEmailVal").value == "no")) {
        if (!mtc1003b( obj.value ) ) {
        throw "EmailInvalid";
        }
    } 

if (obj.name == "WorkPhone") {
    if (!phoneNumberCheck(obj)) {
        throw "PhoneInvalid";
        }
if (!phoneNumberRegExp(obj)) {
        throw "PhoneInvalid";
        }
    } 
getstr += obj.name + "=" + obj.value + "&"; 

        }
        if (obj.type == "checkbox") {
            if (obj.checked) {
                getstr += obj.name + "=" + obj.value + "&";                  
            } else {
                getstr += obj.name + "=&"; 
}
        }
        if (obj.type == "radio") {         
            if (obj.checked) {
                getstr += obj.name + "=" + obj.value + "&";                 
            }
        }
        if (obj.type == "hidden") {         
            getstr += obj.name + "=" + obj.value + "&";
        }
    }   
    if (obj.tagName == "SELECT" ) {  
        if ( !mtc1004ab(obj) ) {
        throw "ReqEmpty";
    }  
        var sel = obj;
getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";           
    }    
    if (obj.tagName == "TEXTAREA") {
        if ( !mtc1004b(obj) ) {
        throw "ReqEmpty";
    }
        getstr += obj.name + "=" + obj.value + "&";        
    }
    if (obj.tagName == "HIDDEN" ) {
        if ( !mtc1004b(obj) ) {
        throw "ReqEmpty";
    }
        getstr += obj.name + "=" + obj.value + "&"; 
    }
   //alert( "getstr: "+getstr);   
    return getstr    
}   

function mtc1003b(str) {
   if(!validateEmailv2(str))  { 
 return false; 
   } else {
    return true; 
}   
}

function mtc1004b(obj) {  

    if ((obj.getAttribute("isRequired") == "true" && obj.value.length == 0)) {     
    return false;
    } else {
    return true;
    } 
}


function mtc1009b(obj) {
var alphaCheck = obj.value.search("[^A-Za-z]");
if ((obj.value.length == 1) || (alphaCheck >= 0)) {     
    return false;
    } else {
    return true;
    } 
}


function mtc1009c(obj) { 
var name= obj.value;
var charpos = obj.value.search("[^A-Za-z ]"); 
var countSpace=0;
if(name.length <= 1 || charpos >= 0)
{ 
return false;
}
else
{
for(i=0;i<name.length;i++)
{
if(name[i]==" ")
{
countSpace++;
if((i==0)||(i==name.length-1))
{

return false;
}
}
}
if(countSpace>1)
{

return false;
} 

}
    return true;
    
}





function phoneNumberRegExp(obj) {
var numCheck = "^\d?(?:(?:[\+]?(?:[\d]{1,3}(?:[ ]+|[\-.])))?[(]?(?:[\d]{3})[\-/)]?(?:[ ]+)?)?(?:[a-zA-Z2-9][a-zA-Z0-9 \-.]{6,})(?:(?:[ ]+|[xX]|(i:ext[\.]?)){1,2}(?:[\d]{1,5}))?$";

            if(!obj.value.match(numCheck)) {         
              return false;                   
            } else {
     return true;
     }  

}

function validateEmailv2(email)
{

// a very simple email validation checking. 
// you can add more complex email checking if it helps 
var checkDomain=email.indexOf('yahoo.') + email.indexOf('gmail.') + email.indexOf('aol.') + email.indexOf('msn.') + email.indexOf('hotmail.') + email.indexOf('earthlink.') + email.indexOf('rediffmail.') + email.indexOf('abc.') + email.indexOf('xyz.') + email.indexOf('mail.') + email.indexOf('aim.') + email.indexOf('gmx.') + email.indexOf('inbox.') + email.indexOf('bluebottle.') + email.indexOf('bluestring.') + email.indexOf('zapak.') + email.indexOf('mywaymail.') + email.indexOf('hotpop.') + email.indexOf('lavabit.') + email.indexOf('topmail.') + email.indexOf('yousendit.') + email.indexOf('mail2web.') + email.indexOf('netaddress.') + email.indexOf('lycos.') + email.indexOf('postmaster.') + email.indexOf('zzn.') + email.indexOf('walla.') + email.indexOf(' fastmail.') + email.indexOf('thatweb.') + email.indexOf('mailinator.') + email.indexOf('30gigs.') + email.indexOf('e-mailanywhere.') + email.indexOf('xasamail.') + email.indexOf('excitemail.') + email.indexOf('myrealbox.') + email.indexOf('flashmail.') + email.indexOf('nameplanet.') + email.indexOf('dodgeit.') + email.indexOf('hushmail.') + email.indexOf('mailandnews.') + email.indexOf('caramail.lycos.fr') + email.indexOf('icqmail.') + email.indexOf('thedoghousemail.') + email.indexOf('webmail.earthlink.net') + email.indexOf('eo.yifan.net') + email.indexOf('prontomail.') + email.indexOf('gurlmail.') + email.indexOf('wowmail.') + email.indexOf('indiatimes.') + email.indexOf('sbc.') + email.indexOf('MailStreet.') + email.indexOf('entergroup.') + email.indexOf('Address.') + email.indexOf('AlloyMail.') + email.indexOf('AltaVista.') + email.indexOf('AnimeNation.') + email.indexOf('Asheville.') + email.indexOf('AsianWired.') + email.indexOf('BBoy.') + email.indexOf('BlazeMail.') + email.indexOf('BoarderMail.') + email.indexOf('BoarderZone.') + email.indexOf('Bolt.') + email.indexOf('Budweiser.') + email.indexOf('Canada.') + email.indexOf('Casino.') + email.indexOf('ClassifiedToday.') + email.indexOf('DarkHorseFan.') + email.indexOf('Juno.') + email.indexOf('ListrakInc.') + email.indexOf('MailBoy2004.') + email.indexOf('MassMailer.') + email.indexOf('Northstar.') + email.indexOf('comcast.') + email.indexOf('verizon.') + email.indexOf('frontiernet.') + email.indexOf('optonline.');
var splitted = email.match("^(.+)@(.+)$");
if(splitted == null){ 
return false; 
} else if(checkDomain != -77){
//alert("You have entered an email account from a free email service or one of the high-volume consumer service providers (i.e. AOL, gmail, Yahoo, MSN, Hotmail, Earthlink, SBC, etc). In an effort to provide you with the best possible access to our products, we require that you enter your corporate email address. Please update your email account below and press the submit button. ");
return false;
} else {
return true;
}


 
}


function mtc1004ab(obj) {  
    if (obj.value.length == 0) {     
    return false;
    } else {
    return true;
    } 
}



function mtc1005() {

//get cookie, check for the value, update, and set
    var nameEQ = "MTC_FORM=";
var ca = document.cookie.split(';');
var value = "";
var found = false;
var formId = "";

if ( document.getElementById('FormID') == null )
{ 
    return;
}
else
{
    formID = document.getElementById('FormID').value;    
}

for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0)
{
    value = c.substring(nameEQ.length,c.length);
break;
}
} 
var caValue = "";
if (value.length > 0)
{
    caValue = value.split(',');
    } 
for(var i=0;i<caValue.length;i++)
{    
    if (caValue[i] == formID)

    {
        found = true;
break;
    }
} 
if (!found)
{
    value =  formID + ',' + value;
}
var date = new Date();
// cookie will expire in one year
date.setTime(date.getTime()+(365*24*60*60*1000));
var test = nameEQ + value + ";expires=" + date.toGMTString() + "; path=/";
document.cookie = test
}

var oldonload = window.onload
if (typeof window.onload != 'function') {
   window.onload = mtc1006; 
} else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      mtc1006();
    };
  }

function mtc1006()
{
    var nameEQ = "MTC_FORM=";
var ca = document.cookie.split(';');
var value = "";
var found = false;
var formID = "";

if (document.getElementById('UseCookie') == null )
    {
        return true;
    }
    else 
    {
       if( document.getElementById('UseCookie').value == "false" )
       {
            return true;
       }
    }
if ( document.getElementById('FormID') == null )
{ 
    return true;
}
else
{
    formID = document.getElementById('FormID').value; 
}

for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0)
{
    value = c.substring(nameEQ.length,c.length);
}
} 
var caValue = "";
if (value.length > 0)
{
    caValue = value.split(',');
    } 
for(var i=0;i<caValue.length;i++)
{    
    if (caValue[i] == formID )
    {
        found = true;
break;
    }
} 
if (found && document.getElementById('retURL') != null)
{ 
    var redirect = "";
    if( document.getElementById('retURL') == null )
    {
        redirect = document.location;
}
    else
    {
        redirect = document.getElementById('retURL').value;
}
    document.write("<html><body></body></html>");
    document.location = redirect;
}
}

function mtc1007( Mappings ) {
    var qsParm = new Array();   

    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
        var pos = parms[i].indexOf('=');
if (pos > 0) {
            var key = parms[i].substring(0,pos);       
            var val = parms[i].substring(pos+1);        
            qsParm[key] = val;
        }
    }   

    for (var i in Mappings) {
      //  alert(i + " : " + Mappings[i] + " : " + qsParm[i]);
        var field = document.getElementById(Mappings[i]);
        if (field != null) { 
           // alert(qsParm[i]);   
            if ( qsParm[i] != null ) {
                field.value = qsParm[i];
            }
        }
    }
}

function CompCheck(obj)
{
var nonCompValues = new Array("null","none","na","n/a");
var comp = obj.value;
comp = trimSpace(comp);
comp = comp.toLowerCase();
if(comp.length == 1)
{
return false;
}
var i;
for(i=0; i<nonCompValues.length; i++)
{
if(comp == nonCompValues[i])
{
return false;
}
}
return true;
}


function trimSpace(x)
{

  var emptySpace = / /g;
  var trimAfter = x.replace(emptySpace,"");
return(trimAfter);

}

function phoneNumberCheck(objValue)
{

var charpos = objValue.value.search("[^0-9x-]"); 
if(charpos >= 0) 
      {                  
        return false; 
      } 
  
   else if((objValue.value.length >17)||(objValue.value.length <10))
    {
    return false; 
     }
else 
     {
   if(objValue.value.length >10)
   {
   var countDash=0;
   var countX=0;
   var posDash=0;
      var i;
   var b=objValue.value.indexOf('x');
   for(i=0; i<objValue.value.length;i++)
   {
   if(objValue.value.charAt(i)=='-')
{
countDash++; 
if(i!=3)
{
if(i!=7)
{
return false;
}
else if((posDash!=3)&&(i==7))
{
return false;
}
else if((posDash==3)&&(i==7)&&(b<12)&&(b!=-1))
{
   return false;
                     } 
  else if((posDash==3)&&(i==7)&&(objValue.value.length<12))
{
    return false;
  }
  else if((posDash==3)&&(i==7)&&(objValue.value.length>=13)&&(b!=12))
    {
  return false;
  }

 }

 else
     {
        posDash=3;
     }
   }

   if(objValue.value.charAt(i)=='x')
   {
countX++;  
      }
   }//end of 'for' loop

   if((countDash==0)&&(countX==0))
    {
   return false;
    }

    else if((countDash>2)||(countX>1))
    {
      return false;
   }

    else if(((countDash==0)||(countDash==1))&&(b==12))
        {
            return false;
   }   
  
    else if(b==(objValue.value.length-1))   
   {
  return false;  
   }

    else if((b!=-1)&&(b<10))
   {
   return false;
   }

    else if((b!=-1)&&(objValue.value.length-b)>5)
      {
  return false;
  }
 
  if(((objValue.value.indexOf("0000000000"))!=-1)||((objValue.value.indexOf("1111111111"))!=-1)||((objValue.value.indexOf("2222222222"))!=-1)||((objValue.value.indexOf("3333333333"))!=-1)||((objValue.value.indexOf("4444444444"))!=-1)||((objValue.value.indexOf("5555555555"))!=-1)||((objValue.value.indexOf("6666666666"))!=-1)||((objValue.value.indexOf("7777777777"))!=-1)||((objValue.value.indexOf("8888888888"))!=-1)||((objValue.value.indexOf("9999999999"))!=-1)||((objValue.value.indexOf("000-000-0000"))!=-1)||((objValue.value.indexOf("111-111-1111"))!=-1)||((objValue.value.indexOf("222-222-2222"))!=-1)||((objValue.value.indexOf("333-333-3333"))!=-1)||((objValue.value.indexOf("444-444-4444"))!=-1)||((objValue.value.indexOf("555-555-5555"))!=-1)||((objValue.value.indexOf("666-666-6666"))!=-1)||((objValue.value.indexOf("777-777-7777"))!=-1)||((objValue.value.indexOf("888-888-8888"))!=-1)||((objValue.value.indexOf("999-999-9999"))!=-1))
  {  
return false;   
  } 
  
           }
  
      if(objValue.value.length==10)
      {
    var m=objValue.value.indexOf('x');   
    var n=objValue.value.indexOf('-');   
   if((m>=0)||(n>=0))
      {
  return false;
  }

    if(((objValue.value.indexOf("0000000000"))!=-1)||((objValue.value.indexOf("1111111111"))!=-1)||((objValue.value.indexOf("2222222222"))!=-1)||((objValue.value.indexOf("3333333333"))!=-1)||((objValue.value.indexOf("4444444444"))!=-1)||((objValue.value.indexOf("5555555555"))!=-1)||((objValue.value.indexOf("6666666666"))!=-1)||((objValue.value.indexOf("7777777777"))!=-1)||((objValue.value.indexOf("8888888888"))!=-1)||((objValue.value.indexOf("9999999999"))!=-1))
  { 
return false;  
  } 
 
  } //end of if(objValue.value.length==10) 
  
  var newregExp = /^[\d]*[\d](0{9})|[\d]*[\d](0{2})-(0{3})-(0{4})$/
  var checkPhone = objValue.value.search(newregExp);
  if(checkPhone >= 0)
{
   return false;
}

      }//end of else
  
  return true;   
}