var timeToBlink = 400;
function reloadCounties(form) {
var val=form.state.options[form.state.options.selectedIndex].value; 
self.location='index.php?step=2&state=' + val ;
}

function showAddDoors(form) {
var vwt = form.doorwidth.options[form.doorwidth.options.selectedIndex].value;
var vht = form.doorheight.options[form.doorheight.options.selectedIndex].value;
var vel = form.doorelectric.options[form.doorelectric.options.selectedIndex].value;
var vqu = form.doorquantity.options[form.doorquantity.options.selectedIndex].value;
self.location='index.php?step=4&doorheight=' + vht +'&doorwidth=' +vwt +'&doorelectric=' +vel +'&doorquantity=' +vqu ;
}

function showAddWindows(form) {
var vwt = form.windowwidth.options[form.windowwidth.options.selectedIndex].value;
var vht = form.windowheight.options[form.windowheight.options.selectedIndex].value;
var vqu = form.windowquantity.options[form.windowquantity.options.selectedIndex].value;
self.location='index.php?step=4&windowheight=' + vht +'&windowwidth=' + vwt + '&windowquantity=' + vqu ;
}

function AddDoor(form) {
 var what = form.doorstyle.options[form.doorstyle.options.selectedIndex].value || 'F'; 
 var vwt = form.doorwidth.options[form.doorwidth.options.selectedIndex].value;
 var vht = form.doorheight.options[form.doorheight.options.selectedIndex].value;
 var vel = form.doorelectric.options[form.doorelectric.options.selectedIndex].value;
 var vqu = form.doorquantity.options[form.doorquantity.options.selectedIndex].value;
 var x = what + '/' + vwt + '/' + vht + '/' + vel + '/' + vqu;
 self.location='index.php?step=4&op=ad&x=' + x;
}

function AddWindow(form) {
var what = form.windowstyle.options[form.windowstyle.options.selectedIndex].value || 'I'; 
var vwt = form.windowwidth.options[form.windowwidth.options.selectedIndex].value || '8';
var vht = form.windowheight.options[form.windowheight.options.selectedIndex].value || '8';
var vqu = form.windowquantity.options[form.windowquantity.options.selectedIndex].value;
var x = what + '/' + vwt + '/' + vht + '/' + vqu;
self.location='index.php?step=4&op=aw&x=' + x;
}

function DelDoor(i) {
self.location='index.php?step=4&op=dd&x=' + i;
}

function DelWindow(i) {
self.location='index.php?step=4&op=dw&x=' + i;
}

function ChangeColor1(form) {
var cc = form.color1.options[form.color1.options.selectedIndex].value ;
self.location='index.php?step=6&c1=' + cc;
}
function ChangeColor2(form) {
var cc = form.color2.options[form.color2.options.selectedIndex].value ;
self.location='index.php?step=6&c2=' + cc;
}
function ChangeColor3(form) {
var cc = form.color3.options[form.color3.options.selectedIndex].value ;
self.location='index.php?step=6&c3=' + cc;
}


function validate0(form) {}
function validate1(form) {}

function validate2(form) {
  var vstate = form.state.options[form.state.options.selectedIndex].value;
  var vcounty = form.county.options[form.county.options.selectedIndex].value;
  var postcode = $('#postcode').val();
  
  if (vstate == '') {
      $('#state').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
      return false;
  }
  else {
      if (vcounty == '') {
          $('#country').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
          return false;
      }
      else {
          if ((postcode == '') || (postcode.length!=5)) {
              $('#postcode').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
              return false;
          }
          else {
              saveStep2();
              loadContent('step3');
              menuMove();
          }
      }
  }
}

function validate3(form) {
  error = 0;	
  var vwidth  = form.width.options[form.width.options.selectedIndex].value;

  if (vwidth == 0) {
      error = 1;
	  $('#width').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
  }else {
      var vlength = form.length.options[form.length.options.selectedIndex].value;
	
      if (vlength == 0) {
	  	$('#length').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
          error = 1;
      }else {
          var vheight = form.height.options[form.height.options.selectedIndex].value;
		  
          if (vheight == 0) {
              error = 1;
			  $('#height').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
          }else {
              var vpitch = form.pitch.options[form.pitch.options.selectedIndex].value;
			 
              if (vpitch == 0) {
                  error = 1;
				  $('#pitch').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
              }
          }
      }
  }
  
  if (error == 1) {
    return false;
  }else{
  	saveStep3();
  	loadContent('step4');
	menuMove();
  } 
}

function validate4(form) {

}

function validate5(form) {

}

function validate6(form) {

}

function validate7(form) {
  var vn1 = form.first_name.value; 
  var vph = form.phone.value;
  var vem = form.email.value;
  var vco = form.completed.value;
  
     err = 0; errstr = '';
     if (vn1.length == 0) { 
       err++; 
       //form.first_name.style.background = 'Yellow';
	   $('#first_name').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
	 } 

     
     if (err ==0 && vph.length == 0) {
         err++;
        // form.phone.style.background = 'Yellow';
         $('#phone').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
     }
     else {
         var stripped = vph.replace(/[\(\)\.\-\ ]/g, '');
         if (err ==0 && isNaN(stripped)) {
             err++;
             //form.phone.style.background = 'Yellow';
			 $('#phone').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
         }
         else {
             if (err ==0 && (stripped.length < 10) || (stripped.length > 11)) {
                 err++;
                // form.phone.style.background = 'Yellow';
				 $('#phone').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
             }
         }
     }
	 
     if (err == 0 && vem.length == 0) {
         err++;
         //form.email.style.background = 'Yellow';
		 $('#email').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
     }else {
         apos = vem.indexOf("@");
         dotpos = vem.lastIndexOf(".");
         if (err == 0 && ((apos < 1) || (dotpos - apos < 2))) {
             err++;
             //form.email.style.background = 'Yellow';
			 $('#email').fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink).fadeOut(timeToBlink).fadeIn(timeToBlink);
         }
     }

     if (err > 0) { 
        return false;
     } else { 
	 	loadContentStep7('step7');
		randpicture = Math.floor(Math.random()*(parseInt(pictures.length)-1));
		$('#leftpanel').html('<img src="images/random/'+pictures[randpicture]+'">');
	 }

}


function validate8(form) {}


