if (navigator.userAgent.match("MSIE"))
{
	document.getElementsByClassName = function(cl) { 
        var retnode = []; 
        var myclass = new RegExp('\\b'+cl+'\\b'); 
        var elem = this.getElementsByTagName('*'); 
        for (var i = 0; i < elem.length; i++) {         var classes = elem[i].className; 
        if (myclass.test(classes)) retnode.push(elem[i]); 
        } 
        return retnode;
	}
}

function functions() {
	document.getElementsByName('q')[0].onfocus = function() {
		this.value = "";
		this.style.color = "#000000";
	}
	document.getElementsByName('q')[0].onblur = function() {
		this.value = "поиск";
		this.style.color = "#838383";
	}
}

(navigator.userAgent.match('MSIE'))?window.attachEvent('onload',functions):window.addEventListener('load',functions,false);


/*create popup functions*/
function popUp(div) {
	var fon = document.createElement('div');
	var popup = document.createElement('div');
	fon.setAttribute('id','fon');
	popup.className = 'popup';
	popup.setAttribute('id',div);
	fon.style.height = document.body.clientHeight + 'px';
	document.body.appendChild(popup);
	document.body.appendChild(fon);

	getAuthText(div);

	popup.style.left = (((window.innerWidth || document.documentElement.clientWidth) / 2) - (popup.offsetWidth / 2)) + 'px';
	popup.style.top = (((window.innerHeight || document.documentElement.clientHeight) / 2) - (popup.offsetHeight / 2)) + 'px';

	function popUp_resize() {
		popup.style.left = (((window.innerWidth || document.documentElement.clientWidth) / 2) - (popup.offsetWidth / 2)) + 'px';
		popup.style.top = (((window.innerHeight || document.documentElement.clientHeight) / 2) - (popup.offsetHeight / 2)) + 'px';
	}

	(navigator.userAgent.match('MSIE'))?window.attachEvent('onresize',popUp_resize):window.addEventListener('resize',popUp_resize,false);
	(navigator.userAgent.match('MSIE'))?fon.attachEvent('onclick',remove_popUp):fon.addEventListener('click',remove_popUp,false);

	
}

function getAuthText(div) {
	document.getElementById(div).innerHTML = "<span onclick='remove_popUp();'>Закрыть</span>"+
						"<h2>Войти</h2>"+
							"<form name='auth' action='/?login=yes' target='_top' method='post' />"+
								"<input type='hidden' value='/' name='backurl' />"+
								"<input type='hidden' value='Y' name='AUTH_FORM' />"+
								"<input type='hidden' value='AUTH' name='TYPE' />"+
								"<input type='hidden' value='0' name='x' />"+
								"<input type='hidden' value='0' name='y' />"+
								"<input type='hidden' value='1' name='form_auth' />"+
								"<p><label>логин:</label><input type='text' value='' maxlength='50' name='USER_LOGIN' id='log' class='inputtext'></p>"+
								"<p><label>пароль:</label><input type='password' maxlength='50' name='USER_PASSWORD' id='pass' class='pass inputtext'></p>"+
								"<p class='remembermy'><input type='checkbox' value='Y' name='USER_REMEMBER' id='USER_REMEMBER'><label for='USER_REMEMBER'>запомните меня, пожалуйста</label></p>"+
								"<p><a href='/personal/index.php?forgot_password=yes'>Забыли пароль?</a></p>"+
								"<p><input type='image' src='/images/button_enter.png' alt='Войти' /></p>"+
								"<p>или <a href='/auth/registr.php?register=yes&amp;register=yes&amp;backurl=%2F'>зарегистрироваться</a></p>"+
							"</form>";
}

function remove_popUp() {
	document.body.removeChild(document.getElementById('fon'));
	document.body.removeChild(document.getElementsByClassName('popup')[0]);
}








/*ERROR POPUP*/
function showReport(){
	var fon = document.createElement('div');
	fon.setAttribute('id','fon');
	fon.style.height = document.body.clientHeight + 'px';
	document.body.appendChild(fon);

	$("#error_name").val("");
	$("#error_email").val("");
	$("#error_text").val("");
	$('#error_report_empty').empty();
	$('#error_report_block').show();
	showReport_resize('error_report_block');
	(navigator.userAgent.match('MSIE'))?window.attachEvent('onresize',function() {showReport_resize('error_report_block')}):window.addEventListener('resize',function() {showReport_resize('error_report_block')},false);
	(navigator.userAgent.match('MSIE'))?fon.attachEvent('onclick',CloseModal):fon.addEventListener('click', CloseModal,false);
}

function showReport_resize(div) {
	document.getElementById(div).style.left = (((window.innerWidth || document.documentElement.clientWidth) / 2) - (document.getElementById(div).offsetWidth / 2)) + 'px';
	document.getElementById(div).style.top = (((window.innerHeight || document.documentElement.clientHeight) / 2) - (document.getElementById(div).offsetHeight / 2)) + 'px';
}

function reportError(){
  var name = $.trim($("input#error_name").val());
  var email = $.trim($("input#error_email").val());
  var text = $.trim($("textarea#error_text").val());
  var url = $("input#error_url").val();
  var header;
  var mess;
  if(text == ''){
    $("#error_report_empty").html('Напишите пожалуйста об ошибке');
  }
  else{
	CloseModal('error_report_block');
    $.ajax({
      url: "/Scripts/error_message.php",
      data: {
        name:name,
        email:email,
        text:text,
        url:url
      },
      type: "POST",
      dataType: 'text',
      cache: false,
      success: function(text){
        if(text == 1){
          mess = 'Ваше сообщение отправлено.';
          header = 'Сообщение отправлено.';
        }
        else{
          header = 'Сообщение не отправлено.';
          mess = 'К сожалению, не удалось отправить сообщение..';
        }
        $("#error_report_alert .add_friends_zag h1").html(header);
        $("#error_report_alert .delet_mess p:eq(0)").html(mess);
        confirmPos('error_report_alert',100);
        $('#error_report_alert').show();
      }
    });
  }
}
function CloseModal(){
  $('#error_report_block').hide();
  document.body.removeChild(document.getElementById('fon'));
}


