﻿
var PSN = 0, ADR = 1, LGN = 2, EMP = 3, BKG = 4, AGR = 5;
var EXT = new Array("doc", "docx", "rtf", "txt", "pdf");

function iA(id,name,valid,opened) { var self = this; this.id = id; this.name = name; this.valid = valid; this.opened = opened; this.isVld = function() { for (var i = 0; i < F.length; i++) { if (F[i].area == this && !F[i].valid) { this.valid = false; return false; } } this.valid = true; return true; } }
function iF(id,name,area,vlds,valid) { var self = this; this.id = id; this.name = name; this.area = area; this.vlds = vlds; this.valid = valid; this.isVld = function() { for (var i = 0; i < this.vlds.length; i++) { if (!this.vlds[i].isVld()) { this.valid = false; _ge(this.id).title = this.vlds[i].msg; return false; } } this.valid = true; _ge(this.id).title = ""; return true; } }
function iFV(vld,msg) { var self = this; this.vld = vld; this.msg = msg; this.isVld = function() { return eval(this.vld); } }

var A = new Array(
    new iA("PSN", "Personal Information", false, false),
    new iA("ADR", "Address & Contact Information", false, false),
    new iA("LGN", "Email & Login Details", false, false),
    new iA("EMP", "Previous & Future Employment", false, false),
    new iA("BKG", "Background & Legal Information", false, true),
    new iA("AGR", "Agreement & Submission", false, false));

