// JavaScript Document
function confirmSubmitSmsSignupForm(){
	if (document.forms[0].phone.value != "" && document.forms[0].fname.value != "" && document.forms[0].email.value != "" && document.forms[0].email2.value != ""){//not empty
	   if(document.forms[0].phone.value.length != 10){
		   window.alert('Phone number must be 10 characters of the format 0712000000');
		   return false;
		   }
		if(document.forms[0].email.value != document.forms[0].email2.value){
		   window.alert('Please confirm the email by entering it twice!\nThe two emails you entered do not match!');
		   return false;			
			}
		
		return true;
		}
		else{
		window.alert('Please supply all the required information!\nRequired fields are indicated by an asterisk*.');			
		return false;
		}	
}//end confirmSubmitSmsSignupForm()

function confirmSubmitEmpSignupForm(){
if(document.forms[0].username.value != "" && document.forms[0].coname.value != "" && document.forms[0].contact.value != "" && document.forms[0].email.value != "" && document.forms[0].physicaladdress.value != "" && document.forms[0].postaladdress.value != "" && document.forms[0].city.value != "" && document.forms[0].phone1.value != "" && document.forms[0].city.value != ""){

		if(document.forms[0].country.value == "0"){//country not selected
			window.alert('You have not selected the country!\nYou must select the country from the list!');			
			return false;
		}
		if(document.forms[0].about.value =="Please type your company summary here."){//company information not supplied
			window.alert('You have not entered company summary information!\nPlease enter a summary about the company and then proceed!');			
			return false;			
		}
		
		return true;
	}else{
		window.alert('Please supply all the required information!\nRequired fields are indicated by an asterisk*.');			
		return false;
	}//empty check
	
}// end of confirmSubmitEmpSignupForm

function confirmSubmitSPSignupForm(){
	if(document.forms[0].spname.value != "" && document.forms[0].contact.value != ""  && document.forms[0].physicaladdress.value != ""  && document.forms[0].postaladdress.value != ""  && document.forms[0].city.value != ""  && document.forms[0].email.value != ""  && document.forms[0].phone1.value != ""  && document.forms[0].spsummary.value != "" ){
		if(document.forms[0].country.value == "Country"){
				window.alert('You must select the country from the list!');
				return false;
			}
		if(document.forms[0].spsummary.value == 'Please type your company summary here.'){
				window.alert('You must enter summary information about or the mission statement of your company!');
				return false;
			}
		if(document.forms[0].country.value == "0"){//country not selected
			window.alert('You have not selected the country!\nYou must select the country from the list!');			
			return false;
		}
		
		return true;
		}else{
		window.alert('Please supply all the required information!\nRequired fields are indicated by an asterisk*.');			
		return false;
	}//empty check
}// end of confirmSubmitSPSignupForm

function confirmSubmitJobUploadForm(){
if(document.forms[0].jobtitle.value != "" && document.forms[0].jobkras.value != ""  && document.forms[0].jobsummary.value != ""  && document.forms[0].jobrequirements.value != ""  && document.forms[0].joblocation.value != ""){
		if(document.forms[0].jobkras.value == "Please type the Key Results Areas here."){
				window.alert('You have not provided the job key results areas!\nPlease type in the KRAs of the job to guide the applicants!');
				return false;
			}
		if(document.forms[0].jobsummary.value == 'Please type the job summary here..'){
				window.alert('You have not provided the job summary!\nPlease type in the job summary to guide applicants!');
				return false;
			}
		if(document.forms[0].jobrequirements.value == "Please type the job requirements here."){//country not selected
			window.alert('You have not provided the job requirents!\nYou must enter the job requirements in the provided box!');			
			return false;
		}
		if(document.forms[0].jobtype.value == "Job Type"){//country not selected
			window.alert('You have not selected the job type!\nPlease select the job type from the list!');			
			return false;
		}
		if(document.forms[0].yrdatestart.value == "Year"){//country not selected
			window.alert('You have not selected the start date year!\nYou must select the start date year from the list');			
			return false;
		}
		if(document.forms[0].mmdatestart.value == "Month"){//country not selected
			window.alert('You have not selected the start date month!\nYou must select the start date month from the list');			
			return false;
		}
		if(document.forms[0].dddatestart.value == "Day"){//country not selected
			window.alert('You have not selected the start date!\nYou must select the start date from the list');			
			return false;
		}

		if(document.forms[0].yrdateexpire.value == "Year"){//country not selected
			window.alert('You have not selected the deadline year from the list!\nPlease select the deadline year!');			
			return false;
		}
		if(document.forms[0].mmdateexpire.value == "Month"){//country not selected
			window.alert('You have not selected the deadline month from the list!\nPlease select the deadline month from the list!');			
			return false;
		}
		if(document.forms[0].dddateexpire.value == "Day"){//country not selected
			window.alert('You have not selected the deadline day!\nPlease select the deadline day from the list!');			
			return false;
		}

		
		return true;
		}else{
		window.alert('Please supply all the required information!\nRequired fields are indicated by an asterisk*.');			
		return false;
	}//empty check
}// end of confirmSubmitJobUploadForm

