

/*******************************************************************************
** 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 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!
		if (arrayCat[intCurrentSection-1].length > 1)
		{
			for (intI=1;intI<arrayCat[intCurrentSection-1].length;intI++)
			{
				if (getNameValue(arrayCat[intCurrentSection-1][intI])[1] != "")
				{
					var newCategorie = new Option(getNameValue(arrayCat[intCurrentSection-1][intI])[1]);
					obj_catlist.options[intI]=newCategorie;
					obj_catlist.options[intI].value = getNameValue(arrayCat[intCurrentSection-1][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 updateForm2 ( )
{
	/*
	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 intI;
		var newCategorie = new Option("All");
		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 = "-1"
		//
		// if the user selected the Not Selected then we just do nothing!
		if ( obj_sectionlist.selectedIndex == 0 ) return; 	
		//
		// fill our categorie selection list!  
		if (arrayCat[intCurrentSection-1].length > 1)
		{
			for (intI=1;intI<arrayCat[intCurrentSection-1].length;intI++)
			{
				if (getNameValue(arrayCat[intCurrentSection-1][intI])[1] != "")
				{
					var newCategorie = new Option(getNameValue(arrayCat[intCurrentSection-1][intI])[1]);							
					obj_catlist.options[intI]=newCategorie;
					obj_catlist.options[intI].value = getNameValue(arrayCat[intCurrentSection-1][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;
	}
	
}
/*******************************************************************************
** fillTheForm                                                                **
*******************************************************************************/

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 )
	{
  	if ( target_form )
		{
		if ( section )			
			{
			if ( target_form._SECTION.options[section] ) 
				{
  				if ( !target_form._SECTION.selectedIndex ) 
					{
					target_form._SECTION.options[section].selected = true;
					updateForm( );
					}
				}
			}
		}
	}

function fillTheForm ( )
{
	/*
	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 on your onload!
	*/
	
	if ( this.obj_sectionlist && this.obj_catlist )
	{
	
		var intI = 0
		var intJ = 0
		var found = 0;
		var intOldValues = new Array(obj_sectionlist.selectedIndex,obj_catlist.selectedIndex)
		
		var maxlenght = new Array(obj_sectionlist.length,obj_catlist.length)
		//
		// If the global var with the name g_strFromDB has been created 
		//g_strFromDB you must create and give some value!
		//alert(intOldValues[0]);
		//alert(intOldValues[1]);
		
		if (g_strFromDB != "")
		{
			/*
			Why this code?
			Ok, you see the guy comes in with categorie id that is stored
			with his data and I try to find that categorie in our array list
			if so change the a array called intOldValues witch I use to 
			restore his previos selected section and categorie				
			*/
			//alert("g_str : " + g_strFromDB);
			ss = "";
			
			for (intI=0;intI<arrayCat.length;intI++)
			{
			ss = ss + "-";
			if (arrayCat[intI][0] != "")
				{
				for (intJ=0;intJ<arrayCat[intI].length;intJ++){
						//alert(arrayCat[intI][intJ]);
					if (arrayCat[intI][intJ] != ""){
							ss = ss + "-" + getNameValue(arrayCat[intI][intJ])[0];
						if (getNameValue(arrayCat[intI][intJ])[0] == g_strFromDB){
							if (( g_strFromDB == '1') || ( g_strFromDB == '2') || ( g_strFromDB == '3') || ( g_strFromDB == '4') || ( g_strFromDB == '5') || ( g_strFromDB == '6') || ( g_strFromDB == '7') || (g_strFromDB == '8')|| (g_strFromDB == '9')|| (g_strFromDB == '10')|| (g_strFromDB == '11')|| (g_strFromDB == '12')|| (g_strFromDB == '13')|| (g_strFromDB == '14')|| (g_strFromDB == '15')|| (g_strFromDB == '16')|| (g_strFromDB == '17')|| (g_strFromDB == '18')|| (g_strFromDB == '19')|| (g_strFromDB == '20')) {
								
								if( g_strFromDB == '14' ) {
									intOldValues[0] = '6';
								}
								if( g_strFromDB == '6' ) {
									intOldValues[0] = '6';
								}
								//alert(g_strFromDB);
								
								if (found == '0') {
									intOldValues[0] = intI+1;
									intOldValues[1] = intJ;
									}
								found = '1';
								}
							else{
								intOldValues[0] = intI+1;
								intOldValues[1] = intJ;
								}
								//alert(intI+1);
								//alert(intJ);
							}
						}
					}
				}
			}
			
			//alert(ss);
		}
		//alert(intOldValues[0]);
		//alert(intOldValues[1]);
		//
		// clean the section and categories selection boxes!
		for(intI=0; intI<maxlenght[0]; intI++)
		{
			obj_sectionlist.options[0]=null;
		}
		//
		for(intI=0; intI<maxlenght[1]; intI++)
		{
			obj_catlist.options[0]=null;
		}
		//
		// Add the fisrt item the selection boxes
		var newSection = new Option("-SELECT-");
		obj_sectionlist.options[0]=newSection
		obj_sectionlist.options[0].value = "0"
		var newCategorie = new Option("-SELECT-");
		obj_catlist.options[0]=newCategorie
		obj_catlist.options[0].value = "0"

		// Add all the sections!
		var dropdown_pos = 0
		for (intI=0;intI<arrayCat.length;intI++)
			{
			if (arrayCat[intI][0] != "")
				{
						var newSection = new Option(getNameValue(arrayCat[intI][0])[1]);
						dropdown_pos++;
						obj_sectionlist.options[dropdown_pos]=newSection;
						obj_sectionlist.options[dropdown_pos].value=getNameValue(arrayCat[intI][0])[0]
				}
			}

		// Looking at this you might think i am "(_. () |)"  or something! :) 
		// I have solved the IE BUG !!!
		
		if ( intOldValues[0] != 0 )
			obj_sectionlist.selectedIndex = intOldValues[0];
		else
			obj_sectionlist.selectedIndex = 0;
		
		//alert("g_str : " + g_strFromDB);
		if( g_strFromDB == '14' || g_strFromDB == '6') {
			intOldValues[1] = g_strFromDB;
		}
		
		updateForm();
		
		//alert(obj_catlist.length);
		
		if(intOldValues[1] == '14' || intOldValues[1] == '6') {
			for (intX=0;intX<obj_catlist.length;intX++) {
				if(obj_catlist.options[intX].value == intOldValues[1])
					intOldValues[1] = intX;
			}
		}
		
		if ( intOldValues[1] != 0 ) {
			obj_catlist.selectedIndex = intOldValues[1];
		} else {
			obj_catlist.selectedIndex = 0;
		}
		//alert("Cat:" + obj_catlist.selectedIndex + " Val 1:" + intOldValues[1]);
		
	} else {
			//alert("fillTheForm();\n Error!\n Please contact Job Mail website support to report this error.");
			return false;
	}
	
}


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 = '<font color="red">Characters Used <strong>' + a.length + '</strong> of <strong>' + iMax +'</strong></font>';
				
				}
			
			if(a.length > iMax)
				{
				spantext.innerHTML = '<font color="red"><strong>Exceeding maximum length with ' +  Math.abs(intUsed) + ' character(s)</strong></font>';
				}
		}
	}

function CCUplaceAdClear()
	{
	var spantext = document.getElementById("_TEXT_COUNT");
	spantext.innerHTML = '<font color="white">.</font>';
	}
