// 'none'               - No validation
// 'must_select'        - Something must be selected on the dropdown if there is an option.
// 'req_select'         - Something must be selected on the dropdown if there is no option can't go on.
// 'must_multiple'      - Something must be selected on the dropdown.
// 'date'               - Checks if it is a valid date only
// 'post_date'          - The date must be after today
// 'post_date_time'     - The date must be after che current moment in time
// 'pre_date'           - The date must be before today
// 'req_comp_dd_2'      - Compares 2 dropdowns to make sure at least 1 is selected and the selections are not the the same.
// 'comp_dd_2'          - Compares 2 dropdowns to make sure the selections are not the the same.
// 'req_comp_dd_3'      - Compares 3 dropdowns to make sure at least 1 is selected and the selections are not the the same.
// 'req_comp_dd_4'      - Compares 4 dropdowns to make sure at least 1 is selected and the selections are not the the same.
// 'comp_dd_3'          - Compares 3 dropdowns to make sure the selections are not the the same.
// 'dd_not_empty'		- Check if the dropdown is not empty
// 'req_txt'            - Text that is required to be filled in.
// 'req_txt_nolimit'    - Text that is required to be filled in, no check on length of word
// 'req_html'           - Text that is required to be filled in including some HTML tags.
// 'req_html_nolimit'   - Text that is required to be filled in including some HTML tags.
//                      - The length will not be checked.  Use textAreaLimit(...) for length validation in textareas.
// 'req_fieldDesc_html' - Text that is required to be filled in including some HTML tags.
//                      - The length will not be checked.  Use textAreaLimit(...) for length validation in textareas.
// 'req_num'            - Number that is greater than 0.
// 'req_num_int'        - I18N version of above
// 'req_decimal'        - Number that is greater than 0 but can contain . and is required
// 'req_neg_decimal     - Number that can have '-' as the first char and can contain a '.' and is required
// 'req_file'           - Allows all characters but is required.
// 'req_txt_2_if_not_empty'	- Previous text field is required to be filled in if field is not empty.
// 'req_txt_2_if_prev_not_empty' - Text field is required to be filled in if previous field is not empty.
// 'min_req_txt'        - Required text that has the minimum validation so files can be uploaded
// 'limit_txt'          - Required text that is between 6 an 10 characters long
// 'match_txt'          - Text that must be the same as the previous text
// 'val_txt'            - Allows valid characters only but is not required.
// 'val_html_desc'      - Allows valid characters only but is not required. Used to allow new desc_field to extend unbroken fieldlength.
//                      - The length will not be checked.  Use textAreaLimit(...) for length validation in textareas.
// 'val_html'           - Allows valid characters only but is not required including some HTML tags.
// 'val_html_nolimit'   - Allows valid characters only but is not required including some HTML tags, no limit on length of words
//                      - The length will not be checked.  Use textAreaLimit(...) for length validation in textareas.
// 'val_email'          - Allows only one valid emails which is required.
// 'val_email_many'     - Allows infinate valid emails only one is required.
// 'val_email_oneormore'- Allows many emails. Must be at least one.
// 'val_email_not_req'  - Allowd one valid email, not required. Passes with the empty String.
// 'val_num'            - Allows valid number only but is not required
// 'val_num_int'        - I18N version of above
// 'val_num_int_pos'    - as above but checks if number is positive
// 'val_java_int'       - Allows a number that fits in a Java int.
// 'val_decimal'        - Allows valid number including . but is not required
// 'val_negdecimal'     - Allows valid number including '.' but is not required. Can have a '-' as the first char.
// 'val_float'          - Allows valid number only but is not required
// 'must_check'         - Ensures the user checks a checkbox
// 'curr_and_int'       - Checks is you fill in an amount you also select a currency.
// 'curr_and_float'     - Checks is you fill in an amount you also select a currency.
// 'greater_than_num'   - Checks the second number is greater than the first
// 'one_dd_2'           - Check you only fill in one dropdown out of the two. ("B")
// 'val_greater_than_zero' - Greater than 0
// 'req_greater_or_equal_zero' - Greater or equal 0, required
// 'textAreaLimit'      - Checks the length of text in a textarea element
// 'must_check_radio'   - Ensures that a a selection is made in a group of radio buttons
// 'val_url_no_prtcl'	- Allows valid url without protocol
// 'req_prev_if_chkd' - If checkbox is checked ensures that previous field is filled in
// 'must_select_if_prev_not_empty' - Something must be selected on the dropdown if previous field is not empty
// 'date_dp' - Date picker, not required 

// ******* Specific **********

// 'an_salary'          - Checks the min and max salary and currency fields
// 'an_salary_int'       - I18N version of above - allows , and . to be used interchangably (requires that tag i18n:javascript is used in the page to set up values for current locale)...
// 'asap'               - This is for the asap check box in activerecruiter main
// 'chk_man'            -
// 'comp_date_for_logging'  - compare date for specific for logging page
// 'comp_date2'         - Comapres from and to date only used in candidate search pages
// 'email_content_txt'  - Forces the user to replace <<x>> with some valid text
// 'req_email_content_txt'  - Forces the user to replace <<x>> with some valid text, in addition to validating that text is entered.
// 'req_email_template_text'    - Checks for standard invalid characters, but allows <<x>>.  Also checks text is enterd.
// 'val_email_template_text'    - same as req_email_template_text but a blank box is allowed
// 'req_email_template_nonhtml_text'    - Checks for standard invalid characters.  Also checks text is entered.
// 'val_email_template_nonhtml_text'    - same as req_email_template_nonhtml_text but a blank box is allowed
// 'jp_self_test'       - Validation for the self test on the public side.
// 'notice'             - Makes sure number of weeks of notice are filled in if the radio button is checked
// 'skill_select'       - Validation for all skills only.
// 'select_one_for_logging' - For logging pages only ensures one this is selected from the whole page
// 'specifc_date'       - Makes sure date is filled in if the radio button is checked
// 'dd_or_text'         - Makes either the dropdown or the textbox filled in.

var fieldName; // Popup Message
var fieldName2; // Popup Message element -1
var fieldName3; // Popup Message element -2
var fieldName4; // Popup Message element -3

// New function for James C to validate single named field

var _namedIsValid = false;

var _isInit = false;

var numberFormatType = 1;

function namedInit() {
_isInit = true;
_namedIsValid = true;
}

function namedPass() {
if (!_isInit) { alert("'namedInit()' needs to be called"); }
return _namedIsValid;
}

function namedValidation(frm,eleName,valType,text){
var newval = new Array();
var frmLength = frm.elements.length * 2;
var isValid = false;

if (_namedIsValid) {
   for (var i = 0; i < frmLength; i += 2) {
      if (frm.elements[(i/2)].name == eleName) {
      newval[i] = valType;
      newval[(i+1)] = text;
      break;
      } else {
      newval[i] = "none";
      newval[(i+1)] = text;
      }
   }

isValid = inputValidation(frm, newval);
_namedIsValid = _namedIsValid && isValid;
}
return isValid;
}

