
var check_arr = new Array();



function check(e, id){

	for(var i=0;i<check_arr.length;i++){

			if(id!=check_arr[i]){
				off("info_"+check_arr[i]);
			}

	}

	if(	(check_div(e, "us_photo_"+id)) || (check_div(e, "info_"+id)))
	{

		if($("#info_"+id).css("display")=='none'){
			show(e, id);
		}
	}
	else{
		off("info_"+id);
	}

}


function delay(prmSec)
{
 prmSec *= 1000;

 var eDate = null;
 var eMsec = 0;

 var sDate = new Date();
 var sMsec = sDate.getTime();

 do {
 eDate = new Date();
 eMsec = eDate.getTime();

 } while ((eMsec-sMsec)<prmSec);
}

function on(id){
	$("#"+id).animate({ opacity: "show" }, "200");
}

function all_off(){
	 var divs = $(".us_info");

	 if(divs!=null){
	 	divs.animate({ opacity: "hide" }, "200");
	 }
}
function check_div(e, id){

	if (e.pageX == null && e.clientX != null ) {
	    var html = document.documentElement
	    var body = document.body

	    e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
	    e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
	}

	m_x		= e.pageX;
	m_y		= e.pageY;
	w		= $("#"+id).width();
	h		= $("#"+id).height();
	d_x		= $("#"+id).offset().left;
	d_y		= $("#"+id).offset().top;


	if(((m_x-d_x)<w) && ((m_y-d_y)<h)){

		return true;

	}
	else{

	//	$("#message").html('false');
		return false;


	}

}

function mes(str){
	$("#message").html(str);
}

function show(e, id){
	if (e.pageX == null && e.clientX != null ) {
	    var html = document.documentElement
	    var body = document.body

	    e.pageX = e.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0)
	    e.pageY = e.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0)
	}

	m_x		= e.pageX;
	m_y		= e.pageY;
	d_x		= $("#us_div_"+id).offset().left;
	d_y		= $("#us_div_"+id).offset().top;

	x=parseInt(m_x-d_x);
	y=parseInt(m_y-d_y);

	//alert("m_x"+m_x+" m_y"+m_y+"d_x"+d_x+" d_y"+d_y);

	$("#info_"+id).css("margin-top",y);
	$("#info_"+id).css("margin-left",x);



	$("#info_"+id).animate({ opacity: "show" }, "200");

}

function off(id){
	$("#"+id).animate({ opacity: "hide" }, "200");
}
function onoff(id){
	if(document.getElementById(id).style.display=='block'){
		document.getElementById(id).style.display='none';

	}
	else{
		document.getElementById(id).style.display='block';
	}
}

function present(id_pr, id_lk, id_us){

	if(id_us<1){
location.href = '_lecReg.php';		 	
//alert('Авторизируйтесь чтобы сделать подарок!');

	}
	else{
		if(id_lk==id_us){
		 alert('Вы не можете подарить себе подарок');

		}
		else{
			  $.get("ajax/presents.php", { id1 : id_pr, id2 : id_lk, id3:id_us },
			   function(data){

			   	if (data.status==1){
			   		alert('Вы сделали подарок стоимостью '+data.price+'$!');
			   		$("#pr_count_"+id_lk).html(data.num);
			   		$("#present_"+id_lk).remove();
			   		$("#for_img_"+id_lk).append('<div class="pr" style="background:url(img/presents/'+data.img+')" id="present_'+id_lk+'"></div>');

			   	}
			   	else{
			   		alert('У вас недостаточно средств ('+data.money+'$)!');
			   		window.location = "/webmasters/wmz/money";
			   	}


			 }, "json");
		 }
	 }

}

function mainchat(id_pr, id_lk){

			  $.get("ajax/mainchat.php", { id1 : id_pr, id2 : id_lk},
			   function(data){

			   	if (data.status=='1'){
			   		alert('Чат установлен основным! Вход с главной страницы будет осуществляться именно в него.');
			   	}
			   	else{
			   		alert('ошибка!');
			   	}

 			}, "json");

}


