﻿var hidden = document.getElementById("jsContent");
var noJS = document.getElementById("noJS"); 
if (noJS && hidden) 
{
	noJS.style.display="none"; 
	hidden.style.display="block";
}

var getMemberCount = false;
var addressChanged = true;
var needToValidate = true;

function validateSalary(sender, args)
{
	args.IsValid = false;
	var from = document.getElementById(salaryFromId);
	if (from && from.value.length > 0)
		args.IsValid = true;
		
	var to = document.getElementById(salaryToId);
	if (to && to.value.length > 0)
		args.IsValid = true;

	var none = document.getElementById(salaryNoneId);

	if (none)
	    args.IsValid |= none.checked;
	
	if (!args.IsValid)
	    from.focus();
}

//Calidates EmploymentList
function validateEmploymentCheckBoxList(sender, args)
{
	args.IsValid = false;
	var chkList = document.getElementById(emplTypeClientId);
    
	if (chkList != null)
    {
        var arrayOfCheckBoxes= chkList.getElementsByTagName("input");
        
	    for(var i=0;i<arrayOfCheckBoxes.length;i++)
			if(arrayOfCheckBoxes[i].checked)
			    args.IsValid = true;
				
		if (!args.IsValid)
		    arrayOfCheckBoxes[0].focus();
	}
}

function SetNoValidation() {
    needToValidate = false;
}

function ShowAddressInGoogle(address)
{
  if (address != null && address.length > 0)
  {
      if (geocoder) 
      {
        var addressControl = document.getElementById("googleAddress");
        if (addressControl != null)    
        {
            addressControl.value = address;
            showAddress(address); 
        }
      }
   }
}

function validateJob()
{
  //debugger; 
  if (getMemberCount) return true;

  Page_ClientValidate("JobDetails");

  if (Page_IsValid)
  {
      var img = this.document.getElementById("jobEntrySaving");
      if(img)img.style.visibility = "visible";
  }

  return Page_IsValid;
}

function validateSingleControl(controlName)
{
    var control = document.getElementById(controlName);
    if (!control)return false;
        
    var valid = (control.value.length > 0 );
    
    if (!valid) control.focus();
		
	return valid;
}

function forceNumeric()
{
	var key = window.event.keyCode; 

	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27) return true;
	return (key >= 48 && key <=57); 
}

function forceNumeric(e)
{
	var key;
	if (window.event)key = event.keyCode;
	else key = e.which;
    
	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27 || (key>47 && key<58))
		return;
	
	if (window.event)window.event.returnValue = null; //IE
	else e.preventDefault(); //FF
}

function UpdateContractCtrlsVisibility(checkbox)
{	        
    var contractRow = document.getElementById(contractRowClientId);
    var duration    = document.getElementById(durationTextClientId);
    var durationDDL = document.getElementById(durationDropClientId);

    if (contractRow) {
    	if (checkbox.checked)
    		contractRow.style.visibility = "visible"; 
    	else
    		contractRow.style.visibility = "hidden";
    }
}

function showLoginControl()
{
	var login = document.getElementById("showLogonControl");
	if (login && login.style.display == "none") {   
	    login.style.display = "block";
	    var button = document.getElementById("ShowLogin");
	    if (button) button.disabled = "disabled";
	}
	return false;
}

function onMapLoaded()
{
	var street  = document.getElementById("streetSearch");
	var city    = document.getElementById("citySearch");
	var state   = document.getElementById("stateSearch");
	var zip     = document.getElementById("zipSearch");
	var country = document.getElementById("countrySearch");

	var hiddenStreet    = document.getElementById(hiddenStreetId);
	var hiddenCity      = document.getElementById(hiddenCityId);
	var hiddenState     = document.getElementById(hiddenStateId);
	var hiddenZip       = document.getElementById(hiddenZipId);
	var hiddenCountry   = document.getElementById(hiddenCountryId);

	if (street != null && hiddenStreet != null)
		street.value = hiddenStreet.value;	

	if (city != null && hiddenCity != null)
		city.value = hiddenCity.value;	

	if (state != null && hiddenState != null)
		state.value = hiddenState.value;	

	if (zip != null && hiddenZip != null)
		zip.value = hiddenZip.value;	

	if (country != null && hiddenCountry != null)
		country.value = hiddenCountry.value;	
}