// End of new function for James C
function inputValidation(frm, valArr){
	inputValidation(frm, valArr, false);
}
//If testMode is set to true, the information about the validation
//is going to be shown in alerts. Only for testing purposes.
function inputValidation(frm, valArr, testMode){
var validate;
var valType;
var i = 0;
var x;

var frmLength = frm.elements.length * 2;
var valLength = valArr.length;
if (frmLength < valLength) { valLength = frmLength; }

    //Loop through all the form elements
    for (var j = 0; j < valLength; j += 2)
    {

    i = j/2;  // Array goes up in steps of 2 elements in steps of 1
    validate = true;  // If there is no validation it is passed as true
    valType = valArr[j]; // Type of validation
    fieldName = valArr[j+1]; // Popup message
    if (j >= 1) { fieldName2 = valArr[j-1]; } else { fieldName2 = fieldName; }
    if (j >= 3) { fieldName3 = valArr[j-3]; } else { fieldName3 = fieldName; }
    if (j >= 5) { fieldName4 = valArr[j-5]; } else { fieldName4 = fieldName; }
if (testMode){
	alert('Element '+i+': '+fieldName+'\nValidation Type: '+valType+'\nField Value: '+frm.elements[i].value);
}

// use TinyMCE to validate contents of editor, only check if not empty
if (valType != "none") {
	if (typeof hasWYSIWYG == 'function' && hasWYSIWYG(frm.elements[i].id)) {
	
		// check if not empty and use TinyMCE's focus method (not that of the textarea)
	    if (frm.elements[i].value.length == 0 && isJPJSValidateRequired() && isFieldRequired(frm.elements[i].name)) {
	        alert(isreq1+ fieldName+ isreqa1);
	        if (frm.elements[i].type!='hidden') {
	            getWYSIWYG(frm.elements[i].id).focus();
	        }
	        return false;
	    }
	    
	    // skip rest of validation for this field
		continue;
	}
}

//Test field against validation mask character
switch (valType) {

case "none": break;

case "must_check":  validate=must_check(frm.elements[i]);
            if(!validate){return false;}
break;

case "must_check_radio":  validate=must_check_radio(frm, frm.elements[i], fieldName);
            if(!validate){return false;}
break;

case "must_select": validate=must_select(frm.elements[i]);
            if(!validate){return false;}
break;

case "req_select":  validate=req_select(frm.elements[i]);
            if(!validate){return false;}
break;

case "must_multiple":   validate=must_multiple(frm.elements[i]);
            if(!validate){return false;}
break;

case "skill_select":    validate=skill_select(frm.elements[i]);
            if(!validate){return false;}
break;

case "req_txt":
			validate = checkIfFieldMightBeAnEmail(frm.elements[i]);
			if(!validate) {
				validate=allowed_text(frm.elements[i],"required");
			}
            if(!validate){return false;}
break;
case "req_txt_nolimit": validate=allowed_text(frm.elements[i],"required_nolimit");
            if(!validate){return false;}
break;

case "req_num": validate=allowed_text(frm.elements[i],"reqnum");
            if(!validate){return false;}
break;

case "req_num_int": validate=allowed_text(frm.elements[i],"reqnumint");
            if(!validate){return false;}
break;

case "req_decimal": validate=allowed_text(frm.elements[i],"reqdecimal");
            if(!validate){return false;}
break;

case "req_neg_decimal": validate=allowed_text(frm.elements[i],"reqnegdecimal");
            if(!validate){return false;}
break;

case "val_num": validate=allowed_text(frm.elements[i],"valnum");
            if(!validate){return false;}
break;

case "val_num_int": validate=allowed_text(frm.elements[i],"valnumint");
	if(!validate){return false;}
break;

case "val_num_int_pos": validate=allowed_text(frm.elements[i],"valnumintpos");
	if(!validate){return false;}
break;

case "val_java_int": validate=allowed_text(frm.elements[i],"valjavaint");
            if(!validate){return false;}
break;

case "req_java_int": validate=allowed_text(frm.elements[i],"reqjavaint");
            if(!validate){return false;}
break;

case "val_decimal": validate=allowed_text(frm.elements[i],"valdecimal");
            if(!validate){return false;}
break;

case "val_neg_decimal": validate=allowed_text(frm.elements[i],"valnegdecimal");
            if(!validate){return false;}
break;

case "val_float":   validate=newIsFloat(frm.elements[i]);
            if(!validate){return false;}
break;

case "min_req_txt": validate=allowed_text(frm.elements[i],"minrequired");
            if(!validate){return false;}
break;

case "req_txt_2_if_not_empty": validate=req_if_prev_not_empty(frm.elements[i-1],frm.elements[i]);
            if(!validate){return false;}
break;

case "req_txt_2_if_prev_not_empty": validate=req_if_prev_not_empty(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "limit_txt":   validate=allowed_text(frm.elements[i],"limited");
            if(!validate){return false;}
break;

case "limit_user":  validate=allowed_text(frm.elements[i],"limitedUser");
            if(!validate){return false;}
break;

case "match_txt":   validate=match_text(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "email_content_txt":   validate=allowed_text(frm.elements[i],"email_con");
            if(!validate){return false;}
break;

case "req_email_content_txt":   validate=allowed_text(frm.elements[i],"req_email_con");
            if(!validate){return false;}
break;

case "req_email_template_text":   validate=allowed_text(frm.elements[i],"req_email_tpl");
            if(!validate){return false;}
break;

case "val_email_template_text":   validate=allowed_text(frm.elements[i],"val_email_tpl");
            if(!validate){return false;}
break;

case "req_email_template_nonhtml_text":   validate=allowed_text(frm.elements[i],"req_email_nonhtml_tpl");
			if(!validate){return false;}
break;

case "val_email_template_nonhtml_text":   validate=allowed_text(frm.elements[i],"val_email_nonhtml_tpl");
			if(!validate){return false;}
break;

case "val_email":   validate=valid_email(frm.elements[i]);
            if(!validate){return false;}
break;

case "val_email_many":  validate=valid_email(frm.elements[i],"multi");
            if(!validate){return false;}
break;

case "val_email_not_req": validate=valid_email(frm.elements[i],"not_req");
                          if (!validate) {return false;}
break;

case "val_email_oneormore" : validate=valid_email(frm.elements[i],"oneormore");
                             if (!validate) {return false;}
break;

case "req_prev_if_chkd":   validate=reqd_prev_if_chkd(frm.elements[i], frm.elements[i-1]);
            if(!validate){return false;}
break;

case "val_txt":
			validate = checkIfFieldMightBeAnEmail(frm.elements[i]);
			if(!validate) {
				validate=allowed_text(frm.elements[i]);
			}
            if(!validate){return false;}
break;
case "val_txt_nolimit": validate=allowed_text(frm.elements[i],"nolimit");
            if(!validate){return false;}
break;

case "req_html":    validate=allowed_text(frm.elements[i],"reqhtml");
            if(!validate){return false;}
break;
case "req_html_nolimit":    validate=allowed_text(frm.elements[i],"reqhtml_nolimit");
            if(!validate){return false;}
break;
case "req_fieldDesc_html":  validate=allowed_text(frm.elements[i],"req_fieldDesc");
            if(!validate){return false;}
break;
case "req_file":    validate=allowed_text(frm.elements[i],"reqfile");
            if(!validate){return false;}
break;

case "val_html":    validate=allowed_text(frm.elements[i],"html");
            if(!validate){return false;}
break;
case "val_html_nolimit":    validate=allowed_text(frm.elements[i],"html_nolimit");
            if(!validate){return false;}
break;

case "val_html_desc": validate=allowed_text(frm.elements[i], "desc_field");
            if(!validate){return false;}
break;

case "asap":    validate=val_asap(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i-3]);
            if(!validate){return false;}
break;
/*case "formated_number":
    for(int j = 0; j < frm.elements[i].length; j++){
        if(frm.elements[i].value[j] != '1')*/
break;

case "an_salary":   validate=chk_currency(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i+1]);
            if(!validate){return false;}
break;

case "an_salary_int":   validate=chk_currency_int(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i+1]);
            if(!validate){return false;}
break;

case "curr_and_int":    validate=chk_currency_pub(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "curr_and_float":  validate=chk_currency_vat(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "req_comp_dd_2":   validate=dd_compare2(frm.elements[i],frm.elements[i-1],"required");
            if(!validate){return false;}
break;

case "comp_dd_2":   validate=dd_compare2(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "req_comp_dd_3":   validate=dd_compare3(frm.elements[i],frm.elements[i-1],frm.elements[i-2],"required");
            if(!validate){return false;}
break;

case "req_comp_dd_4":   validate=dd_compare4(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i-3],"required");
            if(!validate){return false;}
break;

case "comp_dd_3":   validate=dd_compare3(frm.elements[i],frm.elements[i-1],frm.elements[i-2]);
            if(!validate){return false;}
break;

case "one_dd_2":    validate=one_dd_2(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "dd_not_empty":    validate=ddNotEmpty(frm.elements[i]);
            if(!validate){return false;}
break;

case "date":    validate=TheDate(frm.elements[i],frm.elements[i-1],frm.elements[i-2]);
            if(!validate){return false;}
break;

case "post_date":   validate=TheDate(frm.elements[i],frm.elements[i-1],frm.elements[i-2],"post");
            if(!validate){return false;}
break;

case "post_date_time":  validate=TheTime(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i-3],"posttime");
            if(!validate){return false;}
break;

case "pre_date":    validate=TheDate(frm.elements[i],frm.elements[i-1],frm.elements[i-2],"pre");
            if(!validate){return false;}
break;

case "comp_date2":  validate=TheDate(frm.elements[i],frm.elements[i-1],frm.elements[i-2],"onlycompare",frm.elements[i-3],frm.elements[i-4],frm.elements[i-5]);
            if(!validate){return false;}
break;

case "chk_man": validate=checkMamager(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "specifc_date":    validate=val_specifc_date(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i-3]);
            if(!validate){return false;}
break;

case "greater_than_num":    validate=GreaterThanNum(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "val_greater_than_zero":   validate=val_greater_than_zero(frm.elements[i]);
            if(!validate){return false;}
break;

case "req_greater_or_equal_zero":
   			validate=allowed_text(frm.elements[i],"required");
   			if(!validate){return false;}
			validate=val_greater_or_equal_zero(frm.elements[i]);
            if(!validate){return false;}
break;

case "dd_or_text":  validate=comp_dd_or_txt(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "current_job": validate=comp_job_date(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i-3],"cur");
            if(!validate){return false;}
break;

case "previous_job":    validate=comp_job_date(frm.elements[i],frm.elements[i-1],frm.elements[i-2],frm.elements[i-3],"pre");
            if(!validate){return false;}
break;

case "notice":  validate=val_notice(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "select_one_for_logging":  validate=for_logging(frm.elements[i],frm.elements[i+1],frm.elements[i+2],frm.elements[i+3],frm.elements[i+4],frm.elements[i+5],frm.elements[i+6],frm.elements[i+7],frm.elements[i+8]);
            if(!validate){return false;}
break;

case "comp_date_for_logging":   validate=TheDate(frm.elements[i],frm.elements[i-1],frm.elements[i-2],"for_logging",frm.elements[i-3],frm.elements[i-4],frm.elements[i-5]);
            if(!validate){return false;}
break;

case "jp_self_test":    validate=newValTest(frm);
            if(!validate){return false;}
break;

case "val_url_no_prtcl":  validate=isUrl(frm.elements[i]);
            if(!validate){return false;}
break;

case "must_select_if_prev_not_empty": validate=must_select_if_prev_not_empty(frm.elements[i],frm.elements[i-1]);
            if(!validate){return false;}
break;

case "date_dp":
			_namedIsValid = true;
			validate=datePickerValidation(frm.elements[i+4], dp_day_tokens,
			frm.elements[i + 5], dp_month_tokens,
			frm.elements[i + 6], dp_year_tokens,
			frm.elements[i], valText[6]);
			if(!validate){return false;}
break;

default :
  alert("'" + valType + "'\nValidation class does not exist");
break;
}

    }           // End of for loop
    return true;
}               // End of "validateInput" function

// ********************************************************************************************

function checkIfFieldMightBeAnEmail(e) {
	//	try to see if the field might be en email-
	//	if so check if matches an email's pattern else check text.
	var emailRegEx = new RegExp("[eE][mM][aA][iI][lL]");
	if(e.name.match(emailRegEx) != null) {
		return valid_email(e, "oneormore");
	}
	return false;
}

// Validation function for checking that you should enter at least one character
function allowed_text(e,valtype)
{
var space_length=50;
var checklength=true;
var ats = 0;
var pts = 0;
var sco = 0;
var eml = false;
var text = e.value;
var wasQuote = false;

if (valtype=="limitedUser"){space_length=60;}
if (valtype=="minrequired"){space_length=300;}
if (valtype=="email_con"){checklength=false;}
if (valtype=="required_nolimit"){checklength=false;}
if (valtype=="reqhtml_nolimit"){checklength=false;}
if (valtype=="html_nolimit"){checklength=false;}
if (valtype=="req_email_con"){checklength=false;}
if (valtype=="req_email_tpl"){checklength=false;}
if (valtype=="val_email_tpl"){checklength=false;}
if (valtype=="req_email_nonhtml_tpl"){checklength=false;}
if (valtype=="val_email_nonhtml_tpl"){checklength=false;}
if (valtype=="reqfile"){checklength=false;}
if (valtype=="nolimit"){checklength=false;}
if (valtype=="desc_field"){space_length=150;}
if (valtype=="req_fieldDesc"){space_length=150;}
if (valtype=="valjavaint"){space_length=11;}
if (valtype=="reqjavaint"){space_length=11;}

// For HTML validation, don't check the maximum length.  These pages will do individual checking as some allow 6000.
if (((valtype!="html") && (valtype!="html_nolimit") && (valtype!="reqhtml") && (valtype!="reqhtml_nolimit")
            && (valtype!="desc_field") && (valtype!="req_email_con")) && text.length >= 4000) {
    alert(isreq60);
    if (e.focus) {
    	e.focus();
	}
    return false;
}

if ((valtype=="required") || (valtype=="minrequired") || (valtype=="required_nolimit")
        || (valtype=="reqhtml") || (valtype=="reqhtml_nolimit") || (valtype=="reqfile")
        || (valtype=="req_fieldDesc") || (valtype=="req_email_con") || (valtype=="req_email_tpl"))
    {
    if (text.length == 0 && isJPJSValidateRequired())
        {
        alert(isreq1+ fieldName+ isreqa1);
        if (e.type!='hidden' && e.focus) {
            e.focus();
        }
        return false;
        }
    }

if (valtype=="limited")
    {
    if(text.length<6||text.length>10 )
        {
        alert(isreq4 + fieldName+ isreqa4 );
        	e.focus();
        return false;
        }
    }

if (valtype=="limitedUser")
    {
    if(text.length<6||text.length>60 )
        {
        alert(isreq4 + fieldName+ isreqb4 );
        e.focus();
        return false;
        }
    }

if ((valtype!="email_con") && (valtype!="req_email_con") && (valtype!="req_email_tpl") && (valtype!="val_email_tpl"))
    {
    if (text.substring(0,1)==" ")
        {
        alert(isreq45+ fieldName+ isreqa45);
        e.focus();
        return false;
        }
    }
     for (var i=0; i < text.length; i++)
     {
          var ch = text.substring(i,i+1);
          var ch2 = text.substring(i,i+2);

          if (i == 0 && (valtype == "reqnegdecimal" || valtype == "valnegdecimal" || valtype == "valjavaint" || valtype=="reqjavaint") && ch == "-") {
              if (ch == "-" && text.length==i+1)
              {
                alert(isreq18 + fieldName+ isreqa18 );
                e.focus();
                return false;
              }
              continue;
          }

if ( (i<(text.length-space_length))&&(checklength) )
{
          var chunk = text.substring(i,i+space_length)

          if ((chunk.indexOf(" ")==-1)&&(chunk.indexOf("\n")==-1))
                    {
              if (space_length=="35")
                {
                        alert(isreq52);
                        e.focus();
                        return false;
                        }
              else if (space_length=="60")
                {
                        alert(isreq61);
                        e.focus();
                        return false;
                        }
              else if (space_length=="300")
                {
                        alert(isreq62);
                        e.focus();
                        return false;
                        }
              else if (space_length=="150")
                {
                        alert(isreq63);
                        e.focus();
                        return false;
                        }
              else
                {
                  alert(isreq64);
                        e.focus();
                        return false;
                }
            }
}

if (valtype=="reqfile") {
          if (ch=="|")
                {
                alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
                e.focus();
                return false;
                }
}else if (valtype=="minrequired") {
          if ((ch==">")||(ch=="<")||(ch=="|")||(ch=="\""))
                {
                alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
                e.focus();
                return false;
                }
}else if(valtype=="formatnum"){
    if ((ch < "0" || ch > "9") && ch != "," && ch!="." ){
        alert(isreq18 + fieldName+ isreqa18 );
        e.focus();
        return false;
    }

}else if ((valtype=="reqnum")||(valtype=="valnum")||(valtype=="valjavaint")||(valtype=="reqjavaint")) {

          if (ch<"0" || ch>"9")
                {
                alert(isreq18 + fieldName+ isreqa18 );
                e.focus();
                return false;
                }

}else if (valtype=="reqnumint") {

          if (!newIsFloat_int(e))
                {
                alert(isreq18 + fieldName+ isreqa18 );
                e.focus();
                return false;
                }

}else if (valtype=="valnumint") {

	    if (!newIsFloat_int(e))
	          {
	          e.focus();
	          return false;
	          }
}else if (valtype=="valnumintpos"){
		if (!newIsFloat_int_pos(e)){
			e.focus();
			return false;
		}
}else if (valtype == "reqdecimal" || valtype == "valdecimal" ||
          valtype == "reqnegdecimal" || valtype == "valnegdecimal") {

          if ((ch<"0" || ch>"9") && ch != '.')
                {
                alert(isreq18 + fieldName+ isreqa18 );
                e.focus();
                return false;
                }

}else if ((valtype=="html") || (valtype=="html_nolimit") ||(valtype=="reqhtml")
            || (valtype=="reqhtml_nolimit") || (valtype=="desc_field")) {

	      var ch8a = text.substring(i-7,i+1);	
		  if ((ch=="\\")||(ch=="|")||((ch=="=") && !(ch8a=="<a href=")))
            {
            alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
            e.focus();
            return false;
            }

          if (ch=="<")
                {
			          var ch3 = text.substring(i,i+3);
			          var ch4 = text.substring(i,i+4);
			          var ch5 = text.substring(i,i+5);
			          var ch6 = text.substring(i,i+6);
			          var ch8 = text.substring(i,i+8);
                    if (!( (ch3=="<b>") || (ch3=="<u>") || (ch3=="<i>") || (ch3=="<p>") || (ch4=="<br>") || (ch4=="<bl>") 
                    		|| (ch5=="</bl>") || (ch4=="<li>") || (ch5=="</li>") || (ch4=="<ol>") || (ch5=="</ol>") 
                    		|| (ch4=="<ul>") || (ch5=="</ul>") || (ch4=="<dd>") || (ch4=="<dt>") || (ch4=="<dl>") 
                    		|| (ch5=="</dd>") || (ch5=="</dt>") || (ch5=="</dl>") || (ch4=="<hr>") || (ch4=="</b>") 
                    		|| (ch4=="</u>") || (ch4=="</i>") || (ch4=="</p>") || (ch6=="<URL1>") || (ch6=="<URL2>") 
                    		|| (ch8=="<EMAIL1>") || (ch3=="<a>") || (ch3=="<a ") || (ch4=="</a>") ))
                    {
                    alert(isreq15 + fieldName+ isreqa15 + " '" + ch4 + "' " + isreqa66);
                    e.focus();
                    return false;
                    }
                }

          if (ch==">")
                {
        	          var ch2m = text.substring(i-1,i+1);
			          var ch3m = text.substring(i-2,i+1);
			          var ch4m = text.substring(i-3,i+1);
			          var ch5m = text.substring(i-4,i+1);
			          var ch6m = text.substring(i-5,i+1);
			          var ch8m = text.substring(i-7,i+1);
                    if (!( (ch3m=="<b>") || (ch3m=="<u>") || (ch3m=="<i>") || (ch3m=="<p>") || (ch4m=="<br>") || (ch4m=="<bl>") 
                    		|| (ch5m=="</bl>") || (ch4m=="<li>") || (ch5m=="</li>") || (ch4m=="<ol>") || (ch5m=="</ol>") 
                    		|| (ch4m=="<ul>") || (ch5m=="</ul>") || (ch4m=="<dd>") || (ch4m=="<dt>") || (ch4m=="<dl>") 
                    		|| (ch5m=="</dd>") || (ch5m=="</dt>") || (ch5m=="</dl>") || (ch4m=="<hr>") || (ch4m=="</b>") 
                    		|| (ch4m=="</u>") || (ch4m=="</i>") || (ch4m=="</p>") || (ch6m=="<URL1>") || (ch6m=="<URL2>") 
                    		|| (ch8m=="<EMAIL1>") || (ch3m=="<a>") || (ch3=="<a " && ch2m=="\">") || (ch4m=="</a>") ))
                    {
                    alert(isreq15 + fieldName+ isreqa15 + " '" + ch4 + "' " + isreqa66);
                    e.focus();
                    return false;
                    }
                }
}else if ((valtype=="email_con") || (valtype=="req_email_con")) {
	
		  if (ch=="\"") {
			  if (wasQuote) {
				  wasQuote = false;
			  } else {
				  wasQuote = true;
			  }
		  }

          if ((ch==">")||(ch=="<")||(ch=="\\")||(ch=="|"))
                {
              if ((ch2==">>")||(ch2=="<<"))
                    {
                    alert(isreq55);
                    e.focus();
                    return false;
                    }else{
                    alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
                    e.focus();
                    return false;
                    }

                }
}else if (valtype=="req_email_tpl" || valtype=="val_email_tpl") {

    if ((ch=="\\")||(ch=="|")||(ch=="\"")) {
        alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
        e.focus();
        return false;
    }
    if (ch=="<") {
        if (ch2!= "<<") {
            alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
            e.focus();
            return false;
        } else {
            i = i+1;  // Need to skip the next letter so that the second '<' doesn't cause an error
        }
    }
    if (ch==">") {
        if (ch2!= ">>") {
            alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
            e.focus();
            return false;
        } else {
            i = i+1;  // Need to skip the next letter so that the second '>' doesn't cause an error
        }
    }

} else if (valtype == "req_email_nonhtml_tpl" || valtype == "val_email_nonhtml_tpl") {
	continue;
} else{
          if ((ch==">")||(ch=="<")||(ch=="\\")||(ch=="|")||(ch=="\""))
                {
                alert(isreq15 + fieldName+ isreqa15 + " '" + ch + "'");
                e.focus();
                return false;
                }
}

    } // end of character (i) loop
    
if (wasQuote) {
	alert(isreq15 + fieldName + isreqa15 + " '\"'");
    e.focus();
    return false;
}

if(valtype=="reqdecimal" || valtype == "reqnegdecimal" || valtype == "reqjavaint"){
  if(text == null || text == '' ){
      alert (isreq1 + fieldName + isreqa1);
      e.focus();
      return false;
  }
}

// These are the min and max values for a java integer.
if (valtype=="valjavaint" || valtype == "reqjavaint") {
  if (text < -2147483648 || text > 2147483647) {
    alert(isreq18 + fieldName+ isreqa18 );
    e.focus();
    return false;
  }
}

if (((valtype=="reqnum") && (text<=0)) || ((valtype=="reqnumint") && (parseInt(text)<=0)))
    {
   alert (isreq41b);
    e.focus();
    return false;
    }

return true;
};

function valid_email(e,type) {
var singleEmail = "";
var count = 0;
var thisPass = true;
var emailStr = e.value;

if (type == "multi" || type == "oneormore") {
    if (type == "oneormore" && emailStr.length == 0) {
        alert(isreq3 + fieldName+ isreqa3)
        e.focus();
        thisPass = false;
    }
    while (emailStr.length > 0) {
        if  (emailStr.indexOf(";") >= 0){
        singleEmail = emailStr.substring(0,emailStr.indexOf(";"));
        emailStr = emailStr.substring(emailStr.indexOf(";")+1,emailStr.length);
        } else {
        singleEmail = emailStr;
        emailStr = "";
        }

        thisPass = email_check(e,singleEmail);

        if (!thisPass) {emailStr = "";}
        count++
    }
} else {
    if (type == "not_req") {
        if (emailStr.length == 0) {
            return true;
        }
    }

  thisPass = email_check(e,emailStr);
}

return thisPass;
}

function email_check(e,emailStr) {
emailStr=emailStr.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)\x7F-\xDE\xE0-\xFF<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
word="(" + atom + ")"  // Quoted user is currently not allowed as it doesn't get stored.
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
    alert(isreq3 + fieldName+ isreqa3)
    if(e.type != 'hidden') {
        e.focus();
    }
    return false
}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null) {
    alert(isreq3 + fieldName+ isreqa3)
    e.focus();
    return false
}
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    for (var i=1;i<=4;i++) {
        if (IPArray[i]>255) {
            alert(isreq3 + fieldName+ isreqa3)
            e.focus();
            return false
        }
    }
    return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
    alert(isreq3 + fieldName+ isreqa3)
    e.focus();
    return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>4) {
    alert(isreq3 + fieldName+ isreqa3)
    e.focus();
    return false
}
if (len<2) {
    alert(isreq3 + fieldName+ isreqa3)
    e.focus();
    return false
}
return true;
}

