// All candidate registration functions
function checkEmails() {
	var eone = document.getElementById('emailone').value;
	var etwo = document.getElementById('emailtwo').value;
	myRE = new RegExp("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", "gi");
	var msg = '';
	if (myRE.test(eone)) {
		msg = '';
	} else {
		msg = '- The two Email Address\'s you have entered are not valid'+"\n";
	}
	
	if (eone.toUpperCase != etwo.toUpperCase) {
		msg += '- The two Email Address\'s you have entered do not match'+"\n";
	} else {
		msg += '';
	}
	return msg;
}
function checkEmpAgy() {
	if (document.detailsform.EmployView.checked == false && document.detailsform.AgencyView.checked == false) {
		 return "- Please check either to allow an Employer or an Agency to be able to view your details.\n";
	} else {
		return '';
	}
}
function chkPassLen(pass) {
	if (document.getElementById(pass).value.length < 6) {
		return '- Please enter a password longer than 6 characters'+"\n";
	} else {
		return '';
	}
}
function chkPassSame(p1, p2) {
	var pass1 = document.getElementById(p1).value;
	var pass2 = document.getElementById(p2).value;
	if (pass1 != pass2) {
		return '- The Passwords you have entered do not match'+"\n";
	} else {
		return '';
	}
}
function chkSalary(field) {
	var newStr = String(field.value);
	if (isNaN(field.value)) {
		newStr = newStr.replace(/\D|\s/gi,'');
		field.value = newStr;
	}
}
function checkOptions(chkArray, desc) {
	if (chkArray == 1) {
		var boxes = document.profileform.FullPart;
	} else {
		var boxes = document.profileform.PermCont;
	}
	var onCount = 0;
	for (var i=0; i < boxes.length; i++) {
		if (boxes[i].checked == true) {
			onCount++;
		}
	}
	if (onCount == 0) {
		return "- Please check at least one of the "+desc+" options \n";
	} else {
		return '';
	}
}
function chkFP(source,dest) {
	if (source.checked == true) {
		for (var fp=0; fp < dest.length; fp++) {
			dest[fp].checked = true;
		}
	} else {
		for (var fp=0; fp < dest.length; fp++) {
			dest[fp].checked = false;
		}
	}
}
function checkDistance(source, distchk) {
	var reloc = document.getElementById(source);
	var dist = document.getElementById(distchk);
	
	if (reloc.options[reloc.selectedIndex].value == 0 && dist.options[dist.selectedIndex].value == '') {
		return '- Please select a distance to travel to work'+"\n";
	} else {
		return '';
	}
}
function converttoupper(fieldbox){
	box = document.getElementById(fieldbox);
	box.value = box.value.toUpperCase();
}
function DoSpellCheck(aTextField) {
	var newspellwin = window.open('templates/sphpell/spellcheckwindowframeset.php?spellcheckfield='+aTextField, 'SpellCheckWin', 'status=no,location=no,directories=no,menubar=no,toolbar=no,scrollbars=yes,height=340,width=525,resizable=yes,top=150,left=150,screenX=150,screenY=150');
}
function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	} else { 
		// progress bar percentage
		var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit);
		var charsleft = maxlimit - charcnt;
		//	document.getElementById(counter).style.width = parseInt((fieldWidth*percentage)/100)+"%";
		//	alert(document.getElementById(counter).style.width);
		document.getElementById(counter).innerHTML = charsleft+" characters left";
		// color correction on style from CCFFF -> CC0000
		//	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}
function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
function showHide(source, items, rows) {
	var src = document.getElementById(source);
	
	if (src.options[src.selectedIndex].value == 1) {
		for (var sh=0; sh < items.length; sh++) {
			document.getElementById(items[sh]).style.display = "block";
		}
		for (var rh=0; rh < rows.length; rh++) {
			document.getElementById(rows[rh]).style.height = "0px";
		}
	} else {
		for (var sh=0; sh < items.length; sh++) {
			document.getElementById(items[sh]).style.display = "none";
		}
		for (var rh=0; rh < rows.length; rh++) {
			document.getElementById(rows[rh]).style.height = "0px";
		}
	}
}
function showHideRow(catalyst,source) {
	if (document.getElementById(catalyst).value==1) {
		document.getElementById(source).style.height='';
		document.getElementById(source).style.display='';
		document.getElementById(source).style.visibility='visible';
	} else {
		document.getElementById(source).style.height='0px';
		document.getElementById(source).style.display='none';
		document.getElementById(source).style.visibility='hidden';
	}
}
function viewbbox(item1,item2) {
	document.getElementById(item1).style.display='';
	document.getElementById(item1).style.visibility='';
	document.getElementById(item2).style.display='';
	document.getElementById(item2).style.visibility='';
}
