var isIFRAME = (self !== top);

if(window.location.toString().indexOf('?')==-1){
	var PAGE_THIS = window.location.toString();
	var QUERY_STRING = '';
}else{
	var PAGE_THIS = window.location.toString().substring(0,window.location.toString().indexOf('?'));
	var QUERY_STRING = window.location.search.substring(window.location.search.indexOf('?')+1);
}
	
var HASH = window.location.hash;

var loadingGif = new Image();
loadingGif.src = "../assets/img/waiting.gif";
var LOADING = '<img src="'+loadingGif.src+'" class="loadinggif" align="middle"/>';

function overlay(action, tgt, animate, noescape, locked, backcolor){
	var t = tgt || 'body'; 
	$('#overlaydiv', t).remove();
	var noescape = noescape ? ' noescape' : '';
	var locked = locked ? ' locked' : '';
	var backcolor = backcolor || "#555";
	if(action){
		var p = tgt ? 'absolute' : 'fixed';
		var anim = animate ? 1 : 0;
		
		$(t).not(':positioned').css({position:'relative'}).end()
			.css({overflow:'hiddenX'});
			
		$("<div id='overlaydiv' class='escclose"+noescape+locked+" centered' style='padding-top:20%'>"+(anim ? LOADING : '')+"</div>")
		 .css({
			width:"100%",
			height:"100%",
			position:p, // ze trick 
			background: backcolor,
			opacity:.5,
			top:0,
			left:0,
			zIndex: 9999 // everything you want on top, gets higher z-index
		  })
		 .appendTo(t); 
		
		$('#overlaydiv', t).fadeIn();
		//alert($('#overlaydiv', t).length );
		
	}else{
	}
}



function ActivateExport($t){


	/*
	$.fn.tableExport.ignoreCSS = [".te-ignore", "tr.nodisplay"];
	if($t.is(':has(caption.tableexport-caption)')){
		$t.find('caption.tableexport-caption').remove();
	}
	*/
	
	// $t.tableExport({ 
	// 	filename: ($t.data('te-filename') || 'id')
	// });	

	// $t.data('te-instance', T);
	// TableExport.prototype.typeConfig.date.assert = function(value) { return false; };


}

function loadScripts(scripts) {
	var deferred = jQuery.Deferred();
		// console.log( scripts.length );
	function loadScript(i) {
		if (i < scripts.length) {
			
			// console.log( scripts[i] );

			jQuery.ajax({
				url: scripts[i],
				dataType: "script",
				cache: true,
				success: function() {
					// console.log('success with script: '+i);
				loadScript(i + 1);
				},
				error: function(a, b){
					console.log('ERROR with script: '+i);
				}
				
			});
		} else {
			deferred.resolve();
		}
	}
	loadScript(0);

	return deferred;
}

