// JavaScript Document

// -----------------------------------------------
// Function to validate PSS form
// -----------------------------------------------
function genStr(myText, myArray)
	{
		myStr = "";
		for (i=0; i<myArray.length; i++)
			if (myArray[i].selected)
				myStr += myArray[i].value + "|";
		myText.value = myStr.substr(0,myStr.length-1);
		
	}
	
//----------------------------------------------------------------------------------
// Validate PSS Form
//----------------------------------------------------------------------------------
function validatePSSform()
	{		
		myForm = document.frmPSS;

		fileName1 = myForm.myFile1.value;
		fileType1 = fileName1.substring(fileName1.lastIndexOf(".")+1, fileName1.length).toLowerCase();

		fileName2 = myForm.myFile2.value;
		fileType2 = fileName2.substring(fileName2.lastIndexOf(".")+1, fileName2.length).toLowerCase();

		fileName3 = myForm.myFile3.value;
		fileType3 = fileName3.substring(fileName3.lastIndexOf(".")+1, fileName3.length).toLowerCase();

		if (myForm.txtName.value=="")
			{
			alert ("Kindly provide your name!");
			myForm.txtName.focus();
			}
		else if (myForm.txtEmail.value=="")
			{
			alert ("Kindly specify your Email!");
			myForm.txtEmail.focus();
			}
		else if (myForm.txtPhone.value=="")
			{
			alert ("Kindly specify your Phone!");
			myForm.txtPhone.focus();
			}			
		else if (myForm.txtProject.value=="")
			{
			alert ("Kindly specify the proposed project!");
			myForm.txtProject.focus();
			}
		else if (myForm.txtCompanyCR.value=="")
			{
			alert ("Kindly provide your company CR number!");
			myForm.txtCompanyCR.focus();
			}
			
		else if (myForm.txtBahrainis.value=="")
			{
			alert ("Kindly provide number of current employees!");
			myForm.txtBahrainis.focus();
			}
		else if (myForm.txtNonBahrainis.value=="")
			{
			alert ("Kindly provide number of current employees!");
			myForm.txtNonBahrainis.focus();
			}			
		else if (myForm.txtYearsIncorporation.value=="")
			{
			alert ("Kindly provide years of incorporation!");
			myForm.txtYearsIncorporation.focus();
			}
		else if (myForm.txtTurnover.value=="")
			{
			alert ("Kindly provide annual turnover!");
			myForm.txtTurnover.focus();
			}
			
		else if (myForm.lstSector1.selectedIndex == -1)
			{
			alert ("Which economic sector(s) the proposal is anticipated to serve?");
			myForm.lstSector1.focus();
			}
		else if (myForm.lstSector1[15].selected & myForm.txtOtherSector1.value=="")
			{
			alert ("Which economic sector(s) the proposal is anticipated to serve?");
			myForm.txtOtherSector1.focus();
			}
			
		else if (myForm.lstSector2.selectedIndex == -1)
			{
			alert ("Which economic sector(s) your company is serving?");
			myForm.lstSector2.focus();
			}
		else if (myForm.lstSector2[15].selected & myForm.txtOtherSector2.value=="")
			{
			alert ("Which economic sector(s) your company is serving?");
			myForm.txtOtherSector2.focus();
			} 
			
		else if (myForm.chkAssociated[0].checked & myForm.lstAssociated.selectedIndex==-1)
			{
				alert ("Kindly select associated programs!");
				myForm.lstAssociated.focus();
			}
			
		else if (myForm.chkUtilized[0].checked & myForm.lstUtilized.selectedIndex==-1)
			{
				alert ("Kindly provided the utilized projects!");
				myForm.lstUtilized.focus();
			}
			
		else if (myForm.txtDescription.value=="")
			{
			alert ("Please provide a brief description of your proposed project!");
			myForm.txtDescription.focus();
			}			
			
		else if (myForm.lstOutcome.selectedIndex == -1)
			{
			alert ("Kinldy select the anticipated outcome(s) of the project!");
			myForm.lstOutcome.focus();
			}
		else if (myForm.lstOutcome[9].selected & myForm.txtOtherOutcome.value=="")
			{
			alert ("Kinldy provide the anticipated outcome(s) of the project!");
			myForm.txtOtherOutcome.focus();
			}	
			
		else if (myForm.txtTotalCost.value=="")
			{
			alert ("Kindly provide expected total cost of the Project!");
			myForm.txtTotalCost.focus();
			}	
			
		else if (myForm.txtDesc1.value=="")
			{
			alert ("Please provide a breakdown of the total cost!");
			myForm.txtDesc1.focus();
			}				
		else if (myForm.txtCost1.value=="")
			{
			alert ("Please provide a breakdown of the total cost!");
			myForm.txtCost1.focus();
			}
			
		else if (myForm.lstRisks.selectedIndex == -1)
			{
			alert ("What are the risks or challenges that you anticipate from the proposed project!");
			myForm.lstRisks.focus();
			}
		else if (myForm.lstRisks[5].selected & myForm.txtOtherRisks.value=="")
			{
			alert ("What are the risks or challenges that you anticipate from the proposed project!");
			myForm.txtOtherRisks.focus();
			}				

		else if (myForm.lstPartnership.selectedIndex == -1)
			{
			alert ("Kindly indicate the anticipated partnership model with Tamkeen!");
			myForm.lstPartnership.focus();
			}
		else if (myForm.lstPartnership[6].selected & myForm.txtOtherPartnership.value=="")
			{
			alert ("Kindly indicate the anticipated partnership model with Tamkeen!");
			myForm.txtOtherPartnership.focus();
			}

		else if (myForm.chkPartners[0].checked & myForm.txtPartners.value=="")
			{
				alert ("Does the project depend on partners other than Tamkeen?");
				myForm.txtPartners.focus();
			}

		else if (myForm.txtName1.value=="")
			{
			alert ("Please provide the names of individual(s), company(s) and or third parties, and their major role in the project.!");
			myForm.txtName1.focus();
			}				
		else if (myForm.txtRole1.value=="")
			{
			alert ("Please provide the names of individual(s), company(s) and or third parties, and their major role in the project.!");
			myForm.txtRole1.focus();
			}
		else if (myForm.txtNationality1.value=="")
			{
			alert ("Please provide the names of individual(s), company(s) and or third parties, and their major role in the project.!");
			myForm.txtNationality1.focus();
			}

		else if (myForm.txtProvider1.value=="")
			{
			alert ("List three providers that may offer similar or alternative services \ solutions!");
			myForm.txtProvider1.focus();
			}	
		else if (myForm.txtProvider2.value=="")
			{
			alert ("List three providers that may offer similar or alternative services \ solutions!");
			myForm.txtProvider2.focus();
			}	
		else if (myForm.txtProvider3.value=="")
			{
			alert ("List three providers that may offer similar or alternative services \ solutions!");
			myForm.txtProvider3.focus();
			}	
		else if (fileName1 !="" & fileType1 != "pdf" & fileType1 != "doc" & fileType1 != "docx" & fileType1 != "ppt" & fileType1 != "pptx" & fileType1 != "xls" & fileType1 != "xlsx")			
				alert ("You can upload PDF, Word, PowerPoint and Excel files only!");
	
		else if (fileName2 !="" & fileType2 != "pdf" & fileType2 != "doc" & fileType2 != "docx" & fileType2 != "ppt" & fileType2 != "pptx" & fileType2 != "xls" & fileType2 != "xlsx")
				alert ("You can upload PDF, Word, PowerPoint and Excel files only!");
	
		else if (fileName3 !="" & fileType3 != "pdf" & fileType3 != "doc" & fileType3 != "docx" & fileType3 != "ppt" & fileType3 != "pptx" & fileType3 != "xls" & fileType3 != "xlsx")
				alert ("You can upload PDF, Word, PowerPoint and Excel files only!");
		else
			{

			// generate list strings
			genStr(document.frmPSS.strSector1, document.frmPSS.lstSector1);
			genStr(document.frmPSS.strSector2, document.frmPSS.lstSector2);
			genStr(document.frmPSS.strAssociated, document.frmPSS.lstAssociated);
			genStr(document.frmPSS.strUtilized, document.frmPSS.lstUtilized);
			genStr(document.frmPSS.strOutcome, document.frmPSS.lstOutcome);
			genStr(document.frmPSS.strRisks, document.frmPSS.lstRisks);
			genStr(document.frmPSS.strPartnership, document.frmPSS.lstPartnership);

			myForm.Submit.disabled = true;

			return true 
			} 
		return false;
	}

