var IE=!!(window.attachEvent && !window.opera);
var NC = (document.layers); // Netscape
var Opera=  !!window.opera;
var WebKit= navigator.userAgent.indexOf('AppleWebKit/') > -1;
var Gecko=  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1;
var MobileSafari= !!navigator.userAgent.match(/Apple.*Mobile.*Safari/);
var ajxObj;

function getWidth() {
	if (IE || Opera) send = document.body.clientWidth;
 	else if (NC) send = window.innerWidth;
 	else  send = document.body.clientWidth;
	return send;
}

function getHeight() {
 	if (IE || Opera) send = document.body.clientHeight;
 	else if (NC) send = window.innerHeight;
 	else send = document.body.clientHeight;
	return send;
}

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
     
    if (element.tagName=='IMG')
    {
      if (/\.png$/.test(element.src))
      {
        src = element.src;
        element.src = "/theme/promo/img/blank.gif";
      }
    }
    else 
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1];
        element.runtimeStyle.backgroundImage="none"; //убираем фоновое изображение
      }
    }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='image')";
  }
}

function OpenWindow(conteiner,content_container,title,page,lang){
	var title_div = document.getElementById('content_title');
	var src='url("/theme/promo/img/'+title+'_'+lang+'.png")';
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
		title_div.runtimeStyle.backgroundImage = src;
	else
		title_div.style.background = src+' no-repeat';
	fixPNG(title_div);
	var box = document.getElementById(conteiner);
	box.style.display = "block";
	var box_content = document.getElementById(content_container);
	box_content.style.display = "block";
	box_content.style.top = (getHeight()/2)-(box_content.clientHeight/2);
	box_content.style.left = (getWidth()/2)-(box_content.clientWidth/2);
	document.getElementById("textContent").innerHTML='';
	GetPage(page);
}

function CloseWindow(conteiner,content_container){
	var box = document.getElementById(conteiner);
	box.style.display = "none";
	var box_content = document.getElementById(content_container);
	box_content.style.display = "none";
}

function GetPage(page_name){
	var url = "/promo/getpage.html?name="+page_name;
	var ajxObj = createAjxObj();
	ajxObj.onreadystatechange = function() { 
		if (ajxObj.readyState == 4) {
			if (ajxObj.status == 200) {
				document.getElementById("textContent").innerHTML = ajxObj.responseText;
				StartScroller(1);
			}
    	}
	}
	ajxObj.open("GET", url, true);
	ajxObj.send(null);
}


function OpenWindowWinners(conteiner,content_container,title,page,lang,type){
	var title_div = document.getElementById('content_title');
	var src='url("/theme/promo/img/'+title+'_'+lang+'.png")';
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
		title_div.runtimeStyle.backgroundImage = src;
	else
		title_div.style.background = src+' no-repeat';
	fixPNG(title_div);
	var box = document.getElementById(conteiner);
	box.style.display = "block";
	var box_content = document.getElementById(content_container);
	box_content.style.display = "block";
	box_content.style.top = (getHeight()/2)-(box_content.clientHeight/2);
	box_content.style.left = (getWidth()/2)-(box_content.clientWidth/2);
	document.getElementById("textContent").innerHTML='';
	GetPageWinners(page,type);
}

function GetPageWinners(page,type){
	var url = "/promo/getwinners.html?-page="+page+"&-type="+type;
	var ajxObj = createAjxObj();
	ajxObj.onreadystatechange = function() { 
		if (ajxObj.readyState == 4) {
			if (ajxObj.status == 200) {
				document.getElementById("textContent").innerHTML = ajxObj.responseText;
				StartScroller(1);
			}
    	}
	}
	ajxObj.open("GET", url, true);
	ajxObj.send(null);
}

function popup(path, width, height) {
    window.open(path, "_blank", "toolbar=no, location=no, directories=no, status=yes, menubar=no, resizable=no, copyhistory=no, scrollbars=no, width=" + width + ", height=" + height + "");
    return false;
}

function showWarning() {
	$('fog').style.display="block";
	$('popup').style.display="block";
	$('popup_result').style.display="block";
	document.body.style.overflow = 'hidden';
}

function hideWarning() {
	$('fog').style.display="none";
	$('popup').style.display="none";
	$('popup_result').style.display="none";
	document.body.style.overflow = 'auto';
}
