// JavaScript Document
//function to clear the form elements
function clear_form_elements(ele) {
    tags = ele.getElementsByTagName('input');
    for(i = 0; i < tags.length; i++) {
	
        switch(tags[i].type) {
            case 'password':
            case 'text':
                tags[i].value = '';
                break;
            case 'checkbox':
            case 'radio':
                tags[i].checked = false;
                break;
        }
    }
   
    tags = ele.getElementsByTagName('select');
    for(i = 0; i < tags.length; i++) {
        if(tags[i].type == 'select-one') {
            tags[i].selectedIndex = 0;
        }
        else {
            for(j = 0; j < tags[i].options.length; j++) {
                tags[i].options[j].selected = false;
            }
        }
    }

    tags = ele.getElementsByTagName('textarea');
    for(i = 0; i < tags.length; i++) {
        tags[i].value = '';
    }
   
}

//function to add field "Price of Ticket" if futre event 
//and remove the same field if event is past event in event registration form
function events_type(dt)
	{
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						document.getElementById("info").childNodes[0].innerHTML = xmlhttp.responseText;
						if (xmlhttp.responseText =="Future Event")
							{					
								var x = document.getElementById("eventTable");
								if(x.rows[4].cells[0].innerHTML != "Price of Ticket")
									{
									var y = x.insertRow(4);
									var cell1 = y.insertCell(0);
									var cell2 = y.insertCell(1);
									var element1 = document.createElement('input');  
									element1.setAttribute('type','text');
									element1.setAttribute('id','tktprice');
									element1.setAttribute('name','tktprice');
									cell1.innerHTML = "Price of Ticket";
									cell2.appendChild(element1);
									var status= true;
									}
							}
			
						else
							{
								var x = document.getElementById("eventTable");
								if(x.rows[4].cells[0].innerHTML == "Price of Ticket")
								{
									document.getElementById("eventTable").deleteRow(4);
									status=false;
								}
				
				
							}
					}
		}
  
	xmlhttp.open("GET","event_type.php?q="+dt,false);
	xmlhttp.send();
	}
	
//function to add field "Price of Ticket" if futre event 
//and remove the same field if event is past event in edit event form
function events_type_edit(dt)
	{
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
					{
						document.getElementById("info").childNodes[0].innerHTML = xmlhttp.responseText;
						if (xmlhttp.responseText =="Future Event")
							{					
								var x = document.getElementById("edit_eventTable");
								if(x.rows[4].cells[0].innerHTML != "Price of Ticket")
									{
									var y = x.insertRow(4);				//insert a row in table
									var cell1 = y.insertCell(0);		//insert a cell at 0 index in row
									var cell2 = y.insertCell(1);		//insert a cell at 1 index in row
									var element1 = document.createElement('input');  
									element1.setAttribute('type','text');
									element1.setAttribute('id','tktprice');
									element1.setAttribute('name','tktprice');
									cell1.innerHTML = "Price of Ticket";
									cell2.appendChild(element1);		//add element to a cell
									var status= true;
									}
							}
			
						else
							{
								var x = document.getElementById("edit_eventTable");
								if(x.rows[4].cells[0].innerHTML == "Price of Ticket")
								{
									document.getElementById("edit_eventTable").deleteRow(4);
									status=false;
								}
				
				
							}
					}
		}
  
	xmlhttp.open("GET","event_type.php?q="+dt,false);
	xmlhttp.send();
	}


function disable_genres(frm){
	var ele =document.getElementById("artist_type");
	if(ele.value == "Singer" || ele.value == "Musician" )
	{
		
		frm.genres.disabled=false;
	
	}
	else{
		frm.genres.selectedIndex=0;
		frm.genres.disabled=true;
	}
	
}

function professional_name(val)
{

var y=document.getElementById("registrationForm"); 
var x=y.childNodes[0]; 
//alert(x);
if(val=='Artist' && (x.rows[3].cells[0].innerHTML != "Professional Name (optional)"))
				{
				var y = x.insertRow(3);				//insert a row in table
				var cell1 = y.insertCell(0);		//insert a cell at 0 index in row
				var cell2 = y.insertCell(1);		//insert a cell at 1 index in row
				var element1 = document.createElement('input');  
				element1.setAttribute('type','text');
				element1.setAttribute('id','pro_name');
				element1.setAttribute('name','pro_name');
				element1.onkeyup = function(){if (this.value.length > 30) { alert('Character limit has been reached!'); this.value = this.value.substr(0,30); }};
				cell1.innerHTML = "Professional Name (optional)";
				var element2=document.createElement('IMG');
				element2.setAttribute('src','../images/info.png');
				element2.setAttribute('title','Your Band Name or Your Professional Name.');
				cell2.appendChild(element1);		//add element to a cell
				cell2.appendChild(element2);		//add element to a cell
				var status= true;
				}
else if(val=='Fan' && (x.rows[3].cells[0].innerHTML == "Professional Name (optional)"))
				{
					if(x.rows[3].cells[0].innerHTML == "Professional Name (optional)")
					{
						x.deleteRow(3);
						status=false;
					}
	
	
				}	
else{
return true;
}				
}	


 
// select all desired input fields and attach tooltips to them
$("#profileform").tooltip({
 
	// place tooltip on the right edge
	position: "center right",
 
	// a little tweaking of the position
	offset: [-2, 10],
 
	// use the built-in fadeIn/fadeOut effect
	effect: "fade",
 
	// custom opacity setting
	opacity: 0.7
 
});



