/* ------------------------- cookie tools -------------------------- */


function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


/* ------------------------------------------------------------- */




/* ------------------------------------------------------------- */
// BEGIN check auth input

function CheckAuthForm( e )
{
	var f = document.getElementById( 'id_login' );
	var errstr = null;

	while( true )
	{
		//alert( 'email='+f.r_email.value );
		if( f.email.value.length < 1 )
		{
			errstr = 'please input your e-mail.';
			f.email.focus();
			break;
		}

		r = new RegExp( "[0-9a-zA-Z-._]+@[0-9a-zA-Z-._]+\.[0-9a-zA-Z]{2,4}", "g" );
		ar = r.exec( f.email.value );
		if( !ar )
		{
			errstr = 'e-mail is invalid.';
			f.email.focus();
			break;
		}

		if( f.pass.value.length < 1 )
		{
			errstr = 'please input your password.';
			f.pass.focus();
			break;
		}

		break;
	}

	if( errstr )
	{
		alert( errstr );
		if( e && e.preventDefault )
			e.preventDefault(); // DOM style
		if( window.event )
			window.event.returnValue = false;
		return false; // IE style
		/*
		if( !e )
		{
			var e = window.event;
			e.returnValue = false;
		}

		e.cancelBubble = true;
		if( e.stopPropagation )
			e.stopPropagation();
		return false;
		*/
	}

	return true;
}

// END 
/* ------------------------------------------------------------- */



/* ------------------------------------------------------------- */
// BEGIN preload menu images


function PreloadMenu()
{
	return;
	var img_im_home = new Image();
	img_im_home.src = '/images/ultra/menu2/im_home_hover.jpg';

	var img_im_help = new Image();
	img_im_help.src = '/images/ultra/menu2/im_help_hover.jpg';

	var img_im_signup = new Image();
	img_im_signup.src = '/images/ultra/menu2/im_signup_hover.jpg';

	var img_im_mydls = new Image();
	img_im_mydls.src = '/images/ultra/menu2/im_mydls_hover.jpg';

	var img_im_myacc = new Image();
	img_im_myacc.src = '/images/ultra/menu2/im_myacc_hover.jpg';
}

// END
/* ------------------------------------------------------------- */







/* ------------------------------------------------------------- */
// BEGIN freaky header tracking:)

var d_tid;
var d_price;
var http_req;
var signed_in = 0;

function PushHeaderSyncTracker()
{
	//return;
	
	if( signed_in < 1 )
		return;

	setInterval( 'FireHeaderSync();', 10*1000 );
}




function FireHeaderSync()
{
	var ub = getCookie( 'ureflect' );
	if( !ub )
	{
		return;
	}

	document.getElementById( 'id_reflect_ubalance' ).innerHTML = 'Your balance: '+ub+'$';
	deleteCookie( 'ureflect', "/", ".mp3skyline.com" );
}


// END 
/* ------------------------------------------------------------- */







/* ------------------------------------------------------------- */
// BEGIN player settings and installations


var current_fid = 0;
var current_trid = 0;


function CompilePlayerFront( trid, fid )
{
	var front = '<a href="#" onclick="ChasePrelisten( \''+trid+'\', \''+fid+'\' );FlipPlayerFront( \''+trid+'\', \''+fid+'\' );return false;">'+
	'<img src="/images/ultra/player_front.gif" width="80" height="15" border="0" /></a>';

	return front;
}

function FlipPlayerFront( trid, fid )
{
	//alert( 'Unfortunately, preview feature is unavailable yet.\r\n\r\n'+
	//'Please check back in awhile.' );
	//return;

	var landing = CompilePlayer( trid, fid );
	document.getElementById( 'dip_'+trid ).innerHTML = landing;
}

function CompilePlayer( trid, fid )
{
	var landing = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
	'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" '+
	'width="80" height="15" id="'+fid+'">' +
	'<param name="movie" value="/images/ultra/swf/player_small_v21.swf" />'+
	'<param name="AllowScriptAccess" value="always" />'+
	'<param name="quality" value="high" />'+
	'<param name="flashvars" value="trid='+trid+'&self_fid='+fid+'">'+
	'<embed src="/images/ultra/swf/player_small_v21.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" '+
	'flashvars="trid='+trid+'&self_fid='+fid+'" allowScriptAccess="always" type="application/x-shockwave-flash" width="80" height="15"></embed></object>';

	return landing;
}