function vote(id_pr, id_lk, id_us){


		if(id_us<1){
location.href = '_lecReg.php';		 	
//alert('Авторизируйтесь чтобы отдать голос!');
		}
		else{
			if(id_lk==id_us){
			 	alert('Вы не можете отдать себе голос');

			}
			else{
				 $.get("ajax/vote.php", { id1 : id_pr, id2 : id_lk, id3:id_us },
				   function(data){

				   	if (data.status==1){
				   		alert('Ваш голос учтен, вы поставили '+data.count+' балов!');
				   		$("#vote_"+id_lk).html(data.new_vote);
				   		$("#v_"+id_lk).html('<div class="new_vote_link">'+activ_num(id_pr)+'</div>');

				   	}
				   	else{
				   		if (data.status==-1){
				   			alert('У вас недостаточно средств ('+data.money+'$)!');
				   			window.location = "/webmasters/wmz/money";
				   		}
				   		else{
				   		  	if (data.status==0){
				   				alert('Вы уже проголосовали за этого пользователя!');
				   				$("#v_"+id_lk).html('<div class="new_vote_link">'+activ_num(id_pr)+'</div>');
				   			}
				   		}
				   	}

				 }, "json");
			 }
		}

}

function vote(id_pr, id_lk, id_us, id_konkurs){


		if(id_us<=1){
location.href = '_lecReg.php';		 	
//alert('Авторизируйтесь чтобы отдать голос!');
		}
		else{
			if(id_lk==id_us){
			 	alert('Вы не можете отдать себе голос');

			}
			else{
				 $.get("ajax/vote.php", { id1 : id_pr, id2 : id_lk, id3:id_us, id4:id_konkurs },
				   function(data){

				   	if (data.status==1){
				   		alert('Ваш голос учтен, вы поставили '+data.count+' балов!');
				   		$("#vote_"+id_lk).html(data.new_vote);
				   		$("#v_"+id_lk).html('<div class="new_vote_link">'+activ_num(id_pr)+'</div>');

				   	}
				   	else{
				   		if (data.status==-1){
				   			alert('У вас недостаточно средств ('+data.money+'$)!');
				   			window.location = "/webmasters/wmz/money";
				   		}
				   		else{
				   		  	if (data.status==0){
				   				alert('Вы уже проголосовали за этого пользователя!');
				   				$("#v_"+id_lk).html('<div class="new_vote_link">'+activ_num(id_pr)+'</div>');
				   			}
				   		}
				   	}

				 }, "json");
			 }
		}

}

function activ_num(num){

	var str='';

	for(var i=1;i<6;i++){
		if(num==i){
			str+='<span>+'+i+'</span> ';
		}
		else{
		  	str+='+'+i+' ';
		}
	}

	return str;

}

