// JavaScript Document
// this variable is required for lightboxes that pop up onLoad
autoLoadbox = "";

function close_popup(obj) {
    $(obj).hide();
}

function closeWindow() {
    setTimeout(function(){
        if (window.console) window.console.log("window.close()");
        window.close();
    },500);
}

function downloadScattertunes(swfUrl)
{
	if (!swfUrl) {
		swfUrl = 'getLaunchScatterPopup.swf';
	}
    var params = {
        wmode:'transparent',
		flashvars: 'installNow=true'
    };
    var attributes = {};
    var replaceId = 'iBoardLauncherPopup';
    
    swfobject.createSWF({ 
        data:swfUrl, 
        id:replaceId, 
        width:'500', 
        height:'347' 
    }, params, replaceId);
    
    
    var dim = document.viewport.getDimensions();
    var x = (dim.width - 500) / 2;
    var y = (dim.height - 347) / 2;
    
    $('iBoardLauncherPopup').setStyle({
        visibility:'visible',
        left:(x.toString(10) + "px"),
        top:(y.toString(10) + "px")
    });
}

// Handles the homepage more-info button clicks
function moreinfo(trackId, albumId, moreInfoUrl) {
    if (moreInfoUrl) {
        window.location.href = moreInfoUrl;
        return;
    }

    var cmd = JSON.stringify({
        albumId:albumId,
        productId:trackId,
        searchTerm:'WEB PAGE',
        cmd:'VIEW'
    });
    
//    var cmd = '{"albumId": "61f846c0-f66e-4bb5-aa8a-a72698140d75", "productId": "be7441eb-1155-4d7f-830e-14da3d607500",  "searchTerm": "(Remember Me) Im the One Who Loves You",  "cmd": "VIEW"}';   
    var flashvars = 'data=' + encodeURI(cmd);
    var params = {
        wmode:'transparent', 
        flashvars:flashvars
    };
    var attributes = {};
    var replaceId = 'iBoardLauncherPopup';
    
    swfobject.createSWF({ 
        data:'getLaunchScatterPopup.swf', 
        id:replaceId, 
        width:'500', 
        height:'347' 
    }, params, replaceId);
    
    
    var dim = document.viewport.getDimensions();
    var x = (dim.width - 500) / 2;
    var y = (dim.height - 347) / 2;
    
    $('iBoardLauncherPopup').setStyle({
        visibility:'visible',
        left:(x.toString(10) + "px"),
        top:(y.toString(10) + "px")
    });
}
// Handles the homepage more-info button clicks
function valbumMoreinfo(upc, searchTerm, moreInfoUrl) {
    if (moreInfoUrl && moreInfoUrl != '') {
        window.location.href = moreInfoUrl;
        return;
    }

    var cmd = JSON.stringify({
        upc:upc,
        searchTerm:searchTerm,
        cmd:'BUY_ALBUM'
    });
    
//    var cmd = '{"albumId": "61f846c0-f66e-4bb5-aa8a-a72698140d75", "productId": "be7441eb-1155-4d7f-830e-14da3d607500",  "searchTerm": "(Remember Me) Im the One Who Loves You",  "cmd": "VIEW"}';   
    var flashvars = 'data=' + encodeURI(cmd);
    var params = {
        wmode:'transparent', 
        flashvars:flashvars
    };
    var attributes = {};
    var replaceId = 'iBoardLauncherPopup';
    
    swfobject.createSWF({ 
        data:'getLaunchScatterPopup.swf', 
        id:replaceId, 
        width:'500', 
        height:'347' 
    }, params, replaceId);
    
    
    var dim = document.viewport.getDimensions();
    var x = (dim.width - 500) / 2;
    var y = (dim.height + 575) / 2;
    
    $('iBoardLauncherPopup').setStyle({
        visibility:'visible',
        left:(x.toString(10) + "px"),
        top:(y.toString(10) + "px")
    });            
}

