/* -------------------------------------------------

START:: Regular Expressions Function

------------------------------------------------- */
function iniRegex(){
jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
        validLabels = /^(data|css):/,
        attr = {
            method: matchParams[0].match(validLabels) ? 
                        matchParams[0].split(':')[0] : 'attr',
            property: matchParams.shift().replace(validLabels,'')
        },
        regexFlags = 'ig',
        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
}	
}


/* -------------------------------------------------

END:: Regular Expressions Function

------------------------------------------------- */



/* -------------------------------------------------

START:: IS NUMBER ONLY

------------------------------------------------- */

function isNumber(charCode){

   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < charCode.length && IsNumber == true; i++) 
      { 
      Char = charCode.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         return false;
         }
      }
   return true;

}

/* -------------------------------------------------

END:: IS NUMBER ONLY

------------------------------------------------- */


/* -------------------------------------------------

START:: CUFON FUNCTIONS

------------------------------------------------- */

function callCoufon(){
	if (jLang != "Gr"){
    	Cufon.replace('body h1', { fontFamily: 'HelveticaNeue' });
    	Cufon.replace('body h2', { fontFamily: 'HelveticaNeue' });
    	Cufon.replace('body h3', { fontFamily: 'HelveticaNeue' });
    	Cufon.now(); // IE flicker fix
	}
}

/* -------------------------------------------------

END:: CUFON FUNCTIONS

------------------------------------------------- */







/* -------------------------------------------------

START:: BLOCK UI FUNCTIONS

------------------------------------------------- */

function block(id, msg){

if (msg == "" || msg == "undefined"){
	var message = loaderMsg;
}else{
	var message = msg;	
}
$(id).block({message: '<span class="globalLoader"><ul><li>'+ message +'...</li></ul></span>', 
			 css: {width:"238px", 
			       height : "43px", 
				   border : "none", 
				   padding: "0px", 
			 	   margin : "0px", 
				   color : "#000", 
			 	   "font-size" : "11px",
				   backgroundColor: "transparent"},
	 
			overlayCSS:  { 
				backgroundColor: '#fff', 
				opacity:         0.5
			}
});	
	
}

function unblock(id){
$(id).unblock();	
}

/* -------------------------------------------------

END:: BLOCK UI FUNCTIONS

------------------------------------------------- */








/* -------------------------------------------------

START:: STEP1 - POSITION FORM VALIDATION

------------------------------------------------- */
function posFormVal(){
var form= $("#posForm").validate({
success: "valid",
submitHandler: function(form){$(form).ajaxSubmit({
beforeSubmit:function(){
block("#positionHolder","undefined");
},
success:function(data){
if (data == 1){
	window.location = "step2.php";
}
return false;
},
target: ""
});

},
rules: {
		divisionId: "required",
		departmentId: "required",
		candidateType: {
						
						required: true
		},
		candidateInstitute:{
				required: function(element) {
       			 return $("#candidateType").val() == "Intership";
        		 }

		},
		candidateSpecialization:{
				required: function(element) {
       			 return $("#candidateType").val() == "Intership";
        		 }

		},
		candidateYearOfStudy:{
				required: function(element) {
       			 return $("#candidateType").val() == "Intership";
        		 }

		}				
		
				
		
		}
});// end: Validator



}//
/* -------------------------------------------------

END:: STEP1 - POSITION FORM VALIDATION

------------------------------------------------- */






/* -------------------------------------------------

START:: STEP1 - CANDIDATE INTERSHIP/PROF COMBO

------------------------------------------------- */
function typeCombo(){
$("#candidateType").change(function(){
	if ($(this).val() == ""){
		$("#intershipHolder").hide();//hide the extra div		
		
	}else if ($(this).val() == "Intership"){
		$("#intershipHolder").show();
		$("#candidateInstitute").focus();
	
	}else if ($(this).val() == "Professional"){
		$("#intershipHolder").hide();
	}
}); //end:: change function


}
/* -------------------------------------------------

END:: STEP1 - CANDIDATE INTERSHIP/PROF COMBO

------------------------------------------------- */








/* -------------------------------------------------

START:: STEP1 - DIVISION COMBO ACTION

------------------------------------------------- */
function divisionCombo(){
$("#divisionId").change(function(){
		
		if ($(this).val() == ""){
	
		if (jLang == "Gr") var sLang = "Παρακαλώ επιλέξτε Τομέα για να δείτε τα τμήματα";
		if (jLang == "Eng") var sLang = "Please select Division";
		
		$("#departmentId").html("<option value=''>"+ sLang +"</option>");
		$("#availablePositions").slideUp();
		}else{
		block("#positionHolder","");
		
		if ($("#availablePositions").length > 0)
		$("#availablePositions").slideUp();
		
		$.post("_phpIncludes/_fetchAjaxContent/_fetchDep.php",
			  {divisionId: $(this).val(), ajxLang : $("#ajxLang").val() },function(dep){	  
				
				$("#departmentId").html(dep);
				
				$("#step1").attr({"disabled" : "disabled"});
				
				unblock("#positionHolder");
			  
			  
			  });

		}//end:: if
});	
}
/* -------------------------------------------------

END:: STEP1 - DIVISION COMBO ACTION

------------------------------------------------- */








/* -------------------------------------------------

START:: STEP1 - DEPARTMENT COMBO ACTION

------------------------------------------------- */
function departmentCombo(){
$("#departmentId").change(function(){
		if ($(this).val() != ""){
		
		block("#positionHolder","");
		
		$.post("_phpIncludes/_fetchAjaxContent/_fetchPos.php",
			  { departmentId: $(this).val(), ajxLang : $("#ajxLang").val()},function(pos){	  
				$("#availablePositions").html(pos);
				posFormVal();
				callCoufon();
				unblock("#positionHolder");
				posCheck();
				$("#step1").attr({"disabled" : "disabled"});
				$("#availablePositions").slideDown();
			  });
		
		}else{
			$("#availablePositions").slideUp();	
		}
});	
}
/* -------------------------------------------------

END:: STEP1 - DEPARTMENT COMBO ACTION

------------------------------------------------- */







