﻿
if (typeof IsVideoPage == 'undefined') IsVideoPage = false;

 var lastX,lastY;
 function ShowMediaInfo(MediaId,e)
   {
    
    var dvGameInfo=document.getElementById('dvGameInfo')
    dvGameInfo.style.display='none'
    dvGameInfo.innerHTML=
    '<div id="dvGameInfo_InnerDiv" style=";background-repeat:no-repeat;background-image:url('+SiteUrl+'images/loading.gif);background-position:center center">&nbsp;</div>';
    if(document.all)
       e=window.event;
    setWait('dvGameInfo',true,400,200,e)
    req= XMLReqObj('get','common/MediaInfo.aspx?ispage=false&MediaId='+MediaId,
                   'CurrentReq','GameInfoCallBackFunction',false)
    if(req!=null)
    {req.send(null)}  
    else
    {
     dvGameInfo.innerHTML='<iframe frameborder=0 width="100%" height="445px" src="'+SiteUrl+'common/MediaInfo.aspx?ispage=true&MediaId='+MediaId+'" style="border:solid 1px #eeeeee;"/>';
    }
   }
   
   function GameInfoCallBackFunction(Response,Error)
   {
   //setWait('dvGameInfo',false)
   if(Error!=null){} 
   document.getElementById('dvGameInfo').innerHTML=Response;
   setTimeout("Centerize(document.getElementById('dvGameInfo'));",100);
   //SetTopLeft(document.getElementById('dvGameInfo'),null,lastX,lastY)
   }
   
   

_RegesterPupupControl('dvGameInfo')




function SetTopLeft(Element,e,x,y)
{
 if(typeof Element=="String")
    Element=getElementById.get(Element)
    //var div=e?e.target:event.srcElement;
    var width  = GetWidth(),
        height = GetHeight();
    
    var ElementWidth=removepx(Element.style.width),
        ElementHeight=removepx(Element.style.height);
    if(Element.clientHeight>0)
       ElementHeight=Element.clientHeight;
    if(Element.clientWidth>0)
       ElementWidth=Element.clientWidth;
    if(e)        
    {
     if(document.all)
      {
        y = event.clientY + GetScrollTop()  + event.offsetY;
        x = event.clientX + GetScrollLeft() - event.offsetX;//25);	
      } 
     else if(e)
      {
      //e.clientY
      //e.pageX
       y=e.clientY+GetScrollTop();
       x=e.clientX+GetScrollLeft();
     }     
    }
    else
     {
      alert(lastX+'-'+lastY)
     }
//    alert(x+'-'+ElementWidth  +'-'+width+'\n'+
//          y+'-'+ElementHeight +'-'+height
//         )
    if(x+ElementWidth>width)
       {
        x=width-ElementWidth;
       }
    if(y+ElementHeight>height)
       {
        //alert(y+'-'+height+'-'+ElementHeight)
        y=height-ElementHeight;
       }
    lastX=x;
    lastY=y
    Element.style.left=x+'px';
    Element.style.top=y+'px';
}




function removepx(value)
{
 return Val(value.replace('px',''));
}

function UpdateRatingValue(item,value)
{
 document.getElementById('r'+item).value=value;
}


function ShowRating(value)
{
 if(typeof value=='undefined ')value=true;
 document.getElementById('tblRatingView').style.display=value?'none':'';
 document.getElementById('tblRating').style.display=value?'block':'none';
}

function RateGame_CallBack(p1,p2)
{ 
if(p2)p1=p2
 //document.getElementById('tblRating').style.display='none';
 //document.getElementById('dvRaring').style.display=''
 document.getElementById('dvRaringContainer').innerHTML=p1
}
 function RateGame()
 {

  var p1=document.getElementById('ddvGraphics').value,
      p2=document.getElementById('ddvSounds').value,
      p3=document.getElementById('ddvQuality').value,
      p4=document.getElementById('ddvEasyToPlay').value;
 InsertWaitInElement('dvRaringContainer');      
 req= XMLReqObj('get','common/do.aspx?what=rate&MediaId='+MediaId+
                '&p1='+p1+
                '&p2='+p2+
                '&p3='+p3+
                '&p4='+p4+
                '&refresh=true'+
                '&dt='+getRndDate(),
                 null,'RateGame_CallBack')
 //document.write('common/do.aspx?what=dolike&MediaId='+MediaId+'&p1='+p)
    if(req!=null)
    {req.send(null)}
  
 }