function comp_dd_or_txt(e1,e2) {
var dd = parseInt(e2.options[e2.selectedIndex].value);

if( (dd > 0) && (e1.value.length > 0) ) {
  alert(isreq50);
  e1.focus();
  return false;
}

return allowed_text(e1)
}

function match_text(e1,e2)
{
if (e1.value!=e2.value)
    {
    alert(fieldName);
    e1.focus();
    return false;
    }
return true;
};

function dd_compare2(e1,e2,valtype)
{
var val1 = parseInt(e1.options[e1.selectedIndex].value);
var val2 = parseInt(e2.options[e2.selectedIndex].value);

if((val1==0)&&(val2==0)&&(valtype=="required"))
    {
    alert(isreq20 + fieldName+ isreqa20 );
    e2.focus();
    return false;
    }

if( (val1==val2)&&(val1!=0) )
    {
    alert(isreq21 + fieldName+ isreqa21 );
    e2.focus();
    return false;
    }

return true;
}

function dd_compare3(e1,e2,e3,valtype)
{
var val1 = parseInt(e1.options[e1.selectedIndex].value);
var val2 = parseInt(e2.options[e2.selectedIndex].value);
var val3 = parseInt(e3.options[e3.selectedIndex].value);

if((val1==0)&&(val2==0)&&(val3==0)&&(valtype=="required"))
    {
    alert(isreq20 + fieldName+ isreqa20 );
    e3.focus();
    return false;
    }

if( ((val1==val2)&&(val1!=0)) || ((val1==val3)&&(val1!=0)) || ((val2==val3)&&(val2!=0)) )
    {
    alert(isreq21 + fieldName+ isreqa21 );
    e3.focus();
    return false;
    }

return true;
}