/* -------------------------------------------------

START:: STEP1 - POSITIONS CHECKBOX ACTION
		DISABLE/ENABLE SUBMIT BUTTON
		COUNT NUMBER OF CHECK POS - UP TO THREE

------------------------------------------------- */
function posCheck(){
$(".posHolder").click(function(){
	  var checkPos = $(".positionHolder input:checked").length;
	  if (checkPos > 3){
		  alert ("You can Select Up to 3 Positions");
		  id = this.id
		  $("#pos_" + id).removeAttr("checked");
	  }

	if (checkPos >= 1){
		
		$("#step1").removeAttr("disabled");
		$("#stepBtn").removeClass("inactive").addClass("round");
		
	}else{
		
		$("#step1").attr({"disabled" : "disabled"});
		$("#stepBtn").removeClass("round").addClass("inactive");
	}

});
}
/* -------------------------------------------------

END:: STEP1 - POSITIONS CHECKBOX ACTION
		DISABLE/ENABLE SUBMIT BUTTON
		COUNT NUMBER OF CHECK POS - UP TO THREE

------------------------------------------------- */








/* -------------------------------------------------

START:: DATE PICKERS INITIALIZATION

------------------------------------------------- */

function iniDatePicker(){

$('.date,.dateFull').datepicker({
	    			  buttonText: 'Select Date',
					  showOn: 'button',
					  buttonImage: "_images/calendar.gif", 
					  buttonImageOnly: true,
					  dateFormat: 'dd/mm/yy',
					  showButtonPanel: false,
					  changeYear: true,
					  changeMonth: true,
					  hideIfNoPrevNext: false,

						yearRange: '-20:+1'
					  },
					  
					  $.extend({showStatus: true},
					   
					  $.datepicker.regional['gr']
					  
					  ));


$('.dateToStartWork').datepicker({
	    			  buttonText: 'Select Date',
					  showOn: 'button',
					  buttonImage: "_images/calendar.gif", 
					  buttonImageOnly: true,
					  dateFormat: 'dd/mm/yy',
					  showButtonPanel: false,
					  changeYear: true,
					  changeMonth: true,
					  hideIfNoPrevNext: false
					  },
					  
					  $.extend({showStatus: true},
					   
					  $.datepicker.regional['gr']
					  
					  ));





$('.dateBirth').datepicker({
	    			  buttonText: 'Select Date',
					  showOn: 'button',
					  buttonImage: "_images/calendar.gif", 
					  buttonImageOnly: true,
					  dateFormat: 'dd/mm/yy',
					  showButtonPanel: false,
					  changeYear: true,
					  changeMonth: true,
					  hideIfNoPrevNext: false,
					  defaultDate: "-17y",

						yearRange: '-50:0'
					  },
					  
					  $.extend({showStatus: true},
					   
					  $.datepicker.regional['gr']
					  
					  ));





$(".ui-datepicker-trigger").css({"cursor" : "pointer","vertical-align" :"-3px", "margin" : "0px 0px 0px 2px"});

}
/* -------------------------------------------------

END:: DATE PICKERS INITIALIZATION

------------------------------------------------- */







/* -------------------------------------------------

START:: EDUCATION VALIDATION

------------------------------------------------- */


function removeEduErrors(idNum){
$("#candidateEduFromDate" + idNum +"+ img +  .valid").remove();
$("#candidateEduToDate" + idNum +"+ img + .valid").remove();
$("#candidateInstitution" + idNum +"+ .valid").remove();
$("#candidateInstitutionDetails" + idNum +"+ .valid").remove();
$("#candidateQualification" + idNum +"+ .valid").remove();
$("#candidateQualificationDes" + idNum +"+ .valid").remove();

$("#candidateEduFromDate" + idNum +" + img + .error").remove();
$("#candidateEduToDate" + idNum +" + img + .error").remove();
$("#candidateInstitution" + idNum +"+ .error").remove();
$("#candidateInstitutionDetails" + idNum +"+ .error").remove();
$("#candidateQualification" + idNum +"+ .error").remove();
$("#candidateQualificationDes" + idNum +"+ .error").remove();
}

function applyEduErrors(idNum){
removeEduErrors();
var eduError = 0;
if ($("#candidateEduFromDate" + idNum).val() == ""){
$("#candidateEduFromDate" + idNum).parent().append("<div class='error'>"+fromTitle+"</div>");
eduError = 1;
}else{
$("#candidateEduFromDate" + idNum).parent().append("<div class='valid'></div>");	
}


if ($("#candidateEduToDate" + idNum).val() == ""){
$("#candidateEduToDate" + idNum).parent().append("<div class='error'>"+toTitle+"</div>");	
eduError = 1;
}else{
$("#candidateEduToDate" + idNum).parent().append("<div class='valid'></div>");	
}


if ($("#candidateInstitution" + idNum).val() == ""){
$("#candidateInstitution" + idNum).parent().append("<div class='error'>"+institutionTitle+"</div>");	
eduError = 1;
}else{
$("#candidateInstitution" + idNum).parent().append("<div class='valid'></div>");	
}


if ($("#candidateInstitutionDetails" + idNum).val() == ""){
$("#candidateInstitutionDetails" + idNum).parent().append("<div class='error'>"+institutionDetailsTitle+"</div>");	
eduError = 1;
}else{
$("#candidateInstitutionDetails" + idNum).parent().append("<div class='valid'></div>");	
}

if ($("#candidateQualification" + idNum).val() == ""){
$("#candidateQualification" + idNum).parent().append("<div class='error'>"+qualificationTitle+"</div>");
eduError = 1;
}else{
$("#candidateQualification" + idNum).parent().append("<div class='valid'></div>");	
}


if ($("#candidateQualificationDes" + idNum).val() == ""){
$("#candidateQualificationDes" + idNum).parent().append("<div class='error'>"+qualificationDescriptionTitle+"</div>");	
eduError = 1;
}else{
$("#candidateQualificationDes" + idNum).parent().append("<div class='valid'></div>");	
}


	if (eduError == 1) {
		
		return false;	
	
	}else if (eduError == 0){
		
		return true;
		
	}


}

