﻿function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    } else
    {
        window.onload = function()
        {
            if (oldonload)
            {
                oldonload();
            }
            func();
        }
    }
}

//gallery scrolling
var timer;
var interval = 15;
function ScrollTop()
{
    timer = setInterval("document.getElementById('gallery').scrollTop -= 10", interval);
}
function ScrollBottom()
{
    timer = setInterval("document.getElementById('gallery').scrollTop += 10", interval);
    var e = document.getElementById('gallery');
    images = e.getElementsByTagName('img');
    images[images.length - 1].style.marginBottom = 0;
    images[images.length - 2].style.marginBottom = 0;
    images[images.length - 3].style.marginBottom = 0;
}

//popup submenu
function getCurrentPosition(e)
{
    var current = e;
    var currentTop = 0;
    var currentLeft = 0;
    var currentHeight = current.offsetHeight;
    var currentWidth = current.offsetWidth;

    while (current)
    {
        currentLeft += current.offsetLeft;
        currentTop += current.offsetTop;
        current = current.offsetParent;
    }
    return { left: currentLeft, top: currentTop, width: currentWidth, height: currentHeight };
}

function getClientWidth()
{
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}

function ieSelectFix()
{//ie select override bug
    if (document.all && !window.opera)
    {
        var iframe = document.createElement('iframe');
        iframe.setAttribute('frameborder', '0');
        iframe.id = 'iframe';
        document.body.appendChild(iframe);
    }
}

function ShowSubmenu(e, z)
{
    var current = getCurrentPosition(e);
    var submenu = document.getElementById(z);
    var docWidth = getClientWidth();
    submenu.style.right = docWidth - (current.left + current.width);
    submenu.style.top = current.top + current.height;
    submenu.style.display = 'block';
//    var tflash = document.getElementById('tflash');
//    tflash.style.display = 'none';

    var iframe = document.getElementById('iframe'); //ie select override bug
    if (iframe)
    {
        iframe.style.width = submenu.offsetWidth;
        iframe.style.height = parseInt(submenu.offsetHeight) - 28;
        iframe.style.right = submenu.style.right;
        iframe.style.top = parseInt(submenu.style.top) + 7;
        iframe.style.display = 'block';
    }
}

function prepareLinks()
{
    var foodconcept = document.getElementById('foodconcept');
    if (foodconcept)
    {
        var links = foodconcept.getElementsByTagName('a');
        for (i = 0; i < links.length; i++)
        {
            //		    var link = links[i];
            //		    var name = link.getAttribute("name");
            //            var desc = link.getAttribute("desc");

            links[i].onclick = function()
            {
                showInfo();
            }
        }
    }
}
function showInfo(mealid)
{
    var e = document.getElementById('foodconcept');
    var infoblock = document.getElementById('infoblock_' + mealid);
    var infoblock1 = document.getElementById('infoblock1' + mealid);
    var current = getCurrentPosition(e);
    var cl = document.getElementById('cl' + mealid);
    var cr = document.getElementById('cr' + mealid);
    var tc = document.getElementById('tc' + mealid);
    var bc = document.getElementById('bc' + mealid);
    var foodconcept = e;

    infoblock.style.width = foodconcept.offsetWidth;
    infoblock.style.left = current.left;
    infoblock.style.top = current.top - 25;
    infoblock.style.display = 'block';

    tc.style.width = infoblock.offsetWidth - 100;
    tc.getElementsByTagName('div')[0].style.width = tc.style.width;
    bc.style.width = tc.style.width;
    bc.getElementsByTagName('div')[0].style.width = tc.style.width;
    cl.style.height = infoblock.offsetHeight - 100;
    cl.getElementsByTagName('div')[0].style.height = cl.style.height;
    cr.style.height = cl.style.height;
    cr.getElementsByTagName('div')[0].style.height = cl.style.height;
}

function showServInfo(id)
{
    var e = document.getElementById('foodconcept');
    var infoblock = document.getElementById('serv_infoblock_' + id);
    var infoblock1 = document.getElementById('serv_infoblock1' + id);
    var current = getCurrentPosition(e);
    var cl = document.getElementById('serv_cl' + id);
    var cr = document.getElementById('serv_cr' + id);
    var tc = document.getElementById('serv_tc' + id);
    var bc = document.getElementById('serv_bc' + id);
    var foodconcept = e;

    infoblock.style.width = foodconcept.offsetWidth;
    infoblock.style.left = current.left;
    infoblock.style.top = current.top - 25;
    infoblock.style.display = 'block';

    tc.style.width = infoblock.offsetWidth - 100;
    tc.getElementsByTagName('div')[0].style.width = tc.style.width;
    bc.style.width = tc.style.width;
    bc.getElementsByTagName('div')[0].style.width = tc.style.width;
    cl.style.height = infoblock.offsetHeight - 100;
    cl.getElementsByTagName('div')[0].style.height = cl.style.height;
    cr.style.height = cl.style.height;
    cr.getElementsByTagName('div')[0].style.height = cl.style.height;
}


