/*  DECLARATION
*******************************************************************
Script  -  Custom Script for Hot Jobs functionality for RASP 
By - Nirmal Sivaram
Created - DEC 2008
Copryright 2008 RecruitASP
*******************************************************************/


/* Parammeters for Hot Jobs Applet - MODIFY PARAMETERS FOR CUSTOMISATION
**********************************************************************************************************************************************/
//var xmlURL = "https://uat.careers.ingdirect.com.au/jobtools/xml_feeds.current_jobs?in_orgi=14695"; // modify this link with the respective xml url & orgid
//var xmlURL = "http://nestle.qa.recruitasp.com.au/jobtools/xml_feeds.current_jobs?in_orgi=15296";
var xmlURL = "Ajax/proxy.asp";
var widgetstyle = "ticker"; // style needed eg:bullet, list, ticker
var displaybullet = 4; // no:of bullets
var displayticker = 7000; //set the ticker time here
var displayrandom = "Yes"; //For random ticker set randomjobs to Yes or No 
var loader = "<div class='loaderdiv'><img class='loaderimg' border='0' align='absmiddle' src='loader.gif'/><br/><span class='loaderspan'>Loading Jobs...</span></div>";
/* end of Parammeters for Hot Jobs Applet
**********************************************************************************************************************************************/


/*  INCLUDE JS Files - We need this function to include the main js files into this file
*******************************************************************************/
function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}

// now we call the above function witht he js files to include
IncludeJavaScript('Ajax/getXML.js'); //GLOBAL FILE DO NOT MODIFY
IncludeJavaScript('Ajax/XMLHttpRequest.js'); // GLOBAL FILE DO NOT MODIFY

/*  end function and call
*******************************************************************************/


/*  INCLUDE CSS Files - We need this function to include the hotjobs css file into this file
*******************************************************************************/
//function IncludeCSS(cssFile)
//{
//  document.write ('<link type="text/css" href="'
//	+ cssFile + '" rel="stylesheet" />'); 
//}

// now we call the above function with the css files to include
//IncludeCSS('hotjobs_custom.css'); //CUSTOM CSS FILE AND THIS CAN BE MODIFIED

/*  end function and call
******************************************************************************/


/*  CREATE THE WIDGET - here we will create the hotjobs layout
*******************************************************************************/
function CreateWidget()
{
  document.write ('<div>');
  document.write ('<div id="details" name="details"></div>');
  document.write ('</div>');
}

// now we call the above function to create the layout
CreateWidget();

/*  end function and call
******************************************************************************/


/*  SOME ERROR CHECKING - here we will check if we have the values
*******************************************************************************/
function fCollectJobs(keywords,style,options,randomjobs)
	{
		var searchwords = keywords; // get keywords
		var showstyle = style; //get style
		var showoptions = options; // get options
		var showrandom = randomjobs; //get random
		var displayoption
		var displaystyle
		
		//do check for the random jobs for ticker
		if (undefined != showrandom)
			{
				displayrandom = showrandom;
			}
		
		// do check to see if we need the bullet no: or ticker time
		if ((showoptions == undefined) && (undefined != showstyle))
			{
				if (showstyle =="bullet") {
					displayoption = displaybullet;
				}
				
				if (showstyle =="ticker") {
					displayoption = displayticker;
				}
			
			}
		
		// do check and specify the display style
		if ((showstyle == undefined) && (undefined != showoptions))
			{
				displaystyle = widgetstyle;
			}
		
		// if no displaystyle or display option is specified then default to custom
		if ((showstyle == undefined) && (showoptions == undefined))
			{
				displaystyle = widgetstyle;
				if (displaystyle =="bullet") {
					displayoption = displaybullet;
				}
				if (displaystyle =="ticker") {
					displayoption = displayticker;
				}
			}


		// check if all values  exists
		if ((undefined != searchwords) && (undefined != showstyle) && (undefined != showoptions))
			{
				fConfigJobs(keywords,style,options,displayrandom); // if  keyword exists then we need to get the keywords and append the url
			}

		// check if keyword is null and the others have value
		if (searchwords == undefined)
			{
				if ((showstyle == undefined) && (undefined != showoptions))
					{
						fGetJobs(xmlURL,displaystyle,options,displayrandom); 
					}
				if ((showoptions == undefined) && (undefined != showstyle))
					{
						fGetJobs(xmlURL,style,displayoption,displayrandom); 
					}
				if ((undefined != showstyle) && (undefined != showoptions))
					{
						fGetJobs(xmlURL,style,options,displayrandom); 
					}
				if ((showstyle == undefined) && (showoptions == undefined))
					{
						fGetJobs(xmlURL,displaystyle,displayoption,displayrandom); 
					}
			}

			
		// check if style is null and the others have value
		if (showstyle == undefined)
			{
				if ((searchwords == undefined) && (undefined != showoptions))
					{
						fGetJobs(xmlURL,displaystyle,options,displayrandom); 
					}
				if ((showoptions == undefined) && (undefined != searchwords))
					{
						fConfigJobs(keywords,displaystyle,displayoption,displayrandom); 
					}
				if ((undefined != searchwords) && (undefined != showoptions))
					{
						fConfigJobs(keywords,displaystyle,options,displayrandom); 
					}
				if ((searchwords == undefined) && (showoptions == undefined))
					{
						fGetJobs(xmlURL,displaystyle,displayoption,displayrandom); 
					}
			}
			
			
		// check if options is null and the others have value
		if (showoptions == undefined)
			{
				if ((searchwords == undefined) && (undefined != showstyle))
					{
						fGetJobs(xmlURL,style,displayoption,displayrandom); 
					}
				if ((showstyle == undefined) && (undefined != searchwords))
					{
						fConfigJobs(keywords,displaystyle,displayoption,displayrandom); 
					}
				if ((undefined != searchwords) && (undefined != showstyle))
					{
						fConfigJobs(keywords,style,displayoption,displayrandom); 
					}
				if ((searchwords == undefined) && (showstyle == undefined))
					{
						fGetJobs(xmlURL,displaystyle,displayoption,displayrandom);
					}
			}
}
	
/*  end function and call
*********************************************************************************************************************/


/*  GET & SPLIT THE KEYWORDS AND MAKE AJAX CALL - Collect the keywords/style and options and pass it on to the ajax function
*********************************************************************************************************************/
// Start function to retrieve keywords and make connection
function fConfigJobs(keywords,style,options,displayrandom)
	{ 

	var strkeys = new Array(); // create an array for the keywords
	strkeys = keywords.split(','); // now lets split the keywords using comma as a split point
	var newURL = xmlURL; // create a new variable and assign it the basic url
	
	//Now lets  do a for loop to append keyswords to the url 
	for (var i=0;i<strkeys.length;i++){
		newURL += "&in_job_category="+strkeys[i];
	}
	// now call the ajax function with the newly created URL, style and options
	fGetJobs(newURL,style,options,displayrandom);

}

/*  end function and call
********************************************************************************************************************/