function valEdu(){
var index = ($(":regex(id, candidateEduFromDate.*)").length);
//alert ("There Are " + index + "Education Entries That I need to Validate");
countFalse = 0;
countTrue = 0;
for (var i = 1 ; i <= index ; i++){

	//check if candidateFromDate has value
	if ($("#candidateEduFromDate" + i).val() != ""    || $("#candidateEduToDate" + i).val() != "" || 
		$("#candidateInstitution" + i).val() != "" || 	$("#candidateInstitutionDetails" + i).val() != "" ||
		$("#candidateQualification" + i).val() != "" ||  $("#candidateQualificationDes" + i).val() != ""){
		removeEduErrors(i)

		//var checkEdu = applyEduErrors(i);
		if (applyEduErrors(i) == false){
			
			countFalse = countFalse + 1;
			var lastEduError = i;		
			
		}else{
			
			countTrue = countTrue + 1;
			
		}
		
	}else{
		removeEduErrors(i);
	}
}//end:: For
if (countFalse == 0){
	
	return true;

	}else{
	$.scrollTo( "#candidateEduFromDate" +  lastEduError, {onAfter:function(){}});
	return false;
	
	};
}

/* -------------------------------------------------

END:: EDUCATION VALIDATION

------------------------------------------------- */










/* -------------------------------------------------

START:: EMPLOYMENT VALIDATION

------------------------------------------------- */

function applyEmpErrors(idNum){

	removeEmpErrors();
	var empError = 0;
	if ($("#candidateEmpFromDate" + idNum).val() == ""){
		$("#candidateEmpFromDate" + idNum).parent().append("<div class='error'>"+ fromTitle +"</div>");
		empError = 1;
	}else{
		$("#candidateEmpFromDate" + idNum).parent().append("<div class='valid'></div>");	
	}


	if ($("#candidateEmpToDate" + idNum).val() == ""){
	$("#candidateEmpToDate" + idNum).parent().append("<div class='error'>"+ toTitle +"</div>");	
	empError = 1;
	}else{
	$("#candidateEmpToDate" + idNum).parent().append("<div class='valid'></div>");	
	}


	if ($("#candidateEmployer" + idNum).val() == ""){
	$("#candidateEmployer" + idNum).parent().append("<div class='error'>"+ employerTitle +"</div>");	
	empError = 1;
	}else{
	$("#candidateEmployer" + idNum).parent().append("<div class='valid'></div>");	
	}


	if ($("#candidateEmployerAddress" + idNum).val() == ""){
	$("#candidateEmployerAddress" + idNum).parent().append("<div class='error'>"+ employerAddressTitle +"</div>");
	empError = 1;
	}else{
	$("#candidateEmployerAddress" + idNum).parent().append("<div class='valid'></div>");	
	}

	if ($("#candidateEmployerTelephone" + idNum).val() == ""){
	$("#candidateEmployerTelephone" + idNum).parent().append("<div class='error'>"+ employerTelephoneTitle +"</div>");
	empError = 1;
	}else{
	$("#candidateEmployerTelephone" + idNum).parent().append("<div class='valid'></div>");	
	}


	if ($("#candidateEmployerContactPerson" + idNum).val() == ""){
	$("#candidateEmployerContactPerson" + idNum).parent().append("<div class='error'>"+ employerContactPersonTitle +"</div>");	
	empError = 1;
	}else{
	$("#candidateEmployerContactPerson" + idNum).parent().append("<div class='valid'></div>");	
	}


	if ($("#candidatePosition" + idNum).val() == ""){
	$("#candidatePosition" + idNum).parent().append("<div class='error'>"+ employerPositionHeldTitle +"</div>");	
	empError = 1;
	}else{
	$("#candidatePosition" + idNum).parent().append("<div class='valid'></div>");	
	}
	
	if (empError == 1) {
		
		return false;	
	
	}else if (empError == 0){
		
		return true;
		
	}
	
	
}





function removeEmpErrors(idNum){

$("#candidateEmpFromDate" + idNum +"+ img +  .valid").remove();
$("#candidateEmpToDate" + idNum +"+ img + .valid").remove();
$("#candidateEmployer" + idNum +"+ .valid").remove();
$("#candidateEmployerAddress" + idNum +"+ .valid").remove();
$("#candidateEmployerTelephone" + idNum +"+ .valid").remove();
$("#candidateEmployerContactPerson" + idNum +"+ .valid").remove();
$("#candidatePosition" + idNum +"+ textarea + .valid").remove();


$("#candidateEmpFromDate" + idNum +" + img + .error").remove();
$("#candidateEmpToDate" + idNum +" + img + .error").remove();
$("#candidateEmployer" + idNum +"+ .error").remove();
$("#candidateEmployerAddress" + idNum +"+ .error").remove();
$("#candidateEmployerTelephone" + idNum +"+ .error").remove();
$("#candidateEmployerContactPerson" + idNum +"+ .error").remove();
$("#candidatePosition" + idNum +"+ .error").remove();


}


function valEmp(){
var index = ($(":regex(id, candidateEmpFromDate.*)").length);
//alert ("There Are " + index + " Employment Entries That I need to Validate");	
countTrue = 0;
countFalse = 0;
for (var i = 1 ; i <= index ; i++){
	//alert ("checkEmpErro " + i);
	//check if candidateFromDate has value
	if ($("#candidateEmpFromDate" + i).val() != ""    || $("#candidateEmpToDate" + i).val() != "" || 
		$("#candidateEmployer" + i).val() != "" || 	$("#candidateEmployerAddress" + i).val() != "" ||
		$("#candidateEmployerTelephone" + i).val() != "" ||  $("#candidateEmployerContactPerson" + i).val() != "" ||
		$("#candidatePosition" + i).val() != "" 
		){
		
		removeEmpErrors(i);

		if (applyEmpErrors(i) == false){
			
			countFalse = countFalse + 1;
			var lastEmpError = (i);
			
		}else{
			
			countTrue = countTrue + 1;
		
		}
	
	}
}
//alert (countFalse);
if (countFalse == 0){
	
	return true;

	}else{
	$.scrollTo( "#candidateEmpFromDate" +  lastEmpError, {onAfter:function(){}});
	return false;
	
	};
}

/* -------------------------------------------------

END:: EMPLOYMENT VALIDATION

------------------------------------------------- */











/* -------------------------------------------------

START:: LANGUAGES ERRORS VALIDATION - VAL LANG
functions:: valLang() ; removeLangErrors()
------------------------------------------------- */

