
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

 function IsNumeric(sText)
	{
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
	      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsNumber = false;
	         }
	      }
	   return IsNumber;
	   
	}
	   
  function verifycode(obj,tamanho)
  {
  
  	if (IsNumeric(obj.value) == false || obj.value.length < tamanho)
  	{
  		obj.style.background ='#EFAFAF';
  	} else {
  			obj.style.background ='#FFFFFF';
  	}
  	
  }
  
function make_read()
{
    var form_elements = document.getElementsByTagName("input");
    
    for(i=0;i<form_elements.length;i++){
      var nome_element;
      nome_element=form_elements[i].name;
      
      var element=document.getElementById(nome_element);
      //alert(nome_element);
      element.style.backgroundColor='#FFFFFF';
      element.className='form_input_read';      
      element.readOnly=false;
   
   }
   
   var form_elements_select = document.getElementsByTagName("select");
   
   for(j=0;j<form_elements_select.length;j++){
      var nome_element_select;
      nome_element_select=form_elements_select[j].name;
      
      var element_select=document.getElementById(nome_element_select);
      //alert(nome_element);
      element_select.style.backgroundColor='#FFFFFF';
      element_select.className='form_input_read';      
      element_select.disabled=false;
      
   }
   
}

function make_readPass()
{
      
      var element=document.getElementById('password');
 
      element.style.backgroundColor='#FFFFFF';
      element.className='form_input_read';      
      element.readOnly=false;
      
      var element=document.getElementById('new_password');
 
      element.style.backgroundColor='#FFFFFF';
      element.className='form_input_read';      
      element.readOnly=false;
      
      var element=document.getElementById('confirm_password');
 
      element.style.backgroundColor='#FFFFFF';
      element.className='form_input_read';      
      element.readOnly=false;
   
}

function make_readEmail()
{
      
      var element=document.getElementById('email');
 
      element.style.backgroundColor='#FFFFFF';
      element.className='form_input_read';      
      element.readOnly=false;
      
   
}
function make_readGeneral()
{
  var element=document.getElementById('nome');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('morada');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('cidade');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('state');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('cp');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;  
  
  var element=document.getElementById('telefone');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('id_pais');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element_select=document.getElementById('id_pais');
      //alert(nome_element);
      element_select.style.backgroundColor='#FFFFFF';
      element_select.className='form_input_read';      
      element_select.disabled=false;
	  
  var element=document.getElementById('idade');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('usar_dados_fact');
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.disabled=false;
  
  var element=document.getElementById('fact_nome');
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('fact_morada');
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('fact_localidade');
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('fact_codigo_postal');
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element=document.getElementById('id_fact_pais');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
  
  var element_select=document.getElementById('id_fact_pais');
      //alert(nome_element);
      element_select.style.backgroundColor='#FFFFFF';
      element_select.className='form_input_read';      
      element_select.disabled=false;
  
  var element=document.getElementById('contribuinte');
 
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.readOnly=false;
}

function make_readPref()
{
  
  var element=document.getElementById('formato1');
  
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.disabled=false;
  
  var element=document.getElementById('formato2');
  
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.disabled=false;
  
  var element=document.getElementById('weekly_news');
  
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.disabled=false;
  
  var element=document.getElementById('promotional_emails');
  
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.disabled=false;
  
  var element=document.getElementById('email_partner');
  
  element.style.backgroundColor='#FFFFFF';
  element.className='form_input_read';      
  element.disabled=false;
  
  
      
  
}

function change_on(el)
{
  var elem=el;
  
  document.getElementById('img'+ el +'').src='sysimages/edit_track2.jpg'; 
}

function change_off(el)
{
  var elem=el;
  
  document.getElementById('img'+ el +'').src='sysimages/edit_track.jpg'; 
}

function show_hide(value) 
{

	if(document.getElementById('track'+value).style.display=='block')
	{
		document.getElementById('track'+value).style.display='none';
		document.getElementById('track'+value).style.visibility='hidden';
		
		document.getElementById('td'+value).style.paddingTop='0px';
		document.getElementById('td'+value).style.paddingBottom='0px';
		
		resizeMe2();
	}
	else
	{
		document.getElementById('track'+value).style.display='block';
		document.getElementById('track'+value).style.visibility='visible';
		
		document.getElementById('td'+value).style.paddingTop='5px';
		document.getElementById('td'+value).style.paddingBottom='5px';
		
		resizeMe2();
	}
	
}
  