function dd_compare4(e1,e2,e3,e4,valtype)
{
var val1 = parseInt(e1.options[e1.selectedIndex].value);
var val2 = parseInt(e2.options[e2.selectedIndex].value);
var val3 = parseInt(e3.options[e3.selectedIndex].value);
var val4 = parseInt(e4.options[e4.selectedIndex].value);

if((val1==0)&&(val2==0)&&(val3==0)&&(val4==0)&&(valtype=="required"))
    {
    alert(isreq20 + fieldName+ isreqa20 );
    e1.focus();
    return false;
    }
if( ((val1==val2)&&(val1!=0)) || ((val1==val3)&&(val1!=0)) || ((val1==val4)&&(val1!=0)) ||
    ((val2==val3)&&(val2!=0)) || ((val2==val4)&&(val2!=0)) || ((val3==val4)&&(val3!=0)) )
    {
    alert(isreq21 + fieldName+ isreqa21 );
    e4.focus();
    return false;
    }

return true;
}

function one_dd_2(e1,e2)
{
    if ((e1.selectedIndex==0)&&(e2.selectedIndex==0))
        {
        alert(isreq16);
        return false;
        }
    if ((e1.selectedIndex!=0)&&(e2.selectedIndex!=0))
        {
        alert(isreq49);
        return false;
        }

return true;
}

