// JavaScript Document


//Set the tmpLk variable with the link to the TC application ; add at the end of the link the '&' character 
//for example:      var tmpLk = "http://q1000.ro/teststartenwg/default.app?ppCode=10&bscCode=1&wdg=wdg&";  

var tmpLk = "http://asd01.q1000tc.nl/teststartenwg/default.app?ppCode=10&bscCode=1&wdg=wdg&";
//var tmpLk = "http://cristip:7001/teststartenwgx/default.app?ppCode=10&bscCode=1&wdg=wdg&";
//var tmpLk = "http://mihai:7001/teststartenwgx/default.app?ppCode=10&bscCode=1&wdg=wdg&";



//Set the BASE_URL variable with the link to the folder where tc_widget_1.js is
//for example:      var tmpLk = "http://q1000.ro/teststartenwg/widget/";  

var BASE_URL = 'http://asd01.q1000tc.nl/widget/';



//////////////////////////////////////////////////////////////////////////////////////

var tempParam = '?tempParam='+(Math.random()*1000).toString();




//function setIframe(){};


function setIframe(lk){		
	if(typeof(tcwboxLoaded)!='undefined' && tcwboxLoaded && typeof(jqueryLoaded)!='undefined' && jqueryLoaded)
	{ 	
		if(typeof(window.intAutoOpenId)!='undefined') {clearInterval(window.intAutoOpenId);}
		//call function from thickbox that makes the iframe visible and loads the url in it	
		tmpLk += 'refurl='+window.location.hostname+'&';		
		if(document.getElementById('dbgDiv'))document.getElementById('dbgDiv').innerText += '\n'+tmpLk;
		tcw_show('ikki drijfverentest' ,tmpLk+'KeepThis=true&modal=true&TCW_iframe=true&height=320&width=600' , null);
	}
}



MyXssMagic = new function() {
  
  var STYLESHEET = BASE_URL + "css/tcwbox.css"+tempParam;  
  var TCWBOXurl = BASE_URL + "javascript/tcwbox.js"+tempParam;
  var JQUERYurl = BASE_URL + "javascript/jquery.js"+tempParam;
 
  //attach CSS function
  function requestStylesheet(stylesheet_url, id) {
    stylesheet = document.createElement("link");
	stylesheet.id = id;
    stylesheet.rel = "stylesheet";
    stylesheet.type = "text/css";
    stylesheet.href = stylesheet_url;
    stylesheet.media = "all";
    document.lastChild.firstChild.appendChild(stylesheet);
  }
  

  //attach JS function
  function requestJSframework(js_url, id) {
    vScript = document.createElement("script");    
	vScript.id = id;
    vScript.type = "text/javascript";
    vScript.src = js_url;    
    document.lastChild.firstChild.appendChild(vScript);
  }
  
  
  
  //function that inserts the flash element 
	function insertFlash(){		
		if(window.has_size===undefined){ 
			window.has_size = 1;
		}
			
		if(window.has_size == 1)
			{
				var vWidth = '300'; var vHeight = '250';
				var flashFileName = 'widget300x250_1.swf';
			}
		if(window.has_size == 2)
			{
				var vWidth = '336'; var vHeight = '280';
				var flashFileName = 'widget336x280_1.swf';
			}
		if(window.has_size == 3)
			{
				var vWidth = '468'; var vHeight = '60';
				var flashFileName = 'widget468x60_1.swf';
			}
		
		 
		if(window.clickTag === undefined) 
		{
			window.clickTag='';			
		}		
		
		var sFlash = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"+
			"codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+vWidth+"' height='"+vHeight+"'>"+
			"<param name='movie' value='"+ BASE_URL +"flash/"+ flashFileName +"?clickTag="+window.clickTag+"' />"+
			"<param name='allownetworking' value='all' />	<param name='allowscriptaccess' value='always' />"+
			"<param name='quality' value='high' />"+
			"<param name='wmode' value='opaque'>"+
			"<embed allownetworking='all' allowscriptaccess='always' src='"+ BASE_URL +"flash/"+ flashFileName +"?clickTag="+window.clickTag+"' quality='high'"+
			"pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+vWidth+"'"+
			"height='"+vHeight+"' wmode='opaque'></embed></object>";
		document.write(sFlash);
	}

  
  
  
  
  



/*ALTER CSS FILE */
  if(!document.getElementById('thickboxCSSid'))
	  requestStylesheet(STYLESHEET,'thickboxCSSid');  
  /**/
  
/*  ALTER JQUERY*/
  var has_jquery_lib = false;
  var scriptA = document.getElementsByTagName('script');
  for(i=0;i<scriptA.length;i++){
	  if (scriptA[i].src.indexOf('jquery') > 0 )	
		has_jquery_lib = true;
		
  };
  
  if(!has_jquery_lib)
  	{
	  	requestJSframework(JQUERYurl,'jqueryJSid');
		window.linkedJQuery = true;
	}
  else
  {
  	window.linkedJQuery = false;
  	jqueryLoaded = true;
  }
/**/
  
/*  ALTER TCWBOX.JS  */
	if(!document.getElementById('tcwboxJSid'))
				requestJSframework(TCWBOXurl,'tcwboxJSid');
				/**/
				
	//insert Flash				
	insertFlash();
	
}

//////////////////////////////////
/*
var debugD = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(debugD);
debugD.innerHTML += '<br> s-a initializat case 1';*/

//returns the requested GET parameter from the URL
function getUrlParam(param) {
    var regex = '[?&]' + param + '=([^&#]*)';
    var results = (new RegExp(regex)).exec(window.location.href);
    if(results) return results[1];
    return '';
}



if(getUrlParam('autotcw')=='true') { 
	if(typeof(window.autoOpenTcwRuning)!='undefined' && window.autoOpenTcwRuning==false)
	{
			window.intAutoOpenId = setInterval('setIframe("tmp")',500);
			window.autoOpenTcwRuning = true;			
	}
	else{
		if(typeof(window.autoOpenTcwRuning)=='undefined'){
				window.intAutoOpenId = setInterval('setIframe("tmp")',500);
				window.autoOpenTcwRuning = true;			
		}
	}
}

// JavaScript Document