// JavaScript Document

//img preload

function img_preload(img_src) {
	img = new Image(); 
	img.src = img_src;
}

//img preload

// global variables 

var iebody=(document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : iebody;

//general

//ajax
function xmlhttpPost_item(URL,params,div)
{
	var xmlHttpReq = null;	
  
	// Mozilla/Safari
	if (window.XMLHttpRequest)
		xmlHttpReq = new XMLHttpRequest();
	// IE
	else if (window.ActiveXObject)
	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

	xmlHttpReq.open('POST', URL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.setRequestHeader("Content-length", params.length);
	xmlHttpReq.setRequestHeader("Connection", "close");
	
	xmlHttpReq.onreadystatechange = function() {
    	if (xmlHttpReq.readyState==4 && document.getElementById(div)) {    		
		    document.getElementById(div).innerHTML=xmlHttpReq.responseText;		    
    	}
	}
	xmlHttpReq.send(params);
}

/*general*/
function void_() {
	;
}	

//is ie 6
function isie6() {
	
	var nVer = navigator.appVersion;
	var nAgt = navigator.userAgent;
	var browserName  = '';
	var fullVersion  = 0; 
	var majorVersion = 0;

	
	// In Internet Explorer, the true version is after "MSIE" in userAgent
	if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
		browserName  = "Microsoft Internet Explorer";
		fullVersion  = parseFloat(nAgt.substring(verOffset+5));
		majorVersion = parseInt(''+fullVersion);
		
		if (majorVersion<=7) {
			return true;			
		}
	}
	
	return false;
	
}

//show/hide select box >ie6
function show_selects(v) {
	if (isie6()) {
		var elements=document.getElementsByTagName('select');
		for (var i=0; i<elements.length; i++) {		
			if (elements[i].id!='year' && elements[i].id!='month')
				elements[i].style.visibility=v;
		}
	}
}

//hide flash
function show_object(v) {
	var elements=document.getElementsByTagName('embed');
	for (var i=0; i<elements.length; i++) {		
		elements[i].style.visibility=v;
	}
	var elements=document.getElementsByTagName('object');
	for (var i=0; i<elements.length; i++) {		
		elements[i].style.visibility=v;
	}
}

function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
	
function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getMouseOffset(target, ev){
	ev = ev || window.event;
	
	var docPos    = getPosition(target);
	var mousePos  = mouseCoords(ev);
	return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}

function getPosition(e){
	var left = 0;
	var top  = 0;
	
	while (e.offsetParent){
	left += e.offsetLeft;
	top  += e.offsetTop;
	e     = e.offsetParent;
	}
	
	left += e.offsetLeft;
	top  += e.offsetTop;
	
	return {x:left, y:top};
}

function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + iebody.scrollLeft - iebody.clientLeft,
		y:ev.clientY + iebody.scrollTop  - iebody.clientTop
	};
}

function getScrollCoordinates(direction) { 
	if (direction=='w')
		return (document.all) ? iebody.scrollLeft : window.pageXOffset;
	if (direction=='h')
		return (document.all) ? iebody.scrollTop : window.pageYOffset;	
} 

function getPageSizeWithOutScroll(direction)
{     
	if (window.innerHeight) 
	{
		// Firefox         
		yWithScroll = window.innerHeight;
		xWithScroll = window.innerWidth;     
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
		yWithScroll = iebody.clientHeight;         
		xWithScroll = iebody.clientWidth;
	}     
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);     
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
	if (direction=='w')
		return xWithScroll;
	if (direction=='h')
		return yWithScroll;
}

function getPageSizeWithScroll(direction)
{     
	if (window.innerHeight && window.scrollMaxY) 
	{
		// Firefox         
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;     
	} else if (iebody.scrollHeight > iebody.offsetHeight)
	{ // all but Explorer Mac         
		yWithScroll = iebody.scrollHeight;         
		xWithScroll = iebody.scrollWidth;     
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
		yWithScroll = iebody.offsetHeight;         
		xWithScroll = iebody.offsetWidth;
	}     
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);     
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
	if (direction=='w')
		return xWithScroll;
	if (direction=='h')
		return yWithScroll;
}

