// Showme
var stopflag = 0;
var oldmenu = '';
var dnav = '';

function showme(ID){
	stopnoshow('');
	if (oldmenu != ''){
		$(oldmenu).style.display='none';
		
		if(oldmenu == 'contest'){
			$(oldmenu+'_nav').removeClassName('hove');
		}else {
			$(oldmenu+'_nav').removeClassName('hov');
		}
		
	}
	
	if(ID == 'contest'){
		$(ID+'_nav').addClassName('hove');
	}else{
		$(ID+'_nav').addClassName('hov');
	}
	
	$(ID).style.display='block';
	oldmenu = ID;
}
function startnoshow(ID){
	stopflag = 1;
	oldmenu = ID;
	setTimeout("noshow()",'500');
}

function noshow(){
	if (stopflag == 1){
		if (oldmenu != ''){
			$(oldmenu).style.display='none';
			
			if(oldmenu == 'contest'){
				$(oldmenu+'_nav').removeClassName('hove');
			}else{
				$(oldmenu+'_nav').removeClassName('hov');	
			}
			
		}
		oldmenu = '';
		stopflag = 0;
		if (dnav != ''){
			showme(dnav); 
		}
	}
}

function stopnoshow(){
	stopflag = 0;
}

// ############ Blog Tabs

//var showing = 'recent';
var showing = 'recent';

function showtab(ID){
	
	$(showing).style.display = 'none'; // hides current body
	
	$(showing+'_tab').style.backgroundColor='#979797'; // resets current tab
	$(showing+'_tab').style.borderBottom='1px solid #979797';
	$(showing+'_tab').style.height='24px';
	$(showing+'_tab').style.color='#393939';
	$(showing+'_tab').style.backgroundImage='URL(images/bg_blogtab.gif)';


	$(ID+'_tab').style.backgroundColor='#fd920c'; // highlights new tab
	$(ID+'_tab').style.backgroundImage='none';
	$(ID+'_tab').style.borderBottom='none';
	$(ID+'_tab').style.height='25px';
	$(ID+'_tab').style.color='#fff';
	
	
	$(ID).style.display = 'block'; // displays new body
	
	showing = ID; // sets new body to current variable
}

// ################## FLASH JS COMM

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function stopplay(){
	movy = getFlashMovie("singleplayer");
	if (movy.length){
		for(i=0; i < movy.length; i++){
			movy[i].stopit();
		}
	} else {
		movy.stopit();
	}
	bigplayer = getFlashMovie("player");
	if (bigplayer != "undefined")
		bigplayer.stopit();
}




// ################### SCROLL BAR FOR AUDIO DIVS

function initaudiosb(ider){
	// set position to relative, if not absolute
	if ($(ider).style.position != 'absolute') $(ider).style.position='relative';
	// set track prop
	track = $(ider+'_track');
	track.style.height='100%';
	track.style.position='absolute';
	track.style.right='0px';
	track.style.tip='0px';
	// set handle prop
	handle = $(ider+'_handle');
	handle.style.width='100%';
	// set content prop
	content = $(ider+'_content');
	content.style.width = $(ider).scrollWidth - track.scrollWidth -5 + 'px';
	content.style.height = '100%';
	content.style.position = 'absolute';
	content.style.overflow = 'hidden';
	var scrollbar = new Control.ScrollBar(ider+'_content',ider+'_track');
	// scrolling down
	scrollbar.down = false;
	if($(ider+'_d')){
		$(ider+'_d').observe('mousedown',function(event){
			scrollbar.down = true;
			sdown();
			event.stop();
		});
		function sdown(){
			scrollbar.scrollBy(12);
			if(scrollbar.down){
				setTimeout(function(){sdown();}, 50);
			}
		}
		$(ider+'_d').observe('mouseup',function(event){
			scrollbar.down = false;
			event.stop();
		});
	}
	// scrolling up
	scrollbar.up = false;
	if($(ider+'_u')){	
		$(ider+'_u').observe('mousedown',function(event){
			scrollbar.up = true;
			supit();
			event.stop();
		});
		
		function supit(){
			scrollbar.scrollBy(-12);
			if(scrollbar.up){
				setTimeout(function(){supit();}, 50);
			}
		}
		
		$(ider+'_u').observe('mouseup',function(event){
			scrollbar.up = false;
			event.stop();
		});
	}
	return scrollbar;
}


