/**
* Function to submit a HTML form into a Highslide iframe popup.
*/
function submitToHighslide(form) {

    // identify the submit button to start the animation from
    var anchor;
    for (var i = 0; i < form.elements.length; i++) {
    	if (form.elements[i].type == 'submit') {
			anchor = form.elements[i];
			break;
		}
	}

	// open an expander and submit our form when the iframe is ready
	hs.overrides.push('onAfterExpand');
	
	// browser switch
	hs.htmlExpand(anchor, {
		objectType: 'iframe',
		src: 'about:blank',
		width: 640,
		height: 480,
		wrapperClassName: 'borderless',
		dimmingOpacity: 0.75,
		align: 'center',
		objectHeight: 565,
		onAfterExpand: function(expander) {
			form.target = expander.iframe.name;
			form.submit();
		}
	});

	// return false to delay the sumbit until the iframe is ready
	return false;
}


function selectCharity(obj, chId)
{
	var old_charity	= $('#selected_charity').val();
	if (old_charity != '')
	{
		$('div').removeClass('selected_charity');
		$('div').addClass('charity_item');
	}
	$('#selected_charity').val(chId);
	obj.removeAttribute("class", "charity_item");
	obj.setAttribute("class", "selected_charity");
}

function redirectToRegister(charityShortUrl, siteUrl)
{
	if ((charityShortUrl == null) || (charityShortUrl == ''))
	{
		parent.window.location.href = '' + siteUrl + 'index.php?q=register';
	}
	else
	{
		parent.window.location.href = '' + siteUrl + 'index.php?q=register&c=' + charityShortUrl + '';
	}
	/*setTimeout(parent.window.hs.close(), 100); */
	
}

function redirectFromHs(charityShortUrl, targetUrl)
{
	// close opened highslide window
	parent.window.hs.close();
	
	// redirect to target url (optionally keep selected charity in mind)
	if ((charityShortUrl == null) || (charityShortUrl == ''))
	{
		parent.window.location.href = '/' + targetUrl;
	}
	else
	{
		parent.window.location.href = '/' + charityShortUrl + '/' + targetUrl;
	}
}
