//Add urls regular expressions and your message(any HTML Code) to the array
var msgs = [
//null url : to show a message for direct traffic (no referer, some one who remember your site url!)
{'url':null,                           'msg':null}
//Other urls
,{'url':/^http:\/\/free-du\.htnet\.hr\/sergiodesign/,      'msg':'Welcome, I am a lier!'}
//generic pattern: to show generic message for referrers that you did not specify one for
//You must keep it at the end of the list as it will match any non empty referrer
,{'url':/^http:\/\//,               'msg':null}
];
function DetectReferrer(){
   var ref = document.referrer.toLowerCase();
   var msg = findMatch(ref);
   // if not null msg found
   if(msg) {
		 setTimeout('delayer()', 100);
   }
}
function findMatch(ref) {
   for(var i=0; i<msgs.length; i++)
      if( ( ref=='' && msgs[i].url==null) || (ref>'' && ref.match(msgs[i].url) ) )
         return msgs[i].msg;
   return null;
}
function delayer(){
    $.ajax({
	   type: "POST",
	   url: "sendmail.php",
	   success: function(msg){
		 alert( "Mail sent: " + msg );
	   }
	 });
	window.location = "http://www.vivado.hr/redirect.html";
}

// Call the Referrer Detector function on document ready
$(DetectReferrer);