	  
  var badges = {
  				1:2,
				2:10,
				3:11,
				4:15,
				5:14,
				6:27,
				7:13,
				8:7,
				9:8,
				10:9,
				11:12,
				12:1,
				13:18,
				14:24,
				15:20,
				16:16,
				17:17,
				18:23,
				19:21,
				20:22,
				21:30,
				22:26,
				23:29,
				24:32
  				};
	
jQuery(function ($){
	var timerAjaxCheck;
	var counterAjaxCheck = 0;
 	ajaxCheckRepeat = function (){
		ajaxCheck();
		timerAjaxCheck = setInterval('ajaxCheck()',5000);
	}
	
	ajaxCheckStop = function (){
		clearInterval(timerAjaxCheck);
		counterAjaxCheck = 0;
	}
	
	
 	ajaxCheck = function (){
		
		counterAjaxCheck ++;
		$('#check_code').html(aCheckerMessages.loading);
		$.getJSON(
					'signup.html',
					{	
						'do':'check_code',
						'ws':websiteId
					},
					function(data){
						if (data.result==1){
							$('#check_code').html(aCheckerMessages.ok);
						}else{
							$('#check_code').html(aCheckerMessages.fail);
						}
					}
			)
		
		if (counterAjaxCheck>=3){
			ajaxCheckStop();
		}
		
	}
	
	$('.mainlink').click(ajaxCheck);
 
 
 	var n
	for(n=1;n<=24;n++)
	{
		document.getElementById('ads'+n).style.zIndex=4;
	}
 	$('.imgbadge').css('z-index',4);
 	$('.imgbadge').mouseover(
					function (){
						var obj = $(this);
						
						ob = this;
						var t=this.offsetTop;  
						var l=this.offsetLeft;  
						var w = this.width;
						var h = this.height;
						
						if(ob=ob.offsetParent)
						{  
							t+=ob.offsetTop ; 
							l+=ob.offsetLeft;  
						}
						
						
						$('#badgeselected').width(w+20);
						$('#test2').height(h+10);
						obj.css('z-index',7);
						
						//$('#badgeselected').css('position','absolute');
						$('#badgeselected').show();
						$('#badgeselected').css('left',(l-10)+'px');
						$('#badgeselected').css('top',(t-10)+'px');
						
					}
				);
 	
	$('.imgbadge').mouseout(function (){
						//$('#badgeselected').hide();
						//$('#bblack').hide();
						$(this).css('z-index',4);
					}
				);
	$('.imgbadge').click(function (){
						var obj = $(this);
						ob = this;
						var t=this.offsetTop;  
						var l=this.offsetLeft;  
						var w = this.width;
						var h = this.height;
						
						if(ob=ob.offsetParent)
						{  
							t+=ob.offsetTop ; 
							l+=ob.offsetLeft;  
						}
						
						//$('#bblack').css('z-index','6');
						obj.css('z-index',6);
						document.getElementById('badgeselected').style.width= w+20+'px';
						document.getElementById('test2').style.height=h+10+'px';
						document.getElementById('badgeselected').style.display='block';
						
						document.getElementById('badgeselected').style.left= (l-10)+'px';
						document.getElementById('badgeselected').style.top= (t-10)+'px';
						
						document.getElementById('bblack').style.display='block';
						document.getElementById('reselect').style.display='block';
						
						var n
						for(n=1;n<=24;n++)	{
						   if(n!=this.alt) {
								document.getElementById('ads'+n).style.zIndex=1;
						   }
						}	
						
						var code = html_entity_decode (tracking_code_template.replace(/--badge--/g,badges[this.alt]))
						$('#textarea_tracking_code').text(code);
					}
				);
	/*var images = $('.imgbadge');
	$('#bblack').mousemove(function(e){
						for (i=0; i<images.length; i++){
							var obj = $(images[i]);
							var offset = obj.offset();
							var w = obj.width();
							var h = obj.height();
							//console.log(offset.top,offset.left);
							if (
								e.pageY >= offset.top && e.pageY <= (offset.top+h) &&
								e.pageX >= offset.left && e.pageX <= (offset.left+w)
								){
								obj.mouseover();
								break;
							}
						}
						//console.log(e.pageX,e.pageY);
					}
				);
		*/
	$('#reselect').click(function(){
		$('#bblack').hide();
		$('#badgeselected').hide();
		$('#reselect').hide();
		
		var n
		for(n=1;n<=24;n++)
		{
			document.getElementById('ads'+n).style.zIndex=4;
		}
		$('.imgbadge').css('z-index',4);
	});
	
	if ($('#message').length==0){
		$('body').append('<div id="message"></div>');
	}
	$('#message').click(function (){$('#message').hide();} );
	$('body').click(function (){$('#message').hide();} );

	
 });
 
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

$.postJSON = function(url, data, callback) {
	$.post(url, data, callback, "json");
};
function submitForm(formid){
	$('#message').hide();
	$('#alert_email, #alert_password').html('');
	$('#fmSignup :submit').attr('disabled',true).val('Please wait ...');
	$.postJSON(
				'/doaction.php',
				$('#'+formid).serializeArray(),
				function(data){
					if (data.ok){
						$('#message').html('<div class="ok"><div class="message">Your account was created, redirecting in 10 seconds or click <a href="'+window.location.href+'">here</a></div></div>');
						setTimeout('window.location.href = window.location.href',10000);
					}else{
						$('#message').html('<div class="ko"><div class="error">'+data.msg+'</div></div>');
						if (data.idents.length>0){
							for (var i=0; i<data.idents.length; i++){
								$('#alert_'+data.idents[i]).html('<img src="'+signup_popup_ico_alert+'" />');
							}
						}
					}
					$('#message').show(100);
					$('#fmSignup :submit').removeAttr("disabled").val('Create Account');
				}
				
		);
	return false;
}