function applyLangErrors(idNum){

	removeLangErrors();
	var langError = 0;
	if ($("#languageId" + idNum).val() == ""){
		$("#languageId" + idNum).parent().append("<div class='error'>"+languagesLabelTitle+"</div>");
		langError = 1;
	}else{
		$("#languageId" + idNum).parent().append("<div class='valid'></div>");	
	}


	if ($("#candidateLanguageLevel" + idNum).val() == ""){
	$("#candidateLanguageLevel" + idNum).parent().append("<div class='error'>"+languagesSpeakingTitle+"</div>");	
	langError = 1;
	}else{
	$("#candidateLanguageLevel" + idNum).parent().append("<div class='valid'></div>");	
	}
	
	if (langError == 1) {
		
		return false;	
	
	}else if (langError == 0){
		
		return true;
		
	}
	
	
}

function removeLangErrors(idNum){

$("#languageId" + idNum +"+ .valid").remove();
$("#candidateLanguageLevel" + idNum +" + .valid").remove();

$("#languageId" + idNum +" + .error").remove();
$("#candidateLanguageLevel" + idNum +" + .error").remove();

}


function valLang(){
var index = ($(":regex(id, languageId.*)").length);
countTrue = 0;
countFalse = 0;
for (var i = 1 ; i <= index ; i++){
	
	if ($("#languageId" + i).val() != ""  ||  $("#candidateLanguageLevel" + i).val() != ""){
		removeLangErrors(i);
	
		if (applyLangErrors(i) == false){
			countFalse = countFalse + 1;
		}else{
			countTrue = countTrue + 1;
		}
	
	}else{
		removeLangErrors(i);
		return true;
		
	}
}
if (countFalse == 0){return true;}else{return false;};
}

/* -------------------------------------------------

END:: LANGUAGES ERRORS VALIDATION - VAL LANG

------------------------------------------------- */






/* -------------------------------------------------

START:: STEP 2 VALIDATION

------------------------------------------------- */
function step2Validation(){

$.validator.addMethod("checkEdu", function(ph, element) {
if (valEdu()){
return true;	
}else{
return false;

}
return false;
//var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
//// 20 is the minimum number of numbers required
//return ((/\d{12,}/i).test(stripped));

}, "error");

// START:: phoneNumber Validation
$.validator.addMethod("phone", function(ph, element) {
if (ph == null || ph == "") {
return true;
}
var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
// 20 is the minimum number of numbers required
return ((/\d{12,}/i).test(stripped));

}, "");
// END:: phoneNumber Validation



// START:: only string validation
$.validator.addMethod("stringOnly", function(value, element) {
        return this.optional(element) || /^[ A-Za-zΑ-Ωα-ω\ά\έ\ή\ό\ί\ύ\ώ\Ά\Έ\Ή\Ό\Ί\Ύ\Ώ]+$/i.test(value);
    }, "");
// END:: only string validation

// START:: childValidation
$.validator.addMethod("childValidation", function(value, element) {
		if ($(".childRowInfo").length > 0){
			
			var nChilds = $("#candidateNoOfChildren").val();
			var i = 1;
			var correct = 0;
			for (i ; i <= nChilds ; i++){
				checkVal = $("#childInfo_" + i).val();
				
				
				
				if (checkVal == ""){
					
					
					return false;
					
					
					
				}else if (checkVal != "" && isNumber(checkVal) == true) {
					correct = correct + 1
				}	
			
			}

		
		if (correct == nChilds){
		return true	
		}



		}else{
			return true
		}
});
// END:: childValidation




// START:: over18
$.validator.addMethod("over18", function(value, element) {
	var birthDate = $("#candidateDateOfBirth").val().split("/");
	var day = birthDate[0];
	var month = birthDate[1];
	var year = birthDate[2];
	var age = 18;
	var mydate = new Date();
	mydate.setFullYear(year, month-1, day);
	var currdate = new Date();
	currdate.setFullYear(currdate.getFullYear() - age);
	if ((currdate - mydate) < 0){
		//alert("Sorry, only persons over the age of " + age + " may enter this site");
		return false;
	}
	return true;										 
		
}, "");
// END:: over18

var form= $("#step2").validate({
success: "valid",							   
submitHandler: function(form){$(form).ajaxSubmit({
beforeSubmit:function(){
block("#step2","");
},
success:function(data){
if (data == 1){ window.location = "step3.php";}else{alert (data); unblock("#step2");}
return false;
},

target: ""

});

},
 rules:{
		candidateName:{
						stringOnly: true,
						required: true
						
		},
		candidateSurname:{
						required: true,
						stringOnly: true
		},
		candidateFathersName:{
						required: true,
						stringOnly: true
		},		
		candidateMothersName:{
						required: true,
						stringOnly: true
		},		
		candidateDateOfBirth:{
						required: true,
						date: true,
						over18: true
		},
		candidatePlaceOfBirth:{
						required: true	
		},
		candidateSex:{
						required: true	
		},
		candidateCitizenShip:{
						required: true	
		},
		candidateMaritalStatus:{
						required: true	
		},
		candidateNoOfChildren: {
							 childValidation: true	
		},
		candidateHomeAddress: {
							required: true	
		},
		candidateTelephone: {
							required: true,
							phone: true
		},
		candidateMobile:{
							phone: true	
		},
		candidateEmailAddress:{
							email:true	
		},
		candidateCountry:{
							required: true	
		},
		candidatePc:{
							required: true	
		}		
},
messages:{
		candidateDateOfBirth:{
							over18: dateBirthMsg//"Sorry, only persons over the age of 18 may work with SANI SA"
		}
}
});// end: Validator




}
/* -------------------------------------------------

END:: STEP 2 VALIDATION

------------------------------------------------- */




/* -------------------------------------------------

START:: NumChild Function

------------------------------------------------- */


