﻿
var calendarItemOldBG;
var activeCoverDiv = null;

function onOtherKeyPress(cbName, tf)
{
	var cb = findElement(cbName);
	cb.checked = !(tf.value == null || tf.value == "");
}

function getSelectedTemplates()
{
	var sel = "";
	for(var i=0;i<100;i++)
	{
		var name = "template" + i + "checkbox";
		var elm = findElementExact(name);
		if (elm == null)
		{
			return sel;
		}
		
		if (elm.checked)
		{
			if (sel != "") sel = sel + ",";
			sel = sel + elm.value;
			if (elm.value == 0){
				sel = sel + "|" + findElement("otherEventTextBox").value;
			}
		}
	}
	
	return sel;
	
}

function clickButtonOnEnter(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                 
                    //    bt.click(); 
                        __doPostBack(buttonid,'');
						e.returnValue = false; 
                  } 
            } 
            else if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
					__doPostBack(buttonid,'');
					event.returnValue = false; 
                  } 
            } 
      } 
} 

	function __forceDoPostBack(eventTarget, eventArgument) {
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
			theform = document.forms["UserData"];
		}
		else {
			theform = document.UserData;
		}
	
		
		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
	}
	
	function autoFitFrame(name)
	{

		if (parent != null)
		{	
			var elm = parent.document.getElementById(name);
		
	//	alert(parent.document.body.offsetHeight);
			if (elm != null)
			{
				var height = 50;
				if (!window.opera && !document.mimeType && document.all && document.getElementById)
				{
					height = this.document.body.offsetHeight;
				}
				else if(document.getElementById) 
				{
					height=this.document.body.scrollHeight;
				}
				height = height + 30;
				
				elm.style.height = height + "px";
			}
		}
	}
	
	function adjustIFrameSize (iframeWindow) 
	{
		if (iframeWindow.document.height) 
		{
			var iframeElement = parent.document.getElementById(iframeWindow.name);
			iframeElement.style.height = iframeWindow.document.height + 'px';
			iframeElement.style.width = iframeWindow.document.width + 'px';
		}
		else if (document.all) 
		{
			var iframeElement = parent.document.all[iframeWindow.name];
			if (iframeWindow.document.compatMode &&
			 iframeWindow.document.compatMode != 'BackCompat') 
			{
				iframeElement.style.height = 
					iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
				iframeElement.style.width = 
					iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
			}
			else {
				iframeElement.style.height = 
				iframeWindow.document.body.scrollHeight + 5 + 'px';
				iframeElement.style.width = 
				iframeWindow.document.body.scrollWidth + 5 + 'px';
		}
	}
}

function IsNetscape(){
	return !document.all;
}

function getAllElements(type)
{
	if (document.all)
	{
		return document.all;
	}
	
	return document.getElementsByTagName(type);	

}

function findElement(name, type)
{
	if (type == null)
	{
		type = "INPUT";
	}
	
	var elements = getAllElements(type);
	
	for (var i=0;i<elements.length;i++)
	{
		var elm = elements[i];
		var itemName = elm.name;
		if (itemName != null && itemName.indexOf(name) >= 0){
			return elm;
		}
		
		itemName = elm.id;
		if (itemName != null && itemName.indexOf(name) >= 0){
			return elm;
		}
	}
	return null;
}

function findElementExact(name, type)
{
	if (document.all)
	{
		return document.all[name];
	}
	
	return findElement(name, type);
	
}

function TogggleStyle(td, isPressed)
{

    if (isPressed)
    {
        td.style.backgroundColor="#808080";
        td.style.color="#ffffff";
    }
    else
    {
        td.style.backgroundColor="#cccccc";
        td.style.color="#666666";
    }       
}

function DisplayError(msg)
{
	var elm = findElementExact('ErrMsgLabel');
	if (elm != null)
	{
		elm.innerText = msg;
	}
	else
	{
		window.status=msg;
	}
}


function DisplayStatus(msg)
{
	var elm = findElementExact('StatusLabel');
	if (elm != null)
	{
		elm.innerText = msg;
	}
	else
	{
		window.status=msg;	
	}
}



