﻿function HideShow(obj) {          
	$(obj).slideToggle("slow");
}
function Show(obj) {
	/*$('#'+obj).slideDown("slow");*/	
	var element = document.getElementById(obj);
	if(element != null){
		element.style.display = 'block';
	}
}
function Hide(obj) {
	/*$('#'+obj).slideUp("slow");*/
	var element = document.getElementById(obj);	
	if(element != null){
		element.style.display = 'none';
	}
}
function SetElement(obj, color, newcolor) {
	imageon = new Image();
	element = document.getElementById(obj);
	var srcpart=/^(.+)blue(.+)$/;
	for( var x = 0; element.childNodes[x]; x++ ){
		if (element.childNodes[x].tagName == 'IMG') {
			var cur = element.childNodes[x].src;
			var match_array=cur.match(srcpart);
			if (match_array == null) {
				imageon.src = "/bitrix/templates/main/images/pointer_"+newcolor+".gif";
			} else {
				imageon.src = "/bitrix/templates/main/images/pointer_"+color+".gif";
			}
			if (document.images) {
				element.childNodes[x].src = eval("imageon.src");
			}
		}
	}
	if (element.className != 'select_rounded') {
		if (element.className != 'rounded') {
			element.className = 'rounded'
			$("#"+obj).corner("10px");
		} else {
			element.className ='no_rounded';
			for( var x = 0; element.childNodes[x]; x++ ){
				if (element.childNodes[x].tagName == 'DIV') {
					element.removeChild(element.childNodes[x]);
				}
			}
		}
	}
}
function ReplaceColumn(objhide, objshow) {
	$('#'+objhide+'_block').slideUp("slow");
	$('#'+objshow+'_block').slideDown("slow");
	element = document.getElementById(objshow);
	element.className = 'no_active';
	element = document.getElementById(objhide);
	element.className = 'active';
}
function checkSearh() {
	element = document.getElementById('keywords');
	if (element.value == '') {
		element.value = 'Поиск';
	}
}
jQuery(document).ready(function() {
	$(".select_rounded").corner("10px");
});
function createAjaxRequest(){
    /* Ñîçäàíèå íîâîãî îáúåêòà XMLHttpRequest äëÿ îáùåíèÿ ñ Web-ñåðâåðîì */
    var xmlHttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
    @end @*/

    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}
function loadPageToDiv(url, div_id){
	//alert('url='+url+' div_id='+div_id);
	con = createAjaxRequest();
	window.div_id = new String(div_id);
	con.onreadystatechange = function(){
		if (con.readyState == 4) {
	        var response = con.responseText;
			//alert('response='+response);
			elem = document.getElementById(window.div_id);
			if(_isIE()){
				elem.outerHTML = '<div class="select-menu area" id="area">'+response+'</div>';
				//alert(5)
			}else{
				elem.innerHTML = '';
				elem.innerHTML = response;	
			}
			//alert(elem.innerHTML)
			
			
		}
	}
    con.open('GET', url, true);	
	con.send(null);
}
function loadPageToDiv2(url, div_id){
	//alert('url='+url+' div_id='+div_id);
	con = createAjaxRequest();
	window.div_id2 = new String(div_id);
	con.onreadystatechange = function(){
		if (con.readyState == 4) {
	        var response = con.responseText;
			//alert('response='+response);
			elem = document.getElementById(window.div_id2);		
			elem.innerHTML = '';
			elem.innerHTML = response;
		}
	}
    con.open('GET', url, true);	
	con.send(null);
}
function loadOptions2Select(url, div_id){	
	//alert('url='+url+' div_id='+div_id);
	con = createAjaxRequest();
	window.div_id = new String(div_id);
	con.onreadystatechange = function(){
		var response = con.responseText;
		//alert('response2='+response);
		if ((con.readyState == 4) || (response.length > 0)) {	        
			//alert('responsezzz='+response);
			elem = document.getElementById(window.div_id);
			if(_isIE()){
				while(elem.options.length > 0){
					elem.options.remove(0);
				}
				arHTML = elem.outerHTML.split(/<\//);
				elem.outerHTML = arHTML[0] + response + '</' + arHTML[1];
			}else{
				elem.innerHTML = '';
				elem.innerHTML = response;	
			}			
			//alert(elem.innerHTML)
		}
	}
    con.open('GET', url, true);	
	con.send(null);
}
function _isIE(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])	
	if (version >= 5.5){
		return true;
	}else{
		return false;
	}
}
function _isOpera(){
    if(navigator.appName.lastIndexOf('Opera') != -1){
        return true
    }else{
        return false;
    }
}
_isOpera()
function _isIE6(){
	/*
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])	
	if (version < 7){
		return true;
	}else{
		return false;
	}
	*/
	return true;
}