function conf(location, mess){
		if (window.confirm(mess) == false){
		}
		else{
			window.location = location;
		}
}



   interval = null;

  function openProgressBar() {
    /* generate random progress-id */
    uuid = "";
    for (i = 0; i < 32; i++) {
      uuid += Math.floor(Math.random() * 16).toString(16);
    }
    /* patch the form-action tag to include the progress-id */
    document.getElementById("upload").action="http://www.educam.tv/upload.php?X-Progress-ID=" + uuid;

    /* call the progress-updater every 1000ms */
    interval = window.setInterval( function () {  fetch(uuid);  }, 1000 );
  }


  function fetch(uuid) {
    req = new XMLHttpRequest();
    req.open("GET", "/progress", 1);
    req.setRequestHeader("X-Progress-ID", uuid);
    req.onreadystatechange = function () {
    if (req.readyState == 4) {
      if (req.status == 200) {
        /* poor-man JSON parser */
        var upload = eval(req.responseText);



        /* change the width if the inner progress-bar */
        if (upload.state == 'done' || upload.state == 'uploading') {
          bar = document.getElementById('progressbar');
          w = parseInt(100 * (upload.received / upload.size));

          bar.style.width = w+'%';
		  document.getElementById('tp').innerHTML = upload.state +' '+w+'%';

        }
        /* we are done, stop the interval */
        if (upload.state == 'done') {
          document.getElementById('tp').innerHTML = upload.state;
          bar.style.width = '100%';
          window.clearTimeout(interval);
          window.location.href = "_myLec-pass.php";
        }
      }
    }
  }
  req.send(null);
}

  function openProgressBarExample() {
    /* generate random progress-id */

    if (document.getElementById("example").value==''){
		document.getElementById("upload").target="_self";

	}
    else{
	    uuid = "";
	    for (i = 0; i < 32; i++) {
	      uuid += Math.floor(Math.random() * 16).toString(16);
	    }
	    /* patch the form-action tag to include the progress-id */
	    document.getElementById("upload").action="_myLec.php?X-Progress-ID=" + uuid;

	    /* call the progress-updater every 1000ms */
	    interval = window.setInterval( function () {  fetchExample(uuid);  }, 1000 );
    }
  }

  function fetchExample(uuid) {
    req = new XMLHttpRequest();
    req.open("GET", "/progress", 1);
    req.setRequestHeader("X-Progress-ID", uuid);
    req.onreadystatechange = function () {
    if (req.readyState == 4) {
      if (req.status == 200) {
        /* poor-man JSON parser */
        var upload = eval(req.responseText);



        /* change the width if the inner progress-bar */
        if (upload.state == 'done' || upload.state == 'uploading') {
          bar = document.getElementById('progressbar');
          w = parseInt(100 * (upload.received / upload.size));

          bar.style.width = w+'%';
		  document.getElementById('tp').innerHTML = upload.state +' '+w+'%';

        }
        /* we are done, stop the interval */
        if (upload.state == 'done') {
          document.getElementById('tp').innerHTML = upload.state;
          bar.style.width = '100%';
          window.clearTimeout(interval);
           window.location.href = "_myLec.php";
        }
      }
    }
  }
  req.send(null);
}

