






var levxmlhttp;
var lvcurheight=1;
var maxheight = 200;
var lvstep = 5; // pixels
var lvprogressteptime = 5 ; // ms
var giftplacecontent = '' ;
var gr = '' ;
var ldropopened = false;

//preloading loader gif
var myloadergif = new Image;
//myloadergif.src='files/ajax-loader.gif' ;

var lvurltoload="";
var lvdestindoc ="" ;
var lvloadgif ="" ;
var lvprocessinggifinst ;
var lvnoprocessgifinst ;



//-------------------------------------------
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];


//function
}



//--------------------start Ajax ------------------------------------------------------------
//--------------------------------------------------------------
function levloadurl(dest, gr )
{
//ajaxresponse.php-in enq uzum uxarkel ev stanal tvjalnery
    try
    {
    // Moz supports XMLHttpRequest. IE uses ActiveX.
    // browser detction is bad. object detection works for any browser
    levxmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
    //alert('Ok, requerst object created!');
    }
    catch (e)
    {
    // browser doesn't support ajax. handle however you want
    alert("Для отправки нужно включить javascript в браузере!");

    }



    // the xmlhttp object triggers an event everytime the status changes
    // triggered() function handles the events
    levxmlhttp.onreadystatechange = levtriggered; //


    // open takes in the HTTP method and url.
    levxmlhttp.open("POST", dest); //
    levxmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded' );

    // send the request. if this is a POST request we would have
    // sent post variables: send("name=aleem&gender=male)
    // Moz is fine with just send(); but
    // IE expects a value here, hence we do send(null);
    levxmlhttp.send( "greet="+gr );  // uxarkum enq tvjalnery . Ete POST-ov uxarkeinq, petq e parametry null-i pocharen popochakannery greinq : send("name=aleem&gender=male)








// function
}





function levtriggered( ) //pop
{


    // if the readyState code is 4 (Completed)
    // and http status is 200 (OK) we go ahead and get the responseText
    // other readyState codes:
    // 0=Uninitialised 1=Loading 2=Loaded 3=Interactive

    if ( levxmlhttp.readyState == 0  )
    {
    //document.getElementById("info_l").innerHTML = "Uninitialised!" ;


    }


    if ( levxmlhttp.readyState == 1 )
    {
    //document.getElementById("info_l").innerHTML = "loading..." ;
    //alert("Started loading...");
    //document.getElementById("giftloader").src = myloadergif.src ;
    }


    if ((levxmlhttp.readyState == 4) && (levxmlhttp.status == 200))
    {
    // xmlhttp.responseText object contains the response.
    //document.getElementById("output").innerHTML = xmlhttp.responseText;
    document.getElementById("giftloader").src = 'files/spacer.gif' ;

      if(levxmlhttp.responseText=='1' || levxmlhttp.responseText=='2'     )
      {
      alert("Внутренняя ошибка 157 !");
      return ;
      }

      if(levxmlhttp.responseText=='4' || levxmlhttp.responseText=='5' || levxmlhttp.responseText=='6'     )
      {
      alert("Внутренняя ошибка 158 !");
      return ;
      }

      if(levxmlhttp.responseText=='8'  )
      {
      alert("Внутренняя ошибка 159 !");
      return ;
      }

      if(levxmlhttp.responseText=='14'  )
      {
      alert("Нельзя отправить подарок себе!");
      return ;
      }

      if(levxmlhttp.responseText=='11' )
      {
      alert("Пользователь с таким логином не найден!");
      return ;
      }
      //success
      if(levxmlhttp.responseText=='success' )
      {
      alert("Ваш виртуальный подарок отправлен!");
      //$("div#giftplace").slideUp("slow");

      return ;
      }
      else
      {
      //alert( "Внутренняя ошибка 731!.\n Пожалуйста, заходите в свой аккоунт" ); //   "Неизвестная ошибка!"
      alert(levxmlhttp.responseText);
      return ;
      }



    //if is sent request
    }






//function
}

//< gift



//account --------------------------------------