function showAreaSelect(){
	document.getElementById('select_area_win').style.display = 'block';
    //loadDistricts($('#COUNTRY_ID').val());
	//left = (document.body.offsetWidth/2) - 211;
	//document.getElementById('select_area_win').style.left = left+'px';
	//alert(document.width);
    window.scroll(0,0);
	showOverlay();
}
function showReg(){
	document.getElementById('reg_win').style.display = 'block';
	left = (document.body.offsetWidth/2) - 211;
	document.getElementById('reg_win').style.left = left+'px';
	//alert(document.width);
	showOverlay();
}
function showOverlay(){
	var overlay = document.getElementById('overlay');
	if (!overlay)
	{
		//alert('!overlay')
		overlay = document.body.appendChild(document.createElement("DIV"));
		overlay.className = "overlay";
		overlay.id = "overlay";
		overlay.onclick = function() {hideAreaSelect()};
		overlay.style.height = '2000px'
				
	}
    //window.scroll(0,0);
	overlay.style.display = "block";
//	overlay.style.zIndex = 100;
}
function hideOverlay(){
	document.getElementById('overlay').style.display = 'none';
}
function hideAreaSelect(){
	document.getElementById('select_area_win').style.display = 'none';
	hideOverlay();
}
function hideReg(){
	document.getElementById('reg_win').style.display = 'none';
	document.getElementById('overlay').style.display = 'none';
}
function loadAreas(district){
	//loadPageToDiv('/splash_ajax1.php?DISTRICT='+district, 'area', 0);
    $.ajax({ 
        type: "POST", 
        url: '/splash_ajax1.php', 
        data: 'DISTRICT='+district, 
        success: function(msg){ 
            $('#area').html(msg);
            $('#area_selected').html($('#area > a').html());
            $('#AREA_ID').val($('#area > a').attr('id'));
            //loadAreas($('#area > a').attr('id'));
        } 
    });
}
function loadDistricts(country){
    $.ajax({ 
        type: "POST", 
        url: '/splash_ajax1.php', 
        data: 'COUNTRY_ID='+country, 
        success: function(msg){ 
            $('#district_menu').html(msg);
            $('#district_selected').html($('#district_menu > a').html());
            $('#district').val($('#district_menu > a').attr('id'));
            loadAreas($('#district_menu > a').attr('id'));
        } 
    }); 
}
function _loadDistricts(country){
    $.ajax({ 
        type: "POST", 
        url: '/splash_ajax1.php', 
        data: '_COUNTRY_ID='+country, 
        success: function(msg){ 
            $('#district_menu').html(msg);
            $('#district_selected').html($('#district_menu > a').html());
            $('#district').val($('#district_menu > a').attr('id'));
            loadAreas($('#district_menu > a').attr('id'));
        } 
    }); 
}
function showHideSelectMenu(id){
	//alert('id='+id)
	if(id == 'area'){
		elem = document.getElementById('district_menu');
	}else{
		elem = document.getElementById('area');
	}
	elem.style.display = 'none';	
	if(document.getElementById(id).style.display != 'block'){
		document.getElementById(id).style.display = 'block';
	}else{
		document.getElementById(id).style.display = 'none';
	}
}
function selectCountry(id, name){
	//alert('id='+id+' name='+name);
	document.getElementById('country_menu').style.display = 'none';
	document.getElementById('country_selected').innerHTML = name;
    document.getElementById('_COUNTRY_ID').value = id;
	_loadDistricts(id);
}
function selectDistrict(id, name){
	//alert('id='+id+' name='+name);
	document.getElementById('district_menu').style.display = 'none';
	document.getElementById('district_selected').innerHTML = name;
	loadAreas(id);
}
function selectArea(id, name){
	//alert('name='+name)
	document.getElementById('area').style.display = 'none';
	document.getElementById('area_selected').innerHTML = name;
	document.getElementById('AREA_ID').value = id;
}
function closeWin(id){
	hideOverlay();
	document.getElementById(id).style.display = 'none';
}
function nextStep(){
	document.getElementById('first_step').style.display = 'none';
	document.getElementById('third_step').style.display = 'block';
	document.getElementById('prev_btn').style.display = 'block';
	document.getElementById('next_btn').style.display = 'none';
	document.getElementById('description').style.display = 'none';
	
	document.getElementById('send-request-btn').style.display = 'block';
	document.getElementById('send-request-btn-img').style.width = '130px';
	document.getElementById('send-request-btn-img').style.height = '25px';
	
	window.scroll(0, 380)
}
function prevStep(){
	document.getElementById('first_step').style.display = 'block';
	document.getElementById('third_step').style.display = 'none';
	document.getElementById('prev_btn').style.display = 'none';
	document.getElementById('next_btn').style.display = 'block';
	document.getElementById('description').style.display = 'block';
	document.getElementById('send-request-btn').style.display = 'none';
	document.getElementById('response_container').style.display = 'none';	
	window.scroll(0, 380)
}
function calcFormParams(id, addParams, bAsObject){
	var form1 = document.getElementById(id);
    if(bAsObject){
        var params = {};
    }else{
        var params = '';
    }
    $('#'+id+' *').each(function (i) {
        if((this.tagName == 'SELECT') || (this.tagName == 'TEXTAREA') || (this.tagName == 'INPUT')){
            if(($(this).attr('type') == 'checkbox') || ($(this).attr('type') == 'radio')){
                if($(this).attr('checked') == true){
                    if(bAsObject){
                        params[$(this).attr('name')] = encodeURIComponent($(this).val());
                    }else{
                        if(params.length > 0){
    						params += '&';
    					}
    					params += $(this).attr('name') + '=' + encodeURIComponent($(this).val());
                    }						
                }
    		}else if(this.tagName == 'TEXTAREA'){
                if(bAsObject){
                    params[$(this).attr('name')] = encodeURIComponent($("textarea[name='" + $(this).attr('name') + "']").val());
                }else{
                    if(params.length > 0){
    					params += '&';
    				}
    				params += $(this).attr('name') + '=' + encodeURIComponent($("textarea[name='" + $(this).attr('name') + "']").val());
                }	
    		}else{
    	        if(bAsObject){
                    params[$(this).attr('name')] = encodeURIComponent($(this).val());
                }else{
                    if(params.length > 0){
    					params += '&';
    				}
    				params += $(this).attr('name') + '=' + encodeURIComponent($(this).val());
                }			
    		}
        }
    });
	if((addParams != null) && (addParams != false)){
	    if(bAsObject){
            arAddParams = addParams.split('=');
            params[arAddParams[0]] = arAddParams[1];
        }else{
            if(params.length > 0){
    			params += '&';
    		}
        	params += addParams;
        }		
		
	}
	return params;
}
function sendParticipationRequest(){
	var params = calcFormParams('take-part', 'submit=Y');
    
	con = createAjaxRequest();
	con.onreadystatechange = function(){
        //alert('this.readyState='+this.readyState);
        //alert('this.status='+this.status);
		if (con.readyState == 4) {
			document.getElementById('third_step').style.display = 'none';
			document.getElementById('send-request-btn').style.display = 'none';
	        var response = con.responseText;
			document.getElementById('response_container').style.display = 'block';
			document.getElementById('response_container').innerHTML = response;
			
			if(response.lastIndexOf('принята к рассмотрению') != -1){
				document.getElementById('prev_btn').style.display = 'none';
				//document.getElementById('ok_btn').style.display = 'block';
			}
			window.scroll(0, 0);
		}else{
			//alert('Ioeaea i?e nio?aiaiee oanea');
            //alert('test');
		}
	}
	con.open("POST", document.getElementById('take-part').action, true)
	con.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    con.setRequestHeader('Accept-Charset', 'windows-1251,utf-8;');
	con.send(params);
}
function assignFileUrl(flashId, url){
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    if(isIE){
        document.all[flashId].setFileUrl(url);
    }else{
        //alert('i='+i+"\n"+document[flashId].setFileUrl);
        document[flashId].setFileUrl(url);
    }
}
function assignNavigationUrl(flashId, url){
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    if(isIE){
        document.all[flashId].setNavigationUrl(url);
    }else{
        document[flashId].setNavigationUrl(url);
    }
}
function afterLoad(){
    if(window.loadInt > 0){
        for(i in fileUrls){
            //alert(document['banner_'+i].setFileUrl);
            if (document['banner_'+i].setFileUrl == undefined) {
                return;
            }
        }
        clearInterval(window.loadInt);
    }
    for(i in fileUrls){
        assignFileUrl('banner_'+i, window.fileUrls[i]);
        assignNavigationUrl('banner_'+i, window.navigationUrls[i]);
    }

}
window.navigationUrls = new Array();
window.fileUrls = new Array();
//$(document).ready(function(){ 
//    $('object').each(function(i){
//        if(this.name.lastIndexOf('banner_5') != -1){
//            $(this).click(function(){
//                alert(123)
//            });
//        }
//    });
//});
if(_isIE() || _isOpera()){
    window.loadInt = setInterval(afterLoad, 100);
}else{
    var sss = '';
    $(document).ready(function(){
        $('embed').each(function(i){
            if(this.name.lastIndexOf('banner_') != -1){
                $(this).wrap('<div id="' + this.name + '" />')
                $('#' + this.name).click(function(){
                    //alert('123')
                    arName = this.id.split('banner_');
                    window.open(window.navigationUrls[arName[1]])                                        
                });
            }
        });
    });
}
function sendAndShowRequest(formID, url, $resultDivID){
    var data = calcFormParams(formID);
    $.ajax({ 
        type: "POST", 
        url: url, 
        data: data, 
        success: function(msg){ 
            $('#'+$resultDivID).html(msg)
            $('#loading_label').css('display', 'none');
        } 
    });    
}
function win2unicode(str) {
   var charmap   = unescape(
      "%u0402%u0403%u201A%u0453%u201E%u2026%u2020%u2021%u20AC%u2030%u0409%u2039%u040A%u040C%u040B%u040F"+
      "%u0452%u2018%u2019%u201C%u201D%u2022%u2013%u2014%u0000%u2122%u0459%u203A%u045A%u045C%u045B%u045F"+
      "%u00A0%u040E%u045E%u0408%u00A4%u0490%u00A6%u00A7%u0401%u00A9%u0404%u00AB%u00AC%u00AD%u00AE%u0407"+
      "%u00B0%u00B1%u0406%u0456%u0491%u00B5%u00B6%u00B7%u0451%u2116%u0454%u00BB%u0458%u0405%u0455%u0457")
   var code2char = function(code) {
               if(code >= 0xC0 && code <= 0xFF) return String.fromCharCode(code - 0xC0 + 0x0410)
               if(code >= 0x80 && code <= 0xBF) return charmap.charAt(code - 0x80)
               return String.fromCharCode(code)
            }
   var res = ""
   for(var i = 0; i < str.length; i++) res = res + code2char(str.charCodeAt(i))
   return res
}
function publicFilter_loadDistricts(){
    $('#district').load('partners_ajax.php?type=0&p_id='+$('#COUNTRY_ID').val(), null, function(msg){
        publicFilter_loadAreas();
    });
}
function publicFilter_loadAreas(){
    $('#region').load('partners_ajax.php?type=1&p_id='+$('#district').val(), null, function(){
        publicFilter_loadCities();
    });
}
function publicFilter_loadCities(){
    $('#city').load('partners_ajax.php?type=2&p_id='+$('#region').val());
}
var trans = [];
for (var i = 0x410; i <= 0x44F; i++)
  trans[i] = i - 0x350; // А-Яа-я
trans[0x401] = 0xA8;    // Ё
trans[0x451] = 0xB8;    // ё

// Сохраняем стандартную функцию escape()
var escapeOrig = window.escape;

// Переопределяем функцию escape()
window.escape = function(str)
{
  var ret = [];
  // Составляем массив кодов символов, попутно переводим кириллицу
  for (var i = 0; i < str.length; i++)
  {
    var n = str.charCodeAt(i);
    if (typeof trans[n] != 'undefined')
      n = trans[n];
    if (n <= 0xFF)
      ret.push(n);
  }
  return escapeOrig(String.fromCharCode.apply(null, ret));
}