/*
 * $ Default javascript file
 *
 * Copyright (c) 2007 That's-id Multimedia
 */


/*------------------------------------------------------------------------------
	onLoad handler
------------------------------------------------------------------------------*/

function onLoad()
{
	if (typeof $.validator == 'object') $('form').validatorEnable();
	if ( typeof( window[ 'js_supersleigh_loaded' ] ) != "undefined" ) {
		supersleight.run();
	}
}

/*------------------------------------------------------------------------------
	AJAX handlers
------------------------------------------------------------------------------*/

function setIndex(pub_Id, page, archive)
{
	container = 'index_content';
	$.get('/dynamics/getindex.php',{ pub_Id: pub_Id, page: page, archive: archive },
		function(msg) {
			document.getElementById('index_container').innerHTML=msg;
		});
}

function showPub(pub_Id, action)
{
	$.overlay.status.overlayPub = pub_Id;
	$.overlay.status.overlayAction = action;

	$.ajax({
		url:	'/dynamics/getoverlay.php',
		data:	{pub_Id: pub_Id, action: action},
		success: function(content)
		{
			$.overlay.showOverlay();
			$('#popup').html(content);
			$.overlay.showPopup($.overlay.popupWidth, $.overlay.popupHeight);
			$('#overlay form').validatorEnable({ajaxHandler: setForm});
		},
		error: ajaxError

	});
}

function setForm(form_Id)
{
	$.ajax({
		type: 'POST',
		url: '/dynamics/getoverlay.php?pub_Id='+overlayPub+'&action='+overlayAction,
		data: $('form#'+form_Id+' :input').serialize(),
		success: function(content){
			$('#popup').html(content);
			$.overlay.showPopup($.overlay.popupWidth, $.overlay.popupHeight);
			$('#overlay form').validatorEnable({ajaxHandler: setForm});
		},
		error: ajaxError
	});
	return false;
}

/*------------------------------------------------------------------------------
	Various
------------------------------------------------------------------------------*/

function checkCookies(redirect)
{
	var cookieName = 'testCookie';
	document.cookie = cookieName + '=cookieValue';
	var cookiesEnabled = document.cookie.indexOf(cookieName) != -1;
	if (!cookiesEnabled)
	{
		location.href=redirect;
	}
}