var F = new Array(
    new iF("TITLE", "Title", A[PSN], new Array(new iFV("_hev('TITLE')","Please choose a Title.")), false),
    new iF("FORENAME", "Forename", A[PSN], new Array(new iFV("_hev('FORENAME')","Please enter your Forename.")), false),
    new iF("SURNAME", "Surname", A[PSN], new Array(new iFV("_hev('SURNAME')","Please enter your Surname.")), false),
    new iF("FILE", "CV", A[PSN], new Array(new iFV("_hev('FILE')","Please choose a CV to be uploaded."),
        new iFV("(_gev('FILE').lastIndexOf('.') > 0 && _gev('FILE').substring(_gev('FILE').lastIndexOf('.') + 1).toLowerCase() in _ina(EXT))","Your CV is in the wrong format. Please ensure that you only attach CV's of the following file types: .doc .rtf .txt .pdf .docx, CV with up to 2 MB size.")), false),
    new iF("STREET", "Street", A[ADR], new Array(new iFV("_hev('STREET')","Please enter the your Street name and House number.")), false),            
    new iF("STREET2", "", A[ADR], new Array(), true),
    new iF("TOWN", "Town", A[ADR], new Array(new iFV("_hev('TOWN')","Please enter the name of the Town you live in.")), false),
    new iF("POSTCODE", "Postcode", A[ADR], new Array(new iFV("_hev('POSTCODE')","Please enter your Postcode."), 
        new iFV("/^[A-Z]{1,2}[0-9R][0-9A-Z]?[ ]?[0-9][ABD-HJLNP-UW-Z]{2}$/i.test(_gev('POSTCODE'))","Please enter a valid UK postcode.")), false),
    new iF("TELEPHONE", "Phone / Mobile", A[ADR], new Array(new iFV("_hev('TELEPHONE')","Please enter your Phone or Mobile number."),
        new iFV("/^(((\\+44\\s?\\d{4}|\\(?0\\d{4}\\)?)\\s?\\d{3}\\s?\\d{3})|((\\+44\\s?\\d{3}|\\(?0\\d{3}\\)?)\\s?\\d{3}\\s?\\d{4})|((\\+44\\s?\\d{2}|\\(?0\\d{2}\\)?)\\s?\\d{4\\s?\\d{4}))(\\s?\\#(\\d{4}|\\d{3}))?$/.test(_gev('TELEPHONE'))","Please enter a valid UK phone number.")), false),
    new iF("REG_ID", "Region", A[EMP], new Array(new iFV("_hev('REG_ID')","Please choose your Region.")), false),
new iF("CON_ID", "County", A[EMP], new Array(new iFV("_hev('CON_ID')","Please choose your County.")), false),    
new iF("EMAIL", "Email", A[LGN], new Array(new iFV("_hev('EMAIL')","Please enter your Email address."),
        new iFV("/^([A-Z0-9_\.\-])+\@(([A-Z0-9\-])+\.)+([A-Z0-9]{2,4})+$/i.test(_gev('EMAIL'))","Please enter a valid Email address."),
        new iFV("_vld_eml()","This Email address has already been taken.")), false),
    new iF("EMAILC", "Email (confirmation)", A[LGN], new Array(new iFV("_hev('EMAILC')","Please re-enter your Email address."),
        new iFV("/^([A-Z0-9_\.\-])+\@(([A-Z0-9\-])+\.)+([A-Z0-9]{2,4})+$/i.test(_gev('EMAILC'))","Please re-enter a valid Email address."),
        new iFV("(_gev('EMAIL') == _gev('EMAILC'))","This Email address does not match the previous one.")), false),
    new iF("USERNAME", "Username", A[LGN], new Array(new iFV("_hev('USERNAME')","Please enter your Username."),
        new iFV("/^[A-Z0-9_]{6,32}$/i.test(_gev('USERNAME'))","Please enter a Username between 6 and 32 characters with letters and/or numbers."),
        new iFV("_vld_usr()","This Username has already been taken.")), false),
    new iF("PASSWORD", "Password", A[LGN], new Array(new iFV("_hev('PASSWORD')","Please enter your Password."),
        new iFV("(_gev('PASSWORD').length >= 6 && _gev('PASSWORD').length <= 12)","Please enter a Password between 6 and 12 characters with at least a number and a letter."),
        new iFV("/^.*[0-9].*$/.test(_gev('PASSWORD'))", "Please enter a Password between 6 and 12 characters with at least a number and a letter."),
        new iFV("/^.*[A-Z].*$/i.test(_gev('PASSWORD'))", "Please enter a Password between 6 and 12 characters with at least a number and a letter.")), false),
    new iF("PASSWORDC", "Password (confirmation)", A[LGN], new Array(new iFV("_hev('PASSWORDC')","Please re-enter your Password."),
        new iFV("(_gev('PASSWORDC').length >= 6 && _gev('PASSWORDC').length <= 12)","Please re-enter a valid Password."),
        new iFV("(_gev('PASSWORD') == _gev('PASSWORDC'))","This Password does not match the previous one.")), false),
    new iF("CJOBTITLE", "Current Job Title", A[EMP], new Array(new iFV("_hev('CJOBTITLE')","Please enter your current or previous Job Title.")), false),
    new iF("NTC_ID", "Current Notice Period", A[EMP], new Array(new iFV("_hev('NTC_ID')","Please choose your current Notice Period.")), false),
    // new iF("DJOBTITLE", "Desired Job Title", A[EMP], new Array(new iFV("_hev('DJOBTITLE')","Please enter your desired Job Title.")), false),
    new iF("DLOCATION", "Desired Job Location", A[EMP], new Array(new iFV("_hev('DLOCATION')","Please enter your desired Job Title.")), false),
    new iF("SECTORS", "Desired Job Sector", A[EMP], new Array(new iFV("_hev('SECTORS')","Please choose at least one desired Job Sector."),
        new iFV("_vld_sct()", "Please choose up to 5 desired Job Sectors.")), false),
    new iF("SECTORS_TITLES", "Desired Job Titles", A[EMP], new Array(new iFV("_hev('SECTORS_TITLES')", "Please choose at least one desired Job Sector."), new iFV("_vld_s_t()", "Please choose up to 5 titles in each sector.")), false),    
    new iF("SLR_ID", "Desired Job Salary", A[EMP], new Array(new iFV("_hev('SLR_ID')","Please choose your desired Job Salary.")), false),
    new iF("VCN_TYP_ID", "Desired Job Type", A[EMP], new Array(), true),
    new iF("ELLIGIBILITY", "Elligible to work in UK", A[EMP], new Array(new iFV("_hev('ELLIGIBILITY')","Please choose if you are elligible to work in UK."),
        new iFV("(_gev('ELLIGIBILITY') == 'Y')","To register with iCV you need to be able to work and live in UK.")), false),
    new iF("SKILLS", "Please enter up to 10 key skills, separated by commas", A[EMP], new Array(new iFV("_hev('SKILLS')","Please enter up to 10 of your Key Skills.")), false),
    new iF("GENDER", "Gender", A[BKG], new Array(new iFV("_hev('GENDER')","Please choose your Gender.")), false),
    new iF("AGE_ID", "Age Range", A[BKG], new Array(new iFV("_hev('AGE_ID')","Please choose your Age Range.")), false),
    new iF("ETH_ID", "Ethnic Group", A[BKG], new Array(), true),
    new iF("IDS_ID", "Identification", A[BKG], new Array(), true),
    new iF("LICENSE", "Driving License", A[BKG], new Array(), true),
    new iF("TRANSPORT", "Own Transport", A[BKG], new Array(), true),
    new iF("EDU_ID", "Highest Qualification", A[BKG], new Array(), true),
    new iF("TERMS", "I agree to the Terms & Conditions", A[AGR], new Array(new iFV("_ge('TERMS').checked","To register with iCV you need to agree with our Terms &amp; Conditions.")), false)
 );