function onAddressChange()
{
	addressChanged = true;
}

function startSearch()
{
	if (!addressChanged) return;
	
	var address1    = document.getElementById(JobLocationAddress1);
	var address2    = document.getElementById(JobLocationAddress2);
	var city        = document.getElementById(JobLocationCity);
	var state       = document.getElementById(JobLocationState);
	var zip         = document.getElementById(JobLocationZip);
	var country     = document.getElementById(JobLocationCountry);

	var hiddenAddress1  = document.getElementById(hiddenStreetId);
	var hiddenAddress2  = document.getElementById(hiddenStreetId);
	var hiddenCity      = document.getElementById(hiddenCityId);
	var hiddenState     = document.getElementById(hiddenStateId);
	var hiddenZip       = document.getElementById(hiddenZipId);
	var hiddenCountry   = document.getElementById(hiddenCountryId);

	var searchText = "";
	var searchValid = false;
	
	if (address1 != null)
	   searchText += address1.value;

	if (address2 != null)
	   searchText += " " + address2.value;

	if (city != null)
	{
	   searchText += " " + city.value;
	   
	   if (city.value.length > 0) searchValid = true;
	   if (hiddenCity != null) hiddenCity.value = city.value;
	}

	if (state != null)
	{
	   searchText += " " + state.value;

	   if (state.value.length > 0) searchValid = true;
	   if (hiddenState != null) hiddenState.value = state.value;
	}
	
	if (zip != null)
	{
	   searchText += " " + zip.value;
	   if (hiddenZip != null) hiddenZip.value = zip.value;
	}

	if (country != null && country.options != null      && country.options.count > 0 &&
	    country.options[country.selectedIndex] != null  && 
	    country.options[country.selectedIndex].text != "N/A")
	{
	   searchText += " " + country.options[country.selectedIndex].text;

	   if (country.options[country.selectedIndex].text.length > 0) searchValid = true;
	   if (hiddenCountry != null) hiddenCountry.value = country.selectedIndex;
	}

	if (searchValid)
	{
		var addressField = document.getElementById("FullAddress");
		if (addressField != null && gMapObj)
		{
			addressField.value = searchText;
			gMapObj.doSearch(addressField);
		}
	}
}

function SearchComplete()
{
	var loc = document.getElementById(hiddenCountryCodeId);
	var country = document.getElementById(JobLocationCountry);
 
	if (loc != null && country != null)
	{
		for(var i = 0;i<country.options.length;++i)
		{
			var item = country.options[i];
			if (item.value == loc.value)
			{
				country.selectedIndex = i;
				break;
			}
		}
	}

   addressChanged = false;
}

function PopulateFromLocation() {
    PopulateApplicationInputElement(JobLocationAddress1, ApplicationContactAddress1);
    PopulateApplicationInputElement(JobLocationAddress2, ApplicationContactAddress2);
    PopulateApplicationInputElement(JobLocationCity, ApplicationContactCity)
    PopulateApplicationInputElement(JobLocationState, ApplicationContactState);
    PopulateApplicationInputElement(JobLocationZip, ApplicationContactZip);
    PopulateApplicationInputElement(JobLocationCountry, ApplicationContactCountry)
    PopulateApplicationInputElement(JobLocationCompanyName, ApplicationContactCompanyName);
}

function PopulateApplicationInputElement(locationElementName, applicationElementName)
{
    if (locationElementName) {
        var locationElement = document.getElementById(locationElementName)
        if (locationElement && applicationElementName) {
            var applicationElement = document.getElementById(applicationElementName)
            if (applicationElement)
                applicationElement.value = locationElement.value;

        }
    }
}
	

