

/**
 * EAX-Handler for PHC-Content-Refresh
 *
 * @author		JA
 * @since		15.03.2010
 *
 * @param		phc_label String, must.  PHC-Label
 */

function eax_phc_refresh (phc_label)
{
	// checkt ob target div in document
	phcdiv=document.getElementById("ecms_ajax_ac_" + phc_label);

	if (phcdiv != null){
		// target div found, send request to server
		eax_ajax_read(EAX_BASIC_URL+"ecms.php?page=ecms_ajax&cmd[0][action]=phc_render&cmd[0][phc_label]=" + phc_label);

	} else {
		// target div not found
	}
}


/**
 * EAX-Handler for PHC-Content-Refresh
 *
 * Author	JA
 * Since	5.10.2011
 *
 * Param	params Object, must.
 * 			- phc_label String, must.  PHC-Label
 * 			- target_id String, optional.  Element-ID des Targets 
 * 			- get_vars String, optional.  GET Zusatzvariablen 
 */

function eax_phc_render (params)
{
	var divchk=false, eax_url='';	
	
	if (params.hasOwnProperty("target_id") && $("#"+params.target_id).length > 0){
		// Target-Element vorhanden 
		divchk=true;
	} else if ($("#ecms_ajax_ac_"+params.phc_label).length > 0){
		// PHC Refresh Target vorhanden
		divchk=true;
		params.target_id="";
	} else {
		// kein Target vorhanden 
	}
	
	if (divchk==true){
		// Target vorhanden, sendet Render-Request an Server 
		eax_url=EAX_BASIC_URL+"ecms.php?page=ecms_ajax&cmd[0][action]=phc_render&cmd[0][phc_label]=" + params.phc_label+"&cmd[0][trg_id]=" + params.target_id;
		
		if (params.hasOwnProperty("get_vars") && params.get_vars.length > 0){
			eax_url=eax_url+"&"+params.get_vars;
		}
			
		eax_ajax_read(eax_url);
		
	} else {
		// target div not found
	}
}



/**
 * Setzt Variable in Session.
 *
 * @author		JA
 * @since		7.7.2010
 *
 * @param		variable String, must.  Variablename
 * @param		value Mixed, must.  Variablewert
 */

function eax_session_set (variable, value)
{
	// sendet Speicher-Kommando an Server
	eax_ajax_read(EAX_BASIC_URL+"ecms.php?page=ecms_ajax&cmd[0][action]=session_set&cmd[0][var]="+variable+"&cmd[0][val]="+value);
}




/**
 * Setzt ein Element (z.B. DIV) als sichtbar und speicherten den Display-Zustand in der Session.
 *
 * @author		JA
 * @since		7.7.2010
 *
 * @param		div_id String, must.  Element-ID
 */

function eax_display_toggle_show (div_id)
{
	// prueft ob DIV in HTML vorhanden
	var div=document.getElementById(div_id);

	if (div!=undefined){
		// show Content-DIV
		div.style.display="block";
		div.style.visibility="visible";


		// switch Toggle-Links
		document.getElementById(div_id+"__tggl_show").style.display="none";
		document.getElementById(div_id+"__tggl_hide").style.display="inline";


		// speichert Zustand in Session
		eax_session_set("display_toggle|"+div_id.toLowerCase(), 1);

	} else {
		// DIV nicht gefunden
	}
}



/**
 * Setzt ein Element (z.B. DIV) als nicht sichbar und speicherten den Display-Zustand in der Session.
 *
 * @author		JA
 * @since		7.7.2010
 *
 * @param		div_id String, must.  Element-ID
 */

function eax_display_toggle_hide (div_id)
{
	// prueft ob DIV in HTML vorhanden
	var div=document.getElementById(div_id);

	if (div!=undefined){
		// hide Content-DIV
		div.style.display="none";
		div.style.visibility="hidden";


		// switch Toggle-Links
		document.getElementById(div_id+"__tggl_show").style.display="inline";
		document.getElementById(div_id+"__tggl_hide").style.display="none";


		// speichert Zustand in Session
		eax_session_set("display_toggle|"+div_id.toLowerCase(), 0);


	} else {
		// DIV nicht gefunden
	}
}

function eax_jqlayout_settings (key,pane,paneState,plabel)
{
	var size = paneState.size;
	var isClosed = paneState.isClosed;

	if (plabel != undefined){
		// speichert Zustand in Session
		eax_session_set("JQLAYOUT|"+key+"|"+plabel+"|"+pane+"|size", size);
		eax_session_set("JQLAYOUT|"+key+"|"+plabel+"|"+pane+"|isClosed", isClosed);
	}
	else {
		// speichert Zustand in Session
		eax_session_set("JQLAYOUT|"+key+"|"+pane+"|size", size);
		eax_session_set("JQLAYOUT|"+key+"|"+pane+"|isClosed", isClosed);
	}
}
/*
 * Get a dialog box inputs values, create new hidden inputs with this values in the form we want to submit, submit this form
 *
 * @author 	Cristian Codreanu <c.codreanu@e-matters.de>
 * @since	10.12.2010
 *
 * btnObj	- Object, the object that triggered the event action
 * json_str - Json String
 * 		formName - String, the form that needs to be submitted with the new hidden inputs created
 * 		fpf		- String, the input prefix names needed to match inputs that will be created as hidden inputs
 * 		phcid	- String, place holder config id, or any other id to match unique targets sources(used to match the dialog box and the div where we have to insert the new inputs created)
 *
 * @todo check in the jQuery documentation for an form read implementation
 */
function eax_form_transfer(btnObj,jsonstr){
	var myData = JSON.parse(jsonstr);
	
	if (typeof(myData.dialogDivPrefix) === 'undefined' && myData.dialogDivPrefix == null){
		var dialogDiv = 'action_content_'+myData.phcid;
	}
	else{
		var dialogDiv = myData.dialogDivPrefix+myData.phcid;	
	}

	var formPHDiv = 'action_placeholder_'+myData.phcid;
	var contentStr = '';
	bol = false;	
		
	$("#"+dialogDiv+" :input").each(function(index) {
		if (this.type == "checkbox" || this.type == "radio"){
			if (this.checked == true){
				contentStr = contentStr + '<input type="hidden" name="'+this.name+'" value="'+this.value+'">';
			}
			/*else{
				contentStr = contentStr + '<input type="hidden" name="'+this.name+'">';
			}*/
		}
		else{
			if (this.name == btnObj.name){
				contentStr = contentStr + '<input type="hidden" name="'+this.name+'" value="1">';
				bol = true;
			}
			else{
				contentStr = contentStr + '<input type="hidden" name="'+this.name+'" value="'+this.value+'">';
			}
		}
	  });
	  
	if (bol !== true){
		contentStr = contentStr + '<input type="hidden" name="'+btnObj.name+'" value="1">';
	}  

	$("#"+dialogDiv).dialog("destroy");
	$("#"+formPHDiv).html(contentStr);
	$("form[name='"+myData.formname+"']").submit();
}