function openProgressBarTender() {
    /* generate random progress-id */
    uuid = "";
    for (i = 0; i < 32; i++) {
      uuid += Math.floor(Math.random() * 16).toString(16);
    }
    /* patch the form-action tag to include the progress-id */
    document.getElementById("upload").action="tenders.php?X-Progress-ID=" + uuid;

    /* call the progress-updater every 1000ms */
    interval = window.setInterval( function () {  fetchTender(uuid);  }, 1000 );
  }


  function fetchTender(uuid) {
    req = new XMLHttpRequest();
    req.open("GET", "/progress", 1);
    req.setRequestHeader("X-Progress-ID", uuid);
    req.onreadystatechange = function () {
    if (req.readyState == 4) {
      if (req.status == 200) {
        /* poor-man JSON parser */
        var upload = eval(req.responseText);



        /* change the width if the inner progress-bar */
        if (upload.state == 'done' || upload.state == 'uploading') {
          bar = document.getElementById('progressbar');
          w = parseInt(100 * (upload.received / upload.size));

          bar.style.width = w+'%';
		  document.getElementById('tp').innerHTML = upload.state +' '+w+'%';

        }
        /* we are done, stop the interval */
        if (upload.state == 'done') {
          document.getElementById('tp').innerHTML = upload.state;
          bar.style.width = '100%';
          window.clearTimeout(interval);
          window.location.href = "tenders.php?task=my";
        }
      }
    }
  }
  req.send(null);
}
function div_show(){
	if(document.getElementById('video1').value!=''){
		document.getElementById('progress_div').style.display='block';
		document.getElementById('upload').target="uploadframe";
	}
	else{
		document.getElementById('progress_div').style.display='none';
	}

}
function openProgressBarTender2(ks_id, my_id) {
    /* generate random progress-id */
    uuid = "";
    for (i = 0; i < 32; i++) {
      uuid += Math.floor(Math.random() * 16).toString(16);
    }
    /* patch the form-action tag to include the progress-id */
    document.getElementById("upload").action="ksdata.php?X-Progress-ID=" + uuid;

    /* call the progress-updater every 1000ms */
    interval = window.setInterval( function () {  fetchTender2(uuid, ks_id, my_id);  }, 1000 );
  }


  function fetchTender2(uuid, ks_id, my_id) {
    req = new XMLHttpRequest();
    req.open("GET", "/progress", 1);
    req.setRequestHeader("X-Progress-ID", uuid);
    req.onreadystatechange = function () {
    if (req.readyState == 4) {
      if (req.status == 200) {
        /* poor-man JSON parser */
        var upload = eval(req.responseText);



        /* change the width if the inner progress-bar */
        if (upload.state == 'done' || upload.state == 'uploading') {
          bar = document.getElementById('progressbar');
          w = parseInt(100 * (upload.received / upload.size));

          bar.style.width = w+'%';
		  document.getElementById('tp').innerHTML = upload.state +' '+w+'%';

        }
        /* we are done, stop the interval */
        if (upload.state == 'done') {
          document.getElementById('tp').innerHTML = upload.state;
          bar.style.width = '100%';
          window.clearTimeout(interval);
          window.location.href = "ks_anketa.php?user_id="+my_id+"&ks_id="+ks_id;
        }
      }
    }
  }
  req.send(null);
}

 function openProgressBarExample2(lek_id) {

	    uuid = "";
	    for (i = 0; i < 32; i++) {
	      uuid += Math.floor(Math.random() * 16).toString(16);
	    }
	    /* patch the form-action tag to include the progress-id */
	    document.getElementById("upload").action="_myLec-edit.php?X-Progress-ID=" + uuid;

	    /* call the progress-updater every 1000ms */
	    interval = window.setInterval( function () {  fetchExample2(uuid, lek_id);  }, 1000 );

  }
  function fetchExample2(uuid, lek_id) {
    req = new XMLHttpRequest();
    req.open("GET", "/progress", 1);
    req.setRequestHeader("X-Progress-ID", uuid);
    req.onreadystatechange = function () {
    if (req.readyState == 4) {
      if (req.status == 200) {
        /* poor-man JSON parser */
        var upload = eval(req.responseText);



        /* change the width if the inner progress-bar */
        if (upload.state == 'done' || upload.state == 'uploading') {
          bar = document.getElementById('progressbar');
          w = parseInt(100 * (upload.received / upload.size));

          bar.style.width = w+'%';
		  document.getElementById('tp').innerHTML = upload.state +' '+w+'%';

        }
        /* we are done, stop the interval */
        if (upload.state == 'done') {
          document.getElementById('tp').innerHTML = upload.state;
          bar.style.width = '100%';
          window.clearTimeout(interval);
          window.location.href = "_myLec-edit.php?lekID="+lek_id;
        }
      }
    }
  }
  req.send(null);
}

function checkRegForm(form)
{
	var el, elName, value, type;
	var errorList = [];
	var num = document.getElementById('ya_ne_bot').value;

	var errorText = {

	1 : "Вы не заполнили  поле 'Логин'",
	2 : "Вы не заполнили  поле 'Емайл'",
	3 : "Вы не заполнили  поле 'Пароль'",
	4 : "Вы не заполнили  поле 'Секретный код'"

	}

	for (var i = 0; i < form.elements.length; i++)
	{
		el = form.elements[i];
		elName = el.nodeName.toLowerCase();
		value = el.value;
		if (elName == "input")
			{

				type = el.type.toLowerCase();
				switch (type)
				{
					case "text" :
					if (el.name == "login" && value == "") errorList.push(1);
					if (el.name == "email" && value == "") errorList.push(2);
					if (el.name == "ya_ne_bot" && (value == "" || value == "код на картинке!")) errorList.push(4);
					break;
					case "password" :
					if (el.name == "pass" && value == "") errorList.push(3);
					break;
				}
			}

	}

	if (!errorList.length) return true;
	var errorMsg = "При заполнении формы допущены следующие ошибки:\n\n";
	for (i = 0; i < errorList.length; i++)
	{
		errorMsg += errorText[errorList[i]] + "\n";
	}
	alert(errorMsg);
	return false;
}



