

/*******************************************************************************
** getNameValue                                                               **
*******************************************************************************/
function getNameValue ( thestring )
{
	/*
	This function returns a array where the number and text is stored in
	ex: The result will be 888
	var myString = "888||My category" ;
	alert(getNameValue(myString)[0]);
	*/
	var intPipeAt 	= 0
	var returnValue = new Array( "","" )
	if ( thestring != null )
	{
		intPipeAt 		= thestring.indexOf("||")
		returnValue[0] 	= thestring.substring(0,intPipeAt)
		returnValue[1] 	= thestring.substring(intPipeAt+2,thestring.length)
	}
	return returnValue
}
/*******************************************************************************
** updateForm                                                                 **
*******************************************************************************/
function updateForm ( )
{
	/*
	This function needs to have 2 objects called
		obj_sectionlist  :A drop down list
		obj_catlist      :A drop down list
	and a array that holds the sections and categories (see catsec.js)
	call this function when your section drop down box changes
	*/

	if ( ( obj_sectionlist ) && ( obj_catlist ) )
	{

		var intCurrentSection =  obj_sectionlist.selectedIndex;

    var intCurrentSection = obj_sectionlist.options[intCurrentSection].value
    //alert(intCurrentSection);

		var intI;
		var newCategorie = new Option("-SELECT-");
		var maxlenght = new Array(obj_sectionlist.length,obj_catlist.length)

		if ( intCurrentSection < 0 )
		{
			intCurrentSection = 1;
		}
		//
		// empty the categorie selection box
		for(intI=0; intI<maxlenght[1]; intI++)
		{
			obj_catlist.options[0]=null;
		}
		//
		obj_catlist.options[0]=newCategorie
		obj_catlist.options[0].value = "0"
		//
		// if the user selected the Not Selected then we just do nothing!
		if ( obj_sectionlist.selectedIndex == 0 ) return;
		//
		// fill our categorie selection list!
    //alert([intCurrentSection]);
		if (arrayCat[intCurrentSection].length > 1)
		{
			for (intI=0;intI<arrayCat[intCurrentSection].length;intI++)
			{
				if (getNameValue(arrayCat[intCurrentSection][intI])[1] != "")
				{
					var newCategorie = new Option(getNameValue(arrayCat[intCurrentSection][intI])[1]);
					obj_catlist.options[intI+1]=newCategorie;
					obj_catlist.options[intI+1].value = getNameValue(arrayCat[intCurrentSection][intI])[0];
				}//if (get
			}//for
			obj_catlist.selectedIndex = 0;

		}//if (array
	}
	else
	{
		alert("updateForm();\n Error!\n Please contact Job Mail website support to report this error.");
		return false;
	}

}

function fillAdvertDates()
{
	var iCount;
	var selected_print = document.getElementById("_PRINT_1").checked ? 1 : 0
	var selected_product = document.getElementById("_LIVEPRODUCT_1").checked ? 0 : document.getElementById("_LIVEPRODUCT_2").checked ? 1 : -1;
	var _DURATIONSTART = document.getElementById("_DURATIONSTART");
	var _DURATIONEND = document.getElementById("_DURATIONEND");

	if ( selected_print )
		{
		if ( ( selected_product == 0 ) || ( selected_product == 1 ) )
			{
			iArray = selected_product;
			_DURATIONSTART.length = 0;
			_DURATIONEND.length = 0;

			for ( iCount = 0; iCount < arrayDat[iArray].length; iCount++ )
				{
				oOptionStart = new Option( arrayDat[iArray][iCount], arrayDat[iArray][iCount] );
				oOptionEnd = new Option( arrayDat[iArray][iCount], arrayDat[iArray][iCount] );
				_DURATIONSTART.options[iCount] = oOptionStart;
				_DURATIONEND.options[iCount] = oOptionEnd;
				}

			_DURATIONSTART.options[0].selected = true;
			_DURATIONEND.options[_DURATIONEND.length - 1 ].selected = true;
			}
		}
}

function set_section_selection( target_form, section )
	{
    //alert('Here2');
    //alert(g_strFromDB);
    //alert(target_form._SECTION.options.length)
    if(target_form._SECTION.options.length == 1) {
      for (intI=0;intI<arraySec.length;intI++)
      {
        if (getNameValue(arraySec[intI])[1] != "")
        {
          var newSect = new Option(getNameValue(arraySec[intI])[1]);
          obj_sectionlist.options[intI+1]=newSect;
          obj_sectionlist.options[intI+1].value = getNameValue(arraySec[intI])[0];
        }//if (get
      }//for
    }
  	if ( target_form ) {
      if ( section ) {
        for(var i = 0; i < target_form._SECTION.options.length; i++) {
          //alert(target_form._SECTION.options[i].value);
          if(section == target_form._SECTION.options[i].value) {
            target_form._SECTION.selectedIndex = target_form._SECTION.options[i].index;
            updateForm( );
            break;
          }
        }
        for( var i = 0; i < target_form._CATEGORY.options.length;i++) {
          if(g_strFromDB == target_form._CATEGORY.options[i].value) {
            target_form._CATEGORY.selectedIndex = target_form._CATEGORY.options[i].index;
            break;
          }
        }
			}
		}
	}


