jQuery.fn.prettyCheckboxes=function(a){a=jQuery.extend({checkboxWidth:17,checkboxHeight:17,className:"prettyCheckbox",display:"list"},a);$(this).each(function(){$label=$('label[for="'+$(this).attr("id")+'"]');$label.prepend("<span class='holderWrap'><span class='holder'></span></span>");if($(this).is(":checked")){$label.addClass("checked")}$label.addClass(a.className).addClass($(this).attr("type")).addClass(a.display);$label.find("span.holderWrap").width(a.checkboxWidth).height(a.checkboxHeight);$label.find("span.holder").width(a.checkboxWidth);$(this).addClass("hiddenCheckbox");$label.bind("click",function(){$("input#"+$(this).attr("for")).triggerHandler("click");if($("input#"+$(this).attr("for")).is(":checkbox")){$(this).toggleClass("checked");$("input#"+$(this).attr("for")).checked=true;$(this).find("span.holder").css("top",0)}else{$toCheck=$("input#"+$(this).attr("for"));$('input[name="'+$toCheck.attr("name")+'"]').each(function(){$('label[for="'+$(this).attr("id")+'"]').removeClass("checked")});$(this).addClass("checked");$toCheck.checked=true}});$("input#"+$label.attr("for")).bind("keypress",function(b){if(b.keyCode==32){if($.browser.msie){$('label[for="'+$(this).attr("id")+'"]').toggleClass("checked")}else{$(this).trigger("click")}return false}})})};checkAllPrettyCheckboxes=function(b,a){if($(b).is(":checked")){$(a).find("input[type=checkbox]:not(:checked)").each(function(){$('label[for="'+$(this).attr("id")+'"]').trigger("click");if($.browser.msie){$(this).attr("checked","checked")}else{$(this).trigger("click")}})}else{$(a).find("input[type=checkbox]:checked").each(function(){$('label[for="'+$(this).attr("id")+'"]').trigger("click");if($.browser.msie){$(this).attr("checked","")}else{$(this).trigger("click")}})}};

function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
    });
}
preload(['/img/pc/checkbox.png','/img/pc/radio.png']);

$(document).ready(function(){ 

	$("#contactArea").css('height', '0px');
	caheight = 505;desappother = 0;sysoptheight = 0;fndezrother = 0;cutareaother = 0;
	caheighten1 = false;caheighten2 = false;caheighten3 = false;

	$("a.contact").toggle( 
				function () {
					document.getElementById('contactArea').style.display = 'block';
 					$("#contactArea").animate({height: caheight}, {queue:false, duration: 1000, easing: 'easeOutQuad'})
                }, 
                function () { 
					$("#contactArea").animate({height: 0}, {queue:false, duration: 1000, easing: 'easeOutQuad'})  
				} 
		);
		
	$('input[type=checkbox]').prettyCheckboxes();
	$('input[type=radio]').prettyCheckboxes({'display':'inline'});
        
});

function process_fields1(selected) {
  if (selected == "Other") {
	  caheight = caheight + 43; $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  desappother = 43;
	  document.getElementById('desappother-field').style.display = "block";
	  document.getElementById('desappother').focus();
  }else{
	  caheight = caheight - desappother; $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  desappother = 0;
	  document.getElementById('desappother-field').style.display = "none";
  }
}

function process_fields2(selected) {
  if (selected == "") {
	  caheight = caheight - sysoptheight; $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  sysoptheight = 0;
	  document.getElementById('plasma-systems-options').style.display = "none";
	  document.getElementById('combination-systems-options').style.display = "none";
	  document.getElementById('routing-systems-options').style.display = "none";
  }
  if (selected == "Routing Systems") {
	  caheight = caheight + (177 - sysoptheight); $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  sysoptheight = 177;
	  document.getElementById('plasma-systems-options').style.display = "none";
	  document.getElementById('combination-systems-options').style.display = "none";
	  document.getElementById('routing-systems-options').style.display = "block";
  }
  if (selected == "Plasma Cutting Systems") {
	  caheight = caheight + (135 - sysoptheight); $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  sysoptheight = 135;
	  document.getElementById('routing-systems-options').style.display = "none";
	  document.getElementById('combination-systems-options').style.display = "none";
	  document.getElementById('plasma-systems-options').style.display = "block";
  }
  if (selected == "Combination Systems") {
	  caheight = caheight + (177 - sysoptheight); $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  sysoptheight = 177;
	  document.getElementById('plasma-systems-options').style.display = "none";
	  document.getElementById('routing-systems-options').style.display = "none";
	  document.getElementById('combination-systems-options').style.display = "block";
  }
}