function numChildAction(){
var ageEng = new Array();
ageEng[1]="First children age:";
ageEng[2]="Second children age:";
ageEng[3]="Third children age:";
ageEng[4]="Fourth children age:";
ageEng[5]="Fifth children age:";
ageEng[6]="Sixth children age:";
ageEng[7]="Seventh children age:";
ageEng[8]="Eight children age:";
ageEng[9]="Ninth children age:";
ageEng[10]="Tenth children age:";


var ageGr = new Array();
ageGr[1]="Ηλ. πρώτου παιδιού:";
ageGr[2]="Ηλ. δεύτερου παιδιού:";
ageGr[3]="Ηλ. τρίτου παιδιού:";
ageGr[4]="Ηλ. τέταρτου παιδιού:";
ageGr[5]="Ηλ. πέμπτου παιδιού:";
ageGr[6]="Ηλ. έκτου παιδιού:";
ageGr[7]="Ηλ. έβδομου παιδιού:";
ageGr[8]="Ηλ. όγδοου παιδιού:";
ageGr[9]="Ηλ. ένατου παιδιού:";
ageGr[10]="Ηλ. δέκατου παιδιού:";



	$("#candidateNoOfChildren").change(function(){

	$("#childrenHolder").html("");
	var c_n = $(this).val();
	for (var i = 1 ; i <= c_n ; i++){


if (jLang == "Eng"){
$("<div class='childRowInfo' id='childNum"+ i +"'><div class='childInfoRow'><label class='formLabel'><span class='req'>*</span>"+ ageEng[i] +"</label><input name='childInfo[]' tabindex='"+ (10 + i) +"' id='childInfo_"+ i +"' class='childAge' /></div></div>").appendTo("#childrenHolder");
}else{
$("<div class='childRowInfo' id='childNum"+ i +"'><div class='childInfoRow'><label class='formLabel'><span class='req'>*</span>"+ ageGr[i] +"</label><input name='childInfo[]' tabindex='"+ (10 + i) +"' id='childInfo_"+ i +"' class='childAge' /></div></div>").appendTo("#childrenHolder");	
}

}

	if ($("#childInfo_1").length > 0) { 
		$("#childInfo_1").focus();
	}else{
		$("#childInfo_1").focus();
	}
	$("#childInfo_1").focus();
$(".childAge").keyup(function(){
	var inputId = ($(this).attr("id"));
	if (isNumber($(this).val()) && $(this).val().length > 0 && $(this).val().length < 3 ){
		$("#"+inputId+"+ .valid").remove();
		$("#"+inputId+"+ .error2").remove();
		$("#"+ inputId).parent().append("<div class='valid'></div>");
	}else {
		$("#"+inputId+"+ .valid").remove();
		$("#"+inputId+"+ .error2").remove();
		$("#"+ inputId).parent().append("<div class='error2'></div>");
	}



});


	});

} // numChildFunction 


/* -------------------------------------------------

END:: NumChild Function

------------------------------------------------- */



/* -------------------------------------------------

START:: STEP 3 VALIDATION

------------------------------------------------- */

function step3Validation(){
var form= $("#step3").validate({
success: "valid",
submitHandler: function(form){$(form).ajaxSubmit({
beforeSubmit:function(){
block("#content","");
if (valLang() == true && valEdu() == true && valEmp() == true){
	return true;
}else{
	unblock("#content");
	return false;	
}


},
success:function(data){
//alert (data);
if (data == 1){
	window.location = "step4.php";
}else{
unblock("#content");
return false;
}


},
target: ""
});

},
rules: {
		candidateEduFromDate1: "required"
		
		}
});// end: Validator

 

}


/* -------------------------------------------------

END:: STEP 3 VALIDATION

------------------------------------------------- */









/* -------------------------------------------------

START:: ADD MORE EDU FUNCTION

------------------------------------------------- */
function removeEdu(id){
	$("#removeEdu" + id).click(function(){
		$("#educationSubSection"+id).remove();
		var rId = id - 1;
		if (rId > 1){
    	$.scrollTo( "#educationSubSection"+rId, { duration:2000, onAfter:function(){}});
		}else{			
    	$.scrollTo(".eduLocator", { duration:2000, onAfter:function(){}});	
		}
	});
}

function addMoreEdu(){
$("#addEduAction").click(function(){

var index = ($(":regex(id, candidateEduFromDate.*)").length + 1);
	
$(".educationWrapper").append("<div id='educationSubSection"+index+"'><div class='spacer space20'></div><fieldset><div class='formRowEdu aLeft'><label for='candidateEduFromDate"+index+"' class='formLabel'>"+ from +"</label><input type='text' name='candidateEduFromDate[]' id='candidateEduFromDate"+ index +"' value='' tabindex='27' class='formInputEdu dateFull' title='"+ fromTitle +"' readonly='readonly' /></div><div class='formRowEdu aLeft'> <label for='candidateEduToDate"+index+"' class='formLabel'><span class='req'></span>"+ to +"</label><input type='text' name='candidateEduToDate[]' id='candidateEduToDate"+ index +"' value='' tabindex='28' class='formInputEdu dateFull' title='"+ toTitle +"' readonly='readonly' /></div><div class='formRowEdu aLeft'><label for='candidateInstitution"+index+"' class='formLabel'><span class='req'></span>"+ institution +"</label><select id='candidateInstitution"+index+"' name='candidateInstitution[]' class='formComboEdu' tabindex='29' title='"+ institutionTitle +"'><option value=''>"+ institutionDefault +"</option><option value='School'>"+ institutionS +"</option><option value='College'>"+ institutionC +"</option><option value='University'>"+ institutionU +"</option></select></div>   <div class='formRowInstitution aLeft'><label for='candidateInstitutionDetails"+index+"' class='formLabel'><span class='req'></span>"+ institutionDetails +"</label><input type='text' name='candidateInstitutionDetails[]' id='candidateInstitutionDetails"+index+"' value='' tabindex='30' class='formInputInstitution'/></div><div class='spacer space10'></div><div class='formRow aLeft'><label for='candidateQualification"+index+"' class='formLabel'><span class='req'></span>"+ qualification +"</label><select id='candidateQualification"+index+"' name='candidateQualification[]' class='formInput' tabindex='31'><option value=''>"+ qualificationDefault +"</option><option value='Degree'>"+ qualificationDegree +"</option><option value='Diploma'>"+ qualificationDiploma +"</option><option value='Bachelor'>"+ qualificationBachelor +"</option><option value='Master'>"+ qualificationMaster +"</option><option value='PHD'>"+ qualificationPhd +"</option><option cvalue='other'>"+ qualificationOther +"</option></select></div><div class='formRow aRight'><label for='candidateQualificationDes"+index+"' class='formLabel'><span class='req'></span>"+ qualificationDescription +"</label><input type='text' name='candidateQualificationDes[]' id='candidateQualificationDes"+index+"' value='' tabindex='32' class='formInput'/></div><div class='spacer space10'></div><div id='removeEdu' class='removeBtn'><a href='javascript:void(0)' id='removeEdu"+index+"'>"+ remove +"</a></div></fieldset></div>");
iniDatePicker();
removeEdu(index);
//bind scroll to to add
$.scrollTo( "#educationSubSection" +  index, { duration:2000, onAfter:function(){}});
});


}