function val_specifc_date(e1,e2,e3,chk)
{
    if(chk.checked)
        {
        return TheDate(e1,e2,e3,"post");
        }
return true;
}

function val_asap(e0,e1,e2,e3){

  if(e0.checked==true) {
      if ((e1.selectedIndex>0)||(e2.selectedIndex>0)||(e3.selectedIndex>0)) {
          alert( fieldName);
          return false;
        }
    }else{
    fieldName=fieldName2;
    fieldName2=fieldName3;
    fieldName3=fieldName4;
      if ((e1.selectedIndex == 0)||(e2.selectedIndex == 0)||(e3.selectedIndex == 0)) {
          alert(fieldName);
          return false;
      }
      return TheDate(e1,e2,e3);
    }
  return true;
}

function TheTime(yy,mm,dd,tt,valtype)
{
var nowDate = new Date();
var nowTime = (nowDate.getHours()*100)+nowDate.getMinutes();
var SelTime = tt.options[tt.selectedIndex].value

if (valtype=="posttime"){
    if(TheDate(yy,mm,dd,"today")&&(SelTime<nowTime)) {
        alert(isreq9a);
        tt.focus();
        return false;
    }else{
        return (TheDate(yy,mm,dd,"post"));
    }
}
return true;
}

function TheDate(yy,mm,dd,valtype,yy2,mm2,dd2)
{
var nowDate = new Date();
var nowYear = nowDate.getYear();
var nowMonth = nowDate.getMonth()+1;
var nowDay = nowDate.getDate();

if (nowYear<1000) {nowYear += 1900;}

var selDay = parseInt(dd.options[dd.selectedIndex].value);
var selMonth = parseInt(mm.options[mm.selectedIndex].value);
var selYear = parseInt(yy.options[yy.selectedIndex].value);

var selSortDate=selYear*10000+selMonth*100+selDay;
var nowSortDate=nowYear*10000+nowMonth*100+nowDay;

if (valtype=="today"){
    if (nowSortDate==selSortDate){
        return true;
    }else{
        return false;
    }
}

if ((valtype=="compare")||(valtype=="onlycompare")||(valtype=="for_logging")){
var selDay2 = parseInt(dd2.options[dd2.selectedIndex].value);
var selMonth2 = parseInt(mm2.options[mm2.selectedIndex].value);
var selYear2 = parseInt(yy2.options[yy2.selectedIndex].value);
var selSortDate2=selYear2*10000+selMonth2*100+selDay2;
}

if(((dd.selectedIndex!=0)||(mm.selectedIndex!=0)||(valtype=="post")||(valtype=="pre"))&&(yy.selectedIndex==0)){
  alert(isreq44 + fieldName+ isreqa44);
  yy.focus();
  return false;
}

if(((dd.selectedIndex!=0)||(yy.selectedIndex!=0))&&(mm.selectedIndex==0)){
  alert(isreq44 + fieldName2 + isreqa44)
  mm.focus();
  return false;
}

if(((mm.selectedIndex!=0)||(yy.selectedIndex!=0))&&(dd.selectedIndex==0)){
  alert(isreq44 + fieldName3 + isreqa44);
  dd.focus();
  return false;
}

if( ((selDay==31)&&((selMonth==4)||(selMonth==6)||(selMonth==9)||(selMonth==11))) || ((selDay>29)&&(selMonth==2)) )
{
alert(isreq13);
dd.focus();
return false;
}

if( ((selYear%4)!=0)&&(selDay==29)&&(selMonth==2) )  // Leap-year Check
{
alert(isreq12);
dd.focus();
return false;
}

if ((valtype=="post")&&(nowSortDate>selSortDate))
{
  alert(isreq9)
  yy.focus();
  return false;
}

if ((valtype=="pre")&&(nowSortDate<selSortDate))
{
  alert("The date you have selected cannot be later than the current date.")
  yy.focus();
  return false;
}

if (valtype=="for_logging")
{
    if (((selSortDate != 0) && (selSortDate2 == 0)) || ((selSortDate == 0) && (selSortDate2 != 0)))
    {
      alert(isreq56);
      yy.focus();
      return false;
    }

  if ((selSortDate > nowSortDate)||(selSortDate2 > nowSortDate)) {
    alert(isreq59);
    yy.focus();
    return false;
  }
}

if (((valtype=="onlycompare")||(valtype=="for_logging")||(valtype="comp_date2"))
                &&(selSortDate<selSortDate2)&&(selSortDate!=0)&&(selSortDate2!=0))
{
  alert(isreq54);
  yy.focus();
  return false;
}

if (selSortDate2==0)selSortDate2=selSortDate;
if ((valtype=="compare")&&(selSortDate>0)&&((selSortDate2<selSortDate)||(nowSortDate>selSortDate)))
{
  alert(isreq53);
  yy.focus();
  return false;
}

return true;
}