function process_fields3(selected) {
  if (selected == "Other") {
	  caheight = caheight + 43; $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'});
	  fndezrother = 43;
	  document.getElementById('foundezrother-field').style.display = "block";
	  document.getElementById('foundezrother').focus();
  }else{
	  caheight = caheight - fndezrother; $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'});
	  fndezrother = 0;
	  document.getElementById('foundezrother-field').style.display = "none";
  }
}

function process_fields4(selected) {
  if (selected == "Custom") {
	  caheight = caheight + 43; $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  cutareaother = 43;
	  document.getElementById('cutareacustom-field').style.display = "block";
	  document.getElementById('cutareacustom').focus();
  }else{
	  caheight = caheight - cutareaother; $("#contactArea").animate({height: caheight}, {queue:false, duration: 250, easing: 'easeOutQuad'})
	  cutareaother = 0;
	  document.getElementById('cutareacustom-field').style.display = "none";
  }
}

function check_required3(form) {
  var notok = 0;
  var whatnot = '';
  var efilter = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/;
  
    if (document.getElementById('name').value == '') { notok = 1;whatnot = whatnot + '- Full Name\n'; }
    if (document.getElementById('phone').value == '') { notok = 1;whatnot = whatnot + '- Contact Number\n'; }
    if ((!efilter.test(document.getElementById('email').value))||(document.getElementById('email').value == '')) { notok = 1;whatnot = whatnot + '- Email Address\n'; }
    if (document.getElementById('zip').value == '') { notok = 1;whatnot = whatnot + '- Zip Code\n'; }
    //if (document.getElementById('recaptcha_response_field').value == '') { notok = 1;whatnot = whatnot + '- Captcha Code\n'; }
    if ((document.getElementById('sc1').value == '')||(document.getElementById('sc1').value!= '5')) { notok = 1;whatnot = whatnot + '- Anti-Spam Question\n'; }

  if (notok == 1) { jAlert('<div style="font-weight:bold;padding-bottom:6px;">Please correct the following fields:</div>' + whatnot,'Quote Form'); return false; }
}

function check_required1(form) {
  var notok = 0;
  var whatnot = '';
  var efilter = /^([_a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/;
  
    if ((document.getElementById('name1').value == 'Full Name')||(document.getElementById('name1').value == '')) { notok = 1;whatnot = whatnot + '- Full Name\n'; }
    if ((document.getElementById('phone1').value == 'Contact Number')||(document.getElementById('phone1').value == '')) { notok = 1;whatnot = whatnot + '- Contact Number\n'; }
    if ((!efilter.test(document.getElementById('email1').value))||(document.getElementById('email1').value == '')) { notok = 1;whatnot = whatnot + '- Email Address\n'; }
    if ((document.getElementById('comments1').value == 'Message')||(document.getElementById('comments1').value == '')) { notok = 1;whatnot = whatnot + '- Message\n'; }
    if (document.getElementById('recaptcha_response_field').value == '') { notok = 1;whatnot = whatnot + '- Captcha Code\n'; }
  
  if (notok == 1) { jAlert('<div style="font-weight:bold;padding-bottom:6px;">Please correct the following fields:</div>' + whatnot,'Contact Form'); return false; }
}

//TOOLTIPS
$(document).ready(function() 
{
$('.qtip[title]').qtip({
   style: { name: 'cream', tip: true, delay: 0, width: { min: 118 } },
   show: { effect: { type: 'fade', length: 100 } },
   position: {
      corner: {
         target: 'topRight',
         tooltip: 'bottomLeft'
      },
	  adjust: { x: -1, y: -11 }
   }
})
$('.qtip2[title]').qtip({
   style: { name: 'cream', tip: true, delay: 0 },
   show: { effect: { type: 'fade', length: 100 } },
   position: {
      corner: {
         target: 'topRight',
         tooltip: 'bottomLeft'
      },
	  adjust: { x: -21, y: -11 }
   }
})
});
