﻿var browser = navigator.appName;
var iframeObject;
var infoDivTimerId=null;
var progressbarIntervalObj =null;
function funContactUs()
{
    document.getElementById("divContactUs").style.display = 'block';
}

function funAdvertise()
{
    oDiv = document.getElementById("divAdvertise");
    if (oDiv != null)
    {   
        oDiv.style.display = 'block';
    }
    else 
    {
        parent.document.getElementById("divAdvertise").style.display = 'block';        
    }
}

function loadAdvertiseDay(monthSelected)
{
    var dd = new Date('2008', monthSelected, 0);
    //alert(dd.getDate())
    var oDay = document.getElementById("ddlAdvertiseDay");
    oDay.length = 1;
    for (index=1; index <= dd.getDate(); index++)
    {
        oDay.options.add(new Option(index));
    }
}

function saveAdvertiseDay(daySelected)
{
    document.getElementById("hdnSelectedDay").value = daySelected.options.selectedIndex;
}

function funCancel(objId)
{
    switch (objId)
    {
        case "divContactUs" :
            document.getElementById("txteContactUsSendList").innerText = "Enter your request here";
            document.getElementById(objId).style.display = "none";
            break;
        case "divForgetPassword" :
            document.getElementById(objId).style.display = "none";
            break;
        case "divAdvertise" :
            document.getElementById(objId).style.display = "none";
            break;
        default :
            break;
    } 
}
function funSendContactUs()
{
    if(document.getElementById("txteContactUsSendList").innerText != 'Enter your request here')
    {
        doAjaxRequest(buildAjaxContactUs(document.getElementById("txteContactUsSendList").innerText),{method:"GET", onFailure:ajaxFailure});
        document.getElementById("txteContactUsSendList").innerText = 'Enter your request here';
        divContactUs.style.display = 'none';
    }
}
function buildAjaxContactUs(message)
{
    var ajaxCommand = "ajaxFunctionID=21&param=" + message;
    return ajaxCommand;
}

function closeDivSongListitem()
{
    var ifrmWork = parent.document.getElementById("ifrmWork");
    ifrmWork.contentWindow.document.getElementById("divRegistery").style.display = "none";
}

function funVote(obj)
{
    var artistId = "";
    if (browser == "Microsoft Internet Explorer")
        artistId = obj.artistId;
    else
        artistId = obj.attributes[0].nodeValue;
    doAjaxRequest(buildAjaxVote(obj.value, obj.id, artistId),{method:"GET",onSuccess:ajaxVoteSuccess, onFailure:ajaxFailure});
}

function buildAjaxVote(songId, objId, artistId)
{
    var ajaxCommand = "ajaxFunctionID=25&param=" + songId + ";" + objId + ";" + artistId;
    return ajaxCommand;
}

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function ajaxVoteSuccess(oReq)
{
    var oTop = 0, oLeft = 0;

    var ifrmWork = parent.document.getElementById("ifrmWork");
    var ajaxReturnValue = oReq.responseText.split("*~~*");
    var splitAjaxReturnValue = ajaxReturnValue[0].split(";"); 
    if (splitAjaxReturnValue[1] == "false")
    {
        var strObjId = splitAjaxReturnValue[0].split('_');
        
        var oDiv =  ifrmWork.contentWindow.document.getElementById("divRegistery");
        var oLbl;
        if (ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + "lbtnSongVote") != null)
        {
            oLbl = ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + "lbtnSongVote");
        }
        else
        {
            oLbl = ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + strObjId[3] + "_" + strObjId[4] + "_" + "lbtnSongVote");    
        }
        oDiv.style.top = findPosY(oLbl);
        oDiv.style.left = findPosX(oLbl) - 200;
        oDiv.style.display = "block";
    }
    else if (ajaxReturnValue[0] == "wasChecked")
    {
    
    }
    else
    {
        var strObjId = splitAjaxReturnValue[0].split('_');
        if (strObjId.length > 4)
        {
            ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + strObjId[3] + "_" + strObjId[4] + "_" + "lblSongVote").innerText = parseInt(ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + strObjId[3] + "_" + strObjId[4] + "_" + "lblSongVote").innerText) + 1;
            var oSongVote =  ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + strObjId[3] + "_" + strObjId[4] + "_" + "lbtnSongVote");
        }
        else
        {
            ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + "lblSongVote").innerText = parseInt(ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + "lblSongVote").innerText) + 1;
            var oSongVote =  ifrmWork.contentWindow.document.getElementById(strObjId[0] + "_" + strObjId[1] + "_" + strObjId[2] + "_" + "lbtnSongVote");
        }
        oSongVote.src = "ImagesApp/Voted.gif";
        oSongVote.onclick = "";
        oSongVote.style.cursor = "default";
        oSongVote.alt = "Thanks for your vote.";
    }
}

 
 

 