function confirmSubmitCVUploadForm(){
	if(document.forms[0].hobbies.value != "" && document.forms[0].cvsummary.value != ""  && document.forms[0].jobcategory.value != ""  && document.forms[0].jobtype.value != ""){	
		
	}else{
		window.alert('Please supply all the required information!\nRequired fields are indicated by an asterisk*.');			
		return false;
	}//empty check
}// confirmSubmitCVUploadForm

function writeTitle(name){
	var titles = new Array('Mr', 'Mrs', 'Ms', 'Dr', 'Bro', 'Sis', 'Fr', 'Rev');
	document.write('<select style="width: 50px" name="' + name + '">');
	for (var i = 0; i < titles.length; i++){
		if(i == 0)
			document.write('<option value="' + titles[i] + '" selected>' + titles[i] + '</option>');
		else
			document.write('<option value="' + titles[i] + '">' + titles[i] + '</option>');
		}
	document.write('</select>');
	}

function writeUpDownNumber(number, name){
	var maxNumber = number;
	document.write('<select style="width: 40px" name="' + name + '">');
	for (var i = 0; i <= maxNumber; i++){
		if(i == 0)
			document.write('<option value="' + i + '" selected>' + i + '</option>');
		else
			document.write('<option value="' + i + '">' + i + '</option>');
		}
	document.write('</select>');
	}
	
function writeDate(){
	var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	
	//years
	var today = new Date();
	var year = today.getFullYear();
	//adjust year to cater for 12 years and older
	year = year - 12;
	
	document.write('<select style="width: 65px" name="year"><option value="Year" selected>Year</option>');
	//go up to 60 years => anybody older than 72 cannot use the functionality
	for (var i = 0; i < 60; i++){
		document.write('<option value="' + (year - i) + '">' + (year - i) + '</option>');
		}
	document.write('</select>');

	//months
	document.write('<select style="width: 65px" name="month"><option value="Month" selected>Month</option>');
	for (var i = 1; i <= months.length; i++){
		if(i < 10)
			var month = "0" + i;
		else
			var month = i;
		document.write('<option value="' + month + '">' + months[i - 1] + '</option>');
		}
	document.write('</select>');

	//days
	document.write('<select style="width: 50px" name="day"><option value="Day" selected>Day</option>');
	for (var i = 1; i <= 31; i++){
		document.write('<option value="' + i + '">' + i + '</option>');
		}
	document.write('</select>');
}//writeDate

function writeNewDate(intStartYear, intNumYears, strName){
	var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	
	//years
	var startyear = intStartYear;
	var years = intNumYears;
		
	document.write('<select style="width: 65px" name="yr' + strName + '"><option value="Year" selected>Year</option>');
	//check if years is positive or negative
	if(years > 0){
		for (var i = 0; i < intNumYears; i++){
			document.write('<option value="' + (startyear + i) + '">' + (startyear + i) + '</option>');
			}
	}else{
		for (var i = 0; i > intNumYears; i--){
			document.write('<option value="' + (startyear + i) + '">' + (startyear + i) + '</option>');
			}	
	}
	document.write('</select>');

	//months
	document.write('<select style="width: 65px" name="mm' + strName + '"><option value="Month" selected>Month</option>');
	for (var i = 1; i <= months.length; i++){
		if(i < 10)
			var month = "0" + i;
		else
			var month = i;
		document.write('<option value="' + month + '">' + months[i - 1] + '</option>');
		}
	document.write('</select>');

	//days
	document.write('<select style="width: 50px" name="dd' + strName + '"><option value="Day" selected>Day</option>');
	for (var i = 1; i <= 31; i++){
		document.write('<option value="' + i + '">' + i + '</option>');
		}
	document.write('</select>');
}//writeNewDate

