var url = 'http://www.tattooconventieassen.com/captcha/checkcaptcha.php?code=';
var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed


function checkEmailAddress(field) {
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
return false;
} else {
return true;
}
}        
        function getHTTPObject()
        {
        try {
        req = new XMLHttpRequest();
          } catch (err1)
          {
          try {
          req = new ActiveXObject("Msxml12.XMLHTTP");
          } catch (err2)
          {
          try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (err3)
            {
	req = false;
            }
          }
	}
        return req;
	}
        
        var http = getHTTPObject(); // We create the HTTP Object        
        
        function handleHttpResponse(frm) {
        if (http.readyState == 4) {
            captchaOK = http.responseText;
            if(captchaOK != 1) {
              alert('The code you entered is incorrect. Please try again');
              frm.code.value='';
              frm.code.focus();
              return false;
              }
              frm.submit();
           }
        }

        function checkcode(frm) {
		var theCode = frm.code.value;
        http.open("GET", url + escape(thecode), true);
        http.onreadystatechange = handleHttpResponse(frm);
        http.send(null);
        }


function checkContactForm() {
        // First the normal form validation
		var frm = document.contactForm;

        if(frm.name.value=='') {
          alert('Please fill in the field "name" ');
          frm.name.focus();
          return false;
          }
          
        if(frm.email.value=='') {
          alert('Please fill in the field "e-mail" ');
          frm.email.focus();
          return false;
          }
          
        if(checkEmailAddress(frm.email)) {
          alert('The e-mail-address you enetered is not valid. Please enter a valid e-mail address.');
          frm.email.focus();
          return false;
          }
          
        if(frm.code.value=='') {
          alert('Please type in the code as shown in the image.');
          frm.code.value='';
          frm.code.focus();
          return false;
          }
          
          if(frm.remarks.value=='') {
          alert('You have not entered a message.');
          frm.remarks.focus();
          return false;
          }
          
          // Now the Ajax CAPTCHA validation
          checkcode(frm);
          return false;
        } 



function checkStandRequestForm(){
	// First the normal form validation
	
	var frm = document.standRequestForm;
	
      if(frm.name.value=='') {
        alert('Please fill in the field "name" ');
        frm.name.focus();
        return false;
        }
      if(frm.studio.value=='') {
	    alert('Please fill in the field "studio-name / companyname" ');
	    frm.studio.focus();
	    return false;
	    }
	if(frm.address.value=='') {
	   alert('Please fill in the field "Address" ');
	   frm.address.focus();
	   return false;
	   }
	if(frm.zip.value=='') {
	    alert('Please fill in the field "ZIP-code" ');
	    frm.zip.focus();
	    return false;
	    }
      if(frm.city.value=='') {
        alert('Please fill in the field "City" ');
        frm.city.focus();
        return false;
        }
      if(frm.url.value=='' || frm.url.value=='http://') {
	        alert('Please enter your website-url');
	        frm.url.focus();
	        return false;
	        } 
      if(checkEmailAddress(frm.email)) {
        alert('The e-mail-address you enetered is not valid. Please enter a valid e-mail address.');
        frm.email.focus();
        return false;
        }
        
      if(frm.code.value=='') {
        alert('Please type in the code as shown in the image.');
        frm.code.value='';
        frm.code.focus();
        return false;
        }
        
        // Now the Ajax CAPTCHA validation
        checkcode(frm);
        return false;
}


function checkOrderFrm(nm){

var num = document.getElementById('num'+nm).value;
var size = document.getElementById('size'+nm).value;
var nxtNum = nm+1;

	if(num && size){
		document.getElementById('num'+nxtNum).disabled=false;
		document.getElementById('size'+nxtNum).disabled=false;
		document.getElementById('submit').disabled=false;
	}
}

function verifyOrderAddrFrm(frm){
	if(frm.name.value==''){ alert('Please fill in your name'); frm.name.focus(); return false; }
	if(frm.address.value==''){ alert('Please fill in your address'); frm.address.focus(); return false; }
	if(frm.zip.value==''){ alert('Please fill in your ZIP-code'); frm.zip.focus(); return false; }
	if(frm.city.value==''){ alert('Please fill in your city'); frm.city.focus(); return false; }
	if(frm.email.value==''){ alert('Please fill in your e-mail-address'); frm.email.focus(); return false; }
	if(checkEmailAddress(frm.email)) { alert('The e-mail-address you entered is invalid'); frm.email.focus(); return false; }
}