// lvurltoloadparam - url to load,
// lvdestindocparam - ID of the element where to insert the response content
// lvloadgifparam - id of the loading animated gif gif
// lvpostdataparam - whole post string to unsert i.e, paam1=value1&param2=value2...
function lvloadurl( lvurltoloadparam, lvdestindocparam, lvloadgifparam, lvprocessinggifinstparam, lvnoprocessgifinstparam, lvpostdataparam )
{
//ajaxresponse.php-in enq uzum uxarkel ev stanal tvjalnery
//alert("Lvloadurl");


    try
    {
    // Moz supports XMLHttpRequest. IE uses ActiveX.
    // browser detction is bad. object detection works for any browser
    levxmlhttploadurl = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
    //alert('Ok, requerst object created!');
    }
    catch (e)
    {
    // browser doesn't support ajax. handle however you want
    alert("Для отправки нужно включить javascript в браузере!");

    }


lvurltoload = lvurltoloadparam;
lvdestindoc = lvdestindocparam;
lvpostdata = lvpostdataparam;
lvloadgif = lvloadgifparam;
lvprocessinggifinst = lvprocessinggifinstparam;
lvnoprocessgifinst = lvnoprocessgifinstparam;



    // the xmlhttp object triggers an event everytime the status changes
    // triggered() function handles the events
levxmlhttploadurl.onreadystatechange = lvtriggered; //


    // open takes in the HTTP method and url.
levxmlhttploadurl.open("POST", lvurltoload ); //
levxmlhttploadurl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded' );


    // send the request. if this is a POST request we would have
    // sent post variables: send("name=aleem&gender=male)
    // Moz is fine with just send(); but
    // IE expects a value here, hence we do send(null);
levxmlhttploadurl.send( lvpostdata );  //




// function
}







function lvtriggered(  ) //pop
{

/*
lvurltoload = lvurltoloadparam;
lvdestindoc = lvdestindocparam;
lvloadgif = lvloadgifparam;
lvpostdata = lvpostdataparam;
*/


    // if the readyState code is 4 (Completed)
    // and http status is 200 (OK) we go ahead and get the responseText
    // other readyState codes:
    // 0=Uninitialised 1=Loading 2=Loaded 3=Interactive

    if ( levxmlhttploadurl.readyState == 0  )
    {
    //document.getElementById("info_l").innerHTML = "Uninitialised!" ;


    }


    if ( levxmlhttploadurl.readyState == 1 )
    {
    //document.getElementById("info_l").innerHTML = "loading..." ;
    //alert("Started loading...");
    document.getElementById(lvloadgif).src = lvprocessinggifinst.src ;
    }


    if ((levxmlhttploadurl.readyState == 4) && (levxmlhttploadurl.status == 200))
    {
    // xmlhttp.responseText object contains the response.
    document.getElementById(lvloadgif).src = lvnoprocessgifinst.src ;
    document.getElementById(lvdestindoc).innerHTML  = levxmlhttploadurl.responseText;
    //if is sent request
    }






//function
}














//< account


// end of ajax ------------------------------------------------------------












function ldropslowclick()
{

   if(ldropopened==false)
   {
   ldropslow();
   }
   else if(ldropopened==true )
   {
   lvcloseslow();
   }




//function
}




function ldropslow(  )
{



  if( lvcurheight<maxheight && lvcurheight>0 )
  {
  document.getElementById('lvslowdrop1').style.height=lvcurheight+"px" ;
  setTimeout("ldropslow()", lvprogressteptime  );
  lvcurheight+=lvstep ;
  }
  else if(lvcurheight<=0 )
  {
  lvcurheight = 1 ;
  document.getElementById('lvslowdrop1').style.height=lvcurheight+"px" ;
  setTimeout("ldropslow()", lvprogressteptime  );
  lvcurheight+=lvstep ;
  }
  else
  {
  ldropopened=true;
  return;
  }



}



function lvcloseslow()
{

  if( lvcurheight>=1 )
  {
  document.getElementById('lvslowdrop1').style.height=lvcurheight+"px" ;
  setTimeout("lvcloseslow()", lvprogressteptime );
  lvcurheight-= lvstep ;
  }
  else
  {
  ldropopened=false;
  return;
  }




//function
}