function AdjustContactsScrollHeight(mainElementID, divID)
{  

    var elm = findElement(divID);
    var mainElm =findElement(mainElementID);
    if(elm != null && mainElm != null){
	 elm.style.height = mainElm.offsetHeight;
	}
}
var origClassName;
var activeCell = null;

function showWorking(elm)
{
    elm.style.cursor='wait';
 //   findElement('HTMLBody').style.cursor='wait';
}

function hideWorking()
{
    findElement('HTMLBody').style.cursor='pointer';
}

function onOverCell(cell)
{
	if (activeCell != cell)
	{
	    activeCell = cell;
	    origClassName = cell.className;
	    cell.className = 'hoverCell';
	}
}

function onOutCell(cell)
{
	if (activeCell == cell)
	{
		activeCell = null;
		cell.className = origClassName;
	}
}


function onSelChange(combo, editClientID)
{
	var edit = findElement(editClientID);
	if(combo.selectedIndex == 1)
	{
	    combo.style.visibility = "hidden";
		edit.style.visibility = "visible";
		combo.style.width = "0px";
		edit.style.width = "150px";
		edit.focus();
	}
	else
	{
		if(combo.selectedIndex == 2) combo.selectedIndex = 0;
		edit.value = combo.value;
		//alert(edit.value);
	}
}

function onEditKeyPress(edit)
{
	if (window.event != null && window.event.keyCode == 13)
	{
		edit.blur();
	}

}

function onBlur(edit, comboClientID)
{	
	var combo = findElement(comboClientID);
	AddComboItem(combo, edit.value, edit.value);
	
		    edit.style.visibility = "hidden";
		combo.style.visibility = "visible";
		combo.style.width = "150px";
		edit.style.width = "0px";

	combo.focus();
}

function AddComboItem(combo, itemText, itemValue)
{
	for (var i=0;i<combo.options.length;i++)
	{
		if(itemValue == combo.options[i].value)
		{
			combo.options[i].selected = true;
			return;
		}
	}
	
	var index = combo.options.length;
	combo.options[index] = new Option(itemText, itemValue);
	combo.options[index].selected=true;
}

var maskedPassword = "*******";
function OnPwdKillFocus(pwdTextBox, actualTextBox)
{

    var pwdTextBox = findElement(pwdTextBox);
    var actualPwdTextBox = findElement(actualTextBox);

    if(pwdTextBox.value != "" && pwdTextBox.value != null && pwdTextBox.value != maskedPassword){
        actualPwdTextBox.value = pwdTextBox.value; 
    }

    if (actualPwdTextBox.value != "" && actualPwdTextBox.value != null){
        pwdTextBox.value = maskedPassword;
    }
}

var openPopup = null;
function show(object) {

    if(openPopup != null){
        hide(openPopup);
    }
    
	if (document.layers && document.layers[object] != null)
	    document.layers[object].visibility = 'visible';
	else if (document.all)
	    document.all[object].style.visibility = 'visible';
	   // alert(document.body.className);
	    document.body.className = 'modalBodyBackground';
	    
	    openPopup = object;
}
function hide(object) {
	if (document.layers && document.layers[object] != null)
	    document.layers[object].visibility = 'hidden';
	else if (document.all)
	    document.all[object].style.visibility = 'hidden';
	    
	    document.body.className = '';
	    openPopup = null;
}

function ShowChart(ctr, wtrID)
{
    ctr.style.visibility='visible';
    findElementExact(wtrID).style.visibility='hidden';
}

 function selectDropDownItem(ddl, selVal)
 {
      for(var i=0;i<ddl.options.length;i++){
        ddl.options[i].selected = (ddl.options[i].value == selVal);
      }

}

function addToCatHouse()
{
    __doPostBack('AddToProfileButton','');
    findElement('ctl00_BreadCrumb_CatHouseButton').click();
    return false;
}

function randomNumber(){
var now = new Date();
var seed = now.getSeconds();
var random_number = Math.random(seed);

return random_number;

}


