/*******************************************************************
 created on: Tuesday 07th of September 2010 05:05:20 PM
 This file has been dynamically created by javascript.config.inc.php
 *******************************************************************/

function isEmpty1(str) {
 return (str == null) || (str.length == 0);
}

function isMalicious1(str) {
 var re = /^([a-zA-Z0-9@. `'"-]*(union select|UNION SELECT|exec sp_|EXEC SP_|drop table|DROP TABLE|drop database|DROP DATABASE|drop schema|DROP SCHEMA|delete from|DELETE FROM|\` |\' |"|;|=| = |<|>|\'\+\'|\' \+\ '|\*|%|--)+[a-zA-Z0-9@. -'`";=<>+*%--]*)$/
 return re.test(str);
}

function isUsername(str) {
 if (isEmpty1(str) || isMalicious1(str)) return false;
 var regex = /^[^\s]+[a-zA-Z0-9,?!@#:.\/\s-]{1,500}$/
 return regex.test(str);
}

function isPassword(str) {
 if (isEmpty1(str) || isMalicious1(str)) return false;
 var regex = /^[^\s]+[a-zA-Z0-9,?!@#:.\/\s-]{1,500}$/
 return regex.test(str);
}

function isCaptchacode(str) {
 if (isEmpty1(str) || isMalicious1(str)) return false;
 var regex = /^([a-zA-Z]{4})$/
 return regex.test(str);
}

// validate form
function validateForm1(f,preCheck,theformfunction){
 var valid = true;
 var i,e,t,v,g,b,spantxt,spanid,spanelement,hiddenspan,revalidate,errorwarning;
 errorwarning = document.getElementById('errorwarning');

 for(i=0; i < f.elements.length; i++){
 e = f.elements[i];

 //add event & functions to form elements based on the formfucntion string
 if (theformfunction == 'configureValidation1') revalidate = function(){configureValidation1()};
 if (e.type == 'text' || e.type == 'password' || e.type == 'textarea'){e.onkeyup = revalidate};
 if (e.nodeName.toLowerCase() == "select"){e.onchange = revalidate};
 if (e.type == 'file'){e.onchange = revalidate};
 if (e.type == 'radio' || e.type == 'checkbox'){e.onclick = revalidate};

 t = e.type;
 v = e.value;
 g = e.id + "L";

 if(document.getElementById(g)) b = document.getElementById(g);
 spanid = e.id + "m";
 spanelement = document.createElement('span');
 spanelement.id = spanid;
 spanelement.className = "errortxt"
 if (!document.getElementById(spanid)) e.parentNode.appendChild(spanelement);
 hiddenspan = document.getElementById(spanid);

 if(e.optional && !isMalicious1(e.value) && isEmpty1(e.value)) {
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  b.className = '';
  continue;
 }

if(t == 'text' || t == 'password' || t == 'textarea'){

if(isEmpty1(v)){
 valid = false;
 b.className = "errorLabel";
 hiddenspan.style.display = 'block';
 hiddenspan.innerHTML = "<div id='yelMsgBox'><div id='yelMsg'><img src='./ProFormPlus/FormImages/PFP_IMG_warning.gif' style='padding-top:3px'> Required Field</div></div>";
 continue;
}else{
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  b.className = "fixedLabel";
 }

if(isMalicious1(v)){
 valid = false;
 b.className = "errorLabel";
 hiddenspan.style.display = 'block';
 hiddenspan.innerHTML = "<div id='redMsgBox'><div id='redMsg'><img src='./ProFormPlus/FormImages/PFP_IMG_warning_red.gif' style='padding-top:3px'> This is considered Malicious Data</div></div>";
 continue;
}else{
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  b.className = "fixedLabel";
 }

if(v == e.defaultValue && !e.optional && !e.noDefaultCheck){
 valid = false;
 b.className = "errorLabel";
 hiddenspan.style.display = 'block';
 hiddenspan.innerHTML = "<div id='yelMsgBox'><div id='yelMsg'><img src='./ProFormPlus/FormImages/PFP_IMG_warning.gif' style='padding-top:3px'> Replace Default Text</div></div>";
 continue;
}else{
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  b.className = "fixedLabel";
 }

if(e.isUsername || (!isEmpty1(v) && e.optional && e.name=='username')){
if(!isUsername(v) && v != e.defaultValue){
 valid = false;
 b.className = "errorLabel";
 hiddenspan.style.display = 'block';
 hiddenspan.innerHTML = "<div id='redMsgBox'><div id='redMsg'><img src='./ProFormPlus/FormImages/PFP_IMG_warning_red.gif' style='padding-top:3px'> This is not a valid User Name.</div></div>";
 continue;
}else{
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  if (!e.optional) {
    b.className = "fixedLabel";
  } else { b.className = ''; }
 }
}

if(e.isPassword || (!isEmpty1(v) && e.optional && e.name=='password')){
if(!isPassword(v) && v != e.defaultValue){
 valid = false;
 b.className = "errorLabel";
 hiddenspan.style.display = 'block';
 hiddenspan.innerHTML = "<div id='redMsgBox'><div id='redMsg'><img src='./ProFormPlus/FormImages/PFP_IMG_warning_red.gif' style='padding-top:3px'> This is not a valid Password.</div></div>";
 continue;
}else{
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  if (!e.optional) {
    b.className = "fixedLabel";
  } else { b.className = ''; }
 }
}

if(e.isCaptchacode || (!isEmpty1(v) && e.optional && e.name=='captchacode')){
if(!isCaptchacode(v) && v != e.defaultValue){
 valid = false;
 b.className = "errorLabel";
 hiddenspan.style.display = 'block';
 hiddenspan.innerHTML = "<div id='redMsgBox'><div id='redMsg'><img src='./ProFormPlus/FormImages/PFP_IMG_warning_red.gif' style='padding-top:3px'> Does not match Image above.</div></div>";
 continue;
}else{
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  if (!e.optional) {
    b.className = "fixedLabel";
  } else { b.className = ''; }
 }
}

}

if(t.indexOf('select') != -1){
if(e.options[e.selectedIndex].value == 'noselection && !e.optional'){
 valid = false;
 b.className = "errorLabel";
 hiddenspan.style.display = 'block';
 hiddenspan.innerHTML = "<div id='yelMsgBox'><div id='yelMsg'><img src='./ProFormPlus/FormImages/PFP_IMG_warning.gif' style='padding-top:3px'> Required Field </div></div>";
 continue;
}else{
  hiddenspan.style.display = 'none';
  hiddenspan.innerHTML = '';
  if (!e.optional) {
    b.className = "fixedLabel";
  } else { b.className = ''; }
 }
}

}

if(preCheck == false) {valid = false};
if(preCheck == false || valid == false){
 errorwarning.style.display = 'block';
 (window.location.hash == '#errorwarning') ? null : window.location.hash = 'errorwarning';
}else{
  errorwarning.style.display = 'none'
 };
return valid;

}

//configures form[0] or the first form in the document
function configureValidation1(){
f = null;
f = document.forms[0]; //the form must be set here
f.username.isUsername = true;
f.password.isPassword = true;
f.captchacode.isCaptchacode = true;

//deal with radio and check buttons must be set according to page specifics
var preCheck = true;

return validateForm1(f,preCheck,'configureValidation1');
}

