﻿// JScript File
function showNewReviews()
{
    var ele = document.getElementById("NewReviewsBox");
    
    if(ele.style.display == "")
        ele.style.display = "block";
    else
        ele.style.display = "";
}
function showNewRated()
{
    var ele = document.getElementById("NewRatedBox");
    if(ele.style.display == "")
        ele.style.display = "block";
    else
        ele.style.display = "";
}
function FlipPanel(name, colImageName, expandImageName)
{
    PanelSH(name);
    PanelSH(colImageName);
    PanelSH(expandImageName);   
    
}
function PanelSH(name, type)
{

    ele = document.getElementById(name);
    if(type != null && type != undefined)
    {
        ele.style.display = type;
    }
    else
    {
        if(ele.style.display == "" || ele.style.display == "none")
        {
            ele.style.display = "block";
            return "block";
        }
        else
        {
            ele.style.display = "none";
            return "none";
        }
    }
}

function PanelDock(snap, containerId, containerIndex)
{
    PageMethods.DockPanel(snap.ControlId,containerId, containerIndex);
}
function PanelDockGroup(snap, containerId, containerIndex)
{
    PageMethods.DockPanel(snap.ControlId,containerId, containerIndex, groupId);
}
function WasMouseOut(e)
{
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return false;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return false;
	
	return true;
}

function DivExit(e, div)
{
    if(WasMouseOut(e))
        PanelSH(div);
}

function FilterChange(dd, div)
{
    dropDown = document.getElementById(dd);
    if(dropDown.options[dropDown.selectedIndex].value == '=')
        document.getElementById(div).style.display = 'block';
    else
        document.getElementById(div).style.display = 'none';
}
function ChangeClass(divId, newClass)
{
    div = document.getElementById(divId);
    if(div != null)
    {
        div.className = newClass;
    }
}

function SendAjaxRequest(url, callBack, div)
{
    var ar = new AjaxRequest(url, callBack, div);
}

function GetXmlHttpObject() 
{ 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }//if (window.XMLHttpRequest)
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }//else if (window.ActiveXObject)
    return objXMLHttp
}//function GetXmlHttpObject()

