function startTracking( tid ) {
	if( tid == '' ) {
		alert( 'Please fill in a tracking ID' );
	}
	else{
		
		showWaitDialog();
		
		done = false;
		
		var hscroll = (document.all ? document.scrollLeft : window.pageXOffset);
		var vscroll = (document.all ? document.scrollTop : window.pageYOffset);
		if( vscroll > 0 ) {
			for( i = 0; i < (vscroll/3); i++ ) {
				if( i == 0 ) {
					var vscrollnow = vscroll;
				}
				
				scroll( 0, (vscroll-(i*3)));
				
				done = true;
			}
		}
		else{
			done	=	true;
		}
		
		while( true ) {
			
			if( done ) {
				Effect.BlindUp( 'boxrender' );
				
				new Ajax.Request( '/retrieve/track.php?t=' + tid, {
								 method: 'get',
								 onSuccess: function(transport) {
									 var response = transport.responseText;
									 if( response == 'ERROR: 404' ) {
										 alert( 'There is no trackid found' );
									 }
									 else{
										tmp	=	response.split( '::' );
										document.getElementById( 'trackidnr' ).innerHTML = tmp[ 0 ];
										document.getElementById( 'res' ).innerHTML = tmp[ 1 ];
									 }
									 setTimeout( "Effect.BlindDown( 'boxrender' );", 1000 );
									 setTimeout( "ScrollBack("+vscrollnow+",0);", 1700 );
								 },
								 onFailure: function( ) {
									 alert( 'Something went wrong...' );
									 hideWaitDialog();
								 }
				} );
				break;
			}
		}
	}
}

function MarkAsApproved( tid, app ) {
	showWaitDialog();
	new Ajax.Request( '/retrieve/trackapp.php?a=' + app + '&t=' + tid, {
						 method: 'get',
						 onSuccess: function(transport) {
							 var response = transport.responseText;
							 if( response == 200 ) {
								 startTracking( document.getElementById( 'trackid' ).value );
							 }
							 else{
								alert( 'Something went wrong...' ); 
							 }
						 },
						 onFailure: function( ) {
							 alert( 'Something went wrong...' );
						 }
		} );
}

function ScrollBack( first, second ) {
	done = false;
	if( first > 0 ) {
		for( i = 0; i < (first/3); i++ ) {
			scroll( 0,(i*3) );
			done	=	true;
		}
	}
	else{
		done	=	true;
	}
	
	while( true ) {
		if( done ) {
			hideWaitDialog( );
			break;
		}
	}
}

function merCreateGraphic( ) {
	
	showWaitDialog( );
	
	graph0	=	document.getElementById( 'graph0' ).options[document.getElementById( 'graph0' ).selectedIndex].value;
	graph1	=	document.getElementById( 'graph1' ).options[document.getElementById( 'graph1' ).selectedIndex].value;
	graph2	=	document.getElementById( 'graph2' ).options[document.getElementById( 'graph2' ).selectedIndex].value;
	graph3	=	document.getElementById( 'graph3' ).options[document.getElementById( 'graph3' ).selectedIndex].value;
	
	if( graph0 == '' || graph1 == '' || graph2 == '' ) {
		alert( 'You must be chose a chart type and select 2 campaigns.' );
	}
	else if( graph1 == graph2 || graph1 == graph3 || graph2 == graph3 ) {
		alert( 'You need to select different campaigns.' );
	}
	else{
		
		new Ajax.Request( '/retrieve/encode.php?e=' + graph0 + '::' + graph1 + '::' + graph2 + '::' + graph3 + '&a=true', {
						 method: 'get',
						 onSuccess: function(transport) {
							 var response = transport.responseText;
							 tmp	=	response.split( '__AABBCC__' );
							 document.getElementById( '_graph_' ).innerHTML = '<img id="pCimage2" src="images.php?cid=' + tmp[ 0 ] + '" OnMouseMove="getMousePosition(event);" OnMouseOut="nd();" />'; 
							 //document.getElementById( '_graph_' ).innerHTML = tmp[ 1 ];
							 LoadImageMap( "pCimage2", "images.php?cid=" + tmp[ 1 ] );
						 },
						 onFailure: function( ) {
							 alert( 'Something went wrong...' );
						 }
		} );

	}
	
	hideWaitDialog( );
}

function getImageUrl( get1, get2 ) {
	new Ajax.Request( '/retrieve/genurl.php?a=' + get1 + '&b=' + get2, {
						 method: 'get',
						 onSuccess: function(transport) {
							 var response = transport.responseText;
							 tmp	=	response.split( '__AABBCC__' );
							 img.src	=	'images.php?cid=' + tmp[ 0 ];
							 if( get2 != 'no' ) { LoadImageMap( "pCimage1", "images.php?cid=" + tmp[ 1 ] ); } else { img.onload = hideWaitDialog(); }
							 updateLinksTabs( );
						 },
						 onFailure: function( ) {
							 alert( 'Something went wrong...' );
						 }
		} );
}

function getImageUrl2( get1 ) {
	var img	=	document.getElementById( 'pCimage1' );
	id	=	document.getElementById( 'statisticsfrom' );
	
	val	=	id.options[ id.selectedIndex ].value;
	
	new Ajax.Request( '/retrieve/genurl.php?z=' + get1 + '&f=' + val + '&date1=' + document.getElementById( 'statisticsfrom1' ).value + '&date2=' + document.getElementById( 'statisticsfrom2' ).value, {
						 method: 'get',
						 onSuccess: function(transport) {
							 var response = transport.responseText;
							 tmp	=	response.split( '__AABBCC__' );
							 img.src	=	'images.php?cid=' + tmp[ 0 ];
							 //alert( tmp[ 0 ] );
							 //hideWaitDialog();
							 if( tmp[ 1 ] != '' ) { LoadImageMap( "pCimage1", "images.php?cid=" + tmp[ 1 ] ); } else { img.onload = hideWaitDialog(); }
						 },
						 onFailure: function( ) {
							 alert( 'Something went wrong...' );
						 }
		} );
}