function displaylpersonalblock()
{
//alert("Display");
$("#lpersonalblock").hide().slideDown("slow");
}




function hidelpersonalblock( param1, param2, param3, param4, param5, param6 )
{

/*
$("#lpersonalblock").animate({

        opacity: 0.1,

      }, 1000,



function(){
  lvloadurl(param1, param2, param3, param4, param5, param6);
 }

);

*/

$("#lpersonalblock").hide();
lvloadurl(param1, param2, param3, param4, param5, param6);
lvtimer=setTimeout("displaylpersonalblock()", 1000 );




//function
}








//----------------------------------------------
function hidegiftplaceholder()
{
//document.getElementById("giftplace").style.visibility = "hidden";
$("div#giftplace").slideUp("slow");

}







//---------------------------------------------------------------------------------------
// send ajax requests ----------------------------------------------------------------
function lsendrequestgift( )
{



$( ".sendlinkclass" ).each(

    // For each hottie, run this code. The "indIndex" is the
    // loop iteration index on the current element.
    function( intIndex ){

    // Bind the onclick event to simply alert the
    // iteration index value.
    $( this ).show();

    }

 );



var pecipvalue = document.getElementById("rectoid").value;
var sendervalue = document.getElementById("senderid").value ;
var giftidvalue = document.getElementById("giftidid").value;
var gr = document.getElementById("greetingid").value;

//alert("uxarkum enq "+pecipvalue+" in, \nuxarkox:"+sendervalue+"\n nver:"+giftidvalue+"\n message: "+gr  );


  if( !pecipvalue )
  {
  alert("Пожалуйста, введите логин(имя пользователя) получателя виртуального подарка");
  return;
  }
  if( !sendervalue )
  {
  alert("ошибка 158");
  return;
  }
  if( !giftidvalue )
  {
  alert("ошибка 159");
  return;
  }


  //alert("gift id:"+giftidvalue+" sender: "+sendervalue+" recipient: "+pecipvalue );





//return;
//pecipvalue = escape( pecipvalue );
//pecipvalue = encodeURI( pecipvalue );
pecipvalue = encodeURIComponent( pecipvalue );
gr = encodeURIComponent( gr );

levloadurl( "lvajaxprocess.php?mode=virtualgift&rec="+pecipvalue+"&sender="+sendervalue+"&giftid="+giftidvalue, gr );


//function
}








