// JavaScript Document
//----------export_code_js------------------------------------------------------------
var http = getHTTPObject();

function export_code_js (id, type, user)
{	
	var url = "functions/export_code.php";
	url = url+"?type="+type+"&user="+user+"&id="+id;
	
	http.open("GET", url);
	http.onreadystatechange = handleHttpResponse_export;
    http.send(null);
	
    //result = http.responseText;
	//alert(url);
	
}

function handleHttpResponse_export ()
{
	 if(http.readyState == 4)
	 {   
	     var Ua = navigator.userAgent;
		 document.getElementById('blog_code').className = "visible";
		 if(Ua.indexOf("Gecko") > -1)
		 {
		  document.getElementById('footer').className = "notvisible";
		  document.getElementById('footer').style.display = "table";
		 }
		 document.getElementById('blog_code_form').value = http.responseText;
	 }
}
//-------------------------------------------------------------------------------------------


//--fields_js-------------------------------------------------------------------------------
function validate_field(id1)
{
if (document.getElementById(id1).value=='')
return 0;
else
return 1;
}

function display_error (id1,id2,id3,error_subj,ok_subj)
{

 if(validate_field(id3))
 {
  document.getElementById(id1).innerHTML=ok_subj;
  clear_focus(id1,id2);
  return true;
 }
 else
 {
   document.getElementById(id1).innerHTML=error_subj;
   document.getElementById(id1).className="info_error";
   document.getElementById(id2).className="fields_error";
   return false;
 }

}

function show_error (id1,id2,error_subj)
{
   document.getElementById(id1).innerHTML=error_subj;
   document.getElementById(id1).className="info_error";
   document.getElementById(id2).className="fields_error";
   return false;
}

function clear_focus(id1,id2)
{
if(id1!='')
document.getElementById(id1).className="info";
document.getElementById(id2).className="fields";
return 0;
}

function set_focus(id1,id2)
{
if(id1!='')
document.getElementById(id1).className="info_focus";
document.getElementById(id2).className="fields_focus";
return 0;
}
//--------------------------------------------------------------------------------------


//---search_js--------------------------------------------------------------------------
function hide_option()
{
	if(document.getElementById("search_by_artist"))
	document.getElementById("search_by_artist").className="notvisible";
	if(document.getElementById("search_by_author"))
	document.getElementById("search_by_author").className="notvisible";
	document.getElementById("search_by_tag").className="notvisible";
	document.getElementById("search_by_name").checked=true;
	
}

function show_option(id)
{
document.getElementById(id).className="search_option";	
}

//---addfriend_js---------------------------------------------------------------------------


function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}

function add_friend ()
{
   var url = "functions/add_friend_ajax.php?friend="; // The server-side script
   friend=document.getElementById("user_nick").innerHTML;	
   http.open("GET", url + escape(friend));
   http.onreadystatechange = handleHttpResponse_friend;
   http.send(null);

}

function handleHttpResponse_friend ()
{
	if(http.readyState==4)
	{
		if(http.responseText==1)
		{
		document.getElementById('subj_window').innerHTML="Пользователь успешно добавлен в друзья.";	
		document.getElementById('subj_window').className="subj_window";
		setTimeout("document.getElementById('subj_window').className=\"notvisible\"", 3000);
		}
		else if (http.responseText==2)
		{
		document.getElementById('subj_window').innerHTML="Пользователь уже в друзьях.";	
		document.getElementById('subj_window').className="subj_window";
		setTimeout("document.getElementById('subj_window').className=\"notvisible\"", 3000);
		}
		else if (http.responseText==0)
		{
		document.getElementById('subj_window').innerHTML="Произошла ошибка, некого добавлять.";	
		document.getElementById('subj_window').className="subj_window";
		setTimeout("document.getElementById('subj_window').className=\"notvisible\"", 3000);
		}
		else if (http.responseText==-1)
		{
		document.getElementById('subj_window').innerHTML="Вы неавторизированы.";	
		document.getElementById('subj_window').className="subj_window";
		setTimeout("document.getElementById('subj_window').className=\"notvisible\"", 3000);
		}
	}
}
//-----------------------------------------------------------------------------------------
