/* Sogma 23/10/06 */ 

function brightcove(URL)
{
	day = new Date();
	id = day.getTime();
	myWindow = window.open(URL, 'brightcove', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=950,height=560');
}

function brightcove_epk(URL)
{
	day = new Date();
	id = day.getTime();
	myWindow = window.open(URL, 'brightcove_epk', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=486,height=412');
}


// This function sets the cursor at a given position in an input field,
// and selects text between selStart and selEnd if they are not equal
function setSelRange(inputEl, selStart, selEnd)
{
	if (inputEl.setSelectionRange) { 
		inputEl.focus(); 
		inputEl.setSelectionRange(selStart, selEnd); 
	} else if (inputEl.createTextRange) { 
		var range = inputEl.createTextRange(); 
		range.collapse(true); 
		range.moveEnd('character', selEnd); 
		range.moveStart('character', selStart); 
		range.select(); 
	} 
}


if (typeof showBlock!=='function')
{
	function showBlock(elementToToggle)
	{
		if (document.getElementById(elementToToggle)) document.getElementById(elementToToggle).style.display='block';
	}
	function hideBlock(elementToToggle)
	{
		if (document.getElementById(elementToToggle)) document.getElementById(elementToToggle).style.display='none';
	}
	function showInline(elementToToggle)
	{
		if (document.getElementById(elementToToggle)) document.getElementById(elementToToggle).style.display='inline';
	}
	function hideInline(elementToToggle)
	{
		if (document.getElementById(elementToToggle)) document.getElementById(elementToToggle).style.display='none';
	}
}

function toggleShowHideBlock(blockId)
{
	if (document.getElementById(blockId)) {
		if (document.getElementById(blockId).style.display == 'none') {
			showBlock(blockId);
		} else {
			hideBlock(blockId);
		}
	}
}


	
/* Autoresize textarea */
function textareaResize(t)
{
	var agt=navigator.userAgent.toLowerCase();
	a=t.value.split('\n');
	b=1;
	for(x=0;x<a.length;x++){
		if(a[x].length>=t.cols){
			b+=Math.floor(a[x].length/t.cols);
		}
	}
	b+= a.length;
	if(agt.indexOf('opera') == -1){
		t.rows = b;
	}
}


/**
 * Functions to show/hide the status indicators
 *
 * Status indicators have class and id attributes.
 *
 * <div class="statusIndicator" id="statusIndicatorResults">...</div>
 */
function showStatusIndicator(statusIndicatorId)
{
	document.getElementById(statusIndicatorId).style.visibility = 'visible';
}

function hideStatusIndicator(statusIndicatorId)
{
	document.getElementById(statusIndicatorId).style.visibility = 'hidden';
}


function runKeywordSuggest(keywordValue, searchContext, textFieldId, suggestBoxId, populateSearchBox, channelCategory, excludeCategory) 
{
	clearTimeout(window.keywordSuggestTimer);
	if (keywordValue.length < 2) {
		document.getElementById(suggestBoxId).innerHTML = '';
		return true;
	}
	window.keywordSuggestTimer = setTimeout("xajax_Search_suggestKeywords('"+keywordValue+"', '"+searchContext+"', '"+textFieldId+"', '"+suggestBoxId+"', "+populateSearchBox+", "+channelCategory+", " + excludeCategory +")", 500);
}

function runGameExists(gameName, textFieldId)
{
	clearTimeout(window.gameExistsTimer);
	if (gameName.length < 2) {
		return true;
	}
	window.gameExistsTimer = setTimeout("xajax_Search_gameGroupExists('"+gameName+"', '"+textFieldId+"')", 500);
}

function runGroupExists(groupName, textFieldId)
{
	clearTimeout(window.groupExistsTimer);
	if (groupName.length < 2) {
		return true;
	}
	window.groupExistsTimer = setTimeout("xajax_Search_groupExists('"+groupName+"', '"+textFieldId+"')", 500);
}

function alertInline(alertMessage, alertType)
{
	alertMessage = alertMessage || '&nbsp;';
	alertType = alertType || 0;
	alertType = (alertType < 0 || alertType > 1) ? 0 : alertType;
	
	alertImages = ['error.png', 'exclamation.png'];
	
	if (document.getElementById('alertInlineImage')) {
		document.getElementById('alertInlineImage').src = '/core/imgs/icons/' + alertImages[alertType];
	}
	
	if (document.getElementById('alertInline') && document.getElementById('alertInlineMessage')) {
		document.getElementById('alertInlineMessage').innerHTML = alertMessage;
		showBlock('alertInline');
	} else {
		alert(alertMessage);
	}
}

// cookie functions to support ui memory
function getCookie(name)
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie(name, value, expires, path, domain, secure)
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function deleteCookie(name, path, domain)
{
	if ( getCookie( name ) )
		document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/**
 * Script.aculo.us blind functions
 */
function blindUp(elementId)
{
	if (document.getElementById(elementId).style.display == 'block' || document.getElementById(elementId).style.display == '') {
		new Effect.BlindUp(elementId, {duration: 0.5});
	}
}

function blindDown(elementId)
{
	if (document.getElementById(elementId).style.display == 'none') {
		new Effect.BlindDown(elementId, {duration: 0.5});
	}
}