function AddOpinion_CallBack(p1,p2)
{
 if(p2)p1=p2
 document.getElementById('dvOpinionContainer').innerHTML=p1
}
function AddOpinion(p)
{
  InsertWaitInElement('dvOpinionContainer');
  req= XMLReqObj('get','common/do.aspx?what=addopinion&MediaId='+MediaId+'&p1='+p+'&refresh=true&dt='+getRndDate(),
                   null,'AddOpinion_CallBack')
 //document.write('common/do.aspx?what=dolike&MediaId='+MediaId+'&p1='+p)
    if(req!=null)
    {req.send(null)}
}


function AddVideoOpinion_CallBack(p1, p2) {
    if (p2) p1 = p2
    document.getElementById('dvOpinionContainer').innerHTML = p1
}
function AddVideoOpinion(p) {
    InsertWaitInElement('dvOpinionContainer');
    req = XMLReqObj('get', 'common/do.aspx?what=addvideoopinion&MediaId=' + MediaId + '&p1=' + p + '&refresh=true&dt=' + getRndDate(),
                   null, 'AddVideoOpinion_CallBack')
    //document.write('common/do.aspx?what=dolike&MediaId='+MediaId+'&p1='+p)
    if (req != null)
    { req.send(null) }
}













function write_flash(src, width,height) {
    if (width == 0) {
        width = '';
    }
    else {
        width = ' width="' + width + '" ';
    }
    if (height== 0) {
        height = '';
    }
    else {
        height = ' height="' + height + '" ';
    }
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ' + width + height + '>');
	document.write('<param name="movie" value="' + src + '">');
	document.write('<param name="quality" value="high">');
	document.write('<embed src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ' + width + height + ' menu="0"></embed>');
	document.write('</object>');
}