function showRatingPopup(albumID, random, refreshButtonID)
{
    modal("RatingPopup.aspx?albumID=" + albumID+"&rand=" + random, 'height=350,scroll=no,width=350', refreshButtonID);
    return;
}

function revealModal(divID)
{
    window.onscroll = function () { document.getElementById(divID).style.top = document.body.scrollTop; };
    document.getElementById(divID).style.display = "block";
    document.getElementById(divID).style.top = document.body.scrollTop;
}

function hideModal(divID)
{
    document.getElementById(divID).style.display = "none";
}

function showAlbumArtPopup(albumID, random, refreshButtonID)
{
   
    //document.body.className = "modalBackground";
    modal("AlbumArtPopup.aspx?albumID=" + albumID+"&rand=" + random, 'height=600,scroll=no,width=950', refreshButtonID);
	
}

function grayOut(vis, options) 
{  
    // Pass true to gray out screen, false to ungray  
    // options are optional.  This is a JSON object with the following (optional) properties  
    // opacity:0-100         
    // Lower number = less grayout higher = more of a blackout   
    // zindex: #             
    // HTML elements with a higher zindex appear on top of the gray out  
    // bgcolor: (#xxxxxx)    
    // Standard RGB Hex color code  
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});  
    // Because options is JSON opacity/zindex/bgcolor are all optional and can appear  
    // in any order.  Pass only the properties you need to set.  
    var options = options || {};   
    var zindex = options.zindex || 50;  
    var opacity = options.opacity || 70;  
    var opaque = (opacity / 100);  
    var bgcolor = options.bgcolor || '#000000'; 
    var dark=document.getElementById('darkenScreenObject');  
    if (!dark) 
    {    
        // The dark layer doesn't exist, it's never been created.  So we'll    
        // create it here and apply some basic styles.    
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917    
        var tbody = document.getElementsByTagName("body")[0];    
        var tnode = document.createElement('div');           
        
        // Create the layer.        
        tnode.style.position='absolute';                 
        // Position absolutely        
        tnode.style.top='0px';                           
        // In the top        
        tnode.style.left='0px';                          
        // Left corner of the page        
        tnode.style.overflow='hidden';                   
        // Try to avoid making scroll bars                   
        tnode.style.display='none';                      
        // Start out Hidden        
        tnode.id='darkenScreenObject';                   
        // Name it so we can find it later    
        tbody.appendChild(tnode);                            
        // Add it to the web page    
        dark=document.getElementById('darkenScreenObject');  
        // Get the object.  
    }  
    if (vis) 
    {    
        // Calculate the page width and height     
        if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) 
        {        
            var pageWidth = document.body.scrollWidth+'px';        
            var pageHeight = document.body.scrollHeight+'px';    
        } 
        else if( document.body.offsetWidth ) 
        {      
            var pageWidth = document.body.offsetWidth+'px';      
            var pageHeight = document.body.offsetHeight+'px';    
        } 
        else 
        {   
            var pageWidth='100%';       
            var pageHeight='100%';    
        }       
        //set the shader to cover the entire page and make it visible.    
        dark.style.opacity=opaque;                          
        dark.style.MozOpacity=opaque;                       
        dark.style.filter='alpha(opacity='+opacity+')';     
        dark.style.zIndex=zindex;            
        dark.style.backgroundColor=bgcolor;      
        dark.style.width= pageWidth;    
        dark.style.height= pageHeight;    
        dark.style.display='block';                            
    } 
    else 
    {     
        dark.style.display='none';  
    }
    
}


function RemoveFriend(friendID, friendName)
{
    if(confirm("Remove " + friendName + " as a friend. Are you sure?")){
    
        return __doPostBack("ctl00$MainContentPlaceHolder$RemoveFriendButton", friendID);
    }
    
    return false;
}

function AddAlbumToCatalog(albumIX, where)
{
    ShowProgress();
    var params = albumIX + "," + where;
    __doPostBack('ctl00$MainContentPlaceHolder$AddToCatalogButton',params); 
}

function ShowProgress(){
    findElement("ctl00_upUpdateProgress","div").style.display="block";
}