//loader on url
function url(url) {
	window.location=url;			
}

/*submenu*/
function submenu_over(index) {
	document.getElementById('submenu_'+index).style.display='none';
	document.getElementById('submenu_'+index+'_over').style.display='';
}

function submenu_out(index) {
	document.getElementById('submenu_'+index).style.display='';
	document.getElementById('submenu_'+index+'_over').style.display='none';
}

function new_captcha(pref_) {
	document.getElementById(pref_+'_passcode_img').style.display='none';
	document.getElementById(pref_+'_passcode_loader').style.display='';
	document.getElementById(pref_+'_passcode_img').src=HOST+'/passphraseimage.php?code='+escape(captcha_hash());
}

function captcha_hash() {
	var chars = "0123456789ABCDEF";
	var string_length = 32;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}


/*UPDAYE PROFILE*/

function update_profile_change_img(filename,filename_display) {
	add_change_flag();
	document.getElementById('profile_img_loader').style.display='';
	document.getElementById('profile_img').src=artist_url+'/'+filename;
	document.update_profile_form.tmp_profile_img.value=filename;
	document.update_profile_form.tmp_profile_img_name.value=unescape(filename_display);
}

function update_profile_add_track_list(title,filename,duration) {
	
	add_change_flag();
	
	tracks[tracks.length] = [];
	var i = tracks.length-1;	

	tracks[i][0]=unescape(title);
	tracks[i][1]=filename;
	tracks[i][2]=duration;
	
	update_profile_generate_tracks_list(i);
	
}

function update_profile_delete_track(index) {
	
	add_change_flag();
	
	var tracks_ = new Array();
	for (var i=0;i<tracks.length;i++) {
		if (index!=i) {
			tracks_[tracks_.length]=tracks[i];
		}
	}
	
	tracks = tracks_;
	
	update_profile_generate_tracks_list();
}

function update_profile_order(dir,index) {
	
	add_change_flag();
	
	var aux_=new Array();
	aux_ = tracks[index];
	tracks[index] = tracks[index+dir];
	tracks[index+dir]=aux_;
	
	update_profile_generate_tracks_list();
	
}

function update_profile_generate_tracks_list(auto_i) {
	var	buffer="";
		
	for (var i=0;i<tracks.length;i++) {
		buffer+='<table cellpadding="0" cellspacing="0" class="music_list_'+(i%2==0 ? '1' : '0')+'"><tr><td class="music_list_row_1">'+(i+1)+')</td><td class="music_list_row_2">'+(auto_i==i ? "<input type='hidden' id='track_check_fs_"+i+"' value=1 />" : "")+'<div id="track_disp_title_'+i+'" class="track_disp_title" onmouseover="this.className=\'track_disp_title_over\';" onmouseout="this.className=\'track_disp_title\';" onclick="this.style.display=\'none\'; document.getElementById(\'track_title_'+i+'\').style.display=\'inline\'; document.getElementById(\'track_title_'+i+'\').focus();">'+update_profile_limit_track_title(tracks[i][0])+'</div><input type="text" id="track_title_'+i+'" name="track_title_'+i+'" value="'+tracks[i][0]+'" onblur="this.style.display=\'none\'; document.getElementById(\'track_disp_title_'+i+'\').style.display=\'block\'; tracks['+i+'][0]=this.value; document.getElementById(\'track_disp_title_'+i+'\').innerHTML=update_profile_limit_track_title(this.value); " maxlength="64" onchange="add_change_flag();" /><input type="hidden" name="track_file_'+i+'" id="track_file_'+i+'" value="'+tracks[i][1]+'" /></td><td class="music_list_row_3">'+tracks[i][2]+'<input type="hidden" name="track_duration_'+i+'" id="track_duration_'+i+'" value="'+tracks[i][2]+'" /></td><td class="music_list_row_4"><a href="javascript:update_profile_delete_track('+i+')">'+delete_text+'</a></td><td  class="music_list_row_5">'+(i==0 ? '' : '<a href="javascript:update_profile_order(-1,'+i+')" class="up_arrow"></a>')+'</td><td class="music_list_row_6">'+(i==tracks.length-1 ? '' : '<a href="javascript:update_profile_order(1,'+i+')" class="down_arrow">')+'</a></td><td>&nbsp;</td></tr></table>';
	}
	document.getElementById('update_profile_music_list').innerHTML=buffer;
	
	if (auto_i>=0) {
		//setTimeout('update_profile_edit_title('+auto_i+')',50);
	}
}