function comp_job_date(toy,tom,fmy,fmm,type) {
var nowDate = new Date();
var nowYear = nowDate.getYear();
var nowMonth = nowDate.getMonth()+1;

if (nowYear<1000) {nowYear += 1900;}

var fromMonth = parseInt(fmm.options[fmm.selectedIndex].value);
var fromYear = parseInt(fmy.options[fmy.selectedIndex].value);
var toMonth = parseInt(tom.options[tom.selectedIndex].value);
var toYear = parseInt(toy.options[toy.selectedIndex].value);


if ( fromMonth == 0 ) {
        alert(isreq24);
                fmm.focus();
                return false;
}

if ( fromYear == 0 ) {
        alert(isreq25);
                fmy.focus();
                return false;
}

if ( fromYear > nowYear ) {
        alert(isreq22);
                fmy.focus();
                return false;
}

if ( ( fromYear == nowYear ) && ( fromMonth > nowMonth ) ) {
        alert(isreq23);
                fmm.focus();
                return false;
}

if (type == "cur") {

    if ( toMonth > 0 ) {
        alert(isreq33);
                tom.focus();
                return false;
    }

    if ( toYear > 0 ) {
        alert(isreq34);
                toy.focus();
                return false;
    }

} // end of if (type == "cur");

if (type == "pre") {

    if ( toMonth == 0 ) {
        alert(isreq26);
                tom.focus();
                return false;
    }

    if ( toYear == 0 ) {
        alert(isreq27);
                toy.focus();
                return false;
    }

    if ( toYear > nowYear ) {
        alert(isreq30);
                toy.focus();
                return false;
    }

    if ( ( toYear == nowYear ) && ( toMonth > nowMonth ) ) {
        alert(isreq30b);
                tom.focus();
                return false;
    }

    if ( fromYear > toYear ) {
        alert(isreq28);
                toy.focus();
                return false;
    }

    if ( ( fromYear == toYear ) && ( fromMonth > toMonth ) ) {
        alert(isreq29);
                tom.focus();
                return false;
    }

} // end of if (type == "pre");

return true;
}