function InstallPlayer( trid, fid )
{
	var landing = CompilePlayerFront( trid, fid );
	//document.write( landing );

	document.getElementById( 'dip_'+trid ).innerHTML = landing;
}

function ChasePrelisten( trid, fid )
{
	// fid responds to the now-playing player fid
	// *

	if( current_trid < 1 )
	{
		current_trid = trid;
		current_fid = fid;
		return;
	}

	if( current_trid == trid )
		return;

	// flip last fid and update current one
	// *
	try {
	last_player = document.getElementById( fid );
	delete last_player; } catch( e ) { };
	
	
	document.getElementById( 'dip_'+current_trid ).innerHTML = CompilePlayerFront( current_trid, current_fid );
	
	current_trid = trid;
	current_fid = fid;
}

// END
/* ------------------------------------------------------------- */








/* ------------------------------------------------------------- */
// BEGIN chasing menu and etc...


function ChaseMenu( id_item, stat )
{
	if( stat < 1 )
	{
		// mouse out
		// *
		document.getElementById( id_item ).src = '/images/ultra/menu2/'+id_item+'.jpg';
		return;
	}
	else
	{
		// mouse over
		// *
		
		document.getElementById( id_item ).src = '/images/ultra/menu2/'+id_item+'_hover.jpg';
		return;
		
	}
	
}



// END 
/* ------------------------------------------------------------- */






/* ------------------------------------------------------------- */
// BEGIN tracking search focus...


var input_started = 0;

function HandleSearchOnFocus( in_query )
{
	if( in_query != "input your search request here..." )
	{
		return;
	}

	if( input_started )
		return;
	
	document.getElementById('id_q').value = '';
	input_started = 0;
}


function HandleSearchOnBlur( in_query )
{
	if( input_started )
		return;

	document.getElementById('id_q').value = in_query;
}



function HandleHowtdClick()
{
	if( is_htd_hidden )
	{
		div_htd.innerHTML = html_htd;
		document.getElementById( 'id_exp_htd_tip' ).innerHTML = "[-]";
		document.getElementById( 'id_exp_htp_tip' ).innerHTML = "[+]";
		div_htp.innerHTML = '';
		is_htp_hidden = true;
	}
	else
	{
		div_htd.innerHTML = '';
		document.getElementById( 'id_exp_htd_tip' ).innerHTML = "[+]";
		document.getElementById( 'id_exp_htp_tip' ).innerHTML = "[+]";
	}

	is_htd_hidden = !is_htd_hidden;

}

function HandleHowtpClick()
{
	if( is_htp_hidden )
	{
		div_htp.innerHTML = html_htp;
		document.getElementById( 'id_exp_htp_tip' ).innerHTML = "[-]";
		document.getElementById( 'id_exp_htd_tip' ).innerHTML = "[+]";
		div_htd.innerHTML = '';
		is_htd_hidden = true;
	}
	else
	{
		div_htp.innerHTML = '';
		document.getElementById( 'id_exp_htp_tip' ).innerHTML = "[+]";
		document.getElementById( 'id_exp_htd_tip' ).innerHTML = "[+]";
	}

	is_htp_hidden = !is_htp_hidden;

}

// END
/* ------------------------------------------------------------- */

function HandleSearchRequest( e )
{
	
	
	var in_query = document.getElementById( 'id_q' ).value;
	
	if( in_query.length < 1 || in_query == "input your search request here..." )
	{
		alert( 'please type something to search for...' );
		
		if( e && e.preventDefault )
			e.preventDefault(); // DOM style
		if( window.event )
			window.event.returnValue = false;
		return false; // IE style
		
		/*
		return false;
		
		
		alert( e );
		if( !e )
		{
			var e = window.event;
			e.returnValue = false;
		}

		e.cancelBubble = true;
		if( e.stopPropagation )
			e.stopPropagation();
		return false;
		*/
	}
	
	var go_image = document.getElementById( 'go_image' );
	if( go_image )
	    go_image.disabled=true;
	
	return true;
}