function AjaxRequest(url, callBack, div)
{
    this.url = url;
    this.callBack = callBack;
    this.div = div;
    this.xmlHttp = GetXmlHttpObject();
    
    this.OnStateChanged = function()
    {
        if (this.xmlHttp.readyState==4 || this.xmlHttp.readyState=="complete") 
        {
            if(this.callBack != null)
            {
                this.callBack(this.xmlHttp.responseText);
            }//if(this.callBack != null)
            if(this.div != null)
            { 
                this.div.innerHTML = this.xmlHttp.responseText;
            }//if(this.div != null)
        }//if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    }//this.OnReadyStateChange = function() 
    this.GetResponse = function()
    {
        return _this.xmlHttp.responseText;
    }
    this.xmlHttp.onreadystatechange=function()
    {
        _this.OnStateChanged();
    };
    var _this = this;
   this.xmlHttp.open('GET',this.url,true);
   // send request
   this.xmlHttp.send(null);
}//function AjaxRequest(url, callBack, div) 

function Cover(bottom, top, ignoreSize)
{
    var location = Sys.UI.Control.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) 
    {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}
function ConfirmDelete()
{
    return confirm('Are you sure you want to delete this?');
}
function CheckAndText(cb,tb)
{

    if($get(cb).checked && $get(tb).value == "")
    {
        alert('You have selected the private option but did not enter a password.');
        return false;
    }
    return true;    
}

function showPanel(name)
{
    hideAllPanels();
    document.getElementById(name).style.display = "block";
    document.getElementById(name + "Nav").className = name + "Selected fl";
}
function setInfoBackground(color)
{
    document.getElementById("infoBox").className = "infoBox fl " + color + "Background";
}
function CheckRecommendations()
{
    PageMethods.CheckRecommends(userId);
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function GetIframeObjectValue(iframeName, objectName)
{
    var oIframe = document.getElementById(iframeName);
    var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
    if (oDoc.document) oDoc = oDoc.document;
    return oDoc.getElementById(objectName).value
}

var pageLoadFunctions = "";
function pageLoad(sender, e) 
{
    if(pageLoadFunctions != '')
    {
        var sp = pageLoadFunctions.split(',');
        
        for(i=0;i<sp.length;i++)
        {
            if(sp[i] != '')
            {
                try
                {
                    eval(sp[i] + "();");
                }
                catch(err)
                {}
            }
        }
    }
}

var enterHandled = false;
function submitOnEnter(submitBtn) 
{
    var keyCode = document.all ? event.keyCode :evt.which ? evt.which :
    evt.keyCode ? evt.keyCode : evt.charcode;
    if (keyCode == 13) 
    {
        enterHandled = true;
        submitBtn.click();
    }
}
document.onkeypress = suppressEnter;

function suppressEnter()
{
    var keyCode = document.all ? event.keyCode :evt.which ? evt.which :
    evt.keyCode ? evt.keyCode : evt.charcode;
    if(keyCode == 13)
    {
        if(enterHandled)
        {
            enterHandled = false;
            return false;
        }
    }
}

function ChangeUploadType(show, hide, type, hidId)
{
    PanelSH(hide,'none');
    PanelSH(show,'block');
    $get(hidId).value = type;
}

function ShowNewRecommendations(userId, own)
{
    PageMethods.GetRecommends(userId, own, OnDoneShowNewRecs);
    
}

function OnDoneShowNewRecs(result)
{
    $get('recList').innerHTML = result;
    UnHideNewRecs();
}

function UnHideNewRecs()
{
    if($find(openB).get_OnClickBehavior().get_animation().get_isPlaying())
        setTimeout(UnHideNewRecs,100);
    else
        $find(closeB).OnClick();    
}

function PageRated(userId, pageNum, pageSize)
{
    $find(updateB).OnClick();
    PageMethods.PageRatedRecs(userId, pageNum, pageSize, OnDonePageRated);
}

function OnDonePageRated(result)
{
    $get('infoRatedBox').innerHTML = result;
    DoneUpdating();        
}
function DoneUpdating()
{
    if($find(updateB).get_OnClickBehavior().get_animation().get_isPlaying())
        setTimeout(DoneUpdating,100);
    else
        $find(updateB).OnMouseOut();
}

function PageOwned(userId, pageNum, pageSize)
{
    $find(updateB).OnClick();
    PageMethods.PageOwnedRecs(userId, pageNum, pageSize, OnDonePageOwned);
}

function OnDonePageOwned(result)
{
    $get('infoOwnedBox').innerHTML = result;
    DoneUpdating();
}

function PageLatestRatings()
{
    $find(lrB).OnClick();
    PageMethods.PageLatestRatings(OnDoneLatestRatingsPage);
}

function OnDoneLatestRatingsPage(result)
{
    $get('latestDiv').innerHTML = result;
    DoneUpdatingLatestRatings();
}
function DoneUpdatingLatestRatings()
{
    if($find(lrB).get_OnClickBehavior().get_animation().get_isPlaying())
        setTimeout(DoneUpdatingLatestRatings,100);
    else
        $find(lrB).OnMouseOut();
}
function VoteOnPoll()
{
    var answerId = -1;
    var radioButtons = document.getElementsByName(pollId);
    for (var x = 0; x < radioButtons.length; x ++)
    {
        if (radioButtons[x].checked) 
        {
            answerId = radioButtons[x].value;
        }
    }
    
    SendVote(answerId);
}
function SendVote(answerId)
{
    PageMethods.VoteOnPoll(answerId,OnDoneVoting);
}
function OnDoneVoting(result)
{
    $get(pollBodyId).innerHTML = result;
    DoneVoting();
}
function DoneVoting()
{
    if($find(voteStartAB).get_OnClickBehavior().get_animation().get_isPlaying())
        setTimeout(DoneVoting,100);
    else
        $find(voteEndAB).OnMouseOut();
}