function fade(domId){
 obj = document.getElementById(domId);
 if(obj.style.display == "none")  return false; //Return false if the element is already hidden
 
 var alpha = 10; //Set the initial value of alpha to 10 (Opaque)
 function f(){ //Internal function

  alpha--; //Decrement the alpha value
  setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha

  if(alpha > -1){ //If alpha is still bigger than -1 then..
   setTimeout(f, 100); //..then call the function again after 100 milliseconds

  }else{ //otherwise..
   obj.style.display = 'none'; //..otherwise now that we cant see the element anyways, hide it

  }
}
setTimeout(f, 100); //This is where we call the f() function for the first time

};

function setOpacity(domId, val) {
obj = document.getElementById(domId);
obj.style.MozOpacity = val;
obj.style.opacity = val/10;
obj.style.filter = 'alpha(opacity=' + val*10 + ')';

};

function appear(domId){
obj = document.getElementById(domId); //Get the element

 if(obj.style.display != "none") return false; //Return if it is already being displayed

 obj.style.display = ''; //Un-hide the object before its animation
 var alpha = 0; //Set the initial value of alpha to 0 (invisible)

 function a(){ //Internal function
  alpha++; //Increment alpha

  setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha
  if(alpha < 11)setTimeout(a, 100);

/*Till alpha is 10, keep calling the
a() function after 100 milliseconds */
}
setTimeout(a, 100); //This is where we call the a() function for the first time

};
//function that pass parameter to the main iframe  and make postback to the updatepanel inside the iframe
    function chooseGenre(genre,obj,document1)
    {    
    
         for (i=1;i<50;i++)
         {
         
         document1.getElementById('ahref' + i).style.color='White';
         document1.getElementById('ahref' + i).style.fontSize=12;
         }
           obj.style.color='black';
          obj.style.fontSize=18;
        if (document.all)
        {
               var iframeObject = parent.window.frames['ifrmWork'];
        }
        else
            var iframeObject = parent.window.frames[0];
      
       var pagenameArr= parent.window.frames[0].location.pathname.split('/');
       var pagename=pagenameArr[pagenameArr.length-1];
       if (pagename.toLowerCase() != "musiclist.aspx") {
           window.document.frames[0].location = "musiclist.aspx?genreId=" + genre+"&comefromout=true";
          
       }
       else
        iframeObject.__doPostBack('UpdatePanel1', 'Genre;' + genre);
     	
    }
 // implementation for the list view voting button (DataGrid Control "dgSonglist")
   function popUpRegisterDiv(obj,X,Y)
{
 
    var divregister= document.getElementById('divRegistery')
    var x = findPosX(obj);
    var y = findPosY(obj);
       divregister.style.top = y+Y;
       divregister.style.left = x+X;
         divregister.style.display='block';
     

}

  function popUpRegisterDivforSearchResult(obj)
{
  
  var divregister= document.getElementById('divRegistery')
    var x = findPosX(obj);
    var y = findPosY(obj);
         divregister.style.top = y-75;
         divregister.style.left = x-290;
         divregister.style.display='block';
     

}
 //this function implement the dgsonglist voted Image
  function changeVoteImageToVoted(obj)
  {
    obj.src='ImagesApp/Voted.gif';
    obj.disabled=true;
  }
   //this function implement the SearchDataList voted Image
  function changeVoteImageToVotedOnSearchDL(obj)
  {
    obj.src='ImagesApp/Icons/Play.png';
    obj.disabled=true;
  }
   //this function implement the SearchDataList voted Label
  function changeVoteLabelToVotedOnSearchDL(obj,str)
  {
   obj.innerHtml=str;
   obj.innerText=str;
  }
  //this function implement the dgsonglist voted Label
  function changeVoteLabelToVoted(obj)
  {
   obj.innerHtml=(obj.addToCurrentVote);
   obj.innerText=(obj.addToCurrentVote);
  }
  //when click on another page than musiclist the main datalist in music list is reseting , so there is need to reset 
  //the icon (cards/List) as well .. for this ,use resetModeIconToCards()


  
   function resetGenres()
   {
   for (i=1;i<50;i++)
         {
           parent.document.getElementById('ahref' + i).style.color='White';
           parent.document.getElementById('ahref' + i).style.fontSize=12;
         }
    }
 
    
  
     //upload button eventHandler , button location : main search toolbar 
  function uploadButtonClick(obj)
  {
     var div = document.getElementById('uploadWizard');
     div.style.display="block"; 
  }
  
 
  
   function updatePosition(obj) 
   {
     obj.style.top = (window.screenTop-600)*(-1);
   }
   
   function LoadEmbedDiv(obj,songid,artistname,songname)
   {
    var divEmbed = document.getElementById('divEmbed');
    var x = findPosX(obj);
    var y = findPosY(obj);
    divEmbed.style.top = y-185;
    divEmbed.style.display="block";
    var codeTextArea = document.getElementById('embedCodeArea'); 
    var songNamespan = document.getElementById('embedSongNameSpan');
    var artistNamespan=document.getElementById('embedArtistSpan');
    var embedcode= '<object type="application/x-shockwave-flash" allowScriptAccess="never" allowNetworking="internal" height="200" width="400"  <param name="allowScriptAccess" value="sameDomain" />   <param name="wmode" value="transparent" /> <param name="allowNetworking" value="internal" />   <param name="movie" value="http://www.jumbey.com/WebServices/WidgetPlayer/Swf/JumbeyPlayer.swf?trackid=' + songid +'&autoplay=false" /> data="http://www.jumbey.com/WebServices/WidgetPlayer/Swf/JumbeyPlayer.swf?trackid=' + songid +'&autoplay=false"></object> ';
    codeTextArea.value=embedcode;
    songNamespan.innerHTML=songname;
    artistNamespan.innerHTML=artistname;
  }
 function onClientPlayClick(songid, songname) 
    {
           
// need to be changed		  " parent.playThisSong('" + songid + "', '" + songname.Replace("'", "") + "', '" + "" + "', '" + "" + "', '" + "" + "', '" + "" + "')";
	}
	
	function onClientAddClick(songid, songname) {
		alert('Add'+ songid);
		alert('Add'+ songname);
	}
	
	function onClientVoteClick(songid, songname) {
		alert('Vote'+ songid);
		alert('Vote'+ songname);
	}

 function SetChooseSortItem(obj)
 {
   switch (obj.id)
   {
    case  'sortByMostVoted' :
    {
        document.getElementById('sortByMostVoted').className='sortBybarItemChoosed';
        document.getElementById('sortByA-Z').className='sortBybar';
        document.getElementById('sortByNewSong').className='sortBybar';
    }
     
   break;
   
     case  'sortByA-Z' :
    {
         document.getElementById('sortByMostVoted').className='sortBybar';
         document.getElementById('sortByA-Z').className='sortBybarItemChoosed';
         document.getElementById('sortByNewSong').className='sortBybar';
    }
    break;
     case  'sortByNewSong'  :
    {
         document.getElementById('sortByMostVoted').className='sortBybar';
         document.getElementById('sortByA-Z').className='sortBybar';
         document.getElementById('sortByNewSong').className='sortBybarItemChoosed';
    }
    break;
   }
 }
 //home Page Redirection 
