var promo_url = 'http://www.onlineslotsfinder.com/promo.php';
var hClick;

function showPromo(dt){
    //alert(dt);
	if(q){
		try
		{
			if(q.readyState == 0 || q.readyState == 4){
				// запрос серверу
				q.open('POST', promo_url, true);
				q.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				q.onreadystatechange = hPromo;
				q.send('dt='+dt);
			}else{
			}
		}
		catch(e)
		{
			displayErr(e.toString());
		}
	}
}
function hPromo(){
 	if(q.readyState == 4){
 		if(q.status == 200){
 			try{
 				respPromo();
			}catch(e){
				displayErr(e.toString());
			}
		}else{
			displayErr(e.statusText);
		}
	}else{ 	}
}
function respPromo(){
	var response = q.responseText;
	if(response==''){	}else{
		try{

			//alert(response);
			//document.getElementById('promotion').style.display = 'block';
			document.getElementById('promotion').style.visibility = 'visible';
			document.getElementById('promotion').innerHTML = response;
			position();
		}catch(e){
			displayErr(e);
		}
	}
}
function closePromo(id){
    //document.getElementById(id).style.display = 'none';
	document.getElementById('promotion').style.visibility = 'hidden';
}
function initPage(){
	if(document.getElementById('calendar'))
    document.getElementById('calendar').onclick = findMouseLocation;
}
function findMouseLocation(evt){
	var evt = evt ? evt : (window.event ? event : null);
    hClick = evt.clientY;
}
function findScrollTop(){
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function findScrollLeft(){
return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function findClientHeight(){
	if(window.innerHeight){
		windowHeight=window.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight){
		windowHeight=document.documentElement.clientHeight;
	} else if(document.body){
		windowHeight=document.body.clientHeight;
	}
    return windowHeight;
}
function findHeightObject(id){
    return document.getElementById(id).offsetHeight;
}
function position(){
	var hDiv = findHeightObject('promotion');
	var hClient = findClientHeight();
	/*
	alert('findScrollTop()='+findScrollTop());
	alert('hClient='+hClient);
	alert('hClick='+hClick);
    */
	if(hClient - hClick < hDiv){
		y = hClient - hDiv + findScrollTop();
	}else{
		y = hClick + findScrollTop();
	}
	//alert('y='+y);
    document.getElementById('promotion').style.top = (y-150)+'px';
    //document.getElementById('promotion').style.left = (evt.clientX+findScrollLeft())+'px';

}