function update_profile_edit_title(index) {	
	 if (document.getElementById('track_check_fs_'+index) && document.getElementById('track_check_fs_'+index).value==1) {
		 //document.getElementById('track_disp_title_'+index).style.display='none'; 
		 //document.getElementById('track_title_'+index).style.display='inline'; 
		 document.getElementById('track_title_'+index).focus();
	 } else {
	 	setTimeout('update_profile_edit_title('+index+')',50);
	 }
}

function update_profile_limit_track_title(title) {
	if (title.length>0 && title.length>17)
		return title.substr(0,17)+'...';
	return title;
}

var updateing_profile = 0;

function update_update_profile() {
	document.getElementById('update_profile_error').innerHTML='';
	var error___ = 0;
	
	if (tracks.length>MAX_TRACK_NR) {
		var music_nr_error_ = music_nr_error.replace( '#NR#', tracks.length-MAX_TRACK_NR);
		document.getElementById('update_profile_error').innerHTML+=music_nr_error_;
		error___=1;
	}
	if (document.getElementById('genre').value.length==0) {
		document.getElementById('update_profile_error').innerHTML+=(error___==1 ? "<br />" : "")+genre_missing_error;
		error___=1;
	}
	if (error___==0) {		
		updateing_profile = 1;
		document.getElementById('update_profile_loader').style.top = getY(document.getElementById('update_profile_holder'))+'px';
		document.getElementById('update_profile_loader').style.left = getX(document.getElementById('update_profile_holder'))+'px';
		document.getElementById('update_profile_loader').style.display='block';
		
		document.getElementById('profile_music_upload_holder').style.visibility='hidden';
		document.getElementById('profile_img_upload_holder').style.visibility='hidden';
		
		document.getElementById('tracks_count').value=tracks.length;
		document.update_profile_form.command.value='update_profile';
		document.update_profile_form.submit();
	}
}

function cancel_profile_update(url) {
	if (changes_==1) {
		if (confirm(confirm_cancel_profile_update))
			window.location=url;
		else
			;
	} else {
		window.location=url;	
	}
}

function add_change_flag() {
	changes_=1;
}

function remove_change_flag() {
	changes_=0;
}

/*UPDAYE PROFILE*/

/*WIZARD*/

function wizard_update_profile() {
	document.getElementById('update_profile_error').innerHTML='';
	var error___ = 0;
	
	if (tracks.length>MAX_TRACK_NR) {
		var music_nr_error_ = music_nr_error.replace( '#NR#', tracks.length-MAX_TRACK_NR);
		document.getElementById('update_profile_error').innerHTML+=music_nr_error_;
		error___=1;
	}
	if (tracks.length<1) {
		document.getElementById('update_profile_error').innerHTML+=music_nr_at_least_error;
		error___=1;
	}
	if (document.getElementById('genre').value.length==0) {
		document.getElementById('update_profile_error').innerHTML+=(error___==1 ? "<br />" : "")+genre_missing_error;
		error___=1;
	}
	if (error___==0) {		
		document.getElementById('update_profile_loader').style.top = getY(document.getElementById('update_profile_holder'))+'px';
		document.getElementById('update_profile_loader').style.left = getX(document.getElementById('update_profile_holder'))+'px';
		document.getElementById('update_profile_loader').style.display='block';
		
		document.getElementById('profile_music_upload_holder').style.visibility='hidden';
		document.getElementById('profile_img_upload_holder').style.visibility='hidden';
		
		document.getElementById('tracks_count').value=tracks.length;
		document.update_profile_form.command.value='wizard_update_profile';
		document.update_profile_form.submit();
	}
}

