// JavaScript Document


function checkSalary(s)
{
	if (isNaN(s) 	) 		return false;
	if (s < 100)				return false;
	if (s > 99999)			return false;
	
	return true;
}


function checkForm_Offer ( lang )
{
	clearFormColors_Offer();
	check = "ok";

	if (document.getElementById("ShipName").value.length < 2) 					{ check = "false" ; colorAlert_Offer("ShipName"); }
	salaryFrom = document.getElementById("SalaryFrom").value;
	salaryTo = document.getElementById("SalaryTo").value;

//	if (isNaN(salaryFrom)) salaryFrom = 0;
//	if (isNaN(salaryTo)) salaryTo = 0;

	// if (checkSalary(salaryFrom) == false)														{ check = "false" ; colorAlert_Offer("SalaryFrom"); }
	// if (checkSalary(salaryTo) == false)														{ check = "false" ; colorAlert_Offer("SalaryTo"); }

	if (document.getElementById("Contact_Name").value.length < 3) 			{ check = "false" ; colorAlert_Offer("Contact_Name"); }	
	if (document.getElementById("Contact_EMail").value.length < 2) 				{ check = "false" ; colorAlert_Offer("Contact_EMail"); }	
	if (document.getElementById("Contact_Phone").value.length < 5) 			{ check = "false" ; colorAlert_Offer("Contact_Phone"); }
	
	if (document.getElementById("ValidDays").value ==  "none") 					{ check = "false" ; colorAlert_Offer("ValidDays"); }
	if (document.getElementById("Position").value ==  "none") 						{ check = "false" ; colorAlert_Offer("Position"); }
	if (document.getElementById("Flag").value ==  "none") 							{ check = "false" ; colorAlert_Offer("Flag"); }
	if (document.getElementById("ShipType").value ==  "none") 					{ check = "false" ; colorAlert_Offer("ShipType"); }
	if (document.getElementById("SalaryCurrency").value ==  "none") 			{ check = "false" ; colorAlert_Offer("SalaryCurrency"); }

	if (document.getElementById("ContractLength").value.length < 2) 			{ check = "false" ; colorAlert_Offer("ContractLength"); }
	
	if (document.getElementById("Employer_Name").value.length <  4) 			{ check = "false" ; colorAlert_Offer("Employer_Name"); }
	if (document.getElementById("Employer_Location").value.length <  4) 		{ check = "false" ; colorAlert_Offer("Employer_Location"); }
	if (document.getElementById("Armator_Name").value.length <  4) 			{ check = "false" ; colorAlert_Offer("Armator_Name"); }
	if (document.getElementById("Armator_Location").value.length <  4) 		{ check = "false" ; colorAlert_Offer("Armator_Location"); }
	
	if (document.getElementById("Position").value == "0")
	{
		if (document.getElementById("PositionInfo").value.length <  2) 			{ check = "false" ; colorAlert_Offer("PositionInfo"); }
	}
		
		
	if ( (document.getElementById("Position").value == "inne") && ( document.getElementById("PositionInfo").value.length < 2) )		{ check = "false" ; colorAlert_Offer("PositionInfo"); }
	
	if (check == "false") 
	{
		if (lang == "pl") 		alert ("Formularz nie został wypełniony prawidłowo. Popraw dane w wyróżnionych polach.");
		if (lang == "eng") 	alert ("Red marked fields are required!");
	}
	
	if (check == "ok") 
	{
		document.getElementById("SaveOfferButton").disabled = true;
		document.getElementById("WaitMessage").innerHTML = "Please wait...";
		document.formOffer.submit() ;
		//alert ("ok");	
	}
	
	
}


function checkOfferPosition_Inne()
{
	if (document.getElementById("Position").value == "0")
	{
		document.getElementById("PositionInfo").className = "reqField";
	} else {
		document.getElementById("PositionInfo").className = "";
	}
}




function colorAlert_Offer( formField )
{
	document.getElementById(formField).style.backgroundColor = "#ffa0a0";
}


function clearFormColors_Offer()
{
	document.getElementById("ShipName").style.backgroundColor = "#ffffff";
	document.getElementById("ShipType").style.backgroundColor = "#f0f0f0";
	document.getElementById("ValidDays").style.backgroundColor = "#f0f0f0";
	document.getElementById("Flag").style.backgroundColor = "#f0f0f0";
	document.getElementById("SalaryFrom").style.backgroundColor = "#f0f0f0";
	document.getElementById("SalaryTo").style.backgroundColor = "#f0f0f0";
	document.getElementById("SalaryCurrency").style.backgroundColor = "#f0f0f0";
	document.getElementById("Contact_Name").style.backgroundColor = "#f0f0f0";
	document.getElementById("Contact_EMail").style.backgroundColor = "#f0f0f0";
	document.getElementById("Contact_Phone").style.backgroundColor = "#f0f0f0";
	document.getElementById("ContractLength").style.backgroundColor = "#f0f0f0";
	document.getElementById("PositionInfo").style.backgroundColor = "#f0f0f0";
	
	document.getElementById("Employer_Name").style.backgroundColor = "#f0f0f0";
	document.getElementById("Employer_Location").style.backgroundColor = "#f0f0f0";
	document.getElementById("Armator_Name").style.backgroundColor = "#f0f0f0";
	document.getElementById("Armator_Location").style.backgroundColor = "#f0f0f0";
	
}