/* -------------------------------------------------

END:: ADD MORE EDU FUNCTION

------------------------------------------------- */







/* -------------------------------------------------

START:: ADD EMPLOYMENT ROW

------------------------------------------------- */

function removeEmp(id){
	$("#removeEmp" + id).click(function(){
		$("#employmentSubSection"+id).slideUp();
		var rId = id - 1;
		if (rId > 1){
    	$.scrollTo( "#employmentSubSection"+rId, { duration:2000, onAfter:function(){
		$("#employmentSubSection"+id).remove();																		   
		}});
		}else{			
    	$.scrollTo(".addEduSpacer", { duration:2000, onAfter:function(){}});	
		}
	});	
}


function addMoreEmp(){
	
$("#addEmploymentAction").click(function(){

index = ($(":regex(id, candidateEmpFromDate.*)").length + 1);

$("#employmentHolder").append("<div id='employmentSubSection"+index+"'><div class='space20'></div><h2 class='aLeft'>"+employmentHeader+"</h2><div class='spacer'></div><fieldset><div class='formRowEdu aLeft'><label for='candidateEmpFromDate"+index+"' class='formLabel'>"+ from +"</label><input type='text' name='candidateEmpFromDate[]' id='candidateEmpFromDate"+index+"' value='' tabindex='33' class='formInputEdu dateFull' readonly='readonly' /></div><div class='formRowEdu aLeft'><label for='candidateEmpToDate"+index+"' class='formLabel'><span class='req'></span>"+ to +"</label><input type='text' name='candidateEmpToDate[]' id='candidateEmpToDate"+index+"' value='' tabindex='34' class='formInputEdu dateFull' readonly='readonly' /></div><div class='formRowEmp aLeft'><label for='candidateEmployer"+index+"' class='formLabel'><span class='req'></span>"+ employer +"</label><input type='text' name='candidateEmployer[]' id='candidateEmployer"+index+"' value='' tabindex='35' class='formInputEmp' /></div><div class='formRowEmp aLeft'><label for='candidateEmployerAddress"+index+"' class='formLabel'><span class='req'></span>"+ employerAddress +"</label><input type='text' name='candidateEmployerAddress[]' id='candidateEmployerAddress"+index+"' value='' tabindex='36' class='formInputEmp' /></div><div class='spacer space10'></div><div class='formRow aLeft'><label for='candidateEmployerTelephone"+index+"' class='formLabel'><span class='req'></span>"+ employerTelephone +"</label><input type='text' name='candidateEmployerTelephone[]' id='candidateEmployerTelephone"+index+"' value='' tabindex='37' class='formInput'/></div><div class='formRow aRight'><label for='candidateEmployerContactPerson"+index+"' class='formLabel'><span class='req'></span>"+ employerContactPerson +"</label><input type='text' name='candidateEmployerContactPerson[]' id='candidateEmployerContactPerson"+index+"' value='' tabindex='38' class='formInput'/></div><div class='spacer space10'></div><div class='formRow aLeft'><label for='candidatePosition"+index+"' class='formLabel'><span class='req'></span>"+ employerPositionHeld +"</label><textarea name='candidatePosition[]' id='candidatePosition"+index+"' cols='20' rows='5' class='formInput'></textarea></div><div class='spacer space20'></div><div id='removeEmpHolder' class='removeBtn'><a href='javascript:void(0)' id='removeEmp"+index+"'>"+ remove +"</a></div></fieldset>");
iniDatePicker();
removeEmp(index);
callCoufon();
$.scrollTo( "#employmentSubSection" +  index, { duration:2000, onAfter:function(){}});
});

}

/* -------------------------------------------------

END:: ADD EMPLOYMENT ROW

------------------------------------------------- */











/* -------------------------------------------------

START:: INDEX CURRENT AVAILABLE POSITIONS ACTION

------------------------------------------------- */
// IE6 Dom Delay Sollution for Selected option
function loadDropDown(htmlOptions, ctrl, id) {
   $(ctrl).html(htmlOptions);
   try {
      $(ctrl).val(id);
   }
   catch(ex) {
      setTimeout("$('" + ctrl + "').val('" + id + "')",1);
   }
}


function applyCurrent(){

$(".applyNowLink").click(function(){
var data = this.id.split("_");								  
block("#availableNowHolder","");
//start fetch available positions
$.post("_phpIncludes/_ajxValidation/s1.php",
	{divisionId: data[0].substr(1),
	 departmentId: data[1],
	 positions:data[2],
	 candidateType: "Professional",
	 candidateInstitute : "",
	 candidateSpecialization: "",
	 candidateYearOfStudy: "",
	 ajxLang : $("#ajxLang").val()
	
	},function(data){	  
	if (data == 1){
		unblock("#availableNowHolder");
		window.location = "step2.php";
	}else{
		alert (data + "Please Contact Administration Department");	
	}

	
	}); //fetch available positions

});

//	$(".applyNowLink").click(function(){
//
//           var data = this.id.split("_");
//			$("#availablePositions").slideUp();
//			$("#step1").attr({"disabled" : "disabled"});
//			
//		  		
//				$.scrollTo( "#posForm", { duration:500, onAfter:function(){
//			 
//           		
//				//Block Holder
//				block("#positionHolder","");
//				
//				//get Division Id
//				var divId  = data[0].substr(1);
//				
//				//Remove Selected Value From Division Select
//				$("select#divisionId option[selected]").removeAttr("selected");
//				// Set The Selected Division
//				$("select#divisionId option[value='"+divId+"']").attr("selected","selected");
//				
//				
//				$.post("_phpIncludes/_fetchAjaxContent/_fetchDep.php",
//					  {divisionId: divId ,ajxLang : $("#ajxLang").val()},function(dep){	  
//						
//				//If IE6 Dom Delay Sollution Applied	
//				if($.browser.msie && $.browser.version == "6.0"){
//					loadDropDown(dep,"#departmentId",data[1]);	
//				}else{
//					$("#departmentId").html(dep);
//					$("select#departmentId option[selected]").removeAttr("selected");
//					$("select#departmentId option[value='"+data[1]+"']").attr("selected","selected");					
//				}
//
//				//start fetch available positions
//				$.post("_phpIncludes/_fetchAjaxContent/_fetchPos.php",
//					  {departmentId: data[1],ajxLang : $("#ajxLang").val()},function(pos){	  
//				$("#availablePositions").html(pos);
//				posFormVal();
//				callCoufon();
//				posCheck();
//				$("#pos_"+ data[2]).attr({"checked" : "checked"});
//				//var n = $("input:checked").length;
//				$("#step1").removeAttr("disabled");
//				$("#availablePositions").slideDown();
//				unblock("#positionHolder");
//			 }); //fetch available positions
//					  
//			    }); //end:: fetch departments
//			 
//           }}); // end:: scroll to											  
//		});	// end:: click action
		
}


