/**
 * 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
 */

	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
	}

	
	function createDestaque(edition, lang, title, subtitle, image, texto, url, type)
	{
		//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:
		fldTitlePT = document.getElementById(title+"_pt");
		fldTitleEN = document.getElementById(title+"_en");
		fldSubtitlePT = document.getElementById(subtitle+"_pt");
		fldSubtitleEN = document.getElementById(subtitle+"_en");

		fldURL = document.getElementById(url);
		
		fldTextoPT = document.getElementById(texto+"_pt");
		fldTextoEN = document.getElementById(texto+"_en");
		var editionYear = edition;
		var titulo_pt = fldTitlePT.value;
		var titulo_en = fldTitleEN.value;
		
		var subtitulo_pt = fldSubtitlePT.value;
		var subtitulo_en = fldSubtitleEN.value;
		
		var img = "";
		
		if (document.getElementById(image)){
			fldImage = document.getElementById(image);
			img = fldImage.value;
		}
		
		var url = fldURL.value;
		
		var texto_pt = fldTextoPT.value;
		var texto_en = fldTextoEN.value;
		
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].setVar('edition', editionYear);
		ajaxObjectArray[ajaxIndex].setVar('imagem', img);
		ajaxObjectArray[ajaxIndex].setVar('linkURL', url);
		ajaxObjectArray[ajaxIndex].setVar('destaqueType', type);
		ajaxObjectArray[ajaxIndex].setVar('title_pt', titulo_pt);
		ajaxObjectArray[ajaxIndex].setVar('title_en', titulo_en);
		ajaxObjectArray[ajaxIndex].setVar('subtitle_pt', subtitulo_pt);
		ajaxObjectArray[ajaxIndex].setVar('subtitle_en', subtitulo_en);
		ajaxObjectArray[ajaxIndex].setVar('texto_pt', texto_pt);
		ajaxObjectArray[ajaxIndex].setVar('texto_en', texto_en);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/destaques/createDestaque.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			//switchDIV('frmNews')
			switchDIVV('frmDestaques_'+type);
			getDestaques('destaques_module_'+type, '', lang, ajaxObjectArray[ajaxIndex].response.trim(), type);
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				
	}
	
	function removeDestaque(id, edition, lang, type)
	{
		//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('destaqueID', id);
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/destaques/removeDestaque.cfm';
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			callbackRemove = function() {
				getDestaques('destaques_module_'+type, edition, lang, -1, type);
			}
			$( "#destaques_"+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 getDestaques(div, cEdition, lang, animateID, type)
	{
		//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 el = document.getElementById(div);
		//alert(animateID);
		ajaxObjectArray[ajaxObjectArray.length] = new sack();
		var ajaxIndex = ajaxObjectArray.length-1;
		ajaxObjectArray[ajaxIndex].requestFile = siteURL+'backend/admin/destaques/getDestaques.cfm?edition='+cEdition+'&lang='+lang+'&destaqueType='+type;
		ajaxObjectArray[ajaxIndex].onCompletion = function() { 
			//self.status = 'New node has been saved';
			//alert(ajaxObjectArray[ajaxIndex].response);
			el.innerHTML = ajaxObjectArray[ajaxIndex].response;
			callback = function(){
				//switchDIV('frmNews')
			}
			if (animateID > -1)
				$( "#destaques_"+animateID ).effect( 'highlight', null, 1500, callback );
			
		};	// Specify function that will be executed after file has been found	
		
		ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				
	}
