//Image Swopping
var totalImages = 66; // Total images used

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);

ns3up = (browserName == "Netscape" && browserVer >= 3);
ie4up = (browserName.indexOf("Microsoft") >= 0 && browserVer >= 4);

function showPic(imgName) 
{
	if (ns3up || ie4up) 
		imgOn = ("/media/trufm/images/nav/" + imgName);
		
	document.mainpic.src = imgOn;
}

if(document.images)
{
	mFX = new Array(totalImages);
	for(i = 0; i < mFX.length; i++)
	{
		mFX[i] = new Image();
	}
	
	//Main Banner DJ Links
	mFX[0].src = "/media/trufm/images/btn-blue-visit.jpg";
	mFX[1].src = "/media/trufm/images/btn-orange-visit.jpg";
	mFX[2].src = "/media/trufm/images/btn-blue-listen.jpg";
	mFX[3].src = "/media/trufm/images/btn-orange-listen.jpg";
	mFX[4].src = "/media/trufm/images/btn-blue-message.jpg";
	mFX[5].src = "/media/trufm/images/btn-orange-message.jpg";
	//Sub Page Content
	mFX[6].src = "/media/trufm/images/sub-icon_print.jpg";
	mFX[7].src = "/media/trufm/images/sub-icon_print_over.jpg";
	mFX[8].src = "/media/trufm/images/sub-icon_fav.jpg";
	mFX[9].src = "/media/trufm/images/sub-icon_fav_over.jpg";
	mFX[10].src = "/media/trufm/images/sub-icon_send.jpg";
	mFX[11].src = "/media/trufm/images/sub-icon_send_over.jpg";
	//Button Hovers
	mFX[12].src = "/media/trufm/images/nav/btn-nt_search.jpg";
	mFX[13].src = "/media/trufm/images/nav/btn-nt_search_over.jpg";
	mFX[14].src = "/media/trufm/images/home_blogupdates/btn-search_btn.jpg";
	mFX[15].src = "/media/trufm/images/home_blogupdates/btn-search_btn_over.jpg";
	mFX[16].src = "/media/trufm/images/home_newsletter/btn-nc_signup.jpg";
	mFX[17].src = "/media/trufm/images/home_newsletter/btn-nc_signup_over.jpg";
	mFX[18].src = "/media/trufm/images/home_poll/btn-submit.jpg";
	mFX[19].src = "/media/trufm/images/home_poll/btn-submit_over.jpg";
	mFX[20].src = "/media/trufm/images/home_poll/btn-results.jpg";
	mFX[21].src = "/media/trufm/images/home_poll/btn-results_over.jpg";
	mFX[22].src = "/media/trufm/images/sub_contact/btn-ccfc_submit.jpg";
	mFX[23].src = "/media/trufm/images/sub_contact/btn-ccfc_submit_over.jpg";
	mFX[24].src = "/media/trufm/images/sub_contact/btn-ccfc_clear.jpg";
	mFX[25].src = "/media/trufm/images/sub_contact/btn-ccfc_clear_over.jpg";
	mFX[26].src = "/media/trufm/images/sub_account/btn-l_login.jpg";
	mFX[27].src = "/media/trufm/images/sub_account/btn-l_login_over.jpg";
	mFX[28].src = "/media/trufm/images/sub_account/btn-r_check_avail.jpg";
	mFX[29].src = "/media/trufm/images/sub_account/btn-r_check_avail_over.jpg";
	mFX[30].src = "/media/trufm/images/sub_account/btn-ar_send.jpg";
	mFX[31].src = "/media/trufm/images/sub_account/btn-ar_send_over.jpg";
	mFX[32].src = "/media/trufm/images/sub_account/btn-r_update.jpg";
	mFX[33].src = "/media/trufm/images/sub_account/btn-r_update_over.jpg";
	mFX[34].src = "/media/trufm/images/sub_blogs/btn-post_comment.jpg";
	mFX[35].src = "/media/trufm/images/sub_blogs/btn-post_comment_over.jpg";
	mFX[36].src = "/media/trufm/images/home_competitions/bg-competition_item_a.jpg";
	mFX[37].src = "/media/trufm/images/home_competitions/bg-competition_item_ao.jpg";
	mFX[38].src = "/media/trufm/images/home_events/bg-events_item_a.jpg";
	mFX[39].src = "/media/trufm/images/home_events/bg-events_item_ao.jpg";
	
	//Top Nav
	mFX[40].src = "/media/trufm/images/nav/home.jpg";
	mFX[41].src = "/media/trufm/images/nav/home-over.jpg";
	mFX[42].src = "/media/trufm/images/nav/home-on.jpg";
	
	mFX[43].src = "/media/trufm/images/nav/station.jpg";
	mFX[44].src = "/media/trufm/images/nav/station-over.jpg";
	mFX[45].src = "/media/trufm/images/nav/station-on.jpg";
	
	mFX[46].src = "/media/trufm/images/nav/shows.jpg";
	mFX[47].src = "/media/trufm/images/nav/shows-over.jpg";
	mFX[48].src = "/media/trufm/images/nav/shows-on.jpg";
	
	mFX[49].src = "/media/trufm/images/nav/competitions.jpg";
	mFX[50].src = "/media/trufm/images/nav/competitions-over.jpg";
	mFX[51].src = "/media/trufm/images/nav/competitions-on.jpg";
	
	mFX[52].src = "/media/trufm/images/nav/chart.jpg";
	mFX[53].src = "/media/trufm/images/nav/chart-over.jpg";
	mFX[54].src = "/media/trufm/images/nav/chart-on.jpg";
	
	mFX[55].src = "/media/trufm/images/nav/events.jpg";
	mFX[56].src = "/media/trufm/images/nav/events-over.jpg";
	mFX[57].src = "/media/trufm/images/nav/events-on.jpg";
	
	mFX[58].src = "/media/trufm/images/nav/blog.jpg";
	mFX[59].src = "/media/trufm/images/nav/blog-over.jpg";
	mFX[60].src = "/media/trufm/images/nav/blog-on.jpg";
	
    //praekelt added
    mFX[61].src = "/media/trufm/images/home_poll/btn-vote.gif";
	mFX[62].src = "/media/trufm/images/home_poll/btn-vote_over.gif";
	
	//mammoth added - phase 2
	mFX[63].src = "/media/trufm/images/nav/reviews.jpg";
	mFX[64].src = "/media/trufm/images/nav/reviews-over.jpg";
	mFX[65].src = "/media/trufm/images/nav/reviews-on.jpg";
}

