	var tablesCount=new Array();
	tablesCount['careers'] =1;
	tablesCount['university'] =1;
	tablesCount['school'] =1;
	tablesCount['langSkills'] =1;
	tablesCount['compSkills'] =1;
	tablesCount['genInfo'] =1;
	
	var depJobs = new Array();
	depJobs[2] = new Array();
	depJobs[2][0] = "Call Center Managers"
	depJobs[2][1] = "Resources & Intraday Planning Manager"
	depJobs[2][2] = "Training & People Development Manager"
	depJobs[2][3] = "Quality & Process Manager"
	depJobs[2][4] = "Budget & Reporting Manager"
	depJobs[2][5] = "Corporate Back Office & Complaint Manager"
	depJobs[2][6] = "Customer Care Senior Manager"
	depJobs[2][7] = "Call Center Supervisors"
	depJobs[2][8] = "Retention Supervisor"
	depJobs[2][9] = "System Development Supervisor"
	depJobs[2][10] = "Inbound Support Supervisors"
	depJobs[2][11] = "Resources & Intraday Planning Supervisors"
	depJobs[2][12] = "Customer Experience Supervisors"
	depJobs[2][13] = "Call Center Agents"
	
	depJobs[12] = new Array();
	depJobs[12][0] = "SME Supervisor / Senior Supervisor"
	depJobs[12][1] = "SME Sales Executive"
	depJobs[12][2] = "Distribution Sales Executives (Cairo- Delta- Alexandria- Upper Egypt- Canal)"
	depJobs[12][3] = "Budgeting & Planning Supervisor"
	depJobs[12][4] = "Rollout Supervisor"
	depJobs[12][5] = "Retail Sales Executives"
	depJobs[12][6] = "Retail Regional Manager"
	depJobs[12][7] = "Corporate Sales"
	
	depJobs[8] = new Array();
	depJobs[8][0] = "ARPU Senior Specialist - Mass Market"
	depJobs[8][1] = "ARPU Senior Specialist - Niche Market"
	depJobs[8][2] = "Corporate Acquisition Specialist"
	depJobs[8][3] = "CRM Manager"
	
	depJobs[1] = new Array();
	depJobs[1][0] = "Project Leader"
	depJobs[1][1] = "Senior Project Leader"
	depJobs[1][2] = "Pricing / Profitability / Budget Analysts"
	depJobs[1][3] = "Pricing Manager  "
	depJobs[1][4] = "Budget & Planning Manager"
	
	depJobs[0] = new Array();
	depJobs[0][0] = "I.T. Audit Senior Supervisor"
	
	function removeRow(tableId, rowindex)
	{
	  
		table = document.getElementById(tableId);
		rowIndex=document.getElementById(rowindex).rowIndex;
		if( rowIndex > -1 )
		{
			table.deleteRow(rowIndex);
		}
	}
	
	function fill(cmb1){
		document.getElementById("Job").options.length = 0;
		if(depJobs[cmb1.selectedIndex] != null){
			for (var i=0 ; i<depJobs[cmb1.selectedIndex].length ; i++){
				var oOption = document.createElement("OPTION");
				document.getElementById("Job").options.add(oOption);
				oOption.innerHTML = depJobs[cmb1.selectedIndex][i];
				oOption.value = depJobs[cmb1.selectedIndex][i];
			}
		}
	}
	
	function trimString(str)
	{
		return str.replace(/^\s*/, "").replace(/\s*$/, "");
	}
	
	
	function emailCheck(str) {
		str = trimString(str);
		
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str == ''){
			return -1;
		}
		
		if (str.indexOf(at) == -1) {
		   return -2;
		}

		if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr){
		   return -3;
		}

		if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr){
			return -4;
		}

		 if (str.indexOf(at,(lat+1)) != -1) {
			return -5;
		 }

		 if (str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2)==dot){
			return -6;
		 }

		 if (str.indexOf(dot,(lat+2)) == -1) {
			return -7;
		 }

		 if (str.indexOf(" ") != -1){
			return -8;
		 }

		 return 0;
	}


