function validateJob(form) {
	for (z=0; z<form.length;z++) { 
		if (form[z].type != 'submit' && form[z].name != 'job_url' && form[z].name != 'job_location' && form[z].name != 'job_gig_budget' && form[z].name != 'job_gig_timeframe' && form[z].name != 'job_password' && form[z].name != 'job_pp_email' && form[z].name != 'job_pp_txn' && form[z].name != 'promo_code' ) {
			if (isEmpty(form[z].value)) {
				alert('You must fill all the required fields.')
				form[z].focus();
				return false;
			}
		}
	}
	
	if ($('url').value != '') {
		if (!isUrl($('url').value)) {
			alert('The URL you provided is invalid.')
			$('url').focus();
			return false;		
		}
	}
	
	if (!validOption($('category_id').value)) {
		alert('Please choose a category.')
		$('category_id').focus();
		return false;		
	}

	if (!validOption($('type').value)) {
		alert('Please choose a job type (full-time/freelance).')
		$('type').focus();
		return false;		
	}

	return true;
}

/* ----------------------------------- */
function validateAffiliate(form) {
	for (z=0; z<form.length;z++) { 
		if (form[z].type != 'submit') {
			if (isEmpty(form[z].value)) {
				alert('You must fill all the required fields.')
				form[z].focus();
				return false;
			}
		}
	}
	if (!isUrl($('url').value)) {
		alert('The URL you provided is invalid.')
		$('url').focus();
		return false;		
	}
	if (!validEmail($('email').value)) {
		alert('The email address you provided is invalid.')
		$('email').focus();
		return false;		
	}
	if (!validEmail($('paypal').value)) {
		alert('The paypal account you provided is an invalid email.')
		$('paypal').focus();
		return false;		
	}
	/*
	if (!($('agree').checked)) {
		alert('You must agree to the affiliate\'s terms & conditions!')
		return false;		
	}
	*/
	
	return true;
}


/* ----------------------------------- */
/*  FORM VALIDATION GENERAL FUNCTIONS  */
/* ----------------------------------- */
var ccRadio = NaN;
var email = '';

/* ----------------------------------- */
// phone number - strip out delimiters and check for # of digits
function checkNumber(strng, min, max) {
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
		return "illegal";  
	}
	if (min > 0) {
		if ((stripped.length < min) || (stripped.length > max)) {
	  //if (!(stripped.length == len)) {
			return "length";
	  } 
	}
	return false;
}

/* ----------------------------------- */
// password - between # of chars, uppercase, lowercase, and numeral
function invalidPassword (strng, min, max, complex) {
	var illegalChars = /[\W_]/; // allow only letters and numbers
	if ((strng.length < min) || (strng.length > max)) {
		return "length";
	} else if (illegalChars.test(strng)) {
    return "illegal";
  }
  if (complex > 0) {
  	if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
    	return "complex";
   }  
  }

	return false;
}    

/* ----------------------------------- */
// username - # of chars, uc, lc, and underscore only.
function invalidUsername(strng, min, max) {
	var illegalChars = /\W/; // allow letters, numbers, and underscores
  if ((strng.length < min) || (strng.length > max)) {
  	return "length";
  } else if (illegalChars.test(strng)) {
  	return "illegal";
  } 
  return false;
}       

/* ----------------------------------- */
// non-empty textbox
function isEmpty(strng) {
	if (strng.length == 0) {
		return true;
  }
  return false;	  
}

/* ----------------------------------- */
// two stinrgs match
function isEqual(strng1, strng2) {
	if (strng1 == strng2) {
  	return true;
  }
  return false;	  
}

/* ----------------------------------- */
// exactly one radio button is chosen
function noRadio(checkRadio) {
	if (!checkRadio.value) {
		return true;
	}
	return false;
}

/* ----------------------------------- */
// valid selector from dropdown list
function validOption(choice) {
	if (choice == 0) {
  	return false;	
	}
  return true;	  
}    

/* ----------------------------------- */
// email
function validEmail(strng) {
	var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng))) { 
     return false;
  } else {
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
    if (strng.match(illegalChars)) {
     return false;
    }
  }
  return true;
}

/* ----------------------------------- */
// url
function isUrl(strng) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(strng);
}