function must_check(e)
{
    if(!e.checked && isJPJSValidateRequired())
    {
    alert(fieldName);
    e.focus();
    return false;
    }
return true;
}

function for_logging(e1,e2,e3,e4,e5,e6,e7,e8,e9)
{
    if (!(is_it_selectd(e9) || is_it_selectd(e8) || is_it_selectd(e7) || is_it_selectd(e6) || is_it_selectd(e5) || is_it_selectd(e4) || is_it_selectd(e3) || is_it_selectd(e2) || is_it_selectd(e1)) )
    {
    alert(fieldName);
    return false;
    }
return true;
}

function is_it_selectd(e)
{
    if( e.selectedIndex < 1 && e.length > 1 )
    {
    return false;
    }
return true;
}

function must_select(e)
{
    if( e.selectedIndex < 1 && e.length > 1 && isJPJSValidateRequired())
    {
    alert(fieldName);
    e.focus();
    return false;
    }
return true;
}

function req_select(e)
{
    if( e.selectedIndex < 1 && isJPJSValidateRequired())
    {
    alert(fieldName);
    e.focus();
    return false;
    }
return true;
}

function must_multiple(e)
{
    if( e.selectedIndex < 0 && isJPJSValidateRequired())
    {
    alert(fieldName);
    e.focus();
    return false;
    }
return true;
}

function skill_select(e)
{
    if(e.selectedIndex<1)
    {
    alert(fieldName);
    e.focus();
    return false;
    }
return true;
}


function chk_currency(maxsal,minsal,curr,per){
    //the character , is used as a decimal point in German.
    maxsal.value = maxsal.value.replace(',','.');
    minsal.value = minsal.value.replace(',','.');
    return newIsFloat(minsal) && newIsFloat(maxsal) && newGreaterThan(minsal,maxsal) && newNeedCurrency(maxsal,curr) && newNeedPer(maxsal,per);
};

function chk_currency_int(maxsal,minsal,curr,per){
    var res = false;
    if (newIsFloat_int(minsal) && newIsFloat_int(maxsal))
    {
        //clean up values so js can check their relative sizes
        var tmpmaxsal = maxsal.value;
        var tmpminsal = minsal.value;
        maxsal.value = maxsal.value.replace(clean_number_re,'');
        minsal.value = minsal.value.replace(clean_number_re,'');
        maxsal.value = maxsal.value.replace(n_decimal,'.');
        minsal.value = minsal.value.replace(n_decimal,'.');
        res = (newGreaterThan(minsal,maxsal) && newNeedCurrency(maxsal,curr) && newNeedPer(maxsal,per));
        maxsal.value = tmpmaxsal;
        minsal.value = tmpminsal;
    }

    return res;
};

function chk_currency_pub(sal,curr){
    return newIsNum(sal) && newNeedCurrency(sal,curr);
};

function chk_currency_vat(sal,curr){
    sal.value = sal.value.replace(' ',String.fromCharCode(160));
    return newIsFloat_int(sal) && newNeedCurrency(sal,curr);
};

function newNeedCurrency(sal,curr){
    var salval=parseFloat(sal.value);
    var selcurr=curr.selectedIndex;
    if((selcurr==0) && (salval >  0)){
        alert(isreq38);
        curr.focus();
        return false;
    }
    return true;
}


function newNeedPer(sal,per)
{
var salval=parseFloat(sal.value);
var selper=per.selectedIndex;
    if((selper==0) && (salval >  0))
    {
    alert(isreq38b);
    per.focus();
    return false;
    }
return true;
}


function newNeedAmount(sal,curr)
{
var salval=parseFloat(sal.value);
var selcurr=curr.selectedIndex;

    if((selcurr!=0) && ((salval == 0) || (salval == "")) )
    {
    alert(isreq38a);
    sal.focus();
    return false;
    }
return true;
}

function GreaterThanNum(maxnum,minnum)
{
return newIsNum(minnum) && newIsNum(maxnum) &&  newGreaterThan(minnum,maxnum);
};

function newGreaterThan(minsal,maxsal)
{
var minsalval=parseFloat(minsal.value);
var maxsalval=parseFloat(maxsal.value);

    if((minsalval-maxsalval) > 0)
    {
    alert(isreq19);
    maxsal.focus();
    return false;
    }

return true;
}

function newIsNum(e)
{
var ch="";

for(var i=0; i < e.value.length; i++)
    {
    ch = e.value.substring(i,i+1);

    if ((i==0) && (ch==" "))
        {
        alert(isreq45+ fieldName+ isreqa45);
        e.focus();
        return false;
        }

    if (ch<"0" || ch>"9")
        {
        alert(isreq18 + fieldName+ isreqa18 );
        e.focus();
        return false;
        }
    }
return true;
}

function newIsFloat(e)
{
var ch="";
var ch2="";
var count=0;

for(var i=0; i < e.value.length; i++)
    {
    ch = e.value.substring(i,i+1);
    ch2 = e.value.substring(i+1,i+2);

    if ((i==0) && (ch==" "))
        {
        alert(isreq45+ fieldName+ isreqa45);
        e.focus();
        return false;
        }

    if ((i!=0) && (ch=="-"))
        {
        alert(isreq65+ fieldName+ isreqa65);
        e.focus();
        return false;
        }

    if ((i==0) && (ch==".")) {count++;}
    if (ch2==".") {count++;}    // This functionality was added because it you
                        // finished on a '.' it wasn't calculated in time


    if (((ch<"0" || ch>"9") && (ch!=".") && (ch!="-")) || (count>1))
        {
        alert(isreq18 + fieldName+ isreqa18 );
        e.focus();
        return false;
        }
    }
return true;
}

function newIsFloat_int(e)
{
    var numstr = e.value;
    if (numstr.length==1 && (numstr=="-" || numstr=='.'))
    {
        alert(isreq18 + fieldName+ isreqa18 );
        e.focus();
        return false;
    }

    if (numstr.length>0)
    {
        var ch=numstr.charAt(0);

        if (ch==" ")
        {
            alert(isreq45+ fieldName+ isreqa45);
            e.focus();
            return false;
        }

        if (numstr.indexOf("-",1)>0)
        {
            alert(isreq65+ fieldName+ isreqa65);
            e.focus();
            return false;
        }

        if (!number_re.exec(numstr)) {
            alert(fieldName);
            e.focus();
            return false;
        }
    }
    return true;
}

function newIsFloat_int_pos (e)
{
	var val = newIsFloat_int(e);
	if (!val)
	{
		return false;
	} else {
		var numstr = e.value;
		if (numstr.length>0)
			{
		      var ch=numstr.charAt(0);
		      if (ch=="-"){
		    	  alert(fieldName);
		          e.focus();
		          return false;  
		      }
			}
	}
    return true;
}

function checkMamager(dd,chk)
{
if ((dd.selectedIndex==0)&& (chk.checked))
{
alert (isreq46);
dd.focus();
return false;
}

if ((dd.selectedIndex > 0)&& (!chk.checked))
{
alert (isreq47);
dd.focus();
return false;
}

return true;
}