function fnHomePage()
{
 parent.window.frames[0].location = 'http://www.jumbey.com/musiclist.aspx';
  
}
function hideOrShowItem(elementid,page,show)
{
var item = null; 
switch(page)
{
case 'this': {item=this.document.getElementById(elementid); } 
break;
case 'parent': {item=parent.document.getElementById(elementid);  } 
break;
} 
if (show)
item.style.display='block';
else 
item.style.display='none'; 
};
   function mainPageLoad()
   {
        var s1 = new SWFObject('player.swf', 'mpl','450','20','9','#');
               s1.addParam('allowfullscreen','false');
               s1.addParam('allowscriptaccess','always');
               s1.addParam('flashvars','autostart=true&frontcolor=111111&lightcolor=111111&screencolor=111111&repeat=list');
               s1.write('mediaspace'); 
       
   }
   //set genre for the link panel on SongListItem -cards 
   function SetGenre(genre)
   {
     var iframeObject = parent.window.frames[0];
     iframeObject.__doPostBack('UpdatePanel1','Genre;' + genre);
     resetGenres();
     //set the current genre 
     parent.window.document.getElementById('ahref' + genre).style.color='black';
     parent.window.document.getElementById('ahref' + genre).style.fontSize=18;
 }
 function boldGenre(genreid) {
    
     //set the current genre 
     parent.document.getElementById('ahref' + genreid).style.color = 'black';
     parent.document.getElementById('ahref' + genreid).style.fontSize = 18;
 }
 function checkProgressPanelVisiblity()
 {
 var iframeObject = parent.window.frames[0];
 if (iframeObject.document.getElementById('UpdateProgress1').style.display!="none")
     parent.document.getElementById('PanelLoading1').style.display='block';// parent.document.getElementById('PanelLoading1').style.display="block";
 else 
         parent.document.getElementById('PanelLoading1').style.display='none';
 
 }
   function UpdateProgressDiv(Message,timer)
   {
   if (timer>0)
   {
   //show div 
    parent.document.getElementById('progressDiv').style.display='block';
    parent.document.getElementById('LoadingProgressImage').style.display='none';
   //set interval and close it 
        if (infoDivTimerId!=null)
          clearTimeout(infoDivTimerId);
          
          infoDivTimerId =setTimeout("parent.document.getElementById('progressDiv').style.display='none';parent.document.getElementById('LoadingProgressImage').style.display='none';",timer);
      }    
       else if (timer==0)
              {
               //show div  always visible
                parent.document.getElementById('progressDiv').style.display='block';
               parent.document.getElementById('LoadingProgressImage').style.display='block';
         }
         else 
         {
            parent.document.getElementById('progressDiv').style.display='none';
            parent.document.getElementById('LoadingProgressImage').style.display='none';
         }
     
    if (document.all)
  { 
     parent.document.getElementById('ProgressPrecentLabel').innerText=Message;
    
  }
  else 
  {
     parent.document.getElementById('ProgressPrecentLabel').textContent=Message;
     
  }
 
 }   
  
 function ForgotPasswordClick()
 {
  if(RegularExpressionValidatorForgotPassword.isvalid && RequiredFieldValidatorForgotPassword.isvalid)
  {
   UpdateProgressDiv("Please wait...",0);
   email  = parent.document.getElementById('txtEmail');
   parent.PageMethods.ForgotPasswordHandler(email.value,ForgotPasswordClickSucceededHandler,ForgotPasswordClickFailedHandler);
   }
 }
 function UpdateMusicListUpdatePanel()
 {
 var iframeObject = parent.window.frames[0];
     iframeObject.__doPostBack('UpdatePanel1','');
 
 }
 function AdvertiseClick()
 {
  // add validators 
  if (rfvCompanyName.isvalid &&rfvConatcatMan.isvalid&&RevAdvertiseMail.isvalid)
  {
       UpdateProgressDiv("Please wait...",0);
       var txtCompanyName=parent.document.getElementById('txtCompanyName').value;
       var txtContactName=parent.document.getElementById('txtContactName').value;
       var txtEstimatedBudget=parent.document.getElementById('txtEstimatedBudget').value;
       var txtAdvertiseEmail=parent.document.getElementById('txtAdvertiseEmail').value;
       var txtMore=parent.document.getElementById('txtMore').value;
       parent.PageMethods.AdvertiseHandler(txtCompanyName,txtContactName,txtEstimatedBudget,txtAdvertiseEmail,txtMore,AdvertiseSucceedHandler,AdvertiseFailedHandler);
   }
 }
 function fnSetBorder(flag,obj)
 {
 if (flag)
  {
    obj.style.border='1px solid #6487AE';
  }
  else 
  obj.style.border='0px';
 }
  function divlogin_isValid()
  {
   if(parent.$get('RequiredFieldValidatorPasswordDiv').isvalid && parent.$get('RequiredFieldValidatorTextBoxEmailAddress').isvalid && parent.$get('RegularExpressionValidator1').isvalid) 
   return true;
   else 
   return false;
  }