function CCU( oTextArea, iMax )
{
	var intUsed = 0;
	if (oTextArea != null)
	{
		intUsed = iMax - oTextArea.value.length;
		if (intUsed > -1)
		{
			window.status = intUsed + ' character(s) left';
			//oTextArea.form._FREE.value = intUsed;
			this.oTextArea.form._LEN.value = oTextArea.value.length;
		}
		else
		{
			window.status = 'Exceeding maximum length with '+  Math.abs(intUsed) + ' character(s)';
			oTextArea.form._FREE.value = '-'+Math.abs(intUsed);
			oTextArea.form._LEN.value = oTextArea.value.length;
		}
	}
}


function CCUplaceAd( oTextArea, iMax )
	{
	var intUsed = 0;
	var spantext = document.getElementById("_TEXT_COUNT");
	var text = oTextArea.value;
	var a = '';

	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{
	  	for (i = 0; i < text.length; i++)
	  		if (text.charCodeAt(i) == 10)
	  			a = a + String.fromCharCode(13) + String.fromCharCode(10);
	  		else
				a = a + text.charAt(i);
	}
	else
		a = text;
	if ( a != null )
		{
			intUsed = iMax - a.length;
			//limitText(document.getElementById("_ADTEXT"),iMax);
			if (intUsed > -1)
				{
				spantext.innerHTML = '<div class="help-text">Characters Used <strong>' + a.length + '</strong> of <strong>' + iMax +'</strong></div>';

				}

			if(a.length > iMax)
				{
				spantext.innerHTML = '<div class="validation-advice"><strong>Exceeding maximum length with ' +  Math.abs(intUsed) + ' character(s)</strong></div>';
				}
		}
	return true;
	}

function CCUplaceAdClear(){
	var spantext = document.getElementById("_TEXT_COUNT");
	spantext.innerHTML = '<font color="white">.</font>';
}


function textCounter( oTextArea, iMax ) {
  var desc = oTextArea.value
  var spantext = document.getElementById("_TEXT_COUNT");
  var Used = desc.length;
  var diff = iMax - Used;
  if( Used > iMax) {
    spantext.innerHTML = '<div class="validation-advice"><strong>Exceeding maximum length with ' +  Math.abs(diff) + ' character(s)</strong></div>';
  } else {
    spantext.innerHTML = '<div class="help-text">Characters Used <strong>' + Used + '</strong> of <strong>' + iMax +'</strong></div>';
  }
  return true;
}

function GoalsTextCounter( oTextArea, iMax ) {
  var tracktext = "";
  var desc = oTextArea.value
  var spantext = document.getElementById("_TEXT_COUNT");
  tracktext = document.getElementById("_TRACK_FIELD");
  var Used = desc.length;
  var diff = iMax - Used;
  if( Used > iMax) {
    spantext.innerHTML = '<br><div class="validation-advice"><strong>Exceeding maximum length with ' +  Math.abs(diff) + ' character(s)</strong></div>';
	tracktext.innerHTML = 'ERROR';
  } else {
    spantext.innerHTML = '<div class="help-text">Characters Used <strong>' + Used + '</strong> of <strong>' + iMax +'</strong></div>';
    $(".curriculum-vitae").children(".validation-advice").remove();
  }
  return true;
}

function GoalsTextCounterError( oTextArea, iMax ) {
  var tracktext = "";
  var desc = oTextArea.value
  var spantext = document.getElementById("_remaining");

  var Used = desc.length;
  var diff = iMax - Used;
  //if( Used > iMax) {    spantext.innerHTML = 'Exceeding maximum length with ' +  Math.abs(diff) + ' character(s)';
	
  //} else {
   // spantext.innerHTML = 'Characters Used ' + Used + ' of ' + iMax;   
  //}
  spantext.innerHTML = 'Currect character count: '+ Used +' (click off of the text field to update the counter )';
  return true;
}

function as_updateCat(iCat){
	var oDOMCat = document.MainSearchForm._CATEGORY;
	oDOMCat.options.length=0;
	var y=0;
	oDOMCat.options[y++] = new Option('-SELECT-', 0);
	for(k in jobClassification[iCat]){
		oCat = jobClassification[iCat];
		oDOMCat.options[y++] = new Option(jobClassification[iCat][k][0], jobClassification[iCat][k][1]);
	}
}