function val_greater_than_zero(txt) {
if (txt.value.length > 0) {
    if (newIsNum(txt)) {
        if (parseInt(txt.value) <= 0 ) {
        alert(isreq41b);
        txt.focus();
        return false;
        }
    } else {
    return false;
    }
}
return true;
}

function val_greater_or_equal_zero(txt) {
	if (txt.value.length > 0) {
    	if (newIsNum(txt)) {
	        if (parseInt(txt.value) < 0 ) {
		        alert(isreq41b);
	        	txt.focus();
	        	return false;
	        }
	        return true;
	    } else {
    		return false;
    	}
	}
	return true;
}

function val_notice(txt,chk)
{
    if (chk.checked){
        if (txt.value.length == 0)
            {
            alert(isreq1+ fieldName+ isreqa1);
            txt.focus();
            return false;
            }else{
            return newIsNum(txt);
            }
    }else{
        if (txt.value.length != 0)
            {
            txt.focus();
            return false;
            }
    }

return true;
}

//Function checks that candidate must fill the test ans paper properly
function newValTest(frm) {

for (var i=1; i < 193; i+=2)
{
    if ((frm.elements[i].checked) && (frm.elements[i+1].checked))
    {
        alert(isreq35);
        frm.elements[i].focus();
        return false;
    }
}

for (var i=1; i < 193; i+=8)
{
    if ( (!((frm.elements[i].checked) || (frm.elements[i+2].checked) || (frm.elements[i+4].checked) || (frm.elements[i+6].checked))) || (!((frm.elements[i+1].checked) || (frm.elements[i+3].checked) || (frm.elements[i+5].checked) || (frm.elements[i+7].checked))) )
    {
        alert(isreq36);
        frm.elements[i].focus();
        return false;
    }

}

return true;
}

function textAreaLimit(field, maxlen, needAlert , alertMSG){
    if(field.value.length > maxlen){
        if(needAlert){
            alert(alertMSG);
        }
        return false;
    }
    return true;
}


function must_check_radio(frm, field, fieldName) {

    var count = 0;
    for (i = 0; i < frm.length; i++) {
        if(frm.elements[i].type=="radio" && frm.elements[i].name==field.name && frm.elements[i].checked) {
            count=count+1;
        }
    }

    if (count==1) {
        return true;
    } else {
        alert(isreq44+fieldName+isreqa44);
        return false;
    }
}

function checkAtLeastOneCheckbox(frm, field, alertMsg) {

    var count = 0;
    for (i = 0; i < frm.length; i++) {
        if(frm.elements[i].type=="checkbox" && frm.elements[i].name==field && frm.elements[i].checked) {
            count=count+1;
        }
    }

    if (count > 0) {
        return true;
    } else {
        alert(alertMsg);
        return false;
    }
}

function checkOnlyOneCheckbox(frm, field, alertMsg) {

    var count = 0;
    for (i = 0; i < frm.length; i++) {
        if(frm.elements[i].type=="checkbox" && frm.elements[i].name==field && frm.elements[i].checked) {
            count=count+1;
        }
    }

    if (count == 1) {
        return true;
    } else {
        alert(alertMsg);
        return false;
    }
}

function isUrl(s) {
	var url = s.value;
	var isUrl = true;
	if (url.length > 0) {
		var regexp = new RegExp("^([a-zA-Z0-9]+)(\.[a-zA-Z0-9_\-]{2,})+(:[0-9]{1,5})??(\/{1}[a-zA-Z0-9_.?&=+,\-]*\$\%)*");
		var isUrl = regexp.test(url);
		if (!isUrl) {
			alert(fieldName);
		}
	}
	return isUrl;
}

function ddNotEmpty(e) {

    if( e.length == 0 )
    {
	    alert(fieldName);
    	e.focus();
	    return false;
    } else {
    	return true;
    }
}

function req_if_prev_not_empty(e1,e2)
{
if (e2.value.length>0 && e1.value.length == 0)
    {
    alert(fieldName);
    e1.focus();
    return false;
    }
return true;
};

function reqd_prev_if_chkd(chk, e) {

	if(chk.checked) {
		return allowed_text(e,"required");
	} else {
		return true;
	}
}

function must_select_if_prev_not_empty(cur, prev) {

	if(prev.value && prev.value.length > 0) {
		return must_select(cur);
	} else {
		return true;
	}
}

function checkForSameValues(elem1, elem2, msg) {
	var e1v = elem1.value;
	while (e1v.substring(0,1) == ' ') {
		e1v = e1v.substring(1, e1v.length);
	}
	while (e1v.substring(e1v.length-1, e1v.length) == ' ') {
		e1v = e1v.substring(0, e1v.length-1);
	}
	var e2v = elem2.value;
	while (e2v.substring(0,1) == ' ') {
		e2v = e2v.substring(1, e2v.length);
	}
	while (e2v.substring(e2v.length-1, e2v.length) == ' ') {
		e2v = e2v.substring(0, e2v.length-1);
	}
	if (e1v == e2v) {
		_namedIsValid = false;
		alert(msg);
		return false;
	} else {
		return true;
	}
}

var jpjsValidateRequired = true;

function isJPJSValidateRequired() {
	return jpjsValidateRequired
}

function setJPJSValidateRequired(value) {
	jpjsValidateRequired = value;
}

function convert_format_to_float1(txt) {
	return txt.replace(',','');	
}

function convert_format_to_float2(txt) {
	var result = txt.replace('.','');
	return result.replace(',','.');

}

function convert_format_to_float3(txt) {
	var result = txt.replace(' ','');
	return result.replace(',','.');
}

function convert_formated_to_float(txt) {
	var value;
	if (numberFormatType == 2) {
		value = convert_format_to_float2(txt)
	} else if (numberFormatType == 3) {
		value = convert_format_to_float3(txt)
	} else {
		value = convert_format_to_float1(txt)
	}
	return parseFloat(value);
}

function convert_float_to_formated(amount) {
	var delimiter = ",";
	var decimal = "."; 
	if (numberFormatType == 2) {
		delimiter = ".";
		decimal = ",";
	} else if (numberFormatType == 3) {
		delimiter = " ";
		decimal = ",";
	}
	
	var a = amount.split('.',2)
	var decimalValue = a[1];
	if (!decimalValue) {
		decimalValue = '00';
	}
	var intValue = parseInt(a[0]);
	if(isNaN(intValue)) {
		return ''; 
	}
	var minus = '';
	if(intValue < 0) { 
		minus = '-'; 
	}
	intValue = Math.abs(intValue);
	var intStr = new String(intValue);
	var a = [];
	while(intStr.length > 3)	{
		var lastThreeDig = intStr.substr(intStr.length-3);
		a.unshift(lastThreeDig);
		intStr = intStr.substr(0,intStr.length-3);
	}
	if(intStr.length > 0) {
		a.unshift(intStr); 
	}
	intStr = a.join(delimiter);
	if(decimalValue.length < 1) { 
		amount = intStr; 
	} else { 
		amount = intStr + decimal + decimalValue; 
	}
	amount = minus + amount;
	return amount;
}


function setNumberFormatType(data) {
	numberFormatType = data;
}

