var GB_ROOT_DIR = "scripts/greybox/ajs/";

function init(){
	document.getElementById("hideLoading").style.display = 'none';
}
function loading() {
	document.getElementById("hideLoading").style.display = '';
}

function openStaticWindow(file) {
  popupWin = window.open('http://'+file,
    'generic_file_window',
    'null,null,null,null,null,null,resizable,dependent,width=650,height=650,left=0,top=0')
}

function poorman_toggle(id) { 
	var tr = document.getElementById(id); 
	if (tr==null) { return; } 
	var bExpand = tr.style.display == ''; 
	tr.style.display = (bExpand ? 'none' : ''); 
} 
function poorman_changeimage(id, close, open) { 
	var img = document.getElementById(id); 
	if (img!=null){ 
		var bExpand = img.src.indexOf(open) >= 0; 
		if (!bExpand) 
			img.src = open; 
		else 
			img.src = close; 
	} 
}   
function openClose(menuId, style) { 
	poorman_changeimage('menu'+menuId, 'images/'+style+'/arrow_closed.png', 'images/'+style+'/arrow_open.png'); 
	poorman_toggle('component'+menuId);
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}
 
function openClose(id) { 
	var element = document.getElementById(id); 
	if (element==null) { return; } 
	if(element.disabled == false){
		element.disabled = true;
		element.value = '';
	}else{
		element.disabled = false;
	}
}
function checkUploadFiles(assetPath, thumbnailPath) {
	assetFile = document.getElementById(assetPath);
	var assetPathLength = assetFile.value.length;
	
	/*
	if(assetPathLength == 0){
		alert("Asset Needed!");
		return false;
	}
	*/
	
	thumbnailFile = document.getElementById(thumbnailPath);
	var thumbnailPathLength = thumbnailFile.value.length;
	
	if(thumbnailPathLength > 0){
		var lastDot = thumbnailFile.value.lastIndexOf(".");
		var fileType = thumbnailFile.value.substring(lastDot,thumbnailPathLength);
		
		if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG")) {
			return true;
		} else {
			alert("Thumbnail Upload supports .JPG, .PNG, and .GIF image formats. Your file-type is *" + fileType + ".");
			return false;
		}
	}else{
		return true;
	}
}

function showDescription(idValue){
	var div = document.getElementById('description_'+idValue); 
	div.style.display = '';
	var span = document.getElementById('title_'+idValue);
	span.style.color = 'black';
}
function hideDescription(idValue){
	var div = document.getElementById('description_'+idValue); 
	var span = document.getElementById('title_'+idValue);
	div.style.display = 'none';
	span.style.color = '';
}

function validateAssetDelete(title){
	var answer = confirm("Deleting '"+title+"' will delete the 'link' between all users and this asset. Do you still want to delete this asset?")
	if (answer){
		return true;
	}
	else{
		return false;
	}
}

function validateLessonDelete(title){
	var answer = confirm("Deleting '"+title+"' will delete the 'link' between all users and this lesson and its assets. Do you still want to delete this lesson?")
	if (answer){
		return true;
	}
	else{
		return false;
	}
}

function validateLevelDelete(title){
	var answer = confirm("Deleting '"+title+"' will delete the 'link' between all users and this level, its lessons, and its assets. Do you still want to delete this level?")
	if (answer){
		return true;
	}
	else{
		return false;
	}
}

function validateAwardDelete(title){
	var answer = confirm("You are deleting '"+title+"'. Do you still want to delete this award?")
	if (answer){
		return true;
	}
	else{
		return false;
	}
}

function validateVideoDelete(title){
	var answer = confirm("You are deleting '"+title+"'. Do you still want to delete this video?")
	if (answer){
		return true;
	}
	else{
		return false;
	}
}

function validateUserDelete(title){
	var answer = confirm("You are deleting '"+title+"'. Do you still want to delete this user?")
	if (answer){
		return true;
	}
	else{
		return false;
	}
}