function getImageUrl3( get1 ) {
	var img	=	document.getElementById( 'pCimage1' );
	id4		=	document.getElementById( 'stats1from' );
	val		=	id4.options[ id4.selectedIndex ].value;
	
	id1		=	document.getElementById( 'aff1' );
	val1	=	id1.options[ id1.selectedIndex ].value;
	
	id2		=	document.getElementById( 'aff2' );
	val2	=	id2.options[ id2.selectedIndex ].value;
	
	id3		=	document.getElementById( 'aff3' );
	val3	=	id3.options[ id3.selectedIndex ].value;
	
	if( val1 == '' || val2 == '' ) {
		alert( 'You must choose at least 2 affiliates.' );
		hideWaitDialog();
	}
	else if( val1 == val2 || val1 == val3 || val2 == val3 ) {
		alert( 'You need to select different affiliates.' );
		hideWaitDialog();
	}
	else{
		new Ajax.Request( '/retrieve/genurl.php?z=' + get1 + '&f=' + val + '&c=' + val1 + '::' + val2 + '::' + val3 + '&date1=' + document.getElementById( 'statisticsfrom1' ).value + '&date2=' + document.getElementById( 'statisticsfrom2' ).value, {
							 method: 'get',
							 onSuccess: function(transport) {
								 var response = transport.responseText;
								 tmp	=	response.split( '__AABBCC__' );
								 img.src	=	'images.php?cid=' + tmp[ 0 ];
								 //alert( tmp[ 0 ] );
								 //hideWaitDialog();
								 if( tmp[ 1 ] != '' ) { LoadImageMap( "pCimage1", "images.php?cid=" + tmp[ 1 ] ); } else { img.onload = hideWaitDialog(); }
							 },
							 onFailure: function( ) {
								 alert( 'Something went wrong...' );
							 }
			} );
	}
}


function getImageUrl4( get1 ) {
	var img	=	document.getElementById( 'pCimage1' );
	id4		=	document.getElementById( 'stats2from' );
	val		=	id4.options[ id4.selectedIndex ].value;
	
	id1		=	document.getElementById( 'cam1' );
	val1	=	id1.options[ id1.selectedIndex ].value;
	
	id2		=	document.getElementById( 'cam2' );
	val2	=	id2.options[ id2.selectedIndex ].value;
	
	id3		=	document.getElementById( 'cam3' );
	val3	=	id3.options[ id3.selectedIndex ].value;
	
	if( val1 == '' || val2 == '' ) {
		alert( 'You must choose at least 2 campaigns.' );
		hideWaitDialog();
	}
	else if( val1 == val2 || val1 == val3 || val2 == val3 ) {
		alert( 'You need to select different campaigns.' );
		hideWaitDialog();
	}
	else{
		new Ajax.Request( '/retrieve/genurl.php?z=' + get1 + '&f=' + val + '&c=' + val1 + '::' + val2 + '::' + val3 + '&date1=' + document.getElementById( 'statisticsfrom112' ).value + '&date2=' + document.getElementById( 'statisticsfrom212' ).value, {
							 method: 'get',
							 onSuccess: function(transport) {
								 var response = transport.responseText;
								 tmp	=	response.split( '__AABBCC__' );
								 img.src	=	'images.php?cid=' + tmp[ 0 ];
								 if( tmp[ 1 ] != '' ) { LoadImageMap( "pCimage1", "images.php?cid=" + tmp[ 1 ] ); } else { img.onload = hideWaitDialog(); }
							 },
							 onFailure: function( ) {
								 alert( 'Something went wrong...' );
							 }
			} );
	}
}

function getImageUrl5( get1 ) {
	var img	=	document.getElementById( 'pCimage1' );
	id4		=	document.getElementById( 'stats3from' );
	val		=	id4.options[ id4.selectedIndex ].value;
	
	id1		=	document.getElementById( 'scam1' );
	val1	=	id1.options[ id1.selectedIndex ].value;
	
	id2		=	document.getElementById( 'scam2' );
	val2	=	id2.options[ id2.selectedIndex ].value;
	
	id3		=	document.getElementById( 'scam3' );
	val3	=	id3.options[ id3.selectedIndex ].value;
	
	if( val1 == '' || val2 == '' ) {
		alert( 'You must choose at least 2 sub-campaigns.' );
		hideWaitDialog();
	}
	else if( val1 == val2 || val1 == val3 || val2 == val3 ) {
		alert( 'You need to select different sub-campaigns.' );
		hideWaitDialog();
	}
	else{
		new Ajax.Request( '/retrieve/genurl.php?z=' + get1 + '&f=' + val + '&c=' + val1 + '::' + val2 + '::' + val3 + '&date1=' + document.getElementById( 'statisticsfrom113' ).value + '&date2=' + document.getElementById( 'statisticsfrom213' ).value, {
							 method: 'get',
							 onSuccess: function(transport) {
								 var response = transport.responseText;
								 tmp	=	response.split( '__AABBCC__' );
								 img.src	=	'images.php?cid=' + tmp[ 0 ];
								 if( tmp[ 1 ] != '' ) { LoadImageMap( "pCimage1", "images.php?cid=" + tmp[ 1 ] ); } else { img.onload = hideWaitDialog(); }
							 },
							 onFailure: function( ) {
								 alert( 'Something went wrong...' );
							 }
			} );
	}
}