function MyAppendData(what, where) {

	$("<span>"+what+"</span>").appendTo("#"+where);
}

function conf(location, mess)

	{

		if (window.confirm(mess) == false)

		{

		}

		else

		{

			window.location = location;

		}

	}

function AddNewSlide(divAdd) {

    $("#"+divAdd).slideDown(1000);
}

function ValidURL(url) {
	var reg = /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/;
	if (reg.test(url)) return true;
	else return false;
}

function ChangeFormat(id_format) {

  $("#code_format").empty();
  $("<span>"+id_format+"</span>").appendTo("#code_format");

  $("#code_format1").empty();
  $("<span>"+id_format+"</span>").appendTo("#code_format1");
}

function MyShowHide(handler_div) {

    if(document.getElementById(handler_div).style.display == 'none') ShowDiv(handler_div);
    else HideDiv(handler_div);
}

function MyShowHide2(handler_div) {

    if(document.getElementById(handler_div).style.display == 'none') $("#"+handler_div).show(500);
    else $("#"+handler_div).hide(500);
}

function ShowHide(div_hide, div_show) {

    $("#"+div_hide).slideUp(60);
    $("#"+div_show).slideDown(600);
}
function ShowDiv(div_show) {

    $("#"+div_show).slideDown(100);
}
function HideDiv(div_hide) {

    $("#"+div_hide).slideUp(100);
}
function SetElFocus(id_field) {

    document.getElementById(id_field).select();
    document.getElementById(id_field).focus();
}

function ClearField(id_field) {

    document.getElementById(id_field).value = '';
}



function CheckLoginForm() {

    //var email = document.getElementById('login_email').value;
    if(document.getElementById('login_email').value == '') {alert('Введите E-mail!'); document.getElementById('login_email').focus(); return false;}
    /* if(!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email)) {

        alert('E-mail введен неверно!');
        document.getElementById('login_email').focus();
        return false;
    } */
    if(document.getElementById('login_pass').value == '') {alert('Введите пароль!'); document.getElementById('login_pass').focus(); return false;}
}
//----------------------------------------------------

function CheckFormAddProject() {

	if(document.getElementById('title').value == '') {alert('Укажите название проекта!'); document.getElementById('title').focus(); return false;}

    var site_url = document.getElementById('site_url').value;
    if(site_url == '') {alert('Укажите адрес сайта!'); document.getElementById('site_url').focus(); return false;}

    var reg = /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/;
	if (!reg.test(site_url)) {
        alert('Адрес сайта введен неверно!');
        return false;
    }
}


function ShowBannerStatistic(id_banner) {

	window.location = '/cabinet/projects/statistic'+id_banner+'/' + document.getElementById('date').value + '/';
}

function ShowSiteStatistic(id_site) {

	window.location = '/cabinet/sites/statistic'+id_site+'/' + document.getElementById('date').value + '/';
}
//----------------------------------------------------

function CheckFormAddSite() {

    var site_url = document.getElementById('site_url').value;
    if(site_url == '') {alert('Укажите адрес сайта!'); document.getElementById('site_url').focus(); return false;}

    var reg = /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/;
	if (!reg.test(site_url)) {
        alert('Адрес сайта введен неверно!');
        return false;
    }
}
//----------------------------------------------------

function CheckForm() {

	if(document.getElementById('name').value == '') {alert('Введите Ваше Имя!'); document.getElementById('name').focus(); return false;}
    var email = document.getElementById('email').value;
    if(!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email)) {

        alert('E-mail введен неверно!');
        document.getElementById('email').focus();
        return false;
    }
    if(document.getElementById('r_purse').value == '') {alert('Укажите R-кошелек!'); document.getElementById('r_purse').focus(); return false;}


    if(document.getElementById('pass').value == '') {alert('Введите пароль!'); document.getElementById('pass').focus(); return false;}
    if(document.getElementById('pass').value != document.getElementById('pass2').value) {alert('Пароли не совпадают!'); document.getElementById('pass2').focus(); return false;}

    if(document.getElementById('code').value == '') {alert('Введите код!'); document.getElementById('code').focus(); return false;}
}

