var isMSIE = /*@cc_on!@*/false;

function fixPNG(element) {
	if (/MSIE (5\.5|6|7|8).+Win/.test(navigator.userAgent))	{
		var src;
		if (element.tagName=='IMG')	{
			if (/\.png$/.test(element.src)) {
				src = element.src;
				element.src = "/images/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='scale')";
	}
}

function fixInherit(element) {
	element.style.color = element.parentElement.currentStyle.color;
	element.style.textDecoration = element.parentElement.currentStyle.textDecoration;
	element.style.behavior = 'none';
}

function GetWindowY()
{
	// hi habr!
	y = 0;

	if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX)
	{
		y = window.innerHeight + window.scrollMaxY;
		x = window.innerWidth + window.scrollMaxX;

		var deff = document.documentElement;
		var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
		var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;

		x -= (window.innerWidth - wff);
		y -= (window.innerHeight - hff);
	}
	else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
	{
		y = document.body.scrollHeight;
		x = document.body.scrollWidth;
	}
	else
	{
		y = document.body.offsetHeight;
		x = document.body.offsetWidth;
	}

	return y;
}

function ShowSomeForm(content)
{
	$('#popup_windows').html("<div id='popup_windows_border'><div id='popup_windows_cont'><a href='#' onclick='return HideSomeForm();' class='hidebutton'>Закрыть</a>" + content + "</div></div>");
				
	$('#popup_windows').css({marginLeft: '-' + parseInt((500 / 2),10) + 'px', width: 500 + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$('#popup_windows').css({marginTop: '-' + parseInt((220 / 2),10) + 'px'});
	}
				
	$('#popup_windows').css({display: 'block'});
	$('#screen').css({display: 'block', height: GetWindowY()+'px'});
}

function HideSomeForm()
{
	$('#popup_windows').css({display: 'none'});
	$('#screen').css({display: 'none'});
	
	// for a tag ;)
	return false;
}

function GetQuestion(id)
{
	$.get("/request/?id=" + id.toString(), function(data){
		if(data)
		{	
			ShowSomeForm(data);
		}
	});
		
	// for a tag ;)
	return false;
}

function AskPrice(id)
{
	$.get("/askprice/?f_techid=" + id.toString(), function(data){
		if(data)
		{	
			ShowSomeForm(data);
		}
	});
		
	// for a tag ;)
	return false;
}

function ProcessAskPrice()
{
	if(document.forms[0]["f_Contacts"].value == '' ) {
		HideSomeForm();
		return false;
	}
	
	HideSomeForm();
	$.post("/netcat/add.php", {catalogue: "1",  cc: document.forms[0]["cc"].value, sub: document.forms[0]["sub"].value, posting: "1", f_Contacts: document.forms[0]["f_Contacts"].value, f_techid: document.forms[0]["f_techid"].value, utfed: 1, rand: Math.random()}, function(data){ShowSomeForm('<h1 style="font-size: 1.5em; width: 75%; margin-bottom: 25px;">' + data + '</h1>Большое спасибо! Наши операторы свяжутся с вами в ближайшее время.<div style="padding-top: 25px;"><center><button value="Закрыть" type="submit" onclick="return HideSomeForm();" class="price_button"><b>Закрыть</b></button></center></div>'); return true;});
	ShowSomeForm('<h1 style="font-size: 1.5em; width: 75%; margin-bottom: 25px;">Пожалуйста, подождите</h1><div class="loadajah">Загрузка</div><div style="padding-top: 25px;"><center><button value="Закрыть" type="submit" onclick="return HideSomeForm();" class="price_button"><b>Закрыть</b></button></center></div>');
		
	// for a tag ;)
	return false;
}


function ProcessQuestion()
{
	if(document.forms[0]["f_Question"].value == '' && document.forms[0]["f_Contacts"].value == '' ) {
		HideSomeForm();
		return false;
	}
	
	HideSomeForm();
	if(document.forms[0]["id"].value != "0") {
		$.post("/netcat/add.php", {catalogue: "1",  cc: document.forms[0]["cc"].value, sub: document.forms[0]["sub"].value, posting: "1", f_Contacts: document.forms[0]["f_Contacts"].value, id: document.forms[0]["id"].value, rand: Math.random()}, function(data){ShowSomeForm('<h1 style="font-size: 1.5em; width: 75%; margin-bottom: 25px;">' + data + '</h1>Большое спасибо! Наши операторы свяжутся с вами в ближайшее время.<div style="padding-top: 25px;"><center><button value="Закрыть" type="submit" onclick="return HideSomeForm();" class="price_button"><b>Закрыть</b></button></center></div>'); return true;});
	}
	else if(document.forms[0]["f_Question"].value || document.forms[0]["f_Contacts"].value ) {
		$.post("/netcat/add.php", {catalogue: "1",  cc: document.forms[0]["cc"].value, sub: document.forms[0]["sub"].value, posting: "1", f_Question: document.forms[0]["f_Question"].value, f_Contacts: document.forms[0]["f_Contacts"].value, rand: Math.random()}, function(data){ShowSomeForm('<h1 style="font-size: 1.5em; width: 75%; margin-bottom: 25px;">' + data + '</h1>Большое спасибо! Наши операторы свяжутся с вами в ближайшее время.<div style="padding-top: 25px;"><center><button value="Закрыть" type="submit" onclick="return HideSomeForm();" class="price_button"><b>Закрыть</b></button></center></div>'); return true;});
	}
	ShowSomeForm('<h1 style="font-size: 1.5em; width: 75%; margin-bottom: 25px;">Пожалуйста, подождите</h1><div class="loadajah">Загрузка</div><div style="padding-top: 25px;"><center><button value="Закрыть" type="submit" onclick="return HideSomeForm();" class="price_button"><b>Закрыть</b></button></center></div>');
		
	// for a tag ;)
	return false;
}

function FixTop() {
    if( $('div#o2tp').length == 1 ) {
		var w = Math.round ($('div#o2tp').width()/4) - 51;
		if(w < 125) { w = 125}
		$('div#o2tp p').css({width: w + "px"});
	}
}

function FixTopU() {
    if( $('div.phoneorder').length == 1 ) {
		var w = $('div.head').width();
		if(w > 1050) { 
			$('div.phoneorder').css({right: "9%"}); 
		} else { 
			$('div.phoneorder').css({right: "5%"});
		};
	}
}

var fnScrollingHandler = function() {
  var self = $(this);
  var ocontainer= self.find('div.container');
  var ocontent= self.find('div.s_content');
  var oslider = self.find('div.slider1');
  var oindicator = self.find('div.indicator');
  ocontainer.css('overflow', 'hidden');
  ocontainer.css('width', '95%');
  containerSize = jQuery.iUtil.getSize(ocontainer.get(0));
  containerPosition = jQuery.iUtil.getPosition(ocontainer.get(0));
  containerInner = jQuery.iUtil.getClient(ocontainer.get(0));
  contentSize = jQuery.iUtil.getSize(ocontent.get(0));
  if (contentSize.h > 310) {
    oslider.css('display','block');
    oslider.css('top', containerPosition.y + 'px');
    oslider.css('left', containerPosition.x + containerSize.wb + 'px');
    oslider.css('height', containerSize.hb + 'px');      
    var spaceToScroll = contentSize.hb-containerInner.h;
    
    oindicator.css('height', containerInner.h * containerSize.hb / contentSize.hb + 'px');
    oslider.Slider(
      {
        accept:oindicator, 
        onSlide:function( cordx, cordy, x , y) {
          $(ocontent).css('top', 0 - spaceToScroll * cordy / 100 + 'px');
        }
      }
    );
  } else {
    oslider.remove();
    oindicator.remove();
  }
} 

var fnShowScrollBar = function (){
  //alert(parseFloat($.browser.version));
  var opera927 = ($.browser.opera) && (parseFloat($.browser.version) <= 9.27);
  if (!(isMSIE || opera927)){$( 'div.scrolling_content' ).each(fnScrollingHandler);}
};