function expand(value) 
{
  for(x=1;x<=10;x++)
  {
    if(x!=value)
    {
      if(document.getElementById(x))
        document.getElementById(x).style.display='none';
    }
  }

	if(document.getElementById(value).style.display=='block')
	{
		document.getElementById(value).style.display='none';
//		document.getElementById(value).style.overflow='hidden';
	}
	else
	{
		document.getElementById(value).style.display='block';
	}
	
}
function resizeMe2(){ 
		var docHeight;
		
		parent.document.getElementById('conteudo').style.height='0px';
        
		if(window.navigator.appName=="Netscape")
		    docHeight = parent.conteudo.document.body.offsetHeight;
    else
		    docHeight = parent.conteudo.document.body.scrollHeight;
    
    if(docHeight<600) docHeight='600';
		parent.document.getElementById('conteudo').style.height = docHeight + 'px'
		
}

function resizeMe(obj){ 
		var docHeight;
		//alert(obj);
    //obj.style.height = 0 + 'px'
				
    //alert(conteudo.document.body.offsetHeight);
    //alert(conteudo.document.body.scrollHeight);
    
    //docHeight = conteudo.document.body.offsetHeight;
    
		if(window.navigator.appName=="Netscape")
		    docHeight = conteudo.document.body.offsetHeight;
    else
		    docHeight = conteudo.document.body.scrollHeight;
    
    if(docHeight<600) docHeight='600';
		obj.style.height = docHeight + 'px';
}

function hide(){
document.getElementById("div_conta").style.display="none";
}
function show(){
document.getElementById("div_conta").style.display="block";
}

function hidel(){
document.getElementById("div_login").style.display="none";
}
function showl(){
document.getElementById("div_login").style.display="block";
}
function hide_recom(){
document.getElementById("div_recom").style.display="none";
}
function show_recom(){
parent.document.getElementById("div_recom").style.display="block";
}
function hide_gen(div_elem)
{
  document.getElementById(div_elem).style.display="none";
}
function show_gen(div_elem)
{
alert("passou");
  document.getElementById(div_elem).style.display="block";
}
function Validar_login(form)
{
 		return (
 		     ValidarVazio(form.email.value,'Insert E-mail!')
         && ValidarVazio(form.password.value,'Insert Password!')
         && ValidarEmail(form.email.value)
      );
}

function Validar_form_account(form)
{
 		return (
 		     ValidarVazio(form.email.value,'Insert E-mail!')
 		     && ValidarEmail(form.email.value)
         && ValidarPassword(form.new_password.value,form.confirm_password.value,'Password must be equal')
         && ValidarJPGEdit(form.file.value,'Invalid Extension! *.jpg')          
      );
}

function Validar_form_label(form)
{
  return (
 		     ValidarVazio(form.label_nome.value,'Insert Label Name!')
 		     //&& ValidarVazio(form.label_bio.value,'Insert Label Bio!')
 		     && ValidarVazio(form.file.value,'Insert Label Logo!')
        && ValidarJPG(form.file.value,'Invalid Extension! *.jpg')
      );
}
function Validar_form_artist(form)
{
  return (
 		     ValidarVazio(form.artist_nome.value,'Insert Artist Name!')
      );
}

function Validar_form_labelView(form)
{
return (
 		     ValidarVazio(form.label_nome.value,'Insert Label Name!')
 		     //&& ValidarVazio(form.label_bio.value,'Insert Label Bio!')
        && ValidarJPGEdit(form.file.value,'Invalid Extension! *.jpg')
      );
}
function Validar_form_release(form)
{
  return (
 		     ValidarVazio(form.release_nome.value,'Insert Relase Name!')
          && ValidarJPGEdit(form.file.value,'Invalid Extension! *.jpg')
      );
}
function Validar_form_track(form)
{
  return (
 		     ValidarVazio(form.track_nome.value,'Insert Track Name!')
 		     && ValidarVazio(form.mix_nome.value,'Insert Mix Name!')
 		     && ValidarVazio(form.file1.value,'Insert Emaster!')
         && ValidarMP3(form.file1.value,'Invalid Extension! *.mp3')
         && ValidarVazio(form.file2.value,'Insert Clip!')
         && ValidarMP3(form.file2.value,'Invalid Extension! *.mp3')
         && ValidarVazio(form.track_order.value,'Insert Track Order!')
      );
}
function Validar_form_trackedit(form)
{
  return (
 		     ValidarVazio(form.track_nome.value,'Insert Track Name!')
 		     && ValidarVazio(form.mix_nome.value,'Insert Mix Name!') 		     
         && ValidarMP3(form.file1.value,'Invalid Extension! *.mp3')
         && ValidarMP3(form.file2.value,'Invalid Extension! *.mp3')
         && ValidarVazio(form.track_order.value,'Insert Track Order!')
      );
}