function imgFX(img, num)
{
	if(document.images)
	{
		document.images[img].src = mFX[num].src;
	}
}

function navbarFX(element)
{
    alert(element);
}

function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//Btn Rollover
function rolloverBtn(img, num)
{
	document.getElementById(img).src=mFX[num].src;
}

//Player Open
function openPlayer() 
{
	//window.open('/player/playerp2p?participant=yes', 'player', 'location=0,status=0,scrollbars=0,width=385,height=148')
	//window.open('/player/trufmplayer?participant=yes', 'player', 'location=0,status=0,scrollbars=0,width=385,height=148')
	window.open('/player?participant=yes', 'player', 'location=0,status=0,scrollbars=0,width=385,height=148')
}

//Top Nav Morpher
function morpher(id) 
{
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) 
	{
		if (document.getElementById('smenu'+i)) 
		   {document.getElementById('smenu'+i).style.display='none';}
	}
	if (d) 
	   {d.style.display='inline';}
}

//validateSearch
function validateSearch()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("nav_search_term"))
		fv.raiseError("Please enter a search term.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validatePoll
function validatePoll()
{
	fv =  new formValidator();
	
	if (!fv.isCheckedRadio("option_id"))
		fv.raiseError("Please select your answer.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateBlogSearch
function validateBlogSearch()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("search_terms"))
		fv.raiseError("Please enter a search term.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateNewsletter
function validateNewsletter()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("newsletter_email"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("newsletter_email"))
			fv.raiseError("Please enter a valid email address.");
	}
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateContact
function validateContact()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("your_name"))
		fv.raiseError("Please enter your name.");
		
	if (fv.isEmpty("your_email"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("your_email"))
			fv.raiseError("Please enter a valid email address.");
	}
		
	if (fv.isEmpty("your_subject"))
		fv.raiseError("Please enter the subject.");
		
	if (fv.isEmpty("your_message"))
		fv.raiseError("Please enter your message to trufm.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateDJContact
function validateDJContact()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("your_name"))
		fv.raiseError("Please enter your name.");
		
	if (fv.isEmpty("your_email"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("your_email"))
			fv.raiseError("Please enter a valid email address.");
	}
		
	if (fv.isEmpty("your_subject"))
		fv.raiseError("Please enter the subject.");
		
	if (fv.isEmpty("select_dj"))
		fv.raiseError("Please select a DJ.");
		
	if (fv.isEmpty("your_message"))
		fv.raiseError("Please enter your message to the DJ.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateCompetitionDetailEnterT
function validateCompetitionDetailEnterT()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("comp_answer_t"))
		fv.raiseError("Please enter your answer.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateCompetitionDetailEnterR
function validateCompetitionDetailEnterR()
{
	fv =  new formValidator();
	
	if (!fv.isCheckedRadio("comp_answer_r"))
		fv.raiseError("Please select your answer.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validatePostComment
function validatePostComment()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("comment"))
		fv.raiseError("Please enter your comment on this post.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateSendToFriend
function validateSendToFriend()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("your_name"))
		fv.raiseError("Please enter your name.");
		
	if (fv.isEmpty("your_email"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("your_email"))
			fv.raiseError("Please enter a valid email address.");
	}
	
	if (fv.isEmpty("friend_email"))
		fv.raiseError("Please enter your friend/s email address.");
		
	if (fv.isEmpty("your_message"))
		fv.raiseError("Please enter your message.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateReportAbuse
function validateReportAbuse()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("your_name"))
		fv.raiseError("Please enter your name.");
		
	if (fv.isEmpty("your_email"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("your_email"))
			fv.raiseError("Please enter a valid email address.");
	}
		
	if (fv.isEmpty("reason_offence"))
		fv.raiseError("Please enter the reason you found this offensive.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateAccountReminder
function validateAccountReminder()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("your_email"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("your_email"))
			fv.raiseError("Please enter a valid email address.");
	}
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateLogin
function validateLogin()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("username"))
		fv.raiseError("Please enter your username.");
		
	if (fv.isEmpty("password"))
		fv.raiseError("Please enter your password.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateRegister
function validateRegister()
{
	fv =  new formValidator();
	
	if (fv.isEmpty("username"))
		fv.raiseError("Please enter your username.");
		
	if (fv.isEmpty("password"))
		fv.raiseError("Please enter your password.");
		
	if (fv.isEmpty("password_confirm"))
		fv.raiseError("Please confirm your password.");

	if (fv.isEmpty("first_name"))
		fv.raiseError("Please enter your name.");
		
	if (fv.isEmpty("last_name"))
		fv.raiseError("Please enter your surname.");
		
	if (fv.isEmpty("email_address"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("email_address"))
			fv.raiseError("Please enter a valid email address.");
	}
	
	if (fv.isEmpty("spam_protect"))
		fv.raiseError("Please enter the spam protection code.");
		
	if (!fv.isChecked("terms"))
		fv.raiseError("Please accept the trufm terms and conditions to complete the registry process");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateAccountDetails
function validateAccountDetails()
{
	fv =  new formValidator();
		
	if (fv.isEmpty("first_name"))
		fv.raiseError("Please enter your first name.");
		
	if (fv.isEmpty("last_name"))
		fv.raiseError("Please enter your last name.");
		
	if (fv.isEmpty("email_address"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("email_address"))
			fv.raiseError("Please enter a valid email address.");
	}
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateLoginDetails
function validateLoginDetails()
{
	fv =  new formValidator();
		
	if (fv.isEmpty("password"))
		fv.raiseError("Please enter your password.");
		
	if (fv.isEmpty("password_confirm"))
		fv.raiseError("Please confirm your password.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//Add to Favourites
function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	}
	
//Show Line Up Morpher
function dayMorph(id) 
{
	var sd = document.getElementById(id);
	for (var i = 0; i<=10; i++) 
	{
		if (document.getElementById('sd'+i)) 
		   {document.getElementById('sd'+i).style.display='none';}
	}
	if (sd) 
	   {sd.style.display='inline';}
}
//Show Poll Results
function showHideResults() 
{
    options = document.getElementById('poll_options');
    results = document.getElementById('poll_results');

    options_btns = document.getElementById('poll_buttons');
    results_btns = document.getElementById('poll_results_buttons');

    if (options.style.display == 'none')
    {
	    options.style.display='inline';
	    results.style.display='none';
	    
        options_btns.style.display='inline';
	    results_btns.style.display='none';
	}
    else
    {
	    options.style.display='none';
	    results.style.display='inline';
        
        options_btns.style.display='none';
	    results_btns.style.display='inline';
    }


}

/* PHASE 2 JS FUNCTIONS */

//validateEventSubmit
function validateEventSubmit()
{
	fv =  new formValidator();
		
	if (fv.isEmpty("first_name"))
		fv.raiseError("Please enter your first name.");
		
	if (fv.isEmpty("last_name"))
		fv.raiseError("Please enter your last name.");
		
	if (fv.isEmpty("email_address"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("email_address"))
			fv.raiseError("Please enter a valid email address.");
	}
	
	if (fv.isEmpty("contact_number"))
		fv.raiseError("Please enter your contact number.");
		
	if (fv.isEmpty("company"))
		fv.raiseError("Please enter your company name.");
		
	if (fv.isEmpty("event_title"))
		fv.raiseError("Please enter the event title.");
		
	if (fv.isEmpty("venue"))
		fv.raiseError("Please enter the event venue.");
		
	if (fv.isEmpty("city_town"))
		fv.raiseError("Please enter the city or town.");
		
	if (fv.isEmpty("province"))
		fv.raiseError("Please select the province.");
		
	if (fv.isEmpty("sd_day"))
		fv.raiseError("Please select the start date - day.");
		
	if (fv.isEmpty("sd_month"))
		fv.raiseError("Please select the start date - month.");
		
	if (fv.isEmpty("sd_year"))
		fv.raiseError("Please select the start date - year.");
		
	if (fv.isEmpty("ed_day"))
		fv.raiseError("Please select the end date - day.");
		
	if (fv.isEmpty("ed_month"))
		fv.raiseError("Please select the end date - month.");
		
	if (fv.isEmpty("ed_year"))
		fv.raiseError("Please select the end date - year.");
		
	if (fv.isEmpty("category"))
		fv.raiseError("Please select the category.");
		
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//validateGallerySubmit
function validateGallerySubmit()
{
	fv =  new formValidator();
		
	if (fv.isEmpty("first_name"))
		fv.raiseError("Please enter your first name.");
		
	if (fv.isEmpty("last_name"))
		fv.raiseError("Please enter your last name.");
		
	if (fv.isEmpty("email_address"))
		fv.raiseError("Please enter your email address.");
	else
	{	
  		if (!fv.isEmailAddress("email_address"))
			fv.raiseError("Please enter a valid email address.");
	}
	
	if (fv.isEmpty("contact_number"))
		fv.raiseError("Please enter your contact number.");
		
	if (fv.isEmpty("company"))
		fv.raiseError("Please enter your company name.");
		
	if (fv.isEmpty("event_title"))
		fv.raiseError("Please enter the event title.");
		
	if (fv.isEmpty("venue"))
		fv.raiseError("Please enter the event venue.");
		
	if (fv.isEmpty("city_town"))
		fv.raiseError("Please enter the city or town.");
		
	if (fv.isEmpty("ed_day"))
		fv.raiseError("Please select the end date - day.");
		
	if (fv.isEmpty("ed_month"))
		fv.raiseError("Please select the end date - month.");
		
	if (fv.isEmpty("ed_year"))
		fv.raiseError("Please select the end date - year.");
		
	if (fv.isEmpty("gallery_pic_01"))
		fv.raiseError("Please upload at least one picture.");
		
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;
}

//Username check

$(function() {
    $("#avail_check").click(function() {
        response_element = $('#username_byline > p')
        response_element.html('Checking, Please Wait...');
            
        $.post("/ajax/username/", {'username': $('#id_username').attr('value') }, function(data) {
            response_element.html('<span class="error">' + data + '</span>');
        });
        return false;
    });
});

// Comment
function beforeSubmitComment(formData, jqForm, options) {
    $("#bdc_commentsform_btns").css('display', 'none');
    $("#bdc_commentsform_prog").css('display', 'inline');
}

$(function() {
    $('.bdc_commentsform_btns > #submit').live("click", function () {
        var options = { 
            beforeSubmit:  beforeSubmitComment,
            target:        '.bdc_blog_comments_container'
        }
        $('#frmPostComment').ajaxForm(options);
    });
});

// Newsletter Subscribe
function beforeSubmitNewsletterSubscribe(formData, jqForm, options) {
    $("#nc_subscribe_input").css("display", "none");
    $("#nc_subscribe_prog").css("display", "inline");
}

function successNewsletterSubscribe(responseText, statusText) {
    $("#nc_subscribe_input").css("display", "inline");
    $("#nc_subscribe_prog").css("display", "none");
    $("#nc_news_email").attr("value", responseText);
}

$(function() {
    $('.nc_news_btn > #newsletter').live("click", function () {
        var options = { 
             beforeSubmit:  beforeSubmitNewsletterSubscribe,
             success:       successNewsletterSubscribe
        }
        $('#frmNewsletter').ajaxForm(options);
    });
});

// Poll Vote
function beforePollVote(formData, jqForm, options) {
    $("#poll_buttons").css("display", "none");
    $("#poll_prog").css("display", "inline");
}

function successPollVote(responseText, statusText) {
    showHideResults();
    $("#poll_voted").css("display", "inline");
    $("#poll_prog").remove()
    $("#poll_results_buttons").remove();
    $("#poll_buttons").remove();
}

$(function() {
    $('#pollsub').live("click", function () {
        if (validatePoll()) {
            var options = { 
                 beforeSubmit:  beforePollVote,
                 success:       successPollVote
            }
            $('#frmPoll').ajaxForm(options);
        }
        else
            return false;
    });
});
