﻿function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function lb(t, u, w, h, a, f){
    if (w==''){w='400'}
    if (h==''){h='500'}
    if(t == 'on'){
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else {
			if( document.documentElement &&
				( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			  myWidth = document.documentElement.clientWidth;
			  myHeight = document.documentElement.clientHeight;
			} else {
			  if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			  }
			}
		}
		
		myWidth = (myWidth - w) / 2
		myHeight = (myHeight - h) / 2
		
		var arrayPageSize = getPageSize();
	    var arrayPageScroll = getPageScroll();
	    
	    var objBlockUI = document.getElementById('BlockUI');
	    var objLbMain = document.getElementById('lbMain');
		
		objBlockUI.style.height = (arrayPageSize[1] + 'px');
        objBlockUI.style.display = 'block';
        
        
		objLbMain.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - h) / 2) + 'px');
		            
		objLbMain.style.width = w+'px';
		objLbMain.style.height = h+'px';
		objLbMain.style.left = myWidth+'px';
		objLbMain.style.display = 'block';
		opacity('lbMain', 0, 100, 100);
	
		var s = new sack();
		s.requestFile = u;
		s.method = "POST";
		s.element = 'lbContent';
		if(f!='undefined' && f!=''){
		    s.onCompletion = function() { f };
		}
		s.w = w;
		s.h = h;
		s.runAJAX();
		if(a>0){
	        setTimeout ( "lb(\'off\');", a );
	    }
    }else{
        // Block the UI
        document.getElementById('BlockUI').style.display = 'none';
        fadeIt('lbMain');
    }
}

function changeFocus(id){
    document.getElementById(id).focus();
}


function whenLoading(strID, w, h){
	var parentID = document.getElementById(strID).parentNode.id;
	var loadingW = 220;
	var loadingH = 20;

	w = (w - loadingW) / 2
	h = (h - loadingH) / 2
	
	// Write out the loading message
    document.getElementById(strID).innerHTML = '<div class="loading" style="position:absolute;left:'+w+'px;top:'+h+'px;"><img src="/images/netImages/loading.gif" alt="loading" /></div>';
}

function modCSS(a,o,c1,c2)
{
	switch (a){
		case 'swap':
			o.className=!modCSS('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
		break;
		case 'add':
			if(!modCSS('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
		break;
	}
}

function showSearch(searchType,isMember) {
	// Open the AJAX object
	var sackObject = new sack();
	var addToURL = "piece=qlStudioType&searchby=" + searchType;
	if(isMember=='member'){addToURL+='&isMember=True';};
	var searchTitle = document.getElementById('bytitle');
	
	// Set the title
	searchTitle.innerHTML = searchType;
	
	// Set the searching
	sackObject.requestFile = "/pieces.aspx";
	sackObject.method = "GET";
	sackObject.element = 'searchDetails';
	sackObject.w = 450;
	sackObject.h = 75;
	sackObject.runAJAX(addToURL);
}

function openBuddyList() {
  	window.open('/im/buddylist.aspx','BuddyList','toolbar=0,location=0,status=0,menubar=0,width=175,height=550');
}

function gunnadelete(){return confirm("Are you sure you want to delete this?\nIt can NOT be undone!");}
function markrude() {return confirm("This will affect their user rating and delete this. Are you sure you didn\'t mean just to delete it?\n\nClick OK if it\'s rude. Click Cancel to go back.");}
function fadeIt(id){
    opacity(id, 100, 0, 300);
    setTimeout("hideIt('"+id+"')",300);
}
function hideIt(id){
    document.getElementById(id).style.display = 'none';
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

//var xt = 5;
//var yt = 1;
//function uX(){xt = xt-yt;setTimeout("uX()", 1000);if(xt==0){uAU();xt=5;}}
//function uAU(){var sackObject = new sack();sackObject.requestFile="/uAU.aspx";sackObject.method="GET";sackObject.element='oBL';sackObject.onCompletion=function(){cIM()};sackObject.runAJAX();}
//function cIM(){if(document.getElementById('oBL').innerHTML=='1'){openBuddyList();document.getElementById('oBL').innerHTML='';}}
//uX();