function _rst_f(p_field) { p_field.style.backgroundColor = "#FFFFFF"; }
function _opn_a(p_area_id) { _shw_a(p_area_id); for (var i = 0; i < A.length; i++) { if (A[i].id == p_area_id) A[i].opened = true; }; }
function _shw_a(p_area_id) { _ge(p_area_id + "_CTN").className = "icv_box_ctn vsb"; _ge(p_area_id + "_SHW").className = "icv_box_hdr_icn hdn"; _ge(p_area_id + "_HDE").className = "icv_box_hdr_icn vsb"; }
function _hde_a(p_area_id) { _ge(p_area_id + "_CTN").className = "icv_box_ctn hdn"; _ge(p_area_id + "_SHW").className = "icv_box_hdr_icn vsb"; _ge(p_area_id + "_HDE").className = "icv_box_hdr_icn hdn"; }

function _vld() { var vld = true; for (var i = 0; i < F.length; i++) { _sene(F[i].id); _ge(F[i].id).title = ""; _ge(F[i].id).style.backgroundColor = "#FFFFFF"; for (var j = 0; j < F[i].vlds.length; j++) { if (!F[i].vlds[j].isVld()) { _see(F[i].id,F[i].vlds[j].msg,vld); vld = false; break; } } } return vld; }
function _vld_a(p_area) { if (p_area.isVld()) { _ge(p_area.id + "_VLD").className = "icv_box_hdr_vld vsb"; _ge(p_area.id + "_HDE").className = "icv_box_hdr_icn vsb"; if (!p_area.opened) setTimeout("_hde_a('" + p_area.id + "')", 1000); else _ge(p_area.id + "_HDE").className = "icv_box_hdr_icn vsb"; } else { _ge(p_area.id + "_CTN").className = "icv_box_ctn vsb"; _ge(p_area.id + "_SHW").className = "icv_box_hdr_icn hdn"; _ge(p_area.id + "_HDE").className = "icv_box_hdr_icn hdn"; _ge(p_area.id + "_VLD").className = "icv_box_hdr_vld hdn"; } }
function _vld_f(p_field) { var l_field; for (var i = 0; i < F.length; i++) { if (F[i].id == p_field.id) l_field = F[i]; } if (!l_field) return ; if (l_field.isVld()) { _sene(p_field.id); p_field.style.backgroundColor = "#00CC00"; } else { p_field.style.backgroundColor = "#FF0000"; } _vld_a(l_field.area); }

function _vld_eml() { var _ajx_req = _ajx_ri(); if(_ajx_req) { _ajx_req.open("get",_gev("U") + "xml/users.aspx?EMAIL=" + _gev("EMAIL"),false); _ajx_req.send(null); if(!_ajx_req.responseXML || !_ajx_req.responseXML.documentElement || !_ajx_req.responseXML.documentElement.childNodes || _ajx_req.responseXML.documentElement.childNodes.length == 0) return true; } return false; }
function _vld_usr() { var _ajx_req = _ajx_ri(); if(_ajx_req) { _ajx_req.open("get",_gev("U") + "xml/users.aspx?USERNAME=" + _gev("USERNAME"),false); _ajx_req.send(null); if(!_ajx_req.responseXML || !_ajx_req.responseXML.documentElement || !_ajx_req.responseXML.documentElement.childNodes || _ajx_req.responseXML.documentElement.childNodes.length == 0) return true; } return false; }
function _vld_sct() { var _sct = _ge("SECTORS"); var _sct_sel = 0; for (var i = 0; i < _sct.options.length; i++) { if (_sct.options[i].selected && ++_sct_sel > 5) return false; } return true; }

function _vld_f_s(s_field) {
	var xmlHttpRequest = c4jRequestInit();
	var sec = s_field;
	var selected = "";
	for (i = 0; i < sec.options.length; i++)
		if (sec.options[i].selected)
			selected += sec.options[i].value + "|";
		xmlHttpRequest.open("GET", "ajax.ashx?s=" + selected, true);
		xmlHttpRequest.onreadystatechange = function() {
			if (xmlHttpRequest.readyState == C4J_REQUEST_COMPLETE) {
				for (var j = 0; j < _ge("SECTORS_TITLES").childNodes.length; i++)
				_ge("SECTORS_TITLES").removeChild( _ge("SECTORS_TITLES").childNodes[0]) ;
				var data = eval(xmlHttpRequest.responseText);
				for (var i = 0; i < data.length; i++) {
					var og = _ce("optgroup");
					og.style.fontStyle = "normal";
					og.label = data[i].Name;
					_ge("SECTORS_TITLES").appendChild(og);
					for (var j = 0; j < data[i].Options.length; j++) {
						var o = _ce("option");
						o.style.paddingLeft = "5px";
						o.value = data[i].Options[j].Id;
						o.text = data[i].Options[j].Name;
						o.label = data[i].Options[j].Name;
						og.appendChild(o);
					}
				}
			}
		};
	xmlHttpRequest.send(null);

}

function _vld_s_t() { var s_t = _ge("SECTORS_TITLES"); var m_t = 0; for (var i = 0; i < s_t.children.length; i++) { m_t = 0; for (var j = 0; j < s_t.children[i].children.length; j++) { if (s_t.children[i].children[j].selected) { m_t++; if (m_t > 5) { return false; } } } } return true; }