function checkDate(date){//returns true or false
	var fullYear = date.getFullYear();
	var month = date.getMonth();
	var day = date.getDay();
	if((fullYear % 4) != 0){//leap year
		//feb must have atmost 28 days
		if(month == 2){
			if(day > 28){//invalid date
				window.alert('Feb cannot have more than 28 days!');
				return false;
			}
		}
	}else{//leap year
	    //feb can have utmost 29 days
		if(month == 2){
			if(day > 29){//invalid date
				window.alert('Feb cannot have more than 29 days!');
				return false;
			}
		}
	}
	
	return true;
}

function writePeriod(intStartYear, intNumYears, strName){
	var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	
	//years
	var startyear = intStartYear;
	var years = intNumYears;
	
	//months
	document.write('<select style="width: 60px" name="mm' + strName + '"><option value="Month" selected>Month</option>');
	for (var i = 1; i <= months.length; i++){
		if(i < 10)
			var month = "0" + i;
		else
			var month = i;
		document.write('<option value="' + month + '">' + months[i - 1] + '</option>');
		}
	document.write('</select>');
	
	//year	
	document.write('-<select style="width: 60px" name="yr' + strName + '"><option value="Year" selected>Year</option>');
	//check if years is positive or negative
	if(years > 0){
		for (var i = 0; i < intNumYears; i++){
			document.write('<option value="' + (startyear + i) + '">' + (startyear + i) + '</option>');
			}
	}else{
		for (var i = 0; i > intNumYears; i--){
			document.write('<option value="' + (startyear + i) + '">' + (startyear + i) + '</option>');
			}	
	}
	document.write('</select>');


}//writePeriod


function confirmSubmitJSSignupForm(){
if(document.forms[0].username.value != "" && document.forms[0].fname.value != "" && document.forms[0].lname.value != "" && document.forms[0].email.value != "" && document.forms[0].postaladdress.value != "" && document.forms[0].city.value != "" && document.forms[0].phone1.value != "" && document.forms[0].location.value != ""){
		if(document.forms[0].year.value == "Year"){//year not selected
			window.alert('You have not selected the birth year!\nYou must select the birth year from the list!');			
			return false;
		}
		if(document.forms[0].month.value == "Month"){//year not selected
			window.alert('You have not selected the birth month!\nYou must select the birth month from the list!');			
			return false;
		}
		if(document.forms[0].day.value == "Day"){//year not selected
			window.alert('You have not selected the birth day!\nYou must select the birth day from the list!');			
			return false;
		}
		if(document.forms[0].country.value == "0"){//country not selected
			window.alert('You have not selected the country!\nYou must select the country from the list!');			
			return false;
		}
		
		return true;
	}else{
		window.alert('Please supply all the required information!\nRequired fields are indicated by an asterisk*.');			
		return false;
	}//empty check

}//confirmSubmitJSSignupForm

function confirmReset(){
	return window.confirm('This action will clear the data you have filled in the form!\nAre you sure you would like to proceed?');
}

function confirmSendSMS(){
if(document.forms[0].code.value != "" && document.forms[0].number.value != "" && document.forms[0].message.value != ""){//all fields filled
	//construct message
	var to = 'To: ' + document.forms[0].code.value + document.forms[0].number.value + '\n\n';
	var msg = 'Message: ' + document.forms[0].message.value + '\n\n\nProceed to send?';
	if(document.forms[0].number.value.length != 7){
		window.alert('The phone number must be seven digits!\nPlease enter the correct number.');
		return false;
	}
	if(document.forms[0].message.value == 'Type your message here.'){
		window.alert('You have not typed any message!');
		return false;
	}
	
	return window.confirm(to + msg);
	}else{
	window.alert('Please type in the phone number and message!');	
	return false;
	}	

}