﻿jQuery.validator.addMethod("phone", function(ph, element) {
	if (ph == null) return false;
	var stripped = ph.replace(/[\s()+-]|ext\.?/gi, '');
	return ((/\d{10,}/i).test(stripped));
},"Invalid phone format");

jQuery.validator.addMethod("cp", function(cp, element) {
	if (cp == null) return false;
	return ((/^[a-z]\d[a-z]\s?\d[a-z]\d$/i).test(cp)) 
},"Invalid postal code format (A1A 1A1)");
jQuery.validator.addMethod("cpzip", function(cp, element) {
	if (cp == null) return false;
	return ((/^[a-z]\d[a-z]\s?\d[a-z]\d$/i).test(cp) || (/^d{5,5}$/i).test(cp)) 
},"Invalid");

jQuery.validator.addMethod("crn", function(crn, element) {
	if (crn == null) return false;
	return ((/^\d{5,5}\s\d{4,4}\sRR\s\d{4,4}$/i).test(crn))
},"Invalid");
jQuery.validator.addMethod("rnpi", function(rnpi, element) {
	if (rnpi == null) return false;
	return ((/\d{9,9}/i).test(rnpi))
},"Invalid");
jQuery.validator.addMethod("rnpii", function(rnpii, element) {
	if (rnpii == null) return false;
	return ((/\d{4,4}/i).test(rnpii))
},"Invalid");
jQuery.validator.addMethod("quantity", function(quantity, element) {
	if (quantity == null) return false;
	if (quantity > 1000) {return false;}
		else {return true;}
},"Invalid");
jQuery.validator.addMethod("wordc", function(wordc, element) {
	if (wordc == null) return false;
	if (wordc.wordCount() > 250) {return false;}
	else {return true;}
},"Invalid. You have more than 250 words.");
jQuery.validator.addMethod("checkenddate", function(checkenddate, element) {
	if (document.getElementById('startDatehid').value != '') {
		
		if (parseInt(document.getElementById('startDatemth').value) <= parseInt(document.getElementById('endDatemth').value)) {
			
			if (parseInt(document.getElementById('startDatemth').value) == parseInt(document.getElementById('endDatemth').value)) {
			
			if (parseInt(document.getElementById('startDatehid').value) <= parseInt(document.getElementById('endDatehid').value)) {return true;}
			
			}else {return true;}
			
			}else {return false;}
		
		}else {return true;}
},"Invalid. Start date must be before end date.");
jQuery.validator.addMethod("checkstartdate", function(checkstartdate, element) {
		if (document.getElementById('endDatehid').value != '') {
		
		if (parseInt(document.getElementById('startDatemth').value) <= parseInt(document.getElementById('endDatemth').value)) {
			
			if (parseInt(document.getElementById('startDatemth').value) == parseInt(document.getElementById('endDatemth').value)) {
			
			if (parseInt(document.getElementById('startDatehid').value) <= parseInt(document.getElementById('endDatehid').value)) {return true;}
			
			}else {return true;}
			
			}else {return false;}
		
		}else {return true;}
	/*if (document.getElementById('endDatehid').value != '') {
	if (parseInt(document.getElementById('startDatemth').value) <= parseInt(document.getElementById('endDatemth').value)) {
	if (parseInt(document.getElementById('startDatehid').value) <= parseInt(document.getElementById('endDatehid').value) {return true;}}else {return true;}*/
},"Invalid. Start date must be before end date.");
jQuery.validator.addClassRules({
  name: {
    required: true,
    minlength: 2,
	maxlength: 50
  },
  street_cityname: {
    required: true,
    minlength: 3,
	maxlength: 50
  },
  zip: {
    digits: true,
    minlength: 5,
    maxlength: 5
  },
  string: {
    minlength: 5,
    maxlength: 50
  },
  civicnumber: {
    digits: true,
    minlength: 1,
    maxlength: 8
  }
  
});