function showSubNAICs(parentNAICid)
{
	
	removeOptions('subNaic');
	removeOptions('jobTitles');
	if(parentNAICid =="")
	{		
		document.getElementById('subNaic').disabled= true;
		document.getElementById('jobTitles').disabled= true;
		alert("Please choose your industry");
		return;
	}
	showNAICLoading();
	//alert(parentNAICid);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url= rawAjaxUrl+"/getPages.php?industry_id="+parentNAICid;
	xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            updateSubNaic(xmlHttp.responseText);
        }
    }
	xmlHttp.send(null);	

}

function showJobTitles(subNAICid)
{
	
	removeOptions('jobTitles');
	if(subNAICid =="")
	{		
		document.getElementById('jobTitles').disabled= true;
		alert("Please choose your sub-industry");
		return;
	}
	showJobTitlesLoading();
	//alert(parentNAICid);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url= rawAjaxUrl+"/getPages.php?sector_id="+subNAICid;
	xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            updateJobLists(xmlHttp.responseText);
        }
    }
	xmlHttp.send(null);	
}


function updateSubNaic(list)
{
	rows = list.split('*');
	row_count = rows.length;
	for(i=0;i<row_count; i++)
	{
		cols = rows[i].split('|');
		appendOptionLast('subNaic',cols[0], cols[1] );
	}
	hideNAICLoading();
}


function updateJobLists(list)
{
	rows = list.split('*');
	row_count = rows.length;
	for(i=0;i<row_count; i++)
	{
		cols = rows[i].split('|');
		appendOptionLast('jobTitles',cols[0], cols[1] );
	}
	hideJobTitlesLoading();
}

function appendOptionLast(selector_id, value, text)
{
  var elOptNew = document.createElement('option');
  elOptNew.text = text;
  elOptNew.value = value;
  var elSel = document.getElementById(selector_id);

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}

function showNAICLoading()
{
	document.getElementById('loadingSubNaic').style.display= 'block';
	document.getElementById('subNaic').disabled= true;
	document.getElementById('jobTitles').disabled= true;
	
}
function showJobTitlesLoading()
{
	document.getElementById('loadingJobTitles').style.display= 'block';
	document.getElementById('jobTitles').disabled= true;
}

function hideNAICLoading()
{
	document.getElementById('loadingSubNaic').style.display= 'none';
	document.getElementById('subNaic').disabled= false;
}

function hideJobTitlesLoading()
{
	document.getElementById('loadingJobTitles').style.display= 'none';
	document.getElementById('jobTitles').disabled= false;
}


function removeOptions(selector_id)
{
  var elSel = document.getElementById(selector_id);
  elSel.length =1;
  return;
}








function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	// Internet Explorer
	try
	{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	}
	return xmlHttp;
}