/* -------------------------------------------------

END :: INDEX CURRENT AVAILABLE POSITIONS ACTION

------------------------------------------------- */




/* -------------------------------------------------

START:: ADD LANGUAGE ROW 

------------------------------------------------- */

function removeLang(id){
	$("#removeLang" + id).click(function(){
		$("#languageSubSection"+id).remove();
		var rId = id - 1;
		if (rId > 1){
    	//$.scrollTo( "#languageSubSection"+rId, { duration:2000, onAfter:function(){}});
		}else{			
    	//$.scrollTo("#languageSubSection1", { duration:2000, onAfter:function(){}});	
		}
	});	
}


function addMoreLang(){
	
$("#addLanguageAction").click(function(){
 block("#languageHolder","Loading Languages...");
var index = ($(":regex(id, languageId.*)").length + 1);
var construct = ""
//START:: FETCH LANGUAGES
		$.post("_phpIncludes/_fetchAjaxContent/_fetchLang.php",
			  {},function(langData){
				
construct = "<div id='languageSubSection"+index+"'><div class='space10'></div><fieldset><div class='formRow aLeft'><label for='languageId"+index+"' class='formLabel'>"+languagesLabel+"</label><select id='languageId"+index+"' name='languageId[]' class='formInput' tabindex='25' title='"+languagesLabelTitle+"'>";
construct = construct + langData;
construct = construct + "</select></div><div class='formRow aRight'><label class='formLabel' for='candidateLanguageLevel"+index+"'>"+languagesSpeaking+"</label><select id='candidateLanguageLevel"+index+"' name='candidateLanguageLevel[]' title='"+languagesSpeakingTitle+"' class='formInput'><option value=''>"+languagesSpeakingDefault+"</option><option value='Excellent'>"+languagesSpeakingExcellent+"</option><option value='Good'>"+languagesSpeakingGood+"</option><option value='Average'>"+languagesSpeakingAverage+"</option></select></div><div id='removeLangHolder' class='removeBtn'><a href='javascript:void(0)' id='removeLang"+index+"'>"+remove+"</a></div></fieldset></div>";				

$("#languageHolder").append(construct);
				
				unblock("#languageHolder");
				removeLang(index);
			  }); // END POST
//END:: FETCH LANGUAGES



});

}



/* -------------------------------------------------

END:: ADD LANGUAGE ROW 

------------------------------------------------- */







/* -------------------------------------------------

START:: FORM4 VALIDATION

------------------------------------------------- */