function autofitIframe(id)
{
    if (!window.opera && !document.mimeType && document.all && document.getElementById){
        parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
    }
    else if(document.getElementById) {
        parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"
    }
} 

function redirectBrowser(url)
{
    if (parent != self) 
        top.location.href = url;
    else 
        self.location.href = url;
}

function SelectAllFriends(NumFriends, bSelect){

    var ix = 0;
    for (ix=0;ix<NumFriends;ix++){
        var cbName = "friend" + ix + "cb";
       var cb = findElement(cbName);
       if(cb != null){
       cb.checked = bSelect;
       }

    }
}

function InviteFriends(NumFriends, pbButtonName){


    var selectedItems = "";
    
    var count = 0;
    var ix = 0;
    for (ix=0;ix<NumFriends;ix++){
        var cbName = "friend" + ix + "cb";
       var cb = findElement(cbName);
       if(cb != null){
        if(cb.checked){
        selectedItems = selectedItems + "," + cb.value;
         count++;
         }
       }
    }
    
    if(count == 0){
        alert("Please select 1 or more friends to add to CoverCatalog");
        return false;
    }

    if(count > 10){
        alert("You cannot select more than 10 friends a day to add to CoverCatalog");
        return false;
    }
    
    __doPostBack(pbButtonName, selectedItems);
    
    return false;
}

function ajaxRead(fname, params, divName)
{
    var xmlObj = null;
    if(window.XMLHttpRequest)
    {
      xmlObj = new XMLHttpRequest();
    } 
    else if(window.ActiveXObject)
    {
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else {
      return;
    }
    

    xmlObj.onreadystatechange = function()
    {
        if(xmlObj.readyState == 4){
        var items = xmlObj.responseXML.getElementsByTagName('data');
        var s = "";
        for(var i=0;i<items.length;i++){
            s += URLDecode(items[i].firstChild.data);
        }
         updateObj(divName, s);
        }
    }
    xmlObj.open ('GET', fname+'?' + params, true);
    xmlObj.send ('');
}

 function updateObj(obj, data){
   document.getElementById(obj).innerHTML = data;
  }
  
  function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  
  output = replaceIt(output,"+"," "); 
  return output;
}

function replaceIt(sString, sReplaceThis, sWithThis) { 
if (sReplaceThis != "" && sReplaceThis != sWithThis) { 
var counter = 0; 
var start = 0; 
var before = ""; 
var after = ""; 
while (counter<sString.length) { 
start = sString.indexOf(sReplaceThis, counter); 
if (start == -1) { 
break; 
} else { 
before = sString.substr(0, start); 
after = sString.substr(start + sReplaceThis.length, sString.length); 
sString = before + sWithThis + after; 
counter = before.length + sWithThis.length; 
} 
} 
} 
return sString; 
} 

var ver=parseInt(navigator.appVersion)
var ie4=(ver>3  && navigator.appName!="Netscape")?1:0
var ns4=(ver>3  && navigator.appName=="Netscape")?1:0
var ns3=(ver==3 && navigator.appName=="Netscape")?1:0

function playSound(url) {
alert(url);
 if (ie4) document.all['BGSOUND_ID'].src=url;
alert(document.all['BGSOUND_ID'].src);
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
  && self.document.guitar.IsReady()
 )
 {
 self.document.guitar.src= url; 
  self.document.guitar.play()
 }
}

function stopSound() {
 if (ie4) document.all['BGSOUND_ID'].src='images/jsilence.mid';
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-midi']
 )
 {
  self.document.guitar.stop()
 }
}

function setActivateCoverDiv(div)
{
    if(activeCoverDiv == div) return;
    if(activeCoverDiv != null)
    {
       deactivateCover(activeCoverDiv);
    }
    
    activeCoverDiv = div;
    div.style.visibility='visible';
}

function deactivateCover(div)
{
    if(activeCoverDiv != null && activeCoverDiv == div)
    {
        activeCoverDiv.style.visibility='hidden';
    }
    activeCoverDiv = null;
}

	