function Validar_form_Friend(form)
{
  return (
 		     ValidarVazio(form.from.value,'Insert Your Name!')
         && ValidarVazio(form.to.value,'Insert Email (To)!')
         && ValidarEmail(form.to.value)
      );
}

function Validar_form_Recover(form)
{
  return (
 		     ValidarVazio(form.T1.value,'Insert Email!')
         && ValidarEmail(form.T1.value)
      );
}

function Validar_form_credenciais(form)
{
  return (
 		     ValidarVazio(form.password.value,'Insert Password!')
         && ValidarVazio(form.new_password.value,'Insert New Password!')
         && ValidarVazio(form.confirm_password.value,'Confirm Password!')
         && ValidarPassword(form.new_password.value,form.confirm_password.value,'Password must be equal!')
      );
}

function Validar_form_email(form)
{
return (
 		     ValidarVazio(form.email.value,'Insert Email!')
         && ValidarEmail(form.email.value)
      );
}
function Validar_form_general(form)
{
    return (
 		     ValidarVazio(form.nome.value,'Insert Account Name!')
      );
}

  function getXmlHttpRequest() {
  		if (window.XMLHttpRequest) {
  			return new XMLHttpRequest();
  		} else if (window.ActiveXObject) {
  			return new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
 	
 	/**/
 	function encode(key,token)
  {       
    window.open('getfile.php?key='+key+'&token='+token,'DancefuelRecords','scrollbars=yes,width=200,height=200,menubar=no');    
  }
/**/
 	function alter_select(valor, id, tipo)
   {
	  
    var valors=valor;
    var tipo=tipo;
    
    if(tipo=='1')
    {
		var url ="gest/alter_select.php"; 	
			
		var post_data="valors="+valors;	
		post_data=post_data+"&ids="+id;
		post_data=post_data+"&tipos="+tipo;
		//alert(post_data);
		var cmsajaxhttp = getXmlHttpRequest();	//785	
		cmsajaxhttp.open("POST", url+'?'+post_data, true);
		
	 
		cmsajaxhttp.onreadystatechange = function(){
			if (cmsajaxhttp.readyState==4){
				var resultado = cmsajaxhttp.responseText;
        //alert(resultado);
        
				document.getElementById('select_format' + id + '').disabled=false;
			}
		}
		cmsajaxhttp.send(null);
		} else {
      var url ="gest/alter_selectR.php"; 	
  			
  		var post_data="valors="+valors;	
  		post_data=post_data+"&ids="+id;
  		post_data=post_data+"&tipos="+tipo;
  		//alert(post_data);
  		var cmsajaxhttp = getXmlHttpRequest();	//785	
  		cmsajaxhttp.open("POST", url+'?'+post_data, true);
  		
  	 
  		cmsajaxhttp.onreadystatechange = function(){
  			if (cmsajaxhttp.readyState==4){
  				var resultado = cmsajaxhttp.responseText;
          //alert(resultado);
          
  				document.getElementById('select_formatR' + id + '').disabled=false;
  			}
  		}
  		cmsajaxhttp.send(null);
    }
		
	}
	
	function remove_linha(id, tipo, page){
		
    var tipo=tipo;
    if(tipo=='1')
    {	
		var url ="gest/remove_linha.php"; 	
			
		var post_data="id="+id;
		post_data=post_data+"&tipo="+tipo+"&page="+page;
		//alert(url+'?'+post_data);
		var cmsajaxhttp = getXmlHttpRequest();	//785	
		cmsajaxhttp.open("GET", url+'?'+post_data, true);
		
	 
		cmsajaxhttp.onreadystatechange = function(){
            //alert(cmsajaxhttp.readyState);
			if (cmsajaxhttp.readyState==4){
				var resultado = cmsajaxhttp.responseText;
				  
          parent.document.getElementById('crate').src='crate.php?del=1&id_buy='+ id +'';
          
          var res=resultado;
          
                        
          
				  document.getElementById('crate_track').innerHTML=res;
				  				  
				  document.getElementById('summary').src='summary.php';
				  
				  //resizeMe2();
				  
			}
            
		}
		cmsajaxhttp.send(null);
		
		} else {
    var url ="gest/remove_linhaR.php"; 	
			
		var post_data="id="+id;
		post_data=post_data+"&tipo="+tipo;
		//alert(post_data);
		var cmsajaxhttp = getXmlHttpRequest();	//785	
		cmsajaxhttp.open("POST", url+'?'+post_data, true);
		
	 
		cmsajaxhttp.onreadystatechange = function(){
			if (cmsajaxhttp.readyState==4){
				var resultado = cmsajaxhttp.responseText;
				  
          parent.document.getElementById('crate').src='crate.php?del=2&id_buy='+ id +'';
          
          var res=resultado;
          
				  document.getElementById('crate_release').innerHTML=res;
				  
				  document.getElementById('summary').src='summary.php';
				  
				  resizeMe2();
			}
		}
		cmsajaxhttp.send(null);
    }
	}
 

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 YY_StopLayerfx(){ 

  var args = YY_StopLayerfx.arguments;var yydiv;
  for (var i=0; i<args.length; i++){
    yydiv=MM_findObj(args[i]);
    if (yydiv&&(document.layers||document.all||document.getElementById)){
      if(yydiv.yyto!=null)clearTimeout(yydiv.yyto);
      if(yydiv.tmtScrollo!=null)clearTimeout(yydiv.tmtScrollo);
    }
  }
}

function YY_LS(das, ex, ey, dly, sx, loop, dx, dy){

    var s=MM_findObj(das),d=document,c,t,l,ct,cb,cl,cr,ncl,nct,ncr,ncb,doto,sy=sx,yx,yy,st;
    if(!s.ot){s.ot=(d.layers)?s.top:s.style.top;s.ol=(d.layers)?s.left:s.style.left;}
    with(Math)if(d.layers){
        ct=s.clip.top;cb=s.clip.bottom;cl=s.clip.left;cr=s.clip.right;t=s.top;l=s.left;
        yy=abs(round((ct-ey)/sy));dy=round((ey-ct)/yy);
        yx=abs(round((cl-ex)/sx));dx=round((ex-cl)/yx);
        if(yx<1){dx=0}else{yx--};if(yy<1){dy=0}else{yy--};
        s.clip.top=ct+dy; s.clip.bottom=cb+dy;s.top=t-dy;s.clip.left=cl+dx;s.clip.right=cr+dx;s.left=l-dx;
    }else if ((d.all||d.getElementById)&&s.style.clip){
      st=s.style;
        l=parseInt((d.getElementById)?st.left:st.pixelLeft);t=parseInt((d.getElementById)?st.top:st.pixelTop);
        c=st.clip.match(/rect.(\d+)[a-z,A-Z,\s]+(\d+)[a-z,A-Z,\s]+(\d+)[a-z,A-Z,\s]+(\d+).*/);
        ct=c[1]/1;cr=c[2]/1;cb=c[3]/1;cl=c[4]/1;
        yy=abs(round((ct-ey)/sy));yx=abs(round((cl-ex)/sx));
        dx=(yx<1)?0:round(-(cl-ex)/yx);dy=(yy<1)?0:round(-(ct-ey)/yy);
        ncl=cl+dx;nct=ct+dy;ncr=cr+dx;ncb=cb+dy;
        st.pixelTop=t-dy;st.pixelLeft=l-dx;st.left=l-dx;st.top=t-dy;
        eval("st.clip='rect('+nct+' '+ncr+' '+ncb+' '+ncl+')'");yy--;yx--;
    }
    if(s.yyto)clearTimeout(s.yyto);
    if(yy>0||yx>0){doto=true;}else if(dly>-1&&loop==true){
        if(d.layers){s.left=s.ol;s.clip.left=0;s.clip.right=cr-cl;s.top=s.ot;s.clip.top=0;s.clip.bottom=cb-ct;
        }else{eval("st.clip='rect('+0+' '+(cr-cl)+' '+(cb-ct)+' '+0+')'");st.top=s.ot;st.left=s.ol;}
        doto=true;
    }
    if(doto==true)s.yyto=setTimeout("YY_LS(\""+das+"\","+ex+","+ey+","+dly+","+sx+","+loop+","+dx+","+dy+")",dly);
}