function isNumeric(str)
{
	var numericExpression = /^[0-9]+$/;
	if(str.match(numericExpression))
		return true;
	else
		return false
}


function phoneNumberCheck(phoneNumber, isMobile)
{
	var strTemp = trimString(phoneNumber);

	if (isMobile == true) {
		if (strTemp == '')
			return -1;
		if (strTemp.length < 10 || isNumeric(strTemp) == false || strTemp.charAt(0) != '0')
			return -2;
	}
	else {
		if (strTemp == '')
			return -1;
		if (strTemp.length < 7 || isNumeric(strTemp) == false)
			return -2;
	}
	
	return 0;
}


	var cmb1, cmb2;
	function getURLParam(name){
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null ) return "";
		else return results[1];
	}
	
	function getHTMLParams(){
		cmb1 = getURLParam('cmb1');
		cmb2 = getURLParam('cmb2');
	}
	
	
	function imposeMaxLength(Object, e, MaxLen)
	{
		if (e.keyCode != 8)
			return (Object.value.length <= MaxLen);
		else
			return true;
	}


	function submitCareerForm(careersTableId, universityTableId , schoolsTableId , langSkillsTableId , compSkillsTableId , genInfoTableId)
	{ 
		document.getElementById("Etisalat_MainEmp1_Name_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Gender_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_BirthDate_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Nationality_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_MaritalStatus_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Email_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Address_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Country_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_City_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Area_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Military_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Telephone_Error").innerHTML="";
		document.getElementById("Etisalat_MainEmp1_Mobile_Error").innerHTML="";
		
		var g = false; var m = false; var mar = false;
		if(document.cForm.Etisalat_MainEmp1_Gender[0].checked == false && document.cForm.Etisalat_MainEmp1_Gender[1].checked == false)
			g = true;
		if(document.cForm.Etisalat_MainEmp1_Military[0].checked == false && document.cForm.Etisalat_MainEmp1_Military[1].checked == false && document.cForm.Etisalat_MainEmp1_Military[2].checked == false && document.cForm.Etisalat_MainEmp1_Military[3].checked == false)
			m = true;
		
		
		var error = false;
		if (trimString(document.getElementById("Etisalat_MainEmp1_Name").value) == ""){
			document.getElementById("Etisalat_MainEmp1_Name_Error").innerHTML="Please insert the name.";
			error = true;
		}
		if (trimString(document.getElementById("Etisalat_MainEmp1_BirthDate").value) == ""){
			document.getElementById("Etisalat_MainEmp1_BirthDate_Error").innerHTML="Please insert the birth date";
			error = true;
		}
		if (trimString(document.getElementById("Etisalat_MainEmp1_Nationality").value) == ""){
			document.getElementById("Etisalat_MainEmp1_Nationality_Error").innerHTML="Please insert the nationality";
			error = true;
		}
		if (validateOnlyNumbersInput(document.getElementById("Etisalat_MainEmp1_Nationality").value) || !validateSpecialCharacters(trimString(document.getElementById("Etisalat_MainEmp1_Nationality").value))){
			document.getElementById("Etisalat_MainEmp1_Nationality_Error").innerHTML="Please insert a valid nationality";
			error = true;
		}
		
		
		
		if (trimString(document.getElementById("Etisalat_MainEmp1_Address").value) == ""){
			document.getElementById("Etisalat_MainEmp1_Address_Error").innerHTML="Please insert the address";
			error = true;
		}
		
		if (trimString(document.getElementById("Etisalat_MainEmp1_Area").value) == ""){
			document.getElementById("Etisalat_MainEmp1_Area_Error").innerHTML="Please insert the area";
			error = true;
		}
		if (validateOnlyNumbersInput(document.getElementById("Etisalat_MainEmp1_Area").value) || !validateSpecialCharacters(trimString(document.getElementById("Etisalat_MainEmp1_Area").value))){
			document.getElementById("Etisalat_MainEmp1_Area_Error").innerHTML="Please insert a valid area";
			error = true;
		}
		if (trimString(document.getElementById("Etisalat_MainEmp1_Country").value) == ""){
			document.getElementById("Etisalat_MainEmp1_Country_Error").innerHTML="Please insert the country";
			error = true;
		}
		if (validateOnlyNumbersInput(document.getElementById("Etisalat_MainEmp1_Country").value) || !validateSpecialCharacters(trimString(document.getElementById("Etisalat_MainEmp1_Country").value))){
			document.getElementById("Etisalat_MainEmp1_Country_Error").innerHTML="Please insert a valid country";
			error = true;
		}
		if (trimString(document.getElementById("Etisalat_MainEmp1_City").value) == ""){
			document.getElementById("Etisalat_MainEmp1_City_Error").innerHTML="Please insert the city";
			error = true;
		}
		if (validateOnlyNumbersInput(document.getElementById("Etisalat_MainEmp1_City").value) || !validateSpecialCharacters(trimString(document.getElementById("Etisalat_MainEmp1_City").value))){
			document.getElementById("Etisalat_MainEmp1_City_Error").innerHTML="Please insert a valid city";
			error = true;
		}
		
		
		if (trimString(document.getElementById("Etisalat_MainEmp1_Email").value) == ""){
			document.getElementById("Etisalat_MainEmp1_Email_Error").innerHTML="Please insert the email address";
			error = true;
		}
		if(!validateEmail(document.getElementById("Etisalat_MainEmp1_Email").value)){
			document.getElementById("Etisalat_MainEmp1_Email_Error").innerHTML="Please enter a valid email address";
			error = true;
		}
		
		
		
		tele_check_value = phoneNumberCheck(document.getElementById("Etisalat_MainEmp1_Telephone").value, false);
		if (tele_check_value != 0){
			if (tele_check_value == -1)
				document.getElementById("Etisalat_MainEmp1_Telephone_Error").innerHTML="Please enter the home phone";
			else
				document.getElementById("Etisalat_MainEmp1_Telephone_Error").innerHTML="Please enter a valid home phone";
			error = true;
		}
		
		mobile_check_value = phoneNumberCheck(document.getElementById("Etisalat_MainEmp1_Mobile").value, true);
		if (mobile_check_value != 0){
			if (mobile_check_value == -1)
				document.getElementById("Etisalat_MainEmp1_Mobile_Error").innerHTML="Please enter the mobile";
			else
				document.getElementById("Etisalat_MainEmp1_Mobile_Error").innerHTML="Please enter a valid mobile";
			error = true;
		}
		
		
		if(!(document.getElementById("Etisalat_MainEmp1_WorkPhone").value == "")){
			mobile_check_value = phoneNumberCheck(document.getElementById("Etisalat_MainEmp1_WorkPhone").value, true);
			if (mobile_check_value != 0 && mobile_check_value != -1){
				document.getElementById("Etisalat_MainEmp1_WorkPhone_Error").innerHTML="Please enter a valid work number";
				error = true;
			}
			
			if(!validateOnlyNumbersInput(document.getElementById("Etisalat_MainEmp1_WorkPhone").value)){
				document.getElementById("Etisalat_MainEmp1_WorkPhone_Error").innerHTML="Please enter a valid mobile";
				error = true;
			}
		}
		
		
		if(!validateOnlyNumbersInput(document.getElementById("Etisalat_MainEmp1_Telephone").value)){
			document.getElementById("Etisalat_MainEmp1_Telephone_Error").innerHTML="Please enter a valid mobile";
			error = true;
		}
		
		if(!validateOnlyNumbersInput(document.getElementById("Etisalat_MainEmp1_Mobile").value)){
			document.getElementById("Etisalat_MainEmp1_Mobile_Error").innerHTML="Please enter a valid home phone";
			error = true;
		}
		
		
		
		
		
		if (g == true){
			document.getElementById("Etisalat_MainEmp1_Gender_Error").innerHTML="Please select the gender";
			error = true;
		}
		if (m == true){
			document.getElementById("Etisalat_MainEmp1_Military_Error").innerHTML="Please select the military status";
			error = true;
		}
		
		
		var MainEmp1Name = document.getElementById("Etisalat_MainEmp1_Name").value;
		document.getElementById("Etisalat_Emp1_Name").value = MainEmp1Name;
		document.getElementById("Etisalat_Emp_School1_Name").value = MainEmp1Name;
		document.getElementById("Etisalat_Emp_LangSkills1_Name").value = MainEmp1Name;
		document.getElementById("Etisalat_Emp_CompSkills1_Name").value = MainEmp1Name;
		document.getElementById("Etisalat_Emp_GeneralInfo1_Name").value = MainEmp1Name;
		
		tableObject = document.getElementById(careersTableId);
		changeAttributeName("Etisalat_MainEmp1_EmployerName");
		changeAttributeName("Etisalat_MainEmp1_Position");
		changeAttributeName("Etisalat_MainEmp1_TillNow");
		changeAttributeName("Etisalat_MainEmp1_From");
		changeAttributeName("Etisalat_MainEmp1_To");
		changeAttributeName("Etisalat_MainEmp1_MonthlyGrossSalary");
		changeAttributeName("Etisalat_MainEmp1_ReasonsOfLeaving");
		changeAttributeName("Etisalat_MainEmp1_TotalYearsOfExperience");
		document.getElementById("Etisalat_MainEmp1_secRecords").value = tableObject.rows.length;
		
		tableObject = document.getElementById(universityTableId);
		changeAttributeName("Etisalat_Emp1_Degree");
		changeAttributeName("Etisalat_Emp1_Major");
		changeAttributeName("Etisalat_Emp1_College");
		changeAttributeName("Etisalat_Emp1_University");
		changeAttributeName("Etisalat_Emp1_From");
		changeAttributeName("Etisalat_Emp1_To");
		changeAttributeName("Etisalat_Emp1_Score");
		document.getElementById("Etisalat_Emp1_secRecords").value = tableObject.rows.length;
		
		tableObject = document.getElementById(schoolsTableId);
		changeAttributeName("Etisalat_Emp_School1_SchoolName");
		changeAttributeName("Etisalat_Emp_School1_Major");
		changeAttributeName("Etisalat_Emp_School1_GraduationYear");
		document.getElementById("Etisalat_Emp_School1_secRecords").value = tableObject.rows.length;
		

		tableObject = document.getElementById(langSkillsTableId);
		changeAttributeName("Etisalat_Emp_LangSkills1_Language");
		changeAttributeName("Etisalat_Emp_LangSkills1_ProficiencyLevel");
		document.getElementById("Etisalat_Emp_LangSkills1_secRecords").value = tableObject.rows.length;
		
		
		tableObject = document.getElementById(compSkillsTableId);
		changeAttributeName("Etisalat_Emp_CompSkills1_Application");
		changeAttributeName("Etisalat_Emp_CompSkills1_ProficiencyLevel");
		document.getElementById("Etisalat_Emp_CompSkills1_secRecords").value = tableObject.rows.length;
		
		tableObject = document.getElementById(genInfoTableId);
		changeAttributeName("Etisalat_Emp_GeneralInfo1_NoticePeriod");
		changeAttributeName("Etisalat_Emp_GeneralInfo1_ExpectedGrossSalary ");
		changeAttributeName("Etisalat_Emp_GeneralInfo1_Reference");
		changeAttributeName("Etisalat_Emp_GeneralInfo1_Title");
		changeAttributeName("Etisalat_Emp_GeneralInfo1_Employer");
		changeAttributeName("Etisalat_Emp_GeneralInfo1_Contacts");
		document.getElementById("Etisalat_Emp_GeneralInfo1_secRecords").value = tableObject.rows.length;
		
		
		if(document.getElementById("terms").checked == false ){
			alert("Please certify the information supplied before submitting your CV by checking the checkbox below");
			error=true;
		}
		
		  
		if(!error){
			cmb1 = cmb1.replace(/%20/g," ");
			cmb2 = cmb2.replace(/%20/g," ");
			document.getElementById("Etisalat_MainEmp1_Department").value=cmb1;
			document.getElementById("Etisalat_MainEmp1_Job").value=cmb2;
			document.getElementById("cForm").submit();
		}
	}

	
	function addRow(tableId, hiddenTableId)
	{
		table = document.getElementById(tableId);
		hiddenTable = document.getElementById(hiddenTableId);
		templateRow = hiddenTable.rows[0];
		var oldHtml =templateRow.cells[0].innerHTML;
		rowIndex = tablesCount[tableId];
		var newHtml =oldHtml.replace(/ROWCOUNTER/g,rowIndex);
		newRow = table.insertRow(table.rows.length);
		newRow.setAttribute("id","row_"+tableId+"_"+rowIndex);
		var cell = newRow.insertCell('0');
		
		cell.innerHTML=newHtml;
		rowIndex--;
		tablesCount[tableId]=tablesCount[tableId]+1;
	
	}
	
	var dayHeaderBGColor = "#719e19";
	var dayBGColorActive = "#EAEAEA";
	var dayBGColorOver= "#FFFFFF";
	var monthesArray=new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	var daysArray = new Array('sat', 'sun', 'mon', 'tues', 'Wednes', 'thrus', 'fri');
	var baseDir =   '/';    //'<%=request.getContextPath()%>';
	var imgDir =    '/etisalat/templates/263';      //'<%=request.getContextPath()%>/images/calendar';
	var cssDir =    '/etisalat/templates/263';      //'<%=request.getContextPath()%>/css/calendar';
	var lang=       'ENG';                //'<%=localLang%>';
	var am =         'am';                //'<%=resourceBundle.getString("calendar.time.am")%>';
	var pm =         'pm';                //'<%=resourceBundle.getString("calendar.time.pm")%>';
	var rowsCount = 0;

		function createCalendar(id, value)  // id is the id of the input textbox, which u wanna the calendar to attach with
	{
	  calendar                    = new Calendar();
	  calendar.months             = monthesArray;
	  calendar.days               = daysArray;
	  calendar.am                 = am;
	  calendar.pm                 = pm;
	  calendar.language           = lang;
	  calendar.baseDir            = baseDir;
	  calendar.imgDir             = imgDir;
	  calendar.cssDir             = cssDir;
	  calendar.isTimeOnly         = false;
	  calendar.withTime           = false;
	  calendar.isSecondary        = true;
	  calendar._clearButtonActive = false;
	  calendar.readOnly           = false;
	  calendar._currentDate       = value;
	  calendar.draw(id);

	  return calendar.HTMLValue;
	}
	
	
	function changeAttributeName(attributeName){
		var correctCounter = 0;
		for(var i=0;i<100;i++){
			if(document.getElementById(attributeName+i) != null){
				document.getElementById(attributeName+i).setAttribute('name',attributeName+correctCounter);
				correctCounter++;
			}
		}
	}
	
	
	function validateEmail(email) {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = email;
		if(reg.test(address) == false) {
			return false;
		}
		else return true;
	}
	
	//returns true is there are no special characters
	function validateSpecialCharacters(input) {
		var bolReturn = true; 
		if(input!=""){
			var cInput =  new Array();
			for (var i =0; i < input.length; i++) {
				cInput[i] = input.charCodeAt(i);
				if ((parseInt(cInput[i]) >= 33 && parseInt(cInput[i]) <= 47 ) || (parseInt(cInput[i]) >= 58 && parseInt(cInput[i]) <= 64 )||(parseInt(cInput[i]) >= 91 && parseInt(cInput[i]) <= 96 )||(parseInt(cInput[i]) >= 123 && parseInt(cInput[i]) <= 126 )) 
					bolReturn = false;
			}
		}
		return bolReturn;
	}
	
		
	//return true if the input is only numbers
	function validateOnlyNumbersInput(input)
	{
	        var bolReturn = false; 
	        if(input!="")
	        {
	            var cInput =  new Array();
	            for (var i =0; i < input.length; i++) 
	            {
	                    cInput[i] = input.charCodeAt(i);
	                    if ( (parseInt(cInput[i]) >= 48 && parseInt(cInput[i]) <= 57  ) ) 
	                            bolReturn = true;			
	                    
	                    else
	                    {
	                            bolReturn = false;
	                            break;
	                    }
	            }
	        }
	        else
	                bolReturn =  true;
	                
	        return bolReturn;
}