function ShowEmailSubscribeForm()
{
	var d = document.getElementById( 'email_sbscr_block' );

	
	d.style.visibility = 'visible';
	d.style.padding = '5px 5px 5px 10px';
	d.style.margin = '5px 0px 0px 0px';

	


	d.innerHTML = 
	'<input type="text" id="id_sbscr_email" name="s_email" value="your email here..." class="inputauth2" '+
	'onfocus="document.getElementById( \'id_sbscr_email\' ).value=\'\'">';
}

function OpenRecoverLayer()
{
    var holder = document.getElementById( 'id_recover_holder' );
    var layer = document.getElementById( 'id_recover_layer' );
    
    if( !holder )
    {
	alert( 'unexpected error occured. \r\nplease contact our support team via e-mail.' );
	return;
    }
    
    try {
    var mw = document.getElementById( 'mainwrap' );
    
    //var h = document.getElementById( 'id_xheader' );
    //var f = document.getElementById( 'footer_box' );
    /*h.style.filter = f.style.filter =*/ mw.style.filter = "alpha(opacity=50)";
    /*h.style.opacity = f.style.opacity =*/ mw.style.opacity = ".50";
    } catch( e ) {};
    
    var popup_err = document.getElementById( 'id_expand_delayed' );
    if( popup_err )
	if( popup_err.style.display != "none" )
	    popup_err.style.display = "none";
	    
    
    if( holder.style.display == "none" && layer )
    {
	holder.style.display = "block";
	return;
    }
    
    holder.style.display = "block";
    holder.innerHTML = 
    
    '<div style="position:absolute;background:#FFFFFF;left:50%;margin-left:-270px;top:150px;width:500px;border:2px dashed #666666;padding:20px;z-index:10;" id="id_recover_layer">' +
    '<div style="background:#DDDDDD;min-height:120px;height:100%;">' + 
    '<div style="width:100%;text-align:right;padding-top:4px;padding-bottom:4px;background:#000000;"><a href="javascript:void(0);" onclick="CloseRecoverLayer();" style="color:#FFFFFF;text-decoration:none;">'+
    '<div style="float:left;margin-left:10px;">password reminder</div> <strong><u>close</u> [X]</strong></a> &nbsp;</div>' +
    '<div style="clear:both;">' +
    
    '<iframe src="/forgot-password" width="500" height="160" frameborder="0" scrolling="no"></iframe>' + 
    
    '</div>' +
    '</div>';
    
    
}

function OpenPwdLayer()
{
	var layer = document.getElementById( 'id_recover_holder' );
	if( !layer )
	{
		alert( 'unexpected error occured. \r\nplease contact our support team via e-mail.' );
		return;
	}

	layer.innerHTML = ''+
	'<div id="blanket" style="display:none;"></div>'+
	'<div id="forgotPwdDiv" style="display:none;">'+
	'<div style="font-weight:600; height:230px; font-family:Verdana; font-size:14px; color:white; line-height: 90%;">'+
	'<div align="right" style="position:relative;top:20px;left:-20px;">'+
	'<input class="comm-btn" style="font-weight: bold;" type="submit" onclick="popup(\'forgotPwdDiv\')" value="Close" /></div>'+
	'<center><div style="padding-bottom: 16px;">&nbsp;</div>'+
	'<iframe src="/forgot-password" width="500" height="150" frameborder="0" scrolling="no"></iframe></center>' + 
	'</div>'+
	'</div>';

	popup( 'forgotPwdDiv' );
}

function InstallFeedback( t )
{
    if( t == 0 )
	document.write( '<strong><a href="mailto:support@mp3skyline.com">support@mp3skyline.com</a></strong>' );
    else if( t == 1 )
	document.write( 
	'<strong><a style="color:#0000FF;" href="mailto:support@mp3skyline.com">support@mp3skyline.com</a></strong>'
	);
}

function StatInfo()
{
    w = window.open('/info/charge_stat.html', '_blank', 'width=600,height=500,status=no,toolbar=no,menubar=no');
    window.w.focus();
    window.event.returnValue = false;
    return false;
}


function Bookmark()
{
    var title = "MP3skyline.com -- Largest MP3 download catalogue.";
    var url = "http://mp3skyline.com/";
    if (window.sidebar){ window.sidebar.addPanel(title, url,""); }
    else if( window.external ) { window.external.AddFavorite( url, title); }
    else if(window.opera && window.print) { return true; }
}