/************************************************************************************************************
Ajax dynamic content
Copyright (C) 2006  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com


************************************************************************************************************/	

var enableCache = true;
var jsCache = new Array();

var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId,ajaxIndex,url,callbackOnComplete)
{
	var targetObj = document.getElementById(divId);
	targetObj.innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}
	dynamicContent_ajaxObjects[ajaxIndex] = false;
	
	ajax_parseJs(targetObj);
	
	if(callbackOnComplete) {
		executeCallback(callbackOnComplete);
	}
}

function executeCallback(callbackString) {
	if(callbackString.indexOf('(')==-1) {
		callbackString = callbackString + '()';
	}
	try{
		eval(callbackString);
	}catch(e){

	}
}

// ------------------------------------------------------------------------------------------------
// function ajax_loadContent:
// Purpose      :
// Parameters   :       divId   -> DIV to be filled with content 
//                      url     -> url of processing aspx page (possibly also contains querystring)
function ajax_loadContent(linkId)
{
    $.ajax({
        type: "POST",
        url: "/WebS/TooltipRelated.asmx/getTooltipContent_Link",
        contentType: "application/json; charset=utf-8",
        data: "{\"linkId\":\"" + linkId + "\"}",
        dataType: "json",
        success: ajax_loadContent_success,
        error: ajax_loadContent_error
    });
    $('#ajax_tooltip_content').html("<center><img src=\"/Img/Tooltip/AjaxLoad.gif\" alt=\"Even geduld alstublieft..\"></center>");
}

function ajax_loadContent_success(result) {
    var tooltipObj = $('#ajax_tooltip_content')
    if (result && result.d != "") { tooltipObj.html(result.d); }
    //    // 1. getting the valid ID
    //    var validID;
    //    validID = getValidHTMLID(strObjectToRetreiveHTMLFor);
    //    // 2. bounding the HTML object to a AJAX transaction --> calling constructor ajaxObject()
    //    var objBoundItem = new ajaxObject(validID, relativePathFromRoot(providerPage));
    //    // 3. updating the HTML object 's InnerHTML field and thus updating the HTML object.
    //    if (queryKey != null) {
    //        objBoundItem.update(queryKey + '=' + queryValue + '');
    //    }
    //    else {
    //        objBoundItem.update();
    //    }
}

function ajax_loadContent_error(result) {
    var test = '123';
}

function ajax_parseJs(obj)
{
	var scriptTags = obj.getElementsByTagName('SCRIPT');
	var string = '';
	var jsCode = '';
	for(var no=0;no<scriptTags.length;no++){	
		if(scriptTags[no].src){
	        var head = document.getElementsByTagName("head")[0];
	        var scriptObj = document.createElement("script");
	
	        scriptObj.setAttribute("type", "text/javascript");
	        scriptObj.setAttribute("src", scriptTags[no].src);  	
		}else{
			if(navigator.userAgent.toLowerCase().indexOf('opera')>=0){
				jsCode = jsCode + scriptTags[no].text + '\n';
			}
			else
				jsCode = jsCode + scriptTags[no].innerHTML;	
		}
		
	}

	if(jsCode)ajax_installScript(jsCode);
}


function ajax_installScript(script)
{		
    if (!script)
        return;		
    if (window.execScript){        	
    	window.execScript(script)
    }else if(window.jQuery && jQuery.browser.safari){ // safari detection in jQuery
        window.setTimeout(script,0);
    }else{        	
        window.setTimeout( script, 0 );
    } 
}	
	
	
function evaluateCss(obj)
{
	var cssTags = obj.getElementsByTagName('STYLE');
	var head = document.getElementsByTagName('HEAD')[0];
	for(var no=0;no<cssTags.length;no++){
		head.appendChild(cssTags[no]);
	}
}