function iBoardLaunchPopup_hide()
{

    swfobject.removeSWF("iBoardLauncherPopup");
    var container = $('iBoardLauncherPopup-container');
    container.insert('<div id="iBoardLauncherPopup"></div>');
}

// Makes the homepage popups
function popup(obj) {	
    $$('.top10_popup').invoke('hide');

//	document.getElementById("newexclusives_popup").style.visibility="hidden";
//	document.getElementById("onrise_popup").style.visibility="hidden";
//	document.getElementById("hottest_popup").style.visibility="hidden";

	var obj = $(obj);
	var parentDiv = document.getElementById("pagewrapper");
	var xpos, ypos = 0;
	
	if (obj.id=='FEATURE_popup') {
		var bn = $('bn_fboxtop10');
		xpos = parentDiv.offsetLeft+bn.offsetLeft+200;
		ypos = 170;
		}
	else {
		xpos = parentDiv.offsetLeft+125;
		ypos = document.body.offsetTop+219;
	}
    obj.show();
	obj.style.left= xpos + "px";
	obj.style.top= ypos + "px";
}


function validateContactForm(formName) {
	var formElems = document.getElementById(formName).elements;
	var $errors = 0;
	var addr = formElems["email"].value;
	var snailpos = addr.indexOf("@",0);
	
	for (var i=0; i<formElems.length; i++){
			if (formElems[i].name!="phone" && formElems[i].value==""){
			alert (formElems[i].name + " is required.");
			//$errors+=1;
			return false;
			}
		
			else {
			
			if (snailpos <=0) {
				alert ("Your email address appears to be invalid.")
				return false;
			}	
		}	
	}
	return true;
}

// mouseovers 
function rollover(filename) {
	var pic = filename + "_on.gif";	
	this.src=pic;
}

function rollout(filename) {
	var pic = filename + ".gif";
	this.src=pic;
}

function feedback(firstName,lastName,emailAddress,phone,subject,comments)
{
	new Ajax.Request('/WebService/Service.asmx/ContactUs_SupportPage', 
		{
			method: 'post',
			postBody: "firstName=" + escape(firstName) +
				"&lastName=" + escape(lastName) +
				"&email=" + escape(emailAddress) +
				"&phone=" + escape(phone) + 
				"&subject=" + escape(subject) +
				"&comments=" + escape(comments)
		});
				
}

function isMaximized()
{

	if (window.outerHeight != null)
	{
		//FF
		if((document.getElementsByTagName('body')[0].style.overflow = 'scroll') && (screen.width - window.outerWidth == 17))
		{
			//alert('FF');
			return true;
		}
		else if (screen.width - window.outerWidth == -8)
		{
			//alert('IE');
			return true;
		}
	}
	else
	{
		//IE 7.0
		if (document.body.scroll == 'no')
		{
			//alert('IE');
			return true;
		}
		else if((document.getElementsByTagName('body')[0].style.overflow = 'scroll') && (screen.width - window.outerWidth == 21))
		{
			//alert('FF');
			return true;
		}
		else if (screen.width - document.body.clientWidth == 4)
		{
			//alert('IE');
			return true;
		}
	
	}
	
	return false;
}

ScatterTunes = function()
{
    return {
        notify: function(page,detail) {
            new Ajax.Request('/WebService/SiteService.asmx/Notify', {
                contentType: "application/json; charset=utf-8",
                method:'post',
                postBody:JSON.stringify({
                    id: null,
                    channel: "WebSite",
                    page: page,
                    type: "P",
                    detail: detail
                })
            });
        },
        
        notifyInstall: function(airStatus) {
            new Ajax.Request('/WebService/SiteService.asmx/Notify', {
                contentType: "application/json; charset=utf-8",
                method:'post',
                postBody:JSON.stringify({
                    id: null,
                    channel: "WebSite",
                    page: "Get ScatterTunes",
                    type: "C",
                    detail: JSON.stringify({type:'InstallClick', airStatus:airStatus})
                })
            });
        }
    }
}();