
window.onerror = function() {
	handleErr();
}

function handleErr() {
}

/**
 * http://www.arachna.com/edu/tutorials/mini/cookies/javascript.html
 */
function listCookies()
{
	var theCookies = document.cookie.split(';');
	var aString = '';
	for (var i = 1 ; i <= theCookies.length; i++)
	{
		aString += i + ' ' + theCookies[i-1] + "\n";
	}
	return aString;
}

/**
 * http://www.arachna.com/edu/tutorials/mini/cookies/javascript.html
 */
function setCookie(cookieName, cookieValue, nDays)
{
	var today = new Date();
	var expire = new Date();
	var path = false;
	var domain = false;
	var secure = false;

	if (nDays==null || nDays==0) nDays = 1;

	expire.setTime(today.getTime() + 3600000*24*nDays);

	var curCookie = cookieName + "=" + escape(cookieValue) +
					((nDays) ? "; expires=" + expire.toUTCString() : "") +
					((path) ? "; path=" + path : "") +
					((domain) ? "; domain=" + domain : "") +
					((secure) ? "; secure" : "");

	// Set cookie
	document.cookie = curCookie;

	//return curCookie;
}

/**
 * http://www.arachna.com/edu/tutorials/mini/cookies/javascript.html
 */
function getCookie(cookieName)
{
	var theCookies = document.cookie.split(/[; ]+/);
	for (var i = 0 ; i < theCookies.length; i++)
	{
		var aName = theCookies[i].substring(0,theCookies[i].indexOf('='));

		if (aName == cookieName)
		{
			return theCookies[i];
		}
	}
}

/**
 * http://www.arachna.com/edu/tutorials/mini/cookies/javascript.html
 */
function deleteCookie(cookieName)
{
	var aCookie = getCookie(cookieName);
	if (aCookie)
	{
		document.cookie = aCookie + '; expires=Thu, 01-Jan-70 00:00:01 GMT';

		//return cookieName;
	}
}

/**
 * Find an object by id
 */
function getObj(id_name)
{
	if (document.getElementById)
	{
		return document.getElementById(id_name);
	}
	else if (document.all)
	{
		return document.all[id_name];
	}
	else if (document.layers)
	{
		if (document.layers[id_name])
		{
			return document.layers[id_name];
		}
		else
		{
			return document.layers.testP.layers[id_name];
		}
	}
}

function ajaxRequest( url, parameters, successFunction, failFunction )
{
//	var method_type = "get";
	
//	var argv = ajaxRequest.arguments;
//	var argc = argv.length;
	
//	if (argc == 5 && argv[4] == 'post' )
//		method_type = "post";
	
	if ( failFunction == null ) 
		failFunction = function() { alert( 'Problem Ajax Requesting: ' + successDiv ); }

	if ( successFunction == null ) 
		successFunction = function() { }
	
	new Ajax.Request(
		url,
		{
//			method: method_type,
			method: 'POST',
			parameters: parameters,
			onComplete: successFunction,
			onFailure: failFunction
		});
}

function ajaxUpdate( url, parameters, successDiv, successFunction, failFunction )
{
	if ( failFunction == null )
		failFunction = function() { alert( 'Problem Ajax Updating: ' + successDiv ); }

	if ( successFunction == null )
		successFunction = function() { }

	new Ajax.Updater(
					{success: successDiv},
					url,
					{
						method: "POST",
						evalScripts: true,
						parameters: parameters,
						//onSuccess: successFunction,
						onComplete: successFunction,
						onFailure: failFunction
					});
}

// >> Ajax error callbacks

function removeElementError( el_id )
{
	$( el_id ).removeClassName( 'validationFailed' );
	$( "err_" + el_id ).innerHTML = '';
}

function removeErrors( form ) {
	// Comment out below 'cos it did not support textarea fields
	//var items = $( form ).getInputs();

	var items = $( form ).getElements();

	var size = items.length;

	var span = null;

	for ( i = 0; i < size; i++ ) {
		span = $( "err_" + items[i].name );

		// For debugging
		//alert(items[i].name+ ' | '+items[i].value);

		if ( span != null ) {
			span.innerHTML = "";
			$( items[i] ).removeClassName( 'validationFailed' );
		}
	}
}

function reportError( request ) {
	alert( 'error' );
	$F( 'urlResult' ) = "Error with " + request;
}

function sizeGray()
{
	$( 'grayOut' ).style.width = $( 'html' ).getWidth() + 50 + 'px';
	$( 'grayOut' ).style.height = $( 'html' ).getHeight() + 50 + 'px';
}

function positionDiv( divName ) {
	$( divName ).style.top = $( 'bdy' ).scrollTop + 80 + 'px';
	$( divName ).style.left = ( ( $( 'html' ).getWidth() - 400 ) / 2 ) + 'px';
}

// -- Ajax error callbacks
function hide( div ) {
	$( div ).hide();
}

function show( div ) {
	$( div ).show();
}

function cancel()
{
	Effect.Fade('leaveAlert',{delay:0,duration:0.5})
	Effect.Fade('grayOut',{delay:0.25,duration:1});
	$( 'html' ).undoClipping();
}

function next( dst )
{
	Effect.Fade('leaveAlert',{delay:0,duration:2});
	Effect.Fade('grayOut',{delay:0.25,duration:1});
	
	$( 'html' ).undoClipping();

	// Track the external URL
	track( dst );
}

function getSize() {
	var	available_width = $( 'bdy' ).getWidth();

	var size = 'S';

	if ( available_width > 1200 )
		size = 'L';
	else if ( available_width > 1002 )
		size = 'M'

	return size;
}

function styleSize() {
	var	available_width = $( 'bdy' ).getWidth();

	$( 'pageSize' ).removeClassName( 'pageSizeLarge' );
	$( 'pageSize' ).removeClassName( 'pageSizeMedium' );
	$( 'pageSize' ).removeClassName( 'pageSizeSmall' );

	if ( available_width > 1200 )
		$( 'pageSize' ).addClassName( 'pageSizeLarge' );
	else if ( available_width > 1002 )
		$( 'pageSize' ).addClassName( 'pageSizeMedium' );
	else
		$( 'pageSize' ).addClassName( 'pageSizeSmall' );
}

function submitDivHide()
{
	$( 'html' ).undoClipping();
	Effect.Fade('submitDiv',{delay:0,duration:0.5});
	Effect.Fade('grayOut',{delay:0.25,duration:1});
}

function clearReferAPerkError( el_field, error_div )
{
	$( el_field ).removeClassName ( 'validationFailedSmall' );
	$( error_div ).innerHTML = "";
}

function initScrollLayer() {
  var wndo = new dw_scrollObj( 'wn', 'lyr1', 'featuresScroll' );

  dw_scrollObj.GeckoTableBugFix( 'wn' );

  wndo.setUpScrollbar( "dragBar", "track", "h", 1, 1 );
}
