/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}
window.onload = initShowHideDivs;

// general functions

function selectAll(x) {
	for(var i=0,l=x.form.length; i<l; i++)
	if(x.form[i].type == 'checkbox' && x.form[i].name != 'sAll')
	x.form[i].checked=x.form[i].checked?false:true
}

function Redirectit(linkurl) {
	window.location.href=linkurl;
}

// text field insertion

function insertAtCursor(myField, myValue) {
	myValue = ' ' + myValue + ' ';
	//IE support
	if (document.selection) {
		myField.focus();	
		//in effect we are creating a text range with zero
		//length at the cursor location and replacing it
		//with myValue
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	
	//Mozilla/Firefox/Netscape 7+ support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		//Here we get the start and end points of the
		//selection. Then we create substrings up to the
		//start of the selection and from the end point
		//of the selection to the end of the field value.
		//Then we concatenate the first substring, myValue,
		//and the second substring to get the new value.
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

function insertTag(myField, myValue, addValue) {
	if(myValue=='b')
		myValue = ' [b]text[/b] ';
	if(myValue=='i')
		myValue = ' [i]text[/i] ';
	if(myValue=='u')
		myValue = ' [u]text[/u] ';
	if(myValue=='quote')
		myValue = ' [quote]text[/quote] ';
	if(myValue=='code')
		myValue = ' [code]code[/code] ';
	if(myValue=='list')
		myValue = ' [list]text[/list] ';
	if(myValue=='img')
		myValue = ' [img]http://image_url[/img] ';
	if(myValue=='url')
		myValue = ' [url]http://url[/url] ';
	if(myValue=='youtube')
		myValue = ' [youtube]youtube_ID[/youtube] ';
	if(myValue=='color')
		myValue = ' [color='+ addValue +'][/color] ';
	if(myValue=='size')
		myValue = ' [size='+ addValue +'][/size] ';
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	
	//Mozilla/Firefox/Netscape 7+ support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

function SelectAll(id){
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

/* formatação para qualquer mascara */

function popupUC(pg,nome,w,h,s){//popUp Unico Central - onClick="popupUC('localizacao_popup.htm','local',700,500,'yes')"
	var x; 	var y;
	x = (screen.width-w)/2;	y = (screen.height-h)/2;	
	//window.+nome+.resizeTo(x, y);
	window.open(pg,nome,'scrollbars='+s+',toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width='+w+',height='+h+',left='+x+',top='+y+',window.focus( )');	
}

// confirmation

function confirmation(url) {
	var answer = confirm("Are you sure you want to delete it?")
	if (answer)	window.location = url;
}

function reportabuse(url) {
	var answer = confirm("By clicking OK you will report an abuse of the user who published this image. Are you sure you want to proceed?")
	if (answer)	window.location = url;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// content

function RemoveContent(d) {
	document.getElementById(d).style.display = "none";
}

function InsertContent(d) {
	document.getElementById(d).style.display = "";
}

// dynamic pop up

function setOpacity( value,divname ) {
 document.getElementById(divname).style.opacity = value / 5;
 document.getElementById(divname).style.filter = 'alpha(opacity=' + value * 5 + ')';

}

function fadeInMyPopup(divname) {
 for( var i = 0 ; i <= 100 ; i++ ){
   setTimeout( "setOpacity(" + (i / 10) + ",'"+divname+"')" , 8 * i );
   }
}

function fadeOutMyPopup(divname) {
 for( var i = 0 ; i <= 100 ; i++ ) {
   setTimeout( "setOpacity(" + (10 - i / 10) + ",'"+divname+"')" , 8 * i );
 }

 setTimeout("closeMyPopup('"+divname+"')", 800 );
}

function closeMyPopup(divname) {
 document.getElementById(divname).style.display = "none"
}

function fireMyPopup(divname) {
 setOpacity( 0, divname);
 document.getElementById(divname).style.display = "block";
 fadeInMyPopup(divname);
}

// ========================================================
// standard swap image button
// ========================================================
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];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ========================================================
// voting video
// ========================================================
var xmlHttp

function showHint(str){
	if (str.length==0){ 
		document.getElementById("txtHint").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	document.getElementById("txtHint").innerHTML = "<img src='/img/standard/loading.gif' /> Processing request...";
	var url="http://www.theb9.com/includes/vote_video.php"
	url=url+"?ID="+str
	
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
	} 
} 

function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

// ========================================================
// end voting video
// ========================================================

// ========================================================
// voting picture
// ========================================================
var xmlHttp

function showHintP(str){
	if (str.length==0){ 
		document.getElementById("txtHint").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	document.getElementById("txtHint").innerHTML = "<img src='/img/standard/loading.gif' /> Processing request...";
	var url="http://www.theb9.com/includes/vote_picture.php"
	url=url+"?ID="+str
	
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

// ========================================================
// end voting video
// ========================================================

// validate

function ValidaSenha(SENHA){
	if(document.getElementById("pword1").value.length < 6) {// || document.getElementById("senha").value.length > 8)
		alert("Password must have more than 6 letters/numbers");
		return false;
	}
	return true;
}

function ChecaSenha(SENHA2){
	if(document.getElementById("pword1").value != SENHA2){
		alert("The two passwords don't match");
		return false;
	}
	else
		return true;
}


// expressões regulares para validações

//e-mail
re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
//telefone
reTel = /^\d+$/;
//cep
reCep = /^[0-9]/;

function valida(campoemail)
{
	if (document.getElementById(campoemail).value == null || document.getElementById(campoemail).value == ""){
		alert("Please insert a valid e-mail address");
		return false;
	}
	else if (!re.test(document.getElementById(campoemail).value)){
		alert("Please insert a valid e-mail address");
		return false;
	}
	return true;
}

function validateSearch(cadastro){	
	if((cadastro.search_city.value == null || cadastro.search_city.value == "" || cadastro.search_city.value == "Search city") && (cadastro.search_name.value == null || cadastro.search_name.value == "" || cadastro.search_name.value == "Search name")) {
		alert("Please insert at least a city to search something!");
		cadastro.search_city.focus();
		return false;
	}
	
	else
		return true;
}

function validatePost(post){	
	// title
	if(post.msg_title.value == null || post.msg_title.value == "") {
		alert("Please insert title");
		post.msg_title.focus();
		return false;
	} 
	
	// post
	if(post.msg_body.value == null || post.msg_body.value == "") {
		alert("Please insert the text");
		post.msg_body.focus();
		return false;
	}

	else
		return true;
}

function validateLink(cadastro){	
	// titulo do artigo
	if(cadastro.titolo.value == null || cadastro.titolo.value == "") {
		alert("Please insert the title");
		cadastro.titolo.focus();
		return false;
	} 
	
	// link
	else if(cadastro.testo.value == null || cadastro.testo.value == "" || cadastro.testo.value.indexOf("http://")==-1) {
		alert("Please insert a correct link");		
		cadastro.testo.focus();
		return false;
	} 

	else
		return true;
}

function validateArticle(cadastro){
	
	// titulo do artigo
	if(cadastro.titolo.value == null || cadastro.titolo.value == "") {
		alert("Please insert the title");
		cadastro.titolo.focus();
		return false;
	} 
	
	// artigo
	else if(cadastro.testo.value == null || cadastro.testo.value == "") {
		alert("Please insert the article");
		cadastro.testo.focus();
		return false;
	} 

	else
		return true;
}

function validateTopic(cadastro){
	
	// titulo do topic
	if(cadastro.topic_title.value == null || cadastro.topic_title.value == "") {
		alert("Please insert the title");
		cadastro.topic_title.focus();
		return false;
	} 
	
	// topic
	else if(cadastro.topic_body.value == null || cadastro.topic_body.value == "") {
		alert("Please insert the topic");
		cadastro.topic_body.focus();
		return false;
	} 

	else
		return true;
}

function validatePostComment(cadastro){
	// Comment
	if(cadastro.comment.value == "" || cadastro.comment.value == null) {
		alert("Please insert a comment");
		cadastro.comment.focus();
		return false;
	} 	
}

function validateReply(cadastro){
	// Comment
	if(cadastro.topic_body.value == "" || cadastro.topic_body.value == null) {
		alert("Please insert some content");
		cadastro.topic_body.focus();
		return false;
	} 	
}

function validateSendEmailIt(cadastro){
	// Your name
	if(cadastro.yourname.value == "" || cadastro.yourname.value == null) {
		alert("Please insert a valid name");
		cadastro.yourname.focus();
		return false;
	} 
	
	// Email sender
	else if(!valida('youremail')){
		cadastro.youremail.focus();
		return false;
	}
	
	// Email receiver
	else if(!valida('friendemail')){
		cadastro.friendemail.focus();
		return false;
	}
}

function validateSendEmail(cadastro){
	// Your name
	if(cadastro.yourname.value == "" || cadastro.yourname.value == null) {
		alert("Please insert a valid name");
		cadastro.yourname.focus();
		return false;
	} 
	
	// Email sender
	else if(!valida('youremail')){
		cadastro.youremail.focus();
		return false;
	}
	
	if(cadastro.subject.value == "" || cadastro.subject.value == null) {
		alert("Please insert a subject");
		cadastro.subject.focus();
		return false;
	}
	
	// Email receiver
	else if(cadastro.yourmsg.value == "" || cadastro.yourmsg.value == null) {
		alert("Please insert your message");
		cadastro.yourmsg.focus();
		return false;
	}
}

function validateFolderBand(cadastro){
	if(cadastro.artist.options[cadastro.artist.selectedIndex].value == "0") {
		alert("Please select an artist");
		cadastro.artist.focus();
		return false;
	}
	
	if(cadastro.get_date.value == "" || cadastro.get_date.value == null || cadastro.get_date.value == "Select a date") {
		alert("Please insert a date");
		cadastro.get_date.focus();
		return false;
	}

	if(cadastro.country.options[cadastro.country.selectedIndex].value == "0") {
		alert("Please select a country");
		cadastro.country.focus();
		return false;
	}

	if(cadastro.country.options[cadastro.country.selectedIndex].value == "223" && cadastro.state.options[cadastro.state.selectedIndex].value == "0") {
		alert("Please select a state");
		cadastro.state.focus();
		return false;
	}
	
	if(cadastro.city.value == "" || cadastro.city.value == null) {
		alert("Please insert a location");
		cadastro.city.focus();
		return false;
	}
	
	if(cadastro.venue.value == "" || cadastro.venue.value == null) {
		alert("Please insert a venue");
		cadastro.venue.focus();
		return false;
	}
}

function validateNewArtist(cadastro){
	// Your name
	if(cadastro.artist_name.value == "" || cadastro.artist_name.value == null) {
		alert("Please insert a valid name");
		cadastro.artist_name.focus();
		return false;
	} 

	if(cadastro.get_country.options[cadastro.get_country.selectedIndex].value == "0") {
		alert("Please select a country");
		cadastro.get_country.focus();
		return false;
	}

	if(cadastro.get_country.options[cadastro.get_country.selectedIndex].value == "223" && cadastro.get_state.options[cadastro.get_state.selectedIndex].value == "0") {
		alert("Please select a state");
		cadastro.get_state.focus();
		return false;
	}
	
	if(cadastro.artist_city.value == "" || cadastro.artist_city.value == null) {
		alert("Please insert a location");
		cadastro.artist_city.focus();
		return false;
	}
}

function validateNewShow(cadastro){
	// Your name
	if(cadastro.artist.options[cadastro.artist.selectedIndex].value == "0") {
		alert("Please select an artist");
		cadastro.artist.focus();
		return false;
	}

	if(cadastro.get_country.options[cadastro.get_country.selectedIndex].value == "0") {
		alert("Please select a country");
		cadastro.get_country.focus();
		return false;
	}

	if(cadastro.get_country.options[cadastro.get_country.selectedIndex].value == "223" && cadastro.get_state.options[cadastro.get_state.selectedIndex].value == "0") {
		alert("Please select a state");
		cadastro.get_state.focus();
		return false;
	}
	
	if(cadastro.show_city.value == "" || cadastro.show_city.value == null || cadastro.show_city.value.length<2) {
		alert("Please insert a location");
		cadastro.show_city.focus();
		return false;
	}

	if(cadastro.show_venue.value == "" || cadastro.show_venue.value == null || cadastro.show_venue.value.length<2) {
		alert("Please insert a venue");
		cadastro.show_venue.focus();
		return false;
	}
}

function validateChangePword(cadastro){
	// Senha agora
	if(cadastro.pword.value=="" || cadastro.pword.value == null){
		alert("Please insert a password");
		cadastro.pword.focus();
		return false;
	}
	
	// Senha new
	else if(!ValidaSenha(cadastro.pword1.value)){
		cadastro.pword1.focus();
		return false;
	}

	// Senha2 para verificação do cliente
	else if(!ChecaSenha(cadastro.pword2.value)){
		cadastro.pword2.focus();
		return false;
	}
	
	else
		return true;
}

function validateRegister(cadastro){	
	// Nome do cliente
	if(cadastro.usrname.value == null || cadastro.usrname.value == "" || cadastro.usrname.value.length<6) {
		alert("Please insert your username (must be at least 6 letters long)");
		cadastro.usrname.focus();
		return false;
	}
	
	// Email do cliente
	else if(!valida('mail')){
		cadastro.mail.focus();
		return false;
	}
	
	// Senha do cliente
	else if(!ValidaSenha(cadastro.pword1.value)){
		cadastro.pword1.focus();
		return false;
	}

	// Senha2 para verificação do cliente
	else if(!ChecaSenha(cadastro.pword2.value)){
		cadastro.pword2.focus();
		return false;
	}

	// Captcha
	if(cadastro.conf_captcha.value == null || cadastro.conf_captcha.value == "" || cadastro.conf_captcha.value.length<8) {
		alert("Please insert a valid confirmation code");
		cadastro.conf_captcha.focus();
		return false;
	} 
	
	else
		return true;
}

function validateConfirm(cadastro) {
	// place any other field validations that you require here
	// validate myradiobuttons
	myOption = -1;
	for (i=cadastro.no_robot.length-1; i > -1; i--) {
		if (cadastro.no_robot[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1) {
		alert("You must select a answer");
		return false;
	}
	else
		return true;
}

function limpar(elemento)
{
	document.getElementById(elemento).value="";
}