var formCheck;
var sideFormCheck;
function formCheckLoad (id, tips){
var current = window.onload;
window.onload = function (){ current(); formCheck = new FormCheck(id, tips);}
}
function sideFormCheckLoad (id){
var current = window.onload;
window.onload = function (){ current(); sideFormCheck = new FormCheck(id, false); }
}
function FormCheck (id, tips){
if(typeof(tips) != "undefined") this.display_tips = tips;
this.form = document.getElementById(id);
this.id = id;
this.formElements();
}
FormCheck.prototype.id;
FormCheck.prototype.form;
FormCheck.prototype.elements = new Array();
FormCheck.prototype.submit = true;
FormCheck.prototype.initiated = 0;
FormCheck.prototype.freeze_email = false;
FormCheck.prototype.freeze_captcha = false;
FormCheck.prototype.display_tips = true;
FormCheck.prototype.formElements = function ()
{
var FCO = this;
var inlineAjax = new InlineAjax();
inlineAjax.requestObject.onreadystatechange = function()
{
if(inlineAjax.requestObject.readyState == 4)
{
eval(inlineAjax.requestObject.responseText);
FCO.initiateForm();
}
}
query = "name="+this.id;
url = "/packages/FormCheck/includes/form_elements.php?" + query;
inlineAjax.requestObject.open("GET",url,true);
inlineAjax.requestObject.send(null);
}
FormCheck.prototype.submitForm = function(){
if(this.validateElements()){
if(this.freeze_captcha == false && this.freeze_email == false){ this.form.submit(); }
}
}
FormCheck.prototype.submitFormExit = function(){
if(this.validateElements()){
if(this.freeze_captcha == false && this.freeze_email == false){
var exit = document.createElement('input');
exit.type = "hidden";
exit.name = "exit";
exit.value = "exit"
this.form.appendChild(exit);
this.form.submit();
}
}
}
FormCheck.prototype.initiateForm = function(){
for(element in this.elements)
{
if(document.getElementById(element) != null)
{
this.createInteraction(element);
if(this.elements[element]['hint'] != "")
{
this.hintInteraction(element);
}
if(this.elements[element]['define'] != "")
{
this.lookups(element);
}
}
else
{
delete this.elements[element];
}
}
}
FormCheck.prototype.createInteraction = function(id){
if(this.display_tips){
var input = document.getElementById(id);
var parent = input.parentNode;
var msgbox = document.createElement('span');
msgbox.id = 'msg_'+input.id;
parent.appendChild(msgbox);
var msgimg = document.createElement('img');
msgimg.src = "../images/misc/blank.gif";
msgimg.className = "formcheck";
msgimg.id = 'img_'+input.id;
msgimg.style.paddingLeft = "3px";
parent.appendChild(msgimg);
}
this.assignEvents(id);
}
//validation events
FormCheck.prototype.assignEvents = function(id){
var FCO = this;
var input = document.getElementById(id);
var current_onfocus = input.onfocus;
input.onmouseover = function(){
if(typeof(current_onfocus) == "function"){ current_onfocus(); }
if(FCO.display_tips){ document.getElementById('msg_'+this.id).style.display = "inline"; }
FCO.validateElement(this.id);
}
input.onmouseout = function(){
if(FCO.display_tips){ document.getElementById('msg_'+this.id).style.display = "none"; }
FCO.validateElement(this.id);
}
if(this.elements[id]['required'] == "password"){ input.onkeyup = function (){ FCO.isPassword(input.value, this.id); }}
else if(this.elements[id]['define'] == ""){ input.onkeyup = function (){ if(FCO.validateElement(this.id)){ FCO.hintInteraction(this.id); }}}
if(this.elements[element]['required'] == "check"){
input.onclick = function (){
if(FCO.validateElement(this.id)){ FCO.hintInteraction(this.id); }
else { FCO.errorInteraction(this.id); }
}
}
}
FormCheck.prototype.duplicateInteraction = function(id){
if(this.display_tips){
document.getElementById('msg_'+id).innerHTML = "Error: This Email Address is already taken. Please use another or click the Sign In link at the top of the page.";
document.getElementById('msg_'+id).className = "error";
document.getElementById('img_'+id).src = "../images/icons/icon_error.gif";
}
}
FormCheck.prototype.captchaInteraction = function(id){
if(this.display_tips){
document.getElementById('msg_'+id).innerHTML = "";
document.getElementById('msg_'+id).className = "error";
//document.getElementById('img_'+id).src = "../images/icons/icon_error.gif";
}
}
FormCheck.prototype.errorInteraction = function(id){
if(this.display_tips){
document.getElementById('msg_'+id).innerHTML = "Error: " + this.elements[id]['error'];
document.getElementById('msg_'+id).className = "error";
document.getElementById('img_'+id).src = "../images/icons/icon_error.gif";
}
}
FormCheck.prototype.customInteraction = function(id, msg){
if(this.display_tips && msg != ""){
document.getElementById('msg_'+id).innerHTML = "Error: " + msg;
document.getElementById('msg_'+id).className = "error";
document.getElementById('img_'+id).src = "../images/icons/icon_error.gif";
}else if(this.display_tips){
this.blankInteraction(id);
}
}
FormCheck.prototype.hintInteraction = function(id){
if(this.display_tips){
if(this.elements[id]['hint'] == ""){ this.blankInteraction(id); }
else{
if(id != 'captcha'){
document.getElementById('msg_'+id).innerHTML = "Hint: " + this.elements[id]['hint'];
document.getElementById('msg_'+id).className = "info";
document.getElementById('img_'+id).src = "../images/misc/blank.gif";
}
}
}
}
FormCheck.prototype.blankInteraction = function(id){
if(this.display_tips && document.getElementById('msg_'+id) != null){
document.getElementById('msg_'+id).innerHTML = "";
document.getElementById('msg_'+id).className = "";
document.getElementById('img_'+id).src = "../images/misc/blank.gif";
}
}
FormCheck.prototype.lookups = function (id){
var FCO = this;
$("#"+id).change(function(){
FCO.lookupSelect(id);
});
}
FormCheck.prototype.lookupSelect = function (element){
var define = this.elements[element]['define'];
this.lookup_select(element, $("#"+element).val(), this.elements[define]['source'], define, this.elements[define]['display']);
/*var FCO = this;
var FEO = document.getElementById(element);
var DEO = document.getElementById(define);
$("#"+define).empty();
var inlineAjax = new InlineAjax();
inlineAjax.requestObject.onreadystatechange = function(){
if(inlineAjax.requestObject.readyState == 4){
var inner = inlineAjax.requestObject.responseText;
inner = "" + inner;
$("#"+define).html(inner);
//if(document.all){ DEO.outerHTML = DEO.outerHTML; }
if(FCO.elements[define] != null && FCO.elements[define]['define'] != ""){
$("#"+FCO.elements[define]['define']).empty();
$("#"+FCO.elements[define]['define']).html("");
}
}
}
var current = "";
if(DEO != null) current = DEO.value;
if(this.elements[define] != null){
query = "tbl="+this.elements[define]['source']+"&col="+element+"&val="+FEO.value+"&dis="+this.elements[define]['display']+"&cur="+current+"&unique="+Math.ceil(Math.random()*10000);
url = "packages/FormCheck/includes/lookup_select.php?" + query;
inlineAjax.requestObject.open("GET",url,true);
inlineAjax.requestObject.send(null);
}*/
}
FormCheck.prototype.checkUnique = function(id){
var FCO = this;
var FEO = document.getElementById(id);
var inlineAjax = new InlineAjax();
inlineAjax.requestObject.onreadystatechange = function(){
if(inlineAjax.requestObject.readyState == 4){
//alert(inlineAjax.requestObject.responseText);
if(inlineAjax.requestObject.responseText == "duplicate"){
FCO.duplicateInteraction(id);
FCO.freeze_email = true;
}else{ FCO.freeze_email = false; }
}
}
url = "/packages/FormCheck/includes/check_unique.php?email=" + FEO.value;
inlineAjax.requestObject.open("GET",url,true);
inlineAjax.requestObject.send(null);
}
FormCheck.prototype.checkCaptcha = function(id){
var FCO = this;
var FEO = document.getElementById(id);
var inlineAjax = new InlineAjax();
inlineAjax.requestObject.onreadystatechange = function(){
if(inlineAjax.requestObject.readyState == 4){
//alert(inlineAjax.requestObject.responseText);
if(inlineAjax.requestObject.responseText == "incorrect"){
FCO.captchaInteraction(id);
FCO.freeze_captcha = true;
}else{ FCO.freeze_captcha = false; }
}
}
url = "/packages/FormCheck/includes/check_captcha.php?captcha=" + FEO.value;
inlineAjax.requestObject.open("GET",url,true);
inlineAjax.requestObject.send(null);
}
FormCheck.prototype.validateElements = function(id){
var valid = true;
for(element in this.elements){
var name = this.elements[element]['name'];
if(name == id){ break; }
else {
if(this.elements[element]['required'] != ""){
if(!this.validateElement(name)){
if(id == "salary_maximum"){ valid = false; }
else{ this.errorInteraction(name); valid = false; }
}
else { this.hintInteraction(name); }
}
}
}
return valid;
}
FormCheck.prototype.validateElement = function(id){
var input = document.getElementById(id);
var response_handler_url = document.getElementById("response_handler_url");
var response_handler_email = document.getElementById("response_handler_email");
if(input.getAttribute('unique') == "unique"){ if(this.isBlank(input.value) || !this.isEmail(input.value)){ return false;} else{ this.checkUnique(id); }}
if(input.getAttribute('captcha') == "check"){ if(this.isBlank(input.value)){ return false;} else{ this.checkCaptcha(id); } }
if(this.elements[id]['required'] == "text")
{
//if this is the alternative email field
if(id == 'alternative_name')
{
//then check if response_handler_email is checked and validate
//else dont validate
if(response_handler_email.checked)
{
if(this.isBlank(input.value))
{
return false;
}
else
{
return true;
}
}
else{return true;}
}
else if(id == 'job_cc_name')
{
var use_cc = document.getElementById("use_cc");
//then check if use_cc is checked and validate
//else dont validate
if(use_cc.checked)
{
if(this.isBlank(input.value))
{
return false;
}
else
{
return true;
}
}
else{return true;}
}
else if (id == 'region_id')
{
if ($("#country_id").val() == 244)
{
if(this.isBlank(input.value))
{
return false;
}
else
{
return true;
}
} else {
return true;
}
}
else if (id == 'location_id')
{
if ($("#country_id").val() == 244)
{
if(this.isBlank(input.value))
{
return false;
}
else
{
return true;
}
} else {
return true;
}
}
else
{
if(this.isBlank(input.value))
{
return false;
}
else
{
return true;
}
}
}
else if(this.elements[id]['required'] == "suggest"){ if(this.isBlank(input.value)){ return false;} else if(this.isBlank(document.getElementById(this.elements[id]['suggest']).value)){ return false;} else{ return true; }}
else if(this.elements[id]['required'] == "numeric"){ if(!this.isNumeric(input.value)){ return false;} else{ return true; }}
else if(this.elements[id]['required'] == "email")
{
//if this is the alternative email field
if(id == 'alternative_email')
{
//then check if response_handler_email is checked and validate
//else dont validate
if(response_handler_email.checked)
{
if(!this.isEmail(input.value))
{
return false;
}
else
{
return true;
}
}
else{return true;}
}
else if(id == 'job_cc_email')
{
var use_cc = document.getElementById("use_cc");
//then check if use_cc is checked and validate
//else dont validate
if(use_cc.checked)
{
if(!this.isEmail(input.value))
{
return false;
}
else
{
return true;
}
}
else{return true;}
}
else
{
if(!this.isEmail(input.value))
{
return false;
}
else
{
return true;
}
}
}
else if(this.elements[id]['required'] == "confirm"){ if(!this.isEqual(id)){ return false;} else{ return true; }}
else if(this.elements[id]['required'] == "password"){ if(this.isBlank(input.value)){ return false;} else{ return true; }}
else if(this.elements[id]['required'] == "check"){ if(!input.checked){ return false;} else{ return true; }}
else if(this.elements[id]['required'] == "mce"){ if(this.isBlank(tinyMCE.get(id).getContent())){ return false;} else{ return true; }}
else if(this.elements[id]['required'] == "url")
{
if(response_handler_url.checked == true)
{
if(this.isURL(input.value))
{
return true;
}
else
{
//this.blankInteraction(id);
//this.customInteraction(id, "Please Enter a valid URL");
return false;
}
}
else
return true;
}
else if(this.elements[id]['required'] == "salary")
{
var validation = this.salaryValidation();
if(validation == "")
{
return true;
}
else
{
if(id == "salary_frequency"){ this.blankInteraction("salary_maximum"); }
else if(id == "salary_maximum"){ this.blankInteraction("salary_frequency"); }
this.customInteraction(id, validation);
return false;
}
}
else
{
return true;
}
}
FormCheck.prototype.repetitiveValidation = function(id){
var valid = true;
var name = this.elements[id]['name'];
if(this.elements[id]['required'] != ""){
if(!this.validateElement(name)){ this.errorInteraction(name); valid = false; }
else { this.hintInteraction(name); }
}
return valid;
}
FormCheck.prototype.arrayValidation = function(elements){
var valid = true;
for(loop=0;loop 6) score++;
if ( ( string.match(/[a-z]/) ) && ( string.match(/[A-Z]/) ) ) score++;
if (string.match(/\d+/)) score++;
if ( string.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;
if (string.length > 12) score++;
document.getElementById('msg_'+id).innerHTML = "Password Strength:
"+desc[score]+"";
document.getElementById('msg_'+id).className = "info";
document.getElementById('img_'+id).src = "../images/icons/icon_info.gif";
}
FormCheck.prototype.salaryValidation = function() {
var valid = '';
var min = parseInt($("#salary_minimum").val());
//if (min === 0) { min = 1; }
var max = parseInt($("#salary_maximum").val());
var fre = $("#salary_frequency").val();
// if ($("#salary_maximum").val() == '') { valid = 'Salary Range minimum and maximum are required and must be numeric only.'; }
// if(!this.isNumeric(min) || !this.isNumeric(max)){ valid = 'Salary Range minimum and maximum are required and must be numeric only.'; }
if(min > max){ valid = 'Salary Range minimum cannot be more than the maximum.'; }
else if(fre == "MONTHLY" && ( ((min / max) * 100) < 50 ) ) { valid = 'Specified Salary Range is too broad, Monthly salary must be within a 50% range.'; }
//--else if(fre == "MONTHLY" && (max - min) > 100000){ valid = 'Specified Salary Range is too broad, Monthly salary must be within a R100000 range.'; }
else if(fre == "MONTHLY" && max < 1500 && max != 0){ valid = 'Specified Maximum Salary is too small. Are you sure this is a Monthly Range?'; }
else if(fre == "ANNUALLY" && ( ((min / max) * 100) < 50 ) ) { valid = 'Specified Salary Range is too broad, Annual salary must be within a 50% range.'; }
//--else if(fre == "ANNUALLY" && (max - min) > 1000000){ valid = 'Specified Salary Range is too broad, Annual salary must be within a R500000 range.'; }
else if(fre == "ANNUALLY" && max < 18000 && max != 0){ valid = 'Specified Maximum Salary is too small. Are you sure this is a Annual Range?'; }
else if(fre == "WEEKLY" && ( ((min / max) * 100) < 50 ) ){ valid = 'Specified Salary Range is too broad, Weekly salary must be within a 50% range.'; }
//--else if(fre == "WEEKLY" && (max - min) > 20000){ valid = 'Specified Salary Range is too broad, Weekly salary must be within a R20000 range.'; }
//else if(fre == "WEEKLY" && max < 300 && max != 0){ valid = 'Specified Maximum Salary is too small. Are you sure this is a Weekly Range?'; }
else if(fre == "HOURLY" && ( ((min / max) * 100) < 50 ) ){ valid = 'Specified Salary Range is too broad, Hourly salary must be within a 50% range.'; }
//--else if(fre == "HOURLY" && (max - min) > 10000){ valid = 'Specified Salary Range is too broad, Hourly salary must be within a R10000 range.'; }
else if(fre == "HOURLY" && max < 25 && max != 0){ valid = 'Specified Maximum Salary is too small. Are you sure this is an Hourly Range?'; }
return valid;
}
appendSuggested = function (element, value, id, pk){
document.getElementById(element).value = value;
document.getElementById(id).value = pk;
document.getElementById('suggest_' + element).style.display = "none";
}
// ELEMENTS
function escapeHTML(someText) {
var div = document.createElement('div');
var text = document.createTextNode(someText);
div.appendChild(text);
return div.innerHTML;
}
FormCheck.prototype.lookup_select = function(key, value, source, define, display){
var form = this;
var loader;
if (key == 'country_id' && value != '244') {
var new_option = '';
$('#region_id').append(new_option);
$('#region_id').val('0');
$("#region_id").attr("disabled", true);
$("#region_id").attr("readonly", true);
$('#location_id').append(new_option);
$('#location_id').val('0');
$("#location_id").attr("disabled", true);
$("#location_id").attr("readonly", true);
} else {
if (key == 'country_id' && value == '244') {
$("#region_id option[value='0']").remove();
$("#region_id").attr("disabled", false);
$("#region_id").attr("readonly", false);
$("#location_id option[value='0']").remove();
$("#location_id").val('');
$("#location_id").attr("disabled", false);
$("#location_id").attr("readonly", false);
}
if($(define+"_loader").length > 0){
loader = $(define+"_loader");
}else{
loader = $("
").attr({ id: define+"_loader", src:"/images/ajax/small_loader.gif" }).css({ paddingLeft: 5 });
$("#"+define).after(loader);
}
$.get('/packages/FormCheck/includes/lookups.php', { key: key, value: value, source: source, define: define, display: display },
function(data){
$("#"+define).empty();
$(data).find("option").each(function(element){
var option = $("").attr("value", $(this).find("value").text()).html($(this).find("text").text());
$('#'+define).append(option);
});
$(loader).hide();
});
}
}