/*********************************************************************
// Don't alter anything under this line without checking with allard.
*********************************************************************/

var arrIdLocaties=[
//['url','id/class','naam',tagname,nrOccurance,Insertbefore]
['http://www.telecomvergelijker.nl/cat/117/','class','table','t2',1,false]];

var currentURL=this.location.href.split("?")[0]
//var currentURL=this.location.href //test
var bValidUrl=false
var sUrl =0
var objHook = null
var init_all_Started=false
for (sUrl in arrIdLocaties){
   	if ( currentURL==arrIdLocaties[sUrl][0]){
		 	bValidUrl=true
			break;
		}
}
if (bValidUrl==false){ // url not found 
	 init_AR_load("http://telecomvergelijker.nl/")
	//init_Speedtrap_load()
	// alert('not found\n'+currentURL+'\n'+arrIdLocaties[sUrl][0])
}else{
    getHook()
}

function getHook(){	
	switch (arrIdLocaties[sUrl][1]){
			case 'id':
 						objHook =document.getElementById(arrIdLocaties[sUrl][3])
			case 'class'://find object by classname
					 var arrObjHook = document.getElementsByTagName(arrIdLocaties[sUrl][2])
					 var noObjFound=0;
					 for (i=0;i<arrObjHook.length;i++){				 		 															 				 
					    if (arrObjHook[i].className==arrIdLocaties[sUrl][3]){
								 noObjFound++
					 			 if (noObjFound=arrIdLocaties[sUrl][4]){
								    objHook =arrObjHook[i]
										break;
								 }
							}
					 }
	}
	if (objHook==null ){
			setTimeout( getHook, 100 );
	}else{
	  if ( init_all_Started==false){
	    init_all_Started=true
	    init_insertIdTable();
		}
	}
}


function init_insertIdTable(){
    if (objHook) {
 		 		 var oParent=objHook.parentNode;				 				 
    	   var row=document.createElement("tr")
				 var rowBefore=null
         row.setAttribute("id", "idTestHumphries")
         row.style.width="100%"
				 //go through table to find third TR
				 if (objHook.rows.length >3){
				 		rowBefore= objHook.rows[3]
				 }else{
				    rowBefore=objHook.rows[objHook.rows.length-1]
				 }    		
         rowBefore.parentNode.insertBefore(row,rowBefore.nextSibling)
				 
         var tbl= document.getElementById("idTestHumphries")
         var cell = document.createElement("td");
				 cell.setAttribute("id", "idPageInsertHumphries")
         cell.setAttribute("colspan", "4") 
				 cell.style.backgroundColor = '#ffffff';
				 cell.style.border = '0px';
         row.appendChild(cell);
  	}		
		init_AR_load("http://telecomvergelijker.nl/")
		init_Speedtrap_load()
}


function init_AR_load(website){
 var oScript = document.createElement("script");
 oScript.setAttribute("type", "text/javascript");
 oScript.src = 'http://www.activereception.com/Chat/Client_page/Active_reception_tracking.php?website='+website
 try{
 document.body.insertBefore(oScript, document.body.lastChild);
 checkARstart()
 }catch (AR_event){
    AR_Error=true
 }
}

function checkARstart(){
	if(typeof activereception_online_id =='string' && typeof activereception_mTimer !='number')  { 
	   activereception_initiatePOP();
		 activereception_startTracking();
	}else{
 		 setTimeout(checkARstart,100)
	}
}

function init_Speedtrap_load(){
 var oScript = document.createElement("script");
 oScript.setAttribute("type", "text/javascript");
 oScript.src = 'http://www.virtual-affairs.com/popin/speedtrapInsert.js'
 document.body.insertBefore(oScript, document.body.lastChild);
}