//function showInfo(name, desc) {	
//    var foodconcept = document.getElementById('foodconcept');
//    var e = foodconcept;
//	var infoblock = document.getElementById('infoblock');
//	var infoblock1 = document.getElementById('infoblock1');
//	var current = getCurrentPosition(e);
//	var cl = document.getElementById('cl');
//	var cr = document.getElementById('cr');
//	var tc = document.getElementById('tc');
//	var bc = document.getElementById('bc');	
//			
//			
////	var TopMealHeader = document.getElementById('<%= TopMealHeader.ClientID %>');
////	alert(<%= TopMealHeader.ClientID %>);
////	TopMealHeader.Text = name;
////	var TopMealDesc = document.getElementById('<%= TopMealDesc.ClientID %>');
////	TopMealDesc.value = desc;

//	infoblock.style.width = foodconcept.offsetWidth;
//	infoblock.style.left = current.left;
//	infoblock.style.top = current.top - 25;
//	infoblock.style.display = 'block';
//	
//	tc.style.width = infoblock.offsetWidth-100;
//	tc.firstChild.style.width = tc.style.width;
//	bc.style.width = tc.style.width;
//	bc.firstChild.style.width = tc.style.width;
//	cl.style.height = infoblock.offsetHeight-100;
//	cl.firstChild.style.height = cl.style.height;
//	cr.style.height = cl.style.height;
//	cr.firstChild.style.height = cl.style.height;
//}

function hideSubmenu(e)
{
    if (a = document.getElementById('iframe')) (a.style.display = 'none');
    document.getElementById(e).style.display = 'none';
//    var tflash = document.getElementById('tflash');
//    tflash.style.display = 'block';
}

function show(e)
{
    if (a = document.getElementById('iframe')) (a.style.display = 'block');
    e.style.display = 'block';
//    var tflash = document.getElementById('tflash');
//    tflash.style.display = 'none';
}
function hide(e)
{
    if (a = document.getElementById('iframe')) (a.style.display = 'none');
    e.style.display = 'none';
//    var tflash = document.getElementById('tflash');
//    tflash.style.display = 'block';
}

//search input
function searchOver(e)
{
    //e.parentNode.parentNode.style.background = "url(/img/search_new.png) 10px -24px no-repeat";
    e.parentNode.parentNode.style.background = "url(/img/search_200.png) 0px -24px no-repeat";
    if (e.value == 'Поиск по сайту') (e.value = '');
}
function searchOut(e)
{
    //e.parentNode.parentNode.style.background = "url(/img/search_new.png) 10px top no-repeat";
    e.parentNode.parentNode.style.background = "url(/img/search_200.png) no-repeat";
    if (e.value == '') (e.value = 'Поиск по сайту');
}

//buttons hover, IE fix
function infobar2Hover(e)
{
    var infobar2 = document.getElementById('infobar2');
    if (infobar2)
    {
        var links = infobar2.getElementsByTagName('a');
        for (i = 0; i < links.length; i++)
        {
            links[i].onmouseover = function()
            {
                //this.firstChild.style.marginTop = -27	
                this.getElementsByTagName('img')[0].style.marginTop = -27
            }
            links[i].onmouseout = function()
            {
                //this.firstChild.style.marginTop = 0	
                this.getElementsByTagName('img')[0].style.marginTop = 0
            }
        }
    }
}

addLoadEvent(infobar2Hover);
addLoadEvent(ieSelectFix);
//addLoadEvent(prepareLinks);


//Со старого сайта
function openadr()
{
    document.getElementById("showadr").style.display = "block";
}
function closeadr()
{
    document.getElementById("showadr").style.display = "none";
}

function showform()
{
var tmpDiv = document.getElementById("oscript");

      if (tmpDiv && (tmpDiv.childNodes.length == 0)) {
            var tmpframe = document.createElement('iframe');

            tmpframe.src = '/onlinescript/';
            tmpframe.noresize = true;
            tmpframe.setAttribute('scrolling', false);
            tmpframe.frameBorder = 0;
            tmpframe.marginWidth = 0;
            tmpframe.marginHeight = 0;
            tmpframe.style.width = '100%';
            tmpframe.style.height = '120px';
            tmpframe.style.overflow = 'hidden';

            tmpDiv.appendChild(tmpframe);
      }

    document.getElementById("show").style.display = "block";
    document.getElementById("show2").style.display = "none";
    document.getElementById("show3").style.display = "block";
}
function hideform()
{
    document.getElementById("show").style.display = "none";
    document.getElementById("show2").style.display = "block";
    document.getElementById("show3").style.display = "none";
}