function write_shockwave(src, width, height) {
    if (width == 0) {
        width = '';
    }
    else {
        width = ' width="' + width + '" ';
    }
    if (height == 0) {
        height = '';
    }
    else {
        height = ' height="' + height + '" ';
    }
	document.write('<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0" ' + width + height + '>');
	document.write('<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'">');
	document.write('<param name="swStretchStyle" value="meet">');
	document.write('<param name="bgColor" value="#000000">');
	document.write('<param name="src" value="' + src + '">');
	document.write('<embed src="' + src + '" ' + width +  height + ' bgColor="#000000" swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'" swStretchStyle="meet" type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/"></embed>');
	document.write('</object>');
}











/*
  COMMENTS
*/
var _Current_Comment_Page=1;
var _Navigate_To_First_Comment=true
function LoadComments(PageNumber,_dontNavigate)
{
 if(!PageNumber)PageNumber=1;
 _Current_Comment_Page = PageNumber

 var what = 'getcomments';
 if (IsVideoPage) what = 'getvideocomments';

 var url = 'common/do.aspx?what=' + what + '&MediaId=' + MediaId + '&PageNumber=' + PageNumber + '&refresh=true&dt=' + getRndDate();
  
 req=XMLReqObj('get',url,null,LoadComments_CallBack,true)
 if(_dontNavigate==false)
    _Navigate_To_First_Comment=false
 else
    _Navigate_To_First_Comment=true;
 if(req!=null)
    {req.send(null)}
}

function LoadComments_CallBack(responseText)
{ 
 _get('MediaComents').innerHTML=responseText
 if(_Navigate_To_First_Comment)location.href='#comments'   
}




function PostMediaComment(perfix) {
 if (CheckCommentBox(perfix,null,null,false)==false)
     return;
  var tbBox=_get(perfix+'_Comment');    
 var id=tbBox.getAttribute('MediaId');
 if(!id)id=MediaId;
 if(!id)return;
 
 var what = 'postcomment';
 if (IsVideoPage) what = 'postvideocomment';
 var url='common/do.aspx?what='+what+'&MediaId='+id+'&refresh=true&dt='+getRndDate();

 if (_get(perfix + '_Name'))
     url += '&name=' + escape(_get(perfix + '_Name').value);
 
 if (!SupportAjaxPost)
 {
  FrameRequestCallBackFunction=PostMediaComment_CallBack
  SendFramePostRequest(url,"comment="+(tbBox.value));
 }
 else
 {
 req=XMLReqObj('post',url,null,PostMediaComment_CallBack,false)
 if(req!=null)
    {req.send("comment="+escape(tbBox.value))}
    else
    {
     FrameRequestCallBackFunction=PostMediaComment_CallBack
     SendFramePostRequest(url,"comment="+(tbBox.value));
    }
 }
 DiscardCommentBox(perfix)
}
function PostMediaComment_CallBack(responseText,Error)
{
 if(Error)
     ShowMessage(Error,MessageType.ERROR)
 else {
   LoadComments(1);  
 }
}


function SpamComment(CommentId) {
    var what = 'spamcomment';
    if (IsVideoPage) what = 'spamvideocomment';
  var url='common/do.aspx?what='+what+'&MediaId='+MediaId+'&CommentId='+CommentId+'&refresh=true&dt='+getRndDate();
 req=XMLReqObj('get',url,null,MediaCommentAlert_CallBack,false)
 if(req!=null)
    {req.send(null)}
}
function RateComment(CommentId,val) {

    var what = 'ratecomment';
    if (IsVideoPage) what = 'ratevideocomment';
 //if(!IsUser)return  ShowMessage(Messages.NotAuthenticated,MessageType.ERROR)
var url='common/do.aspx?what='+what+'&MediaId='+MediaId+'&CommentId='+CommentId+'&rateid='+val+'&refresh=true&dt='+getRndDate();
 req=XMLReqObj('get',url,null,MediaCommentAlert_CallBack,false)
 if(req!=null)
    {req.send(null)}
}

function MediaCommentAlert_CallBack(responseText,Error)
{
 if(Error)
    ShowMessage(Error,MessageType.ERROR)
 else
 {  
  LoadComments(_Current_Comment_Page,false);
  ShowMessage(responseText,MessageType.MESSAGE);
 }
}


function AddToFavorite()
{
    //if(!IsUser)return  ShowMessage(Messages.NotAuthenticated,MessageType.ERROR)
    var what = 'addtofavorite';
    if (IsVideoPage) what = 'addvideotofavorite';
 var url='common/do.aspx?what='+what+'&MediaId='+MediaId+'&Title='+escape(MediaTitle)+'&refresh=true&dt='+getRndDate();
 req=XMLReqObj('get',url,null,AddToFavorite_CallBack,false)
 if(req!=null)
    {req.send(null)}
}
function AddToFavorite_CallBack(responseText,Error)
{
 if(Error)
   { ShowMessage(Error,MessageType.ERROR)}
 else
 {  
  if(responseText=="1")HideFavorite();
 }
}


function RemoveFromFavorite() {
    var what = 'removefromfavorite';
  var id;
  if (arguments.length > 0) {
      id = arguments[0]
      if (!IsValidGuid(id)) {
          what = 'removevideofromfavorite';
      }
  }
  else {
      id = MediaId
      if (IsVideoPage)
      { what = 'removevideofromfavorite'; }
  }
 
 var url='common/do.aspx?what='+what+'&MediaId='+id+'&refresh=true&dt='+getRndDate();
 req=XMLReqObj('get',url,null,RemoveFromFavorite_CallBack,false)
 if(req!=null)
    {req.send(null)}
}
function RemoveFromFavorite_CallBack(responseText,Error)
{
 if(Error)
   { ShowMessage(Error,MessageType.ERROR)}
 else
 {  
  if(responseText=="1")
    if(IsMediaPage==true)
       ShowFavorite();
    else
       location.reload();
       //location.href=location.href;
 }
}
function HideFavorite()
{
_get('dvFavorite').style.display='none';
}
function ShowFavorite()
{
_get('dvFavorite').style.display='';
}





function AddGameView() {
    //req = XMLReqObj('get', 'common/do.aspx?what=addmediaview&MediaId=' + MediaId + '&dt=' + getRndDate(), null, function () { });
    //url, method, data, CallBackFunction
    SendIndividualRequest(
    'common/do.aspx?what=addmediaview&MediaId=' + MediaId + '&dt=' + getRndDate(),
    'get',
    null,
     function () { }
     );
    //if (req != null)    { req.send(null) }
}





var RelatedMediaBox = 'RelatedMediaBox';
function LoadRelatedMedia(target, PageNumber,mediaid) {
    if (!target) RelatedMediaBox = target;
    if (!PageNumber) PageNumber = 1;
    if (!mediaid) mediaid = MediaId;
    var url = 'common/do.aspx?what=getrelatedmedia&MediaId=' + mediaid + '&PageNumber=' + PageNumber + '&target=' + RelatedMediaBox + '&refresh=true&dt=' + getRndDate();
    InsertWaitInElement(RelatedMediaBox);      
    req = XMLReqObj('get', url, null, LoadRelatedMedia_CallBack, true)    
    if (req != null)
    { req.send(null) }
}

function LoadRelatedMedia_CallBack(responseText) {

    _get('RelatedMediaBox').innerHTML = responseText
    location.href = '#related-media'
}