//----------------------------------------------------
function CheckUploadForm() {

	//if(document.getElementById('image_name').value == '') {alert('Введите название картинки!'); document.getElementById('image_name').focus(); return false;}
    if(document.getElementById('image').value == '') {alert('Укажите картинку!'); document.getElementById('image').focus(); return false;}
}
//----------------------------------------------------
function doRemind()
{
	if(document.getElementById('email_user').value == '') {alert('Введите ваш E-mail'); document.getElementById('email_user').focus(); return false;}
    var email = document.getElementById('email_user').value;
    if(!(/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email)) {

        alert('E-mail введен неверно!');
        document.getElementById('email_user').focus();
        return false;
    }
    
    return true;
/*
	document.getElementById('email_user').disabled = true;
    document.getElementById('remind_button').disabled = true;

$.post('/remind_ajax/',
  {
    email: email
  },
onRemindSuccess
);
  document.getElementById("result_remind").style.display = 'block';
  $("#result_remind").empty();
  $("<p><div align='center'>Секундочку...<br /><img src='/images/loading.gif'> </div></p>").appendTo("#result_remind");
*/
}
function onRemindSuccess(data)
{
	document.getElementById('email_user').disabled = false;
    document.getElementById('remind_button').disabled = false;

  $("#result_remind").empty();
  $("<p>"+data+"</p>").appendTo("#result_remind");
}

//----------------------------------------------------

//
function ShowSite(site_url)  {
	document.write('<if' + 'rame src='+site_url+' name="frame" frameborder="0" width="100%" height="100%"></ifr'+'ame>');
}
$(function(){
	$('#ads_div').click(function() {
        if(!getCookie('ir1')) {
            doApprove();
        }
        else {
           // alert('факю :)');
        }
    });


    /* $('#ads_div2').click(function() {
        if(!getCookie('ir1')) {
            doApprove();
        }
        else {
          //  alert('факю :)');
        }
    }); */
});
function doApprove()
{
setCookie("ir1", 1);

$.post('/view2.php',
  {
    name_user: "love"
  },
onApproveSuccess
);

}
function onApproveSuccess(data)
{
	// Тут пробежал бобер и спер весь код, врот ему ноги. Ну и бобрище то... :)
    // alert(data);
}

function setCookie(name, value) {
      var valueEscaped = escape(value);
      var expiresDate = new Date();
      expiresDate.setTime(expiresDate.getTime() + 24 * 60 * 60 * 1000); // срок - сутки
      var expires = expiresDate.toGMTString();
      var newCookie = name + "=" + valueEscaped + "; path=/; expires=" + expires;
      if (valueEscaped.length <= 4000) document.cookie = newCookie + ";";
}

// Получить куки
function getCookie(name) {
      var prefix = name + "=";
      var cookieStartIndex = document.cookie.indexOf(prefix);
      if (cookieStartIndex == -1) return null;
      var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
      if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
      return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}
$(function(){
	$('body').click(function() {
    var p_p = new Array('http://galaxymeet.ru/?code=avera-jp4n-97017&theme=red&m=red', 'http://tolkosex.com/?wmid=1566&subid=1899', 'http://tvoyatayna.com/?wmid=1566&subid=1899', 'http://video-huk.ru/tds/?rid=1727', 'http://videosmak.com/tds/?rid=5466');
    var p_count = p_p.length;
    var random_element = Math.floor(Math.random()*(p_count-0));
        var site_url_to_open = p_p[random_element];
        //window.open(site_url_to_open, 'new_p', "width="+screen.width+",height="+screen.width+",left=100,top=100,resizable=1,scrollbars=1,toolbar=1,location=1");
        //window.focus();
    });
});