var CONST_SHOW_MARKINGS	= true;				//Constant for ease of use, ad WITH ad-markings
var CONST_HIDE_MARKINGS	= false;			//Constant for ease of use, ad WITHOUT ad-markings 
var CONST_SHOW_ADS		= true;				//Safety trigger to enable/disable ads.

var CONST_UNIQUE_NUM = getUniqueNumber();	//Get a somewhat unique number for this pageload
var strHeliosKey = "";						//For adding searchkey parameters. Use setHeliosKey() for this.


/**
 * Examples of use:
	showHeliosAd("1040213", "17993", CONST_SHOW_MARKINGS);
	showHeliosAd("1040207", "17993", CONST_HIDE_MARKINGS);
*/


function setHeliosKey( strNewKey ) {
/*=======================================================
 * DESCRIPTION
 * Used to set the global variable strHeliosKey,
 * that is used for all ads on current page.
 * 
 * INPUT PARAMETERS
 * strNewKey - the new value of strHeliosKey, string
 *
 * RETURNS
 * N/A. No return value from function, sets global variable.
 */
	strHeliosKey = escape(strNewKey);
}


function getUniqueNumber() {
/*=======================================================
 * DESCRIPTION
 * Used to get a unique number for current page,
 * to prevent cacheing of adstrings.
 * 
 * INPUT PARAMETERS
 * N/A
 * 
 * RETURNS
 * Number of milliseconds from the year 2000.
 */
	var mill = new Date(2000, 00, 01, 00, 00, 00);
	return new Date()-mill;
}


function showHeliosAd( intPlacement, intPage, blnMarkings ) {
/*=======================================================
 * DESCRIPTION
 * Writes out the ad, with supplied parametes.
 * Also depends on the global variables: CONST_SHOW_ADS, CONST_UNIQUE_NUM
 * 
 * INPUT PARAMETERS
 * intPlacement - placement of ad, int
 * intPage - site specific code for page, int
 * blnMarkings - if we should write out ad markings or not, boolean
 * 
 * RETURNS
 * N/A. No return value from function
 */
	if(!CONST_SHOW_ADS) { return; }

//With ad marking
	if (blnMarkings == true) {
		if (/_am2_/.test(window['cu_'+intPlacement]))
		{
			document.writeln('<script language="JavaScript">')
			document.writeln(	'if (typeof(cu_' + intPlacement + '_getAdId)=="function" && cu_' + intPlacement + '_getAdId()>0)')
			document.writeln(		'{if (typeof(cu_' + intPlacement + ')=="function") {')
			document.writeln(			'cu_' + intPlacement + '();')
			document.writeln(		'}')
			document.writeln(	'}')
			document.writeln('</script>')
		} else {
			document.writeln('<script language="JavaScript">')
			document.writeln(	'if (typeof(cu_' + intPlacement + '_getAdId)=="function" && cu_' + intPlacement + '_getAdId()>0)')
			document.writeln(		'{if (typeof(cu_' + intPlacement + ')=="function") {')
			document.writeln(			'document.write("<table border=0 cellspacing=0 cellpadding=0 class=adMarkings><tr><td>");')
			document.writeln(			'cu_' + intPlacement + '();')
			document.writeln(			'document.write("</td></tr></table>");')
			document.writeln(		'}')
			document.writeln(	'}')
			document.writeln('</script>')
		}
	} 
	
// Without marking	
	else {

		document.writeln('<script language="JavaScript">')
		document.writeln(	'if (typeof(cu_' + intPlacement + '_getAdId)=="function" && cu_' + intPlacement + '_getAdId()>0)')
		document.writeln(		'{if (typeof(cu_' + intPlacement + ')=="function") {')
		document.writeln(			'cu_' + intPlacement + '();')
		document.writeln(		'}')
		document.writeln(	'}')
		document.writeln('</script>')
	}

}