function wizard_go_final() {
	
	document.getElementById('wizard_step2_loader').style.top = getY(document.getElementById('wizard_step2_holder'))+'px';
	document.getElementById('wizard_step2_loader').style.left = getX(document.getElementById('wizard_step2_holder'))+'px';
	document.getElementById('wizard_step2_loader').style.display='block';

	document.getElementById('wizard_step2_holder').style.visibility='hidden';
	url(HOST+'/wizard.php?step=3');
}

function wizard_go_finish() {
	
	document.getElementById('wizard_step3_loader').style.top = getY(document.getElementById('wizard_step3_holder'))+'px';
	document.getElementById('wizard_step3_loader').style.left = getX(document.getElementById('wizard_step3_holder'))+'px';
	document.getElementById('wizard_step3_loader').style.display='block';

	document.getElementById('wizard_step3_holder').style.visibility='hidden';
	url(HOST+'/dashboard.php');
}

/*WIZARD*/

/*CONTROL PANEL*/

function control_panel_get_chk_songs() {
	var count_=0;
	for (var k=0;k<parseInt(document.getElementById('songs_list_len').value);k++)
		if (document.getElementById('approved_list_id_'+k) && document.getElementById('approved_list_id_'+k).checked==true)
			count_++;
	return parseInt(count_);
}

function approve_music_list() {
	var confirm_msg=approve_track_msg.replace('#NR#',control_panel_get_chk_songs());
	if (confirm(confirm_msg)) {
		document.music_list_form.command.value='admin_approve_music';
		document.music_list_form.approve_music_btn.disabled=true;
		document.music_list_form.delete_music_btn.disabled=true;
		document.music_list_form.submit();
		document.getElementById('control_panel_music_list').innerHTML="<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"height: 100%;\"><tr><td align=center valign=middle style=\"color: #044597;\"><img src=\""+HOST+"/img/loader.gif\" border=\"0\" align=absmiddle /> "+approving_tracks+"...</td></tr></table>";
	}
}

function delete_music_list() {
	var confirm_msg=delete_track_msg.replace('#NR#',control_panel_get_chk_songs());
	if (confirm(confirm_msg)) {
		document.music_list_form.command.value='admin_delete_music';
		document.music_list_form.approve_music_btn.disabled=true;
		document.music_list_form.delete_music_btn.disabled=true;
		document.music_list_form.submit();
		document.getElementById('control_panel_music_list').innerHTML="<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"height: 100%;\"><tr><td align=center valign=middle style=\"color: #044597;\"><img src=\""+HOST+"/img/loader.gif\" border=\"0\" align=absmiddle /> "+deleting_tracks+"...</td></tr></table>";
	}
}

function control_panel_search_artist_list(value) {
	if (document.getElementById('control_panel_search'))
		document.getElementById('control_panel_search').className='control_panel_search_loading';
	control_panel_search_artist_list_post(value);
}

