﻿window.onload = submitForm;

function submitForm() {
	document.forms.uploadCV.onsubmit = checkForm;
	document.getElementById("refresh").onclick = refresh;
}

var errorMsg;

function checkForm() {
	if (!checkRadiobuttons()) return false;
	if (!checkSelect()) return false;
	allInputs = document.getElementsByTagName("input");
	for (i=0; i<allInputs.length; i++) {
		if (allInputs[i].className == "req") {
			allInputs[i].onblur = setClass;
			if (!allInputs[i].value) {
				allInputs[i].className = "error";
				alert ("'"+allInputs[i].name.replace(/_/g," ")+"' is required, please fill the required field!");
				allInputs[i].focus();
				return false;
				}
			}
	}
	if (!checkTextarea()) return false;
	this.action = "submit-cv.php"
}

function setClass() {
	this.className = "req";
}

function checkRadiobuttons() {
	allInputs = document.getElementsByTagName("input");
	var allRadios = Array();
	j=0;
	for (i=0; i<allInputs.length; i++) {
		if (allInputs[i].type == "radio") allRadios[j++] = allInputs[i];
	}
	for (i=0; i<allRadios.length; i++) {
		if (allRadios[i].checked) return true;
	}
	alert ("Please select Title!");
	return false;
}

function checkSelect() {
	if (document.getElementById("Seeking").selectedIndex==0) {
		alert("Please select 'Are you Seeking'");
		document.getElementById("Seeking").className = "error";
		document.getElementById("Seeking").focus();
		document.getElementById("Seeking").onblur = setClass;
		return false;
		}
	return true;
}

function checkTextarea() {
	if (document.getElementById("Additional_information").value=="") {
		alert("Please fill 'Additional Information' text area. This field is required!");
		document.getElementById("Additional_information").className = "error";
		document.getElementById("Additional_information").focus();
		document.getElementById("Additional_information").onblur = setClass;
		return false;
		}
	return true;
}

function refresh() {
	document.gdf.src = "gdf.php"+ '?' + (new Date()).getTime();
}