function step4Val(){

var form4 = $("#step4").validate({
success: "valid",
submitHandler: function(form){$(form).ajaxSubmit({
beforeSubmit:function(){
block("#step4","");
},
success:function(data){
if (data == 1){
	window.location = "step5.php";
}else{
	//alert (data);
	return false;
}
return false;
},
target: ""
});

},
rules: {

			candidateHasTransportation:{
					required: function(element) {
					 return $("#candidateHasDrivingLicense").val() != "" || $("#candidateHasDrivingLicense").val() != 1;
					 }
	
			},


			candidateRelativesAtSaniDes:{
					required: function(element) {
					 return $("#candidateRelativesAtSani").val() == "1";
					 }
	
			},
			candidatePreviousWorkAtSaniDes:{
					required: function(element) {
					 return $("#candidatePreviousWorkAtSani").val() == 1;
					 }
	
			},
			candidateMilitaryDischarge:{
					required: function(element) {
					 return $("#candidateMilitaryService").val() == 2;
					 }				
			},
			candidateHealthIssues:{
					required: function(element) {
					 return $("#candidateHealthStatus").val() == 2;
					 }				
		}, 
		
		candidateAvailableToStartWork: "required",
			candidateAvailableToStartDate:{
					required: function(element) {
					 return $("#candidateAvailableToStartWork").val() == 2;
					 }			
		},
		
		candidateCurrentSalary: {
								digits: true 
		}	
	
		}
});// end: Validator


//selection boxes action

//Start
$("#candidateHasDrivingLicense").change(function(){
	if ($(this).val() == "" || $(this).val() == 1){
		//$("#candidateRelativesAtSaniL").prepend("<span class='req'>*</span>");

		$("#candidateHasTransportation").attr({"disabled" : "disabled"});
		$("#candidateHasTransportation").val("");
		$("#candidateHasTransportationL span").removeClass("req").addClass("reqI");
		$("#candidateHasTransportationL").addClass("formLabelInactive");		
	}else{
		$("#candidateHasTransportationL").removeClass("formLabelInactive");
		$("#candidateHasTransportationL span").removeClass("reqI").addClass("req");
		$("#candidateHasTransportation").removeAttr("disabled");
		$("#candidateHasTransportation").focus();		

	}
});
// End


//Start
$("#candidateRelativesAtSani").change(function(){
	if ($(this).val() == 1){
		//$("#candidateRelativesAtSaniL").prepend("<span class='req'>*</span>");
		$("#candidateRelativesAtSaniL").removeClass("formLabelInactive");
		$("#candidateRelativesAtSaniL span").removeClass("reqI").addClass("req");
		$("#candidateRelativesAtSaniDes").removeAttr("readonly");
		$("#candidateRelativesAtSaniDes").focus();
	}else{
		$("#candidateRelativesAtSaniDes").attr({"readonly" : "readonly"});
		$("#candidateRelativesAtSaniDes").val("");
		$("#candidateRelativesAtSaniL span").removeClass("req").addClass("reqI");
		$("#candidateRelativesAtSaniL").addClass("formLabelInactive");
	}
});
// End


//Start
$("#candidatePreviousWorkAtSani").change(function(){
	if ($(this).val() == 1){
		//$("#candidateRelativesAtSaniL").prepend("<span class='req'>*</span>");
		$("#candidatePreviousWorkAtSaniL").removeClass("formLabelInactive");
		$("#candidatePreviousWorkAtSaniL span").removeClass("reqI").addClass("req");
		$("#candidatePreviousWorkAtSaniDes").removeAttr("readonly");
		$("#candidatePreviousWorkAtSaniDes").focus();
	}else{
		$("#candidatePreviousWorkAtSaniDes").attr({"readonly" : "readonly"});
		$("#candidatePreviousWorkAtSaniDes").val("");
		$("#candidatePreviousWorkAtSaniL span").removeClass("req").addClass("reqI");
		$("#candidatePreviousWorkAtSaniL").addClass("formLabelInactive");
	}
});
// End

//Start
$("#candidateMilitaryService").change(function(){
	if ($(this).val() == 2){
		//$("#candidateRelativesAtSaniL").prepend("<span class='req'>*</span>");
		$("#candidateMilitaryDischargeL").removeClass("formLabelInactive");
		$("#candidateMilitaryDischargeL span").removeClass("reqI").addClass("req");
		$("#candidateMilitaryDischarge").removeAttr("readonly");
		$("#candidateMilitaryDischarge").focus();
	}else{
		$("#candidateMilitaryDischarge").attr({"readonly" : "readonly"});
		$("#candidateMilitaryDischarge").val("");
		$("#candidateMilitaryDischargeL span").removeClass("req").addClass("reqI");
		$("#candidateMilitaryDischargeL").addClass("formLabelInactive");
	}
});
// End

//Start
$("#candidateHealthStatus").change(function(){
	if ($(this).val() == 2){
		//$("#candidateRelativesAtSaniL").prepend("<span class='req'>*</span>");
		$("#candidateHealthIssuesL").removeClass("formLabelInactive");
		$("#candidateHealthIssuesL span").removeClass("reqI").addClass("req");
		$("#candidateHealthIssues").removeAttr("readonly");
		$("#candidateHealthIssues").focus();
	}else{
		$("#candidateHealthIssues").attr({"readonly" : "readonly"});
		$("#candidateHealthIssues").val("");
		$("#candidateHealthIssuesL span").removeClass("req").addClass("reqI");
		$("#candidateHealthIssuesL").addClass("formLabelInactive");
	}
});
// End


//Start
$("#candidateAvailableToStartWork").change(function(){
	if ($(this).val() == 2){
		//$("#candidateRelativesAtSaniL").prepend("<span class='req'>*</span>");
		$("#candidateAvailableToStartDateL").removeClass("formLabelInactive");
		$("#candidateAvailableToStartDateL span").removeClass("reqI").addClass("req");
		$("#candidateAvailableToStartDate").removeAttr("readonly");
		$("#candidateAvailableToStartDate").focus();
		$(".dateToStartWork").datepicker("enable");
		$(".dateToStartWork").datepicker( 'show' );
	}else{
		$("#candidateAvailableToStartDate").attr({"readonly" : "readonly"});
		$("#candidateAvailableToStartDate").val("");
		$("#candidateAvailableToStartDateL span").removeClass("req").addClass("reqI");
		$("#candidateAvailableToStartDateL").addClass("formLabelInactive");
		$(".dateToStartWork").datepicker("disable");
		$("#candidateAvailableToStartDate + .valid").remove();
	}
});
// End
}
/* -------------------------------------------------

END:: FORM4 VALIDATION

------------------------------------------------- */





/* -------------------------------------------------

START:: FORM BUTTONS ROLLOVER ACTION

------------------------------------------------- */

function step5Val(){

var form= $("#step5").validate({
submitHandler: function(form){$(form).ajaxSubmit({
beforeSubmit:function(){
block("#wrapper","");
},
success:function(data){
if (data == 1){
	window.location = "completeForm.php";
}else{
	//alert (data);
	return false;	
}

},
target: ""
});

},
rules: {
	   }
});// end: Validator
	
}

/* -------------------------------------------------

START:: FORM BUTTONS ROLLOVER ACTION

------------------------------------------------- */








/* -------------------------------------------------

START:: FORM BUTTONS ROLLOVER ACTION

------------------------------------------------- */
function nextBtn(){
   $('#stepBtn').hover(
		function(){
			 $(this).addClass('rollover');
		},
		function(){
			$(this).removeClass('rollover');
		}
		);
	
}
/* -------------------------------------------------

END:: FORM BUTTONS ROLLOVER ACTION

------------------------------------------------- */







/* -------------------------------------------------

START:: DOCUMENT READY

------------------------------------------------- */
$(document).ready(function(){						   
$("#langSelector").change(function(){
window.location='index.php?currentLang='+ $(this).val() +'';
});


$('#wrapper').supersleight({shim: '/_images/transparent.gif'});
		
		//scrollDown To Form Content
		if ($(".formContent").length > 0)
		$.scrollTo( ".formContent", {onAfter:function(){}});
		
		
		//Apply NextBtn Rollover
		nextBtn();

		//STEP5 VALIDATION
		step5Val();

		//STEP4 VALIDATION
		step4Val();
		
		// STEP3 Languages Row Action
		addMoreLang();


		// INDEX page Action For Currently Available Positions
		applyCurrent(); // LINE 1050
		
		
		typeCombo(); // line 257
		
		// initialize Date Pickers
		iniDatePicker();   //Line 213

		
		//Disable date picker for Candidate Available to start Work
		$(".dateToStartWork").datepicker("disable");
		
		//Step 2 Validation
		step2Validation(); // Line 259
		
		//Step 3 Validation
		step3Validation(); // Line 877		
		
		// Child Num Function
		numChildAction();  // Line 339                                             

		// Add Row Function 
		addMoreEdu(); // Line 520
		addMoreEmp();
		
		//divisionOnChangeAction / Index Page
		divisionCombo(); // Line 107
		
		//divisionOnChangeAction / Index Page
		departmentCombo(); // Line 139
		
		
		// Call positionFormValidation / Index Page
		posFormVal();  // Line 73
		
		//ini Reqular expressions 
		iniRegex(); // Line 1


}); //End:: Document Ready