function control_panel_search_artist_list_post(value)
{
	URL=HOST+"/inline_popup.php";
	params="command=admin_search_artist_list&sword="+escape(value);
	
	var xmlHttpReq = null;	
  
	// Mozilla/Safari
	if (window.XMLHttpRequest)
		xmlHttpReq = new XMLHttpRequest();
	// IE
	else if (window.ActiveXObject)
	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

	xmlHttpReq.open('POST', URL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.setRequestHeader("Content-length", params.length);
	xmlHttpReq.setRequestHeader("Connection", "close");
	
	xmlHttpReq.onreadystatechange = function() {
    	if (xmlHttpReq.readyState==4) {    		
		    //respons
			if (document.getElementById('control_panel_search'))
				document.getElementById('control_panel_search').className='control_panel_search';
			if (document.getElementById('control_panel_artist_list'))
				document.getElementById('control_panel_artist_list').innerHTML=xmlHttpReq.responseText;
    	}
	}
	xmlHttpReq.send(params);
}

function delete_profile(artist,id,i) {
	var confirm_msg=delete_profile_msg.replace('#ARTIST#',artist);
	if (confirm(confirm_msg)) {
		var j=0;
		document.getElementById('artists_list_'+i).style.display='none';
		for (var k=0;k<parseInt(document.getElementById('artist_list_len').value);k++)
			if (document.getElementById('artists_list_'+k) && document.getElementById('artists_list_'+k).style.display!='none') {
				document.getElementById('artists_list_'+k).className='artists_list_'+(j%2==0 ? '1' : '0');
				if (document.getElementById('artists_list_index_'+k))
					document.getElementById('artists_list_index_'+k).innerHTML=(j+1);			
				j++;
			}
		control_panel_delete_profile_post(id);
	}
}

function control_panel_delete_profile_post(id)
{
	document.getElementById('control_panel_music_list').innerHTML="<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"height: 100%;\"><tr><td align=center valign=middle style=\"color: #044597;\"><img src=\""+HOST+"/img/loader.gif\" border=\"0\" align=absmiddle /></td></tr></table>";
	document.music_list_form.approve_music_btn.disabled=true;
	document.music_list_form.delete_music_btn.disabled=true;
	
	URL=HOST+"/inline_popup.php";
	params="command=admin_delete_artist_profile&id="+escape(id);
	
	var xmlHttpReq = null;	
  
	// Mozilla/Safari
	if (window.XMLHttpRequest)
		xmlHttpReq = new XMLHttpRequest();
	// IE
	else if (window.ActiveXObject)
	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

	xmlHttpReq.open('POST', URL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.setRequestHeader("Content-length", params.length);
	xmlHttpReq.setRequestHeader("Connection", "close");
	
	xmlHttpReq.onreadystatechange = function() {
    	if (xmlHttpReq.readyState==4) {
			if (xmlHttpReq.responseText.length>0) {
				document.getElementById('control_panel_music_list').innerHTML=xmlHttpReq.responseText;
				document.music_list_form.approve_music_btn.disabled=false;
				document.music_list_form.delete_music_btn.disabled=false;
			}
    	}
	}
	xmlHttpReq.send(params);
}

/*CONTROL PANEL*/

/*MUSICIANS*/

function fix_musicians_list_height() {
	var height_=document.getElementById('genre_holder').offsetHeight,
		top_ = getY(document.getElementById('genre_holder')),
		top_1 = getY(document.getElementById('musicians_artist_list_holder_1')),
		top_2 = getY(document.getElementById('musicians_artist_list_holder_2'));		
	document.getElementById('musicians_artist_list_holder_1').style.height=(height_-(top_1-top_))+'px';
	document.getElementById('musicians_artist_list_1').style.height=((height_-(top_1-top_))-9)+'px';
	document.getElementById('musicians_artist_list_holder_2').style.height=(height_-(top_2-top_))+'px';
	document.getElementById('musicians_artist_list_2').style.height=((height_-(top_2-top_))-9)+'px';
}

function musicians_search_artist_list(value) {
	if (document.getElementById('musicians_search'))
		document.getElementById('musicians_search').className='musicians_search_loading';
	musicians_search_artist_list_post(value);
}

function musicians_search_artist_list_post(value)
{
	URL=HOST+"/inline_popup.php";
	params="command=search_artist_list&sword="+escape(value)+"&genre="+escape(sel_genre);
	
	var xmlHttpReq = null;	
  
	// Mozilla/Safari
	if (window.XMLHttpRequest)
		xmlHttpReq = new XMLHttpRequest();
	// IE
	else if (window.ActiveXObject)
	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

	xmlHttpReq.open('POST', URL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.setRequestHeader("Content-length", params.length);
	xmlHttpReq.setRequestHeader("Connection", "close");
	
	xmlHttpReq.onreadystatechange = function() {
    	if (xmlHttpReq.readyState==4) {    		
		    //respons
			if (document.getElementById('musicians_search'))
				document.getElementById('musicians_search').className='musicians_search';
			if (document.getElementById('musicians_artist_list_2'))
				document.getElementById('musicians_artist_list_2').innerHTML=xmlHttpReq.responseText;
    	}
	}
	xmlHttpReq.send(params);
}

/*MUSICIANS*/

/*DASHBOARD*/

function show_plays_stats() {
	document.plays_stats_form.command.value='generate_plays_stats';
	document.plays_stats_form.submit();
	document.getElementById('dashboard_stat_holder').innerHTML="<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"height: 100%;\"><tr><td align=center valign=middle style=\"color: #044597;\"><img src=\""+HOST+"/img/loader.gif\" border=\"0\" align=absmiddle /> "+generating_graph_msg+"...</td></tr></table>";
	//document.popup_loader.location=HOST+'/inline_popup.php?command=generate_plays_stats&m='+escape(m)+'&y='+escape(y);
}

function update_googlead_code() {
	document.update_googlead_form.command.value='update_googlead_code';
	document.update_googlead_form.submit();
	document.update_googlead_form.command.value='';
	document.update_googlead_form.google_code.disabled=true;
	document.update_googlead_form.google_code_btn.disabled=true;
	document.update_googlead_form.google_code.className='googlead_area_update';
	document.getElementById('google_code_status').className='googlead_status_update';
	document.getElementById('google_code_status').innerHTML='&nbsp;'+google_code_up_msg;
}

function validpass(pass) {
	pass=pass.toLowerCase();
	count=pass.length;
	if (count>16 || count<6)
		return false;
	return true;
}

function dashboard_update_personal() {
	/*
	if (document.update_personal_form.name.value.length==0) {
		alert(name_missing);
		document.update_personal_form.name.focus();
		return false;
	}
	if (document.update_personal_form.fullname.value.length==0) {
		alert(fullname_missing);
		document.update_personal_form.fullname.focus();
		return false;
	}
	if (document.update_personal_form.password.value.length>0 && !validpass(document.update_personal_form.password.value)) {
		alert(password_invalid);
		document.update_personal_form.password.focus();
		return false;
	}
	if (document.update_personal_form.country.options[document.update_personal_form.country.selectedIndex].value=='') {
		alert(country_missing);
		document.update_personal_form.country.focus();
		return false;
	}
	*/
	document.update_personal_form.command.value='dashboard_update_personal';
	document.getElementById('dashboard_update_btn').disabled=true;
	document.getElementById('update_personal_loading').style.display='inline';
	return true;
}

/*DASHBOARD*/

/*PROMOTE*/

function send_twitter_message() {
	if (document.tweet_to_f_form.twitter_uname.value.length==0) {
		document.tweet_to_f_form.twitter_uname.select();
		alert(twitter_username_missing);
		return false;
	}
	if (document.tweet_to_f_form.twitter_pword.value.length==0) {
		document.tweet_to_f_form.twitter_pword.select();
		alert(twitter_password_missing);
		return false;
	}
	if (document.tweet_to_f_form.twitter_message.value.length==0) {
		document.tweet_to_f_form.twitter_message.select();
		alert(twitter_message_missing);
		return false;
	}	
	document.tweet_to_f_form.command.value='send_twitter_message';
	document.getElementById('tweet_to_f_loading').style.display='block';
	return true;
}

function email_contact_support(email) {
	email=email.toLowerCase();
	if ( email.indexOf("@gmail.com") != -1 || email.indexOf("@hotmail.com") != -1 || email.indexOf("@yahoo.com") != -1 || email.indexOf("@aol.com") != -1)
		return true;
	return false;
}

function check_email_contact() {
	if (document.email_contact_form.email.value.length==0) {
		document.email_contact_form.email.select();
		alert(email_contact_email_missing);
		return false;
	}
	/*
	if (!email_contact_support(document.email_contact_form.email.value)) {
		document.email_contact_form.email.select();
		alert(email_contact_email_not_supported);
		return false;
	}
	*/
	if (document.email_contact_form.password.value.length==0) {
		alert(email_contact_password_missing);
		document.email_contact_form.password.select();
		return false;
	}
	document.email_contact_form.command.value='check_email_contact';
	document.getElementById('promote_invite_contacts_loading').style.display='block';
	return true;
}

function check_all_invite_email_form(value) {
	for(var i=0;i<1000;i++)
		if (document.getElementById('email_'+i)) {
			document.getElementById('email_'+i).checked=value;
		} else {
			return;
		}
}

function send_email_contact() {
	for(var i=0;i<1000;i++)
		if (document.getElementById('email_'+i)) {
			if (document.getElementById('email_'+i).checked) {
				document.invite_email_form.command.value='send_email_contact';	
				document.invite_email_form.submit();
				id_='inline_popup_inner';
				if (document.getElementById(id_)) {		
					var width=document.getElementById(id_).offsetWidth;
					var height=document.getElementById(id_).offsetHeight-20;
					document.getElementById(id_).innerHTML="<table width='"+width+"' style='height: "+height+"px;'><tr><td align=center valign=middle style='color: #003459;'><img src='"+HOST+"/img/loader.gif' border=0 align='absmiddle' /> "+sending_invitations+"...</td></tr></table>";
				}
				return true;
			}
		} else {
			alert(no_contact_email_selected);
			return false;
		}	
}

function check_email_list() {
	if (document.email_list_form.list.value.length==0) {
		document.email_list_form.list.select();
		alert(list_is_empty);
		return false;
	}
	document.email_list_form.command.value='check_email_list';
	document.getElementById('email_list_loading').style.display='block';
	return true;
}

/*PROMOTE*/

/*DELETE*/

function delete_profile_() {
	document.user_profile_delete.command.value='delete_profile';
	document.user_profile_delete.submit();
}

/*DELETE*/

/*PROFILE*/

function generate_embed_script(client) {
	var count=parseInt(document.getElementById('song_count').value),
		slist="";
	for (var i=0;i<count;i++)
		if (document.getElementById('song_chk_'+i) && document.getElementById('song_chk_'+i).checked)
			slist+=document.getElementById('song_chk_'+i).value+"|";
	if (slist.length==0) {
		document.getElementById('embed_text').disabled = true;
	} else {
		document.getElementById('embed_text').disabled = false;
		document.getElementById('embed_text').value='<script type="text/javascript">moozzix_client = "'+client+'"; moozzix_format = "240x145"; moozzix_slist = "'+slist+'";</script><script type="text/javascript" src="'+HOST+'/moozzix/m.js"></script>';
	}
}

/*PROFILE*/

/*AD CODE*/

function update_ad_code_xmlhttpPost_item(URL,params)
{
	var xmlHttpReq = null;	
  
	// Mozilla/Safari
	if (window.XMLHttpRequest)
		xmlHttpReq = new XMLHttpRequest();
	// IE
	else if (window.ActiveXObject)
	    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");

	xmlHttpReq.open('POST', URL, true);
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.setRequestHeader("Content-length", params.length);
	xmlHttpReq.setRequestHeader("Connection", "close");
	
	xmlHttpReq.onreadystatechange = function() {
    	if (xmlHttpReq.readyState==4) {
			var response=parseInt(xmlHttpReq.responseText);
			switch (response) {
				case -1:
					url(HOST+'/index.php?logout=true');
					break;
				case 1:
					parent.document.update_googlead_form.google_code.disabled=false;
					parent.document.update_googlead_form.google_code_btn.disabled=false;
					parent.document.update_googlead_form.google_code.className='googlead_area';
					parent.document.getElementById('google_code_status').className='googlead_status';
					parent.document.getElementById('google_code_status').innerHTML=status_txt+': '+active_txt;
					document.getElementById('core_preview').src=HOST+'/ad_script.php?command=code_preview';
					break;
				default:
					parent.document.update_googlead_form.google_code.disabled=false;
					parent.document.update_googlead_form.google_code_btn.disabled=false;
					parent.document.update_googlead_form.google_code.className='googlead_area_invalid';
					parent.document.getElementById('google_code_status').className='googlead_status_invalid';
					parent.document.getElementById('google_code_status').innerHTML=status_txt+': '+inactive_txt;	
					document.getElementById('core_preview').src=HOST+'/ad_script.php?command=code_preview';
					break;
			}
    	}
	}
	xmlHttpReq.send(params);
}

function update_ad_code() {
	document.update_googlead_form.google_code.disabled=true;
	document.update_googlead_form.google_code_btn.disabled=true;
	document.update_googlead_form.google_code.className='googlead_area_update';
	document.getElementById('google_code_status').className='googlead_status_update';
	document.getElementById('google_code_status').innerHTML='&nbsp;'+google_code_up_msg;
	
	update_ad_code_xmlhttpPost_item(HOST+'/inline_popup.php','command=update_ad_code&code='+escape(document.getElementById('google_code').value))
	
}