var id_menu = new Array('sub_menu_1', 'sub_menu_2', 'sub_menu_3', 'sub_menu_7', 'sub_menu_8', 'sub_menu_9');

function allclose()
{
    for (i = 0; i < id_menu.length; i++)
    {
        document.getElementById(id_menu[i]).style.display = "none";
    }
}

function openMenu(id)
{
    for (i = 0; i < id_menu.length; i++)
    {
        if (id != id_menu[i])
        {
            document.getElementById(id_menu[i]).style.display = "none";
        }
    }
    if (document.getElementById(id).style.display == "block")
    {
        document.getElementById(id).style.display = "none";
    } else
    {
        document.getElementById(id).style.display = "block";
    }
}




function ShowSubmenuUa(e, z)
{
    var current = getCurrentPosition(e);
    var submenu = $("#"+z);
    var docWidth = getClientWidth();
    submenu.css({ right: docWidth - (current.left + current.width) + "px", top: (current.top + current.height)-3 + "px" });
    submenu.show();
}
function hideSubmenuUa(e)
{
//    if (a = document.getElementById('iframe')) (a.style.display = 'none');
    document.getElementById(e).style.display = 'none';
}

function showUa(e)
{
//    if (a = document.getElementById('iframe')) (a.style.display = 'block');
    e.style.display = 'block';
}
function hideUa(e)
{
//    if (a = document.getElementById('iframe')) (a.style.display = 'none');
    e.style.display = 'none';
}

//belarus
function belarus_flag_over(imgname){
imgname.src = "/img/belarus02.gif"
}
function belarus_flag_out(imgname){
imgname.src = "/img/belarus01.gif"
}

$.fn.clearForm = function() {
  // iterate each matching form
  return this.each(function() {
 // iterate the elements within the form
 $(':input', this).each(function() {
   var type = this.type, tag = this.tagName.toLowerCase();
   if (type == 'text' || type == 'password' || tag == 'textarea')
  this.value = '';
   else if (type == 'checkbox' || type == 'radio')
  this.checked = false;
   else if (tag == 'select')
  this.selectedIndex = -1;
 });
  });
};

$(document).ready(function(){

	$("#aviaReg").live("click", function(){
		var tlink = $(this).attr('href');
		$('<div>').html( '<iframe style="border:none; width:99%; height:99%" src="'+tlink+'"></iframe>' ).dialog({
			modal : true,
			close : function () { $(this).remove(); },
			width : $(window).width() - 50,
			height : $(window).height() - 80
			});
		return false;
		});

$(".box1").mouseover(function(){

	$(this).css('border', '1px solid #3366CC').css('background', '#CCFFFF');
});

$(".box1").mouseout(function(){
	$(this).css('border', '1px solid #ADADAD').css('background', 'white');
});

$("#GiftHunterRegister").live("click", function(){
	var ss = $("#GiftHunterForm").serialize();
	var err = 0;

	$.post('/pages/GiftHunterRegistration.php', ss, function(data) { 
	//alert ( data );
			
	if ( data == 1 ) {
	$('<div>').html('Спасибо за регистрацию.').dialog({ buttons : {'Закрыть' : function () { 
			//$("#GiftHunterForm").clearForm(); 
			$(this).remove(); } 
			}});
		} else {


			if ( data == 3 ) {
				var tt = 'Номер ваучера должен состоять из чисел. В числе должно быть не меньше 6 знаков.';
				}
			if ( data == 2 ){
				var tt = 'Поля помеченные красным цветом не заполнены.';
				}
			if ( data == 4 ){
				var tt = 'Данный номер ваучер уже зарегистрирован в системе.';
			}
			

			$("#GiftHunterForm :input").each(function(){
				//values[this.name] = $(this).val();
				if ( $(this).val() == '' ) { $(this).css('background', 'red'); err = 1; }
				});

		$('<div>').html( tt ).dialog({
			close : function(){ $(this).remove(); }
			});
		

		} // end if

		}); // end of post
	
	

	}); // end function

});


$(".notDifferent").live("click", function(){

	var st = $(".notDifferent").attr('checked');

	if ( st ) { 
		$("#Address2").hide();
		} else {
                $("#Address2").show();
		}






});