//-------------------------------------------------------------
function display_send_gift( event, giftnid, useruid )
{

  if( !useruid)
  {
  alert( "Нужно зайти в свою учетную запись, прежде чем отправить виртуальный подарок!"  );
  return;
  }



$( ".sendlinkclass" ).each(

    // For each hottie, run this code. The "indIndex" is the
    // loop iteration index on the current element.
    function( intIndex ){

    // Bind the onclick event to simply alert the
    // iteration index value.
    $( this ).show();

    }

 );




 $( ".lgiftplace1" ).each(

    // For each hottie, run this code. The "indIndex" is the
    // loop iteration index on the current element.
    function( intIndex ){

    // Bind the onclick event to simply alert the
    // iteration index value.
    $( this ).hide('slow').remove();

    }

 );







/*
//scroll
var scrollarray = getScrollXY() ;
var x = scrollarray[0];
var y = scrollarray[1];

//alert(document.getElementById("giftplace") );

        if(document.getElementById("giftplace"))
        {
        document.getElementById("giftplace").style.visibility="hidden" ;
        document.getElementById("giftplace").setAttribute("id", "" );
        }
        if(document.getElementById("senderid"))
        {
        //alert("senderid kar");
        document.getElementById("senderid").setAttribute("id", "" );
        }
        if(document.getElementById("giftidid"))
        {
        //alert("giftidid kar");
        document.getElementById("giftidid").setAttribute("id", "" );
        }
        if(document.getElementById("rectoid"))
        {
        //alert("rectoid kar");
        document.getElementById("rectoid").setAttribute("id", "" );
        }





//---------------------------------------

var placehldraddgift = document.createElement('div'); //
placehldraddgift.id = 'giftplace' ;
document.body.appendChild(placehldraddgift);
document.getElementById("giftplace").style.border='1px solid #ADC923';
document.getElementById("giftplace").style.fontFamily= "Verdana, Arial" ;
document.getElementById("giftplace").style.fontSize= "12px";
document.getElementById("giftplace").style.color = "#B5544B";
document.getElementById("giftplace").style.backgroundColor='#F3EEDA';
document.getElementById("giftplace").style.position= 'absolute';
document.getElementById("giftplace").style.padding='10px';
document.getElementById("giftplace").style.textAlign='right';
document.getElementById("giftplace").style.left= (event.clientX+x)+"px" ;
document.getElementById("giftplace").style.top= (event.clientY+y)+"px" ;
giftplacecontent = "<form accept-charset='UTF-8' >Логин(имя пользователя)<br>получателя:<br><input type=text value='' name='rec_to' id='rectoid' />&nbsp;<br />" ;
giftplacecontent += "<input type='hidden' value='"+useruid+"' name='sender' id='senderid'  />" ;
giftplacecontent += "<br>Комментарий<br>(необязательно):<br><textarea name='greeting' id='greetingid'  cols=30 rows=3 style='font-size:12px; ' ></textarea>" ;
giftplacecontent += "<input type='hidden' value='"+giftnid+"' name='giftid' id='giftidid'  /> " ;
giftplacecontent += "<br /><br /><center><input type='button'  value=' Отправить ' onclick='javascript:lsendrequestgift( )' /></center></form>";
giftplacecontent += "<img id='giftloader' src='files/spacer.gif'  />";
giftplacecontent += "<span style='cursor:pointer; font-family:Arial; font-size:14px; font-weight:bold; color:#DA9786; padding:3px; border:1px solid #ADC923' onclick='javascript:hidegiftplaceholder()' onmouseover='javascript:this.style.backgroundColor=\"#FFFFFF\" ' onmouseout='javascript:this.style.backgroundColor=\"#F3EEDA\" '    >&nbsp;X&nbsp;</span>";

document.getElementById("giftplace").innerHTML=giftplacecontent ;
//document.getElementById("giftplace").style.visibility= "hidden" ;
document.getElementById("giftplace").style.display = "none" ;
*/

var htmltogiftplace = '<div class="lgiftplace1" id="giftplace" style="font-family: Verdana, Arial; font-size:12px; width:220px; display:none;"  > ';

htmltogiftplace += "<form accept-charset='UTF-8' >Логин(имя пользователя) получателя:<br><input style = 'border:1px solid #ADC923' type=text value='' name='rec_to' id='rectoid' />&nbsp;<br />" ;
htmltogiftplace += "<input type='hidden' value='"+useruid+"' name='sender' id='senderid'  />" ;
htmltogiftplace += "Комментарий(необязательно):<br><textarea name='greeting' id='greetingid'  cols=30 rows=3 style='font-size:12px; border:1px solid #ADC923; ' ></textarea>" ;
htmltogiftplace += "<input type='hidden' value='"+giftnid+"' name='giftid' id='giftidid'  /> " ;
htmltogiftplace += "<br /><br /><center><input type='button' style = 'border:1px solid #ADC923' value=' Отправить ' onclick='javascript:lsendrequestgift( )' onmouseover='javascript:this.style.backgroundColor=\"#FFFFFF\" ' onmouseout='javascript:this.style.backgroundColor=\"#F3EEDA\" ' /></center></form>";
htmltogiftplace += "<img id='giftloader' src='files/spacer.gif'  />";
//htmltogiftplace += "<span style='cursor:pointer; font-family:Arial; font-size:14px; font-weight:bold; color:#DA9786; padding:3px; border:1px solid #ADC923' onclick='javascript:hidegiftplaceholder()' onmouseover='javascript:this.style.backgroundColor=\"#FFFFFF\" ' onmouseout='javascript:this.style.backgroundColor=\"#F3EEDA\" '    >&nbsp;X&nbsp;</span>";

htmltogiftplace += "</div>";


$( "#g"+giftnid ).append(htmltogiftplace);

$("#giftplace").slideDown("slow");



$("#sendlink"+giftnid).hide();







//function
}
