//globel Vars
var layerDivId 		= "questionReportDetailLayer";

var question_type	= null;
var sid				= null;
var inputnames		= null;
var dbprefix		= null;
var question_name	= null;
var site			= 1;
var qlabels 		= null;
var alabels 		= null;

function ajaxQuestionReportDetailLayerCallPhpFunc(dateiName, phpFunction, stringParameters){
	       
    var daten = '';
    var url = '/includes/php/ajax/';
    
    try {
        var myAjax = new Ajax.Request(url + dateiName + '.php?phpFunction=' + phpFunction, {
            method: 'post',
            asynchronous: false,
            parameters: stringParameters,
            onComplete: function(transport){
                daten = transport.responseText;
            }
        });
    }catch(err){
	   var myAjax = new Request(
	                                    {
	                                       url: url +dateiName+'.php?phpFunction=' + phpFunction,
	                                       method: 'post',
	                                       encoding: 'utf-8',
	                                       async: false,
	                                       data: stringParameters,
	                                       onComplete : function(responseText)
	                                       {
	                                          daten = responseText;
	                                       }
	                                    }
	                             ).send(); 
    }
    return daten;
    
}

function getQRDContent(){
	if( question_type != null && sid != null && inputnames != null && dbprefix != null && question_name != null ){		
		var getString  = "";
			getString += "generateQuestionReport_" + question_type;
			getString += "&paging_qrd=" + site;
	
		var postString  = "";
			postString += "sid=" + sid;
			postString += "&inames=" + inputnames.replace(/ /g, "+").replace(/#/g, "_");
			postString += "&xiferp=" + dbprefix;
			postString += "&qname=" + question_name;
			
		if( qlabels != null ){
			postString += "&qlabels=" + qlabels;
		}
		
		if( alabels != null ){
			postString += "&alabels=" + alabels;
		}
			
		var result 		= ajaxQuestionReportDetailLayerCallPhpFunc( "ajax_question_report_detail_layer", getString, postString );
		var resultOBJ 	= decodeJSONString(result);
	
		return resultOBJ.data;
	}
}

function showQuestionReportDetailLayer( qtype, id, inames, xiferp, qname ){				
	if( qtype && id && inames && xiferp && qname ){
		question_type 	= qtype;
		sid 			= id;
		inputnames 		= inames;
		dbprefix 		= xiferp;
		question_name	= qname;
		site = 1;
		
		if( typeof(showQuestionReportDetailLayer.arguments[5]) != 'undefined' ){
			qlabels = showQuestionReportDetailLayer.arguments[5];
		}
		
		if( typeof(showQuestionReportDetailLayer.arguments[6]) != 'undefined' ){
			alabels = showQuestionReportDetailLayer.arguments[6];
		}
		
		setBrowserLayer(layerDivId, 640, 520, 0,false,'');	
		updateQuestionReportDetailLayerContent();
	}
}

function qrdPagingShowPage( s ){
	if( s ){
		site = s;
		updateQuestionReportDetailLayerContent();
	}
}

function updateQuestionReportDetailLayerContent(){
    var OBJ = $(layerDivId + "_content");
    var ausgabe = false;
    
    if (OBJ) {
    	OBJ.innerHTML = getQRDContent();
        ausgabe = true;
    }
    return ausgabe;
}