function initcontestsb(ider){
	// set position to relative, if not absolute
	if ($(ider).style.position != 'absolute') $(ider).style.position='relative';
	// set track prop
	track = $(ider+'_track');
	track.style.height='100%';
	track.style.position='absolute';
	track.style.right='0px';
	track.style.tip='0px';
	// set handle prop
	handle = $(ider+'_handle');
	handle.style.width='100%';
	// set content prop
	content = $(ider+'_content');
	content.style.width = $(ider).scrollWidth - track.scrollWidth -5 + 'px';
	content.style.height = '100%';
	content.style.position = 'absolute';
	content.style.overflow = 'hidden';
	var scrollbar = new Control.ScrollBar(ider+'_content',ider+'_track');
	// scrolling down
	scrollbar.down = false;
	if($(ider+'_d')){
		$(ider+'_d').observe('mousedown',function(event){
			scrollbar.down = true;
			sdown();
			event.stop();
		});
		function sdown(){
			scrollbar.scrollBy(12);
			if(scrollbar.down){
				setTimeout(function(){sdown();}, 50);
			}
		}
		$(ider+'_d').observe('mouseup',function(event){
			scrollbar.down = false;
			event.stop();
		});
	}
	// scrolling up
	scrollbar.up = false;
	if($(ider+'_u')){	
		$(ider+'_u').observe('mousedown',function(event){
			scrollbar.up = true;
			supit();
			event.stop();
		});
		
		function supit(){
			scrollbar.scrollBy(-12);
			if(scrollbar.up){
				setTimeout(function(){supit();}, 50);
			}
		}
		
		$(ider+'_u').observe('mouseup',function(event){
			scrollbar.up = false;
			event.stop();
		});
	}
	return scrollbar;
}

function makenumber(value){
	clean = value.replace(/[^\d]/g, ''); 
	return clean;
}

function validateComments(blogID)
{
	filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	
	if( $('commentedBy'+blogID).value == "" ) {
		alert('Please enter your name');
		$('commentedBy'+blogID).focus();
		return false;
	}
	else if( ( $('email'+blogID).value == "" ) ) {
		alert('Please enter your email address');
		$('email'+blogID).focus();
		return false;
	}
	else if( filter.test($('email'+blogID).value) == false ) {
		alert('Please enter valid email address');
		$('email'+blogID).focus();
		return false;
	}
	else if( $('comments'+blogID).value == "" ) {
		alert('Please enter your comments');
		$('comments'+blogID).focus();
		return false;
	}
	/*else if( $('code'+blogID).value != $('captcha'+blogID).value ) {
		alert('Invalid captcha code');
		$('code'+blogID).focus();
		return false;
	}*/
}

function showhide(showDiv, hideDiv, cla1, cla2) {
	if($(showDiv).style.display == 'none') {
		$(showDiv).style.display = '';
		$(hideDiv).style.display = 'none';
		/*$(cla1).setAttribute("class", "link3");
		$(cla2).setAttribute("class", "link2");*/
	} else {
		$(showDiv).style.display = 'none';
		$(hideDiv).style.display = 'none';
		/*$(cla1).setAttribute("class", "link3");
		$(cla2).setAttribute("class", "link2")*/;
	}
	/*$(showDiv).style.display = '';
	$(hideDiv).style.display = 'none';
	$(cla1).setAttribute("class", "link3");
	$(cla2).setAttribute("class", "link2");*/
}

