/**
 * Harmos Festival
 *
 * @version 1
 * @author  Rolling Mill, http://www.rolling-mill.pt
 * @created 2010-09-10
 * @updated 2010-11-30
 * @link    http://www.harmos.com
 */

	//var siteURL = "http://mondego/harmos/";
	//var ajaxObjectArray = new Array();

	function switchDIV(id) {
		el = document.getElementById(id);
		
		el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
		el.style.display = (el.style.display == "inline") ? "none" : "inline";
		
		
	}
	
	function showAdmin(id) {
		el = document.getElementById(id);
		el.className = 'boxFocus';
		
	}
	
	function hideAdmin(id) {
		el = document.getElementById(id);
		el.className = 'boxNoFocus';
	}
	
	function showTextAdmin(id) {
		el = document.getElementById(id);
		el.className = 'textBoxFocus';
		optEl = document.getElementById('options_'+id);
		optEl.style.visibility = "visible";
	}
	
	function hideTextAdmin(id) {
		el = document.getElementById(id);
		el.className = '';
		optEl = document.getElementById('options_'+id);
		optEl.style.visibility = "hidden";
	}
	
	function showAdminField(id) {
		el = document.getElementById(id);
		el.style.backgroundColor = 0xcccccc;
		optEl = document.getElementById('options_'+id);
		optEl.style.visibility = "visible";
	}
	
	function hideAdminField(id) {
		el = document.getElementById(id);
		el.style.backgroundColor = '';
		optEl = document.getElementById('options_'+id);
		optEl.style.visibility = "hidden";
	}
	
	function showTextField(id, tarea) {
		elLabel = document.getElementById(id);
		elLabel.style.display = 'none';
		elEdit = document.getElementById('edit_'+id);
		elEdit.style.display = "inline-block";
		//alert("div height:" + $(elLabel).height());
		//alert(tarea.height())
		//if (tarea){
		//	if ($(elLabel).height() > 20)
		//		$(tarea).height(200);
		//}
		//optEl = document.getElementById('options_edition_'+id);
		//optEl.style.display = "none";
	}
	
	function hideTextField(id, type) {
		elLabel = document.getElementById(id);
		elLabel.style.display = type;
		elEdit = document.getElementById('edit_'+id);
		elEdit.style.display = "none";
		//optEl = document.getElementById('options_edition_'+id);
		//optEl.style.display = "none";
	}
	
	function showComboEdit(id, tarea) {
		elLabel = document.getElementById(id);
		elLabel.style.display = 'none';
		elEdit = document.getElementById('edit_'+id);
		elEdit.style.display = "inline";
		elEdit.style.visibility = "visible";
	}
	
	function hideComboEdit(id) {
		elLabel = document.getElementById(id);
		elLabel.style.display = 'inline';
		elEdit = document.getElementById('edit_'+id);
		elEdit.style.display = "none";
		elEdit.style.visibility = "hidden";
	}
	
	function confirmDelete(id, edition, lang, area, var1, var2) {
		$( "#dialog-confirm" ).dialog('option', 'buttons',
			{
				"Sim, Apagar": function() {
					if (area == 'news')
						removeNews(id, edition, lang);
					else if (area == 'events')
						removeEvent(id, edition, lang, var1);
					else if (area == 'schools')
						removeSchool(id, edition, lang);
					else if (area == 'musicians')
						removeMusician(id, edition, lang);	
					else if (area == 'destaques')
						removeDestaque(id, edition, lang, var1);
					else if (area == 'sponsors')
						removeSponsor(id, edition, lang);
					else if (area == 'sponsorCategories')
						removeSponsorCategory(id, edition, lang);
					else if (area == 'press')
						removePress(id, edition, lang);
					else if (area == 'projects')
						removeProject(id, edition, lang);
					else if (area == 'links')
						removeLink(id, edition, lang);
					else if (area == 'users')
						removeUser(id, edition, lang);
					else if (area == 'photoGallery')
						removeMedia(id, edition, lang, var1, var2);
					else if (area == 'audioPlaylist')
						removePlaylistMedia(id, edition, lang, var1, var2);	
					else if (area == 'multimedia')
						removeGallery(id, edition, lang, var1, var2);
					else if (area == 'multimediaItem')
						removeGalleryItem(id, edition, lang, var1, var2);
					else if (area == 'comments')
						removeComment(id, edition, lang, var1, var2);
					else if (area == 'cities')
						removeCity(id, edition, lang);
					else if (area == 'countries')
						removeCountry(id, edition, lang);
					else if (area == 'instruments')
						removeInstrument(id, edition, lang);
					else if (area == 'orchestra')
						removeOrchestra(id);
					else if (area == 'venues')
						removeVenue(id, lang, var1);
					else if (area == 'permissions')
						removeUserPermission(id, var1);
					else if (area == 'ads')
						removeAd(id);
					else if (area == 'snlink')
						removeSocialNetwork(id, var1, edition, var2);
					$( this ).dialog( "close" );
				},
				"Cancelar": function() {
					$( this ).dialog( "close" );
				}
			}
		);
		$( "#dialog-confirm" ).dialog('open');
	}
	
	function updateField(table, column, value, isField, key, id, callback, divID, divItemID, displayType, isSelect){
		//self.status = 'Ready to save node ' + nodeText + ' which is a sub item of ' + parentId;
		// Use an ajax method here to save this new node. example below:
		var fldName;
		var valor;
		if (isField == true){
			fldName = value;
			fld = document.getElementById(value);
			valor = fld.value.replace(/\r/g, "<br>"); 
		}
		else {
			valor = value;	
		}
		
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('table', table);
		ajaxObjectArray[ajaxIndex].setVar('column', column);
		ajaxObjectArray[ajaxIndex].setVar('value', valor);
		ajaxObjectArray[ajaxIndex].setVar('key', key);
		ajaxObjectArray[ajaxIndex].setVar('id', id);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/updateText.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() {
			if (callback != null)
				eval(callback)();
				
			if (divID != null){
				var d = divID+"_only_"+divItemID;
				//alert(d);
				if(isSelect == true){
					//alert(valor);
					$( "#"+d ).html($("#"+fldName+" option[value="+valor+"]").text());
					//$("#"+fldName+" :selected").text(); 
				}
				else
					$( "#"+d ).html(valor);
				
				//alert($( "#"+d ));
				hideTextField(divID+'_'+divItemID, displayType);	
			}
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			//switchDIV('frmNews')
			//getNews('news', edition, lang, ajaxObjectArray[ajaxIndex].response.trim());
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
	}
	
	function registerUserCMS(nome,email,pass,country,newsletter,lang,level)
	{
		
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('nome', nome);
		ajaxObjectArray[ajaxIndex].setVar('email', email);
		ajaxObjectArray[ajaxIndex].setVar('pass', pass);
		ajaxObjectArray[ajaxIndex].setVar('country', country);
		ajaxObjectArray[ajaxIndex].setVar('newsletter', newsletter);
		ajaxObjectArray[ajaxIndex].setVar('level', level);
		ajaxObjectArray[ajaxIndex].setVar('lang', lang);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/users/createUser.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			showRegisterResponseCMS(ajaxObjectArray[ajaxIndex].response.trim(), nome, email, level);
		};
		ajaxObjectArray[ajaxIndex].onError = function() { 
			showRegisterResponseCMS('error');
		};
		ajaxObjectArray[ajaxIndex].onFail = function() { 
			showRegisterResponseCMS('error');
		};
		
		ajaxObjectArray[ajaxIndex].runAJAX();
				
	}
	
	function removeUser(id, edition, lang)
	{
		//self.status = 'Ready to save node ' + nodeText + ' which is a sub item of ' + parentId;
		// Use an ajax method here to save this new node. example below:
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('userID', id);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/users/removeUser.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			removeItem(id);
			callbackRemove = function() {
				//getLinks('links', edition, lang);
				
			}
			//$( "#link_"+id).effect( 'highlight', null, 500, callbackRemove );
			//getNews('news', edition, lang);
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				
	}
	
	function createUserPermission(userID,area,itemID)
	{
		
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('userID', userID);
		ajaxObjectArray[ajaxIndex].setVar('area', area);
		ajaxObjectArray[ajaxIndex].setVar('itemID', itemID);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/users/createUserPermission.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			showPermissionResponseCMS(ajaxObjectArray[ajaxIndex].response.trim(), area, itemID, "-");
		};
		ajaxObjectArray[ajaxIndex].onError = function() { 
			showPermissionResponseCMS('error');
		};
		ajaxObjectArray[ajaxIndex].onFail = function() { 
			showPermissionResponseCMS('error');
		};
		
		ajaxObjectArray[ajaxIndex].runAJAX();
				
	}
	
	function removeUserPermission(id, idx)
	{
		//self.status = 'Ready to save node ' + nodeText + ' which is a sub item of ' + parentId;
		// Use an ajax method here to save this new node. example below:
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('itemID', id);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/users/removeUserPermission.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//removeItem(id);
			removePermissionItem(id, idx);
			callbackRemove = function() {
			}
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				
	}