//----------------------------------------------------------------------------------
// Validate HCD Form
//----------------------------------------------------------------------------------
function validateHCDform()
	{		
		myForm = document.frmHCD;

		fileName1 = myForm.myFile1.value;
		fileType1 = fileName1.substring(fileName1.lastIndexOf(".")+1, fileName1.length).toLowerCase();

		fileName2 = myForm.myFile2.value;
		fileType2 = fileName2.substring(fileName2.lastIndexOf(".")+1, fileName2.length).toLowerCase();

		fileName3 = myForm.myFile3.value;
		fileType3 = fileName3.substring(fileName3.lastIndexOf(".")+1, fileName3.length).toLowerCase();

		if (myForm.txtName.value=="")
			{
			alert ("Kindly provide your name!");
			myForm.txtName.focus();
			}
		else if (myForm.txtEmail.value=="")
			{
			alert ("Kindly specify your Email!");
			myForm.txtEmail.focus();
			}
		else if (myForm.txtPhone.value=="")
			{
			alert ("Kindly specify your Phone!");
			myForm.txtPhone.focus();
			}			
		else if (myForm.txtProject.value=="")
			{
			alert ("Kindly specify the proposed project!");
			myForm.txtProject.focus();
			} 
		
		else if (myForm.lstSector1.selectedIndex == -1)
			{
			alert ("The proposed project will target which economic sector(s)?");
			myForm.lstSector1.focus();
			}
		else if (myForm.lstSector1[15].selected & myForm.txtOtherSector1.value=="")
			{
			alert ("The proposed project will target which economic sector(s)?");
			myForm.txtOtherSector1.focus();
			}
			
		else if (myForm.lstJobs.selectedIndex == -1)
			{
			alert ("The proposed project will target or create which of the following job(s) categories?");
			myForm.lstJobs.focus();
			}
		else if (myForm.lstJobs[9].selected & myForm.txtOtherJob.value=="")
			{
			alert ("The proposed project will target or create which of the following job(s) categories?");
			myForm.txtOtherJob.focus();
			} 
			
		else if (myForm.chkRelated[0].checked & myForm.lstRelated.selectedIndex==-1)
			{
				alert ("Is the proposed project related to any of Tamkeen's current programs?");
				myForm.lstRelated.focus();
			}
			
		else if (myForm.chkUtilized[0].checked & myForm.lstUtilized.selectedIndex==-1)
			{
				alert ("Kindly provided the utilized projects!");
				myForm.lstUtilized.focus();
			}
			
		else if (myForm.txtDescription.value=="")
			{
			alert ("Please provide a brief description of your proposed project!");
			myForm.txtDescription.focus();
			}			
			
		else if (myForm.lstOutcome.selectedIndex == -1)
			{
			alert ("Your proposed project will aim at which of the following outcome(s)?");
			myForm.lstOutcome.focus();
			}
		else if (myForm.lstOutcome[9].selected & myForm.txtOtherOutcome.value=="")
			{
			alert ("Your proposed project will aim at which of the following outcome(s)?");
			myForm.txtOtherOutcome.focus();
			}	
			
		else if (myForm.txtIndividuals.value=="")
			{
			alert ("Kindly provide Number of individuals who will benefit from this project!");
			myForm.txtIndividuals.focus();
			}			

		else if (myForm.txtAge.value=="")
			{
			alert ("Kindly provide Age of targeted individuals!");
			myForm.txtAge.focus();
			}	

		else if (myForm.lstSkills.selectedIndex == -1)
			{
			alert ("Kindly select skills to be attained!");
			myForm.lstSkills.focus();
			}
		else if (myForm.lstSkills[9].selected & myForm.txtOtherSkills.value=="")
			{
			alert ("Kindly select skills to be attained!");
			myForm.txtOtherSkills.focus();
			}	

		else if (myForm.txtFinancialRewards.value=="")
			{
			alert ("Kindly provide Financial rewards or assistance (i.e. Salary) per month!");
			myForm.txtFinancialRewards.focus();
			}	

		else if (myForm.txtExpectedTotal.value=="")
			{
			alert ("Kindly provide Expected total cost of the Project!");
			myForm.txtExpectedTotal.focus();
			}	
			
		else if (myForm.txtDesc1.value=="")
			{
			alert ("Please provide a breakdown of the total cost!");
			myForm.txtDesc1.focus();
			}				
		else if (myForm.txtCost1.value=="")
			{
			alert ("Please provide a breakdown of the total cost!");
			myForm.txtCost1.focus();
			}
			
		else if (myForm.lstRisks.selectedIndex == -1)
			{
			alert ("What are the risks or challenges that you anticipate from the proposed project!");
			myForm.lstRisks.focus();
			}
		else if (myForm.lstRisks[5].selected & myForm.txtOtherRisks.value=="")
			{
			alert ("What are the risks or challenges that you anticipate from the proposed project!");
			myForm.txtOtherRisks.focus();
			}				

		else if (myForm.lstPartnership.selectedIndex == -1)
			{
			alert ("Kindly indicate the anticipated partnership model with Tamkeen!");
			myForm.lstPartnership.focus();
			}
		else if (myForm.lstPartnership[6].selected & myForm.txtOtherPartnership.value=="")
			{
			alert ("Kindly indicate the anticipated partnership model with Tamkeen!");
			myForm.txtOtherPartnership.focus();
			}

		else if (myForm.chkPartners[0].checked & myForm.txtPartners.value=="")
			{
				alert ("Does the project depend on partners other than Tamkeen?");
				myForm.txtPartners.focus();
			}

		else if (myForm.txtName1.value=="")
			{
			alert ("Please provide the names of individual(s), company(s) and or third parties, and their major role in the project.!");
			myForm.txtName1.focus();
			}				
		else if (myForm.txtRole1.value=="")
			{
			alert ("Please provide the names of individual(s), company(s) and or third parties, and their major role in the project.!");
			myForm.txtRole1.focus();
			}
		else if (myForm.txtNationality1.value=="")
			{
			alert ("Please provide the names of individual(s), company(s) and or third parties, and their major role in the project.!");
			myForm.txtNationality1.focus();
			}

		else if (myForm.txtProvider1.value=="")
			{
			alert ("List three providers that may offer similar or alternative services \ solutions!");
			myForm.txtProvider1.focus();
			}	
		else if (myForm.txtProvider2.value=="")
			{
			alert ("List three providers that may offer similar or alternative services \ solutions!");
			myForm.txtProvider2.focus();
			}	
		else if (myForm.txtProvider3.value=="")
			{
			alert ("List three providers that may offer similar or alternative services \ solutions!");
			myForm.txtProvider3.focus();
			}	
		else if (fileName1 !="" & fileType1 != "pdf" & fileType1 != "doc" & fileType1 != "docx" & fileType1 != "ppt" & fileType1 != "pptx" & fileType1 != "xls" & fileType1 != "xlsx")			
				alert ("You can upload PDF, Word, PowerPoint and Excel files only!");
	
		else if (fileName2 !="" & fileType2 != "pdf" & fileType2 != "doc" & fileType2 != "docx" & fileType2 != "ppt" & fileType2 != "pptx" & fileType2 != "xls" & fileType2 != "xlsx")
				alert ("You can upload PDF, Word, PowerPoint and Excel files only!");
	
		else if (fileName3 !="" & fileType3 != "pdf" & fileType3 != "doc" & fileType3 != "docx" & fileType3 != "ppt" & fileType3 != "pptx" & fileType3 != "xls" & fileType3 != "xlsx")
				alert ("You can upload PDF, Word, PowerPoint and Excel files only!");
		else
			{

			// generate list strings
			genStr(document.frmHCD.strSector1, document.frmHCD.lstSector1);
			genStr(document.frmHCD.strJobs, document.frmHCD.lstJobs);
			genStr(document.frmHCD.strRelated, document.frmHCD.lstRelated);
			genStr(document.frmHCD.strUtilized, document.frmHCD.lstUtilized);
			genStr(document.frmHCD.strOutcome, document.frmHCD.lstOutcome);
			genStr(document.frmHCD.strSkills, document.frmHCD.lstSkills);
			genStr(document.frmHCD.strRisks, document.frmHCD.lstRisks);
			genStr(document.frmHCD.strPartnership, document.frmHCD.lstPartnership);

			myForm.Submit.disabled = true;

			return true 
			} 
		return false;
	}

//----------------------------------------------------------------------------------
// Validate Login Form
//----------------------------------------------------------------------------------
function validateLoginForm()
	{
		myForm = document.frmLogin;
		if (myForm.txtUser.value=="" | myForm.txtPass.value=="")
			{
			alert ("Kindly provide login information!");
			myForm.txtUser.focus();
			}
		else
			return true;
		return false;
	}