function showhide1(showDiv, count) {

	for(var i = 0; i < count; i++) {
		
		commentDiv = 'commentDiv'+i;
		postCommentDiv = 'postCommentDiv'+i; 
		
		C1 = 'C1'+i;
		C2 = 'C1'+i;
		
		if( (showDiv == commentDiv) || (showDiv == postCommentDiv) ) {
			
			if(showDiv == commentDiv) {
				if($(commentDiv).style.display == 'none') {
					$(commentDiv).style.display = '';
					$(postCommentDiv).style.display = 'none';
				} else {
					$(commentDiv).style.display = 'none';
					$(postCommentDiv).style.display = 'none';
				}
			} else {
				if($(postCommentDiv).style.display == 'none' ) {
					$(postCommentDiv).style.display = '';
					$(commentDiv).style.display = 'none';
				} else {
					$(postCommentDiv).style.display = 'none';
					$(commentDiv).style.display = 'none';
				}
			}
			
		} else {
			
			$(commentDiv).style.display = 'none';
			$(postCommentDiv).style.display = 'none';
			$(C1).setAttribute("class", "link2");
			$(C2).setAttribute("class", "link2");
			
		}
		
	}
}

function validateSubmitEntry(){
	filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	
	if($('name').value == ""){
		alert("All fields are required");
		$('name').focus();
		return false;
	} else if($('location').value == "") {
		alert("All fields are required");
		$('location').focus();
		return false;
	} else if($('userEmail').value == "") {
		alert("All fields are required");
		$('userEmail').focus();
		return false;
	} else if(!filter.test($('userEmail').value)) {
		alert("Please enter valid email address");
		$('userEmail').focus();
		return false;
	} else if($('userEmail').value != $('reEmail').value) {
		alert("The email addresses that you have entered do not match");
		$('reEmail').focus();
		return false;
	} else if($('image').value == "") {
		alert("All fields are requirede");
		$('image').focus();
		return false;
	} else if(checkPhoto('image') == false) {
		alert("Please enter .gif, .jpg or .png image");
		$('image').focus();
		return false;
	} else if($('uTubeLink').value == "") {
		alert("All fields are required");
		$('uTubeLink').focus();
		return false;
	} else if($('acceptTerms').checked == false) {
		alert("Please confirm that you have read the contest rules");
		$('acceptTerms').focus();
		return false;
	}
}

function checkPhoto(picField) {
 var picFile = picField;
 var imagePath = $(picFile).value;
 var pathLength = imagePath.length;
 var lastDot = imagePath.lastIndexOf(".");
 var fileType = imagePath.substring(lastDot,pathLength);
 if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".jpeg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG") || (fileType == ".JPEG")) {
  	return true;
 } else {
	return false;
 }
}

function validateComment(){
	if($('name').value == ""){
		alert("Please enter your name.");
		$('name').focus();
		return false;
	}
	if($('comments').value == ""){
		alert("Please enter your comments.");
		$('comments').focus();
		return false;
	}
}

function validateVotingEmail(email){
	
	filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if(document.getElementById(email).value == ""){
		alert("Please enter your email address.");
		$(email).focus();
		return false;
	}
	
	if(!filter.test($(email).value)){
		alert("Please enter valid email address.");
		$(email).focus();
		return false;
	}
}

function validateDownloadInfo()
{
	filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	
	if($('name').value == ""){
		alert("Please enter your name");
		$('name').focus();
		return false;
	} else if($('city').value == "") {
		alert("Please enter your city");
		$('city').focus();
		return false;
	} else if($('userEmail').value == "") {
		alert("Please enter your email");
		$('userEmail').focus();
		return false;
	} else if(!filter.test($('userEmail').value)) {
		alert("Please enter valid email address");
		$('userEmail').focus();
		return false;
	} else if($('acceptTerms').checked == false) {
		alert("Please confirm that you have read the Contest  - Non-Exclusive Beat Agreement");
		$('acceptTerms').focus();
		return false;
	}
	$('contactfv').style.visibility = 'hidden';
	document.contest_beats.submit();
}
