function showAnswer(id){
	a = document.getElementById(id);
	if (a.style.display == "none")
		{a.style.display = "block";}
	else
		{a.style.display = "none";}
	}
if (document.images) {
	var iExpando = new Image();
	iExpando.src = sApplicationPath+"/Engine/Assets/images/expand.o.gif"; 
	var iExpandd = new Image();
	iExpandd.src = sApplicationPath+"/Engine/Assets/images/expand.gif";
}
function ServiceOver(title,image) {
	if (document.all) {
		t = document.getElementById(title);
		i = document.getElementById(image);
		t.style.color = "#ebebeb";
		i.src = iExpando.src
		}
	}
function ServiceOut(title,image) {
	if (document.all) {
		t = document.getElementById(title);
		i = document.getElementById(image);
		t.style.color = "#21409a";
		i.src = iExpandd.src
		}
	}
var oPopup = window.createPopup();
function showChannel(itemID) {
	if (document.all) {
		divChannel = document.getElementById(itemID);    
		var PopBody = oPopup.document.body;
		PopBody.style.backgroundColor = '#ebebeb';
		PopBody.style.border = 'solid black 1px';
		PopBody.style.padding = '2px';
		PopBody.style.fontFamily = '"Trebuchet MS"';
		PopBody.style.fontSize = '11px';
		PopBody.innerHTML = divChannel.innerHTML;
		PopBody.innerHTML = PopBody.innerHTML + '<div align="right"><a href="Javascript:void(0);" onclick="parent.oPopup.hide();">Close</a> &nbsp;</div>'
		oPopup.show(0, 0, 300, 0);    
		var realHeight = PopBody.scrollHeight;
		oPopup.hide();
		oPopup.show(50, -25, 300, realHeight, event.srcElement);
		}
	}
function launchService(id,region) {
	locvar='services.aspx?i=' + id + '&r=' + region;
	stats='toolbar=no,location=no,directories=no,status=no,menubar=no,'
	stats += 'scrollbars=yes,resizable=yes,width=400,height=600'
	ServiceWin = window.open (locvar,"ServiceWin",stats)
	}
function launchDataForm(id) {
	locvar='contest.aspx?i=' + id;
	stats='toolbar=no,location=no,directories=no,status=no,menubar=no,'
	stats += 'scrollbars=no,resizable=yes,width=400,height=400'
	ContestWin = window.open (locvar,"ContestWin",stats)
	}
function showControlWin(id,pageid) {		
	locvar=sApplicationPath+'/Engine/Framework/Admin/Controls/popUp.htm?i=' + id + '&p=' + pageid;
	window.status = 'Control Window Loading...';
	stats='dialogHeight:555px;dialogWidth:615px;dialogTop: px;dialogLeft: px;';
	stats += 'edge:Raised;center:Yes;help:No;resizable:Yes;status:No;scroll:No;';
	//CtrlWin = window.open (locvar,"ControlWindow",stats);
	var Post = 0;
	Post = window.showModalDialog(locvar,self,stats);
	window.status = '';	
	if (isThere(Post) && isGuid(Post) && !isNullGuid(Post)) {
		window.location.reload();
		}
	}
function changeClass(obj,css) {
	if (obj.className == css) {
		obj.className = '';
		} else {
		obj.className = css; }
	}
function changeStatus(s) {
	status = '';
	}
// Admin Functions
function closeControlWin(id) {
	parent.returnValue = id;
	parent.close();
	}
function setItemID(id) {
	parent.returnValue = id;
	}
function InsertImageCustom(editor) {
	editor.focus();
	obj = GetRangeReference(editor);
	if (obj.tagName == 'IMG') {
		editor.document.execCommand('insertimage',1,'');
		return;	}
	var folder = 'assets/media/uploads';
	var galleryscript = sApplicationPath + 'Admin/imagegallery.aspx?rif='+folder+'&cif='+folder;
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:560px; dialogHeight:500px;help:0;status:0;resizeable:1;');
	if (imgArr != null) {
		imagestring = '<img src="' + imgArr['filepath'] + '" height=' + imgArr['height'] + ' width=' + imgArr['width'] + ' border=0 />';
		obj = editor.document.selection.createRange();
		obj.pasteHTML(imagestring);
	} else {
		//alert("You did not select an image");
	}}
function InsertChannelImage(img) {
	var folder = 'assets/media/uploads/logos';
	var galleryscript = sApplicationPath + 'Admin/imagegallery.aspx?rif='+folder+'&cif='+folder;
	imgArr = showModalDialog(galleryscript,window,'dialogWidth:560px; dialogHeight:500px;help:0;status:0;resizeable:1;');
	if (imgArr != null) {
		img = document.getElementById(img);
		img.innerHTML = '<img src="' + imgArr['filepath'] + '" height=' + imgArr['height'] + ' width=' + imgArr['width'] + ' border=0 />';
		var ctrl = "hdnChLogo";
		var wform = window.document.forms[0]	
		var txtField = eval('wform.' + ctrl);
		txtField.value = imgArr['filename'];
	} else {
		alert("You did not select an image");
	}}
function InsertHTML(editor,htmlmode,text,value) {
    if (htmlmode) return;
	editor.focus();
	sel = editor.document.selection.createRange();
	sel.pasteHTML(value);
	}
function InsertLink(editor,htmlmode,name,value) {
	if (htmlmode) return;
	editor.focus();
	sel = editor.document.selection.createRange();
	var sName = window.prompt("Set a Link Label", name);
	sel.pasteHTML('<a href=' + value + '>' + sName + '</a>');
	}
function InsertFile(editor,htmlmode,name,value) {
	if (htmlmode) return;
	editor.focus();
	sel = editor.document.selection.createRange();
	var sName = window.prompt("Set a Link Label", name);
	sel.pasteHTML('<a href=' + value + '>' + sName + '</a>');
}
function GetRangeReference(editor) {
	editor.focus();
	var objReference = null;
	var RangeType = editor.document.selection.type;
	var selectedRange = editor.document.selection.createRange();
	switch(RangeType) {
		case 'Control' :
			if (selectedRange.length > 0 )  {
				objReference = selectedRange.item(0);
			} break;
		case 'None' :
			objReference = selectedRange.parentElement();
			break;
		case 'Text' :
			objReference = selectedRange.parentElement();
			break;	}
	return objReference
}
// regex tests //
var reWhitespace = /^\s+$/;
var reNumber = /^\d+$/;
var reGuid = /^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/;
var reNullGuid = /^[0]{8}-[0]{4}-[0]{4}-[0]{4}-[0]{12}$/;
function isEmpty(s) { return ((s == null) || (s.length == 0)) }
function isNumber(s) { return ((s == null) || reNumber.test(s)); }
function isWhitespace (s) { return (isEmpty(s) || reWhitespace.test(s)); }
function isGuid(s) { return ((s == null) || reGuid.test(s)); }
function isNullGuid(s) { return ((s == null) || reNullGuid.test(s)); }
function isThere(s) { 
	if (isEmpty(s)) return false;
   	else {
	if (isWhitespace(s))
      	return false; } 
	return true; }