

var characterDropDownSemiphor = false;
function createProfessionDropdown( divID, charID, primSecond )
	{
	if(characterDropDownSemiphor)
		return 0;
	characterDropDownSemiphor = true;
	var professions = new Array("--None--","Alchemy","Blacksmithing", "Armorsmith","Swordsmith","Axesmith","Hammersmith","Enchanting","Disenchanting","Engineering","Gnomish Eng","Goblin Eng","Herbalism","Leatherworking", "Elemental LW", "Tribal LW","Dragon LW","Mining","Skinning","Tailoring");
	professions.sort();
	var selected = document.getElementById(divID).innerHTML;
	var temp = "<input type=hidden id='" + divID + "profBackup' value='" + selected + "'><input type=hidden id='" + divID + "HiddenCharID' value='" + charID + "'>";
	if( primSecond == 1)
		temp += "<input type=hidden id='" + divID + "primaryProfession' value='1'>";
	else
		temp += "<input type=hidden id='" + divID + "secondaryProfession' value='1'>";
	temp  += "<select id='" + divID + "dropdown' onChange=\"updateProfessionDropDown('" + divID + "', this);\"  class='membersMain'  onBlur=\"document.getElementById('" + divID + "').innerHTML = this.options[this.selectedIndex].value; characterDropDownSemiphor = false;\">";
	for(var i=0; i<professions.length; i++)
		temp += "<option value='" + professions[i] + "'" + (selected == professions[i] ? " SELECTED" : "") + ">" + professions[i] + "</option>";
	temp += "</select>";
	
	
	document.getElementById(divID).innerHTML = temp;
	document.getElementById(divID + "dropdown").focus();
	}

function updateProfessionDropDown( divID , dropdown)
	{	
    var http_request = makeHttpRequest();
	var parameters = "s=ajax&a=professionUpdate&charid=" + document.getElementById(divID + "HiddenCharID").value;
	if(document.getElementById(divID + "primaryProfession"))
		parameters += "&prof1=" + document.getElementById(divID + 'dropdown').options[document.getElementById(divID + 'dropdown').selectedIndex].value;
	if(document.getElementById(divID + "secondaryProfession"))
		parameters += "&prof2=" + document.getElementById(divID + 'dropdown').options[document.getElementById(divID + 'dropdown').selectedIndex].value;
		
	//alert(parameters);
	
	ajaxPassing(http_request, "index.php", parameters, function() 
		{ 
		if( checkReturnStatus(http_request) ) 
			{ 
			characterDropDownSemiphor = false;
			if(http_request.responseText == "0")
				{
				alert("An error occured while attempting to save changes.");
				document.getElementById(divID).innerHTML = document.getElementById(divID + "profBackup").value;				
				}
				
			document.getElementById(divID).innerHTML = dropdown.options[dropdown.selectedIndex].value;
			}
		} );	
	}
	
function createMainDropdown( divID, charID )
	{
	if(characterDropDownSemiphor)
		return 0;
	characterDropDownSemiphor = true;
	var selected = document.getElementById(divID).innerHTML;
	var temp = "<input type=hidden id='" + divID + "mainBackup' value='" + selected + "'><input type=hidden id='" + divID + "CharID' value='" + charID + "'>";
	temp  += "<select id='" + divID + "dropdown' onChange=\"updateMainDropDown('" + divID + "', this);\"  class='membersMain'  onBlur=\"document.getElementById('" + divID + "').innerHTML = this.options[this.selectedIndex].value; characterDropDownSemiphor = false;\">";
	for(var i=0; i<characters.length; i++)
		temp += "<option value='" + characters[i] + "'" + (selected == characters[i] ? " SELECTED" : "") + ">" + characters[i] + "</option>";
	temp += "</select>";
	
	
	document.getElementById(divID).innerHTML = temp;
	document.getElementById(divID + "dropdown").focus();
	}
	
function updateMainDropDown( divID , dropdown)
	{	
    var http_request = makeHttpRequest();
	var parameters = "s=ajax&a=mainUpdate&charid=" + document.getElementById(divID + "CharID").value + "&newMain=" + dropdown.options[dropdown.selectedIndex].value;
	
	ajaxPassing(http_request, "index.php", parameters, function() 
		{ 
		if( checkReturnStatus(http_request) ) 
			{ 
			characterDropDownSemiphor = false;
			if(http_request.responseText == "0")
				{
				alert("An error occured while attempting to save changes.");
				document.getElementById(divID).innerHTML = document.getElementById(divID + "mainBackup").value;				
				}
				
			document.getElementById(divID).innerHTML = dropdown.options[dropdown.selectedIndex].value;
			}
		} );	
	}
	
	
function createAccountDropdown( divID, charID )
	{
	if(characterDropDownSemiphor)
		return 0;
	characterDropDownSemiphor = true;
	var selected = document.getElementById(divID).innerHTML;
	var temp = "<input type=hidden id='" + divID + "backup' value='" + selected + "'><input type=hidden id='" + divID + "CharID' value='" + charID + "'>";
	temp  += "<select id='" + divID + "dropdown' onChange=\"updateMainDropDown('" + divID + "', this);\"  class='membersMain'  onBlur=\"document.getElementById('" + divID + "').innerHTML = this.options[this.selectedIndex].value; characterDropDownSemiphor = false;\">";
	for(var i=0; i<members.length; i++)
		temp += "<option value='" + members[i] + "'" + (selected == members[i] ? " SELECTED" : "") + ">" + members[i] + "</option>";
	temp += "</select>";
	
	
	document.getElementById(divID).innerHTML = temp;
	document.getElementById(divID + "dropdown").focus();
	}
	
function updateMainDropDown( divID , dropdown)
	{	
    var http_request = makeHttpRequest();
	var parameters = "s=ajax&a=accountUpdate&charid=" + document.getElementById(divID + "CharID").value + "&newAccount=" + dropdown.options[dropdown.selectedIndex].value;
	
	ajaxPassing(http_request, "index.php", parameters, function() 
		{ 
		if( checkReturnStatus(http_request) ) 
			{ 
			characterDropDownSemiphor = false;
			if(http_request.responseText == "0")
				{
				alert("An error occured while attempting to save changes.");
				document.getElementById(divID).innerHTML = document.getElementById(divID + "backup").value;				
				}
				
			document.getElementById(divID).innerHTML = dropdown.options[dropdown.selectedIndex].value;
			}
		} );	
	}
	
	
	
function makeHttpRequest()
	{
	var http_request = false;
	if(window.XMLHttpRequest)
		{ // Mozilla, Safari, ...
           http_request = new XMLHttpRequest();
           if (http_request.overrideMimeType) 
			{
               http_request.overrideMimeType('text/xml');
               // See note below about this line
           	}
       	} 
	else if (window.ActiveXObject) 
		{ // IE
           try 
			{
               http_request = new ActiveXObject("Msxml2.XMLHTTP");
           	} 
		catch (e) 
			{
              	try 
				{
                   http_request = new ActiveXObject("Microsoft.XMLHTTP");
               	} 
			catch (e) { return false; }
           	}
       	}
	return http_request;
	}
function ajaxPassing(http_request, filename, parameters, pfunction)
	{
    http_request.onreadystatechange = pfunction;
    http_request.open('POST', filename, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);				
	}

function checkReturnStatus(http_request)
	{
       if (http_request.readyState == 4) 
		{
			// alert(http_request.responseText);
           if (http_request.status == 200) {  return true; } 
		else { return false; }
       	}
	}		

	
	
	
	
	function hideID( name )
		{		
		document.getElementById(name).style.visibility = 'hidden'; 
		document.getElementById(name).style.display = 'none'; 
		}
	function showID( name )
		{			
		document.getElementById(name).style.visibility = 'visible';
		document.getElementById(name).style.display = 'block'; 
		}
	function toggleID ( name )
		{
		if(document.getElementById(name).style.visibility == "hidden")
			showID(name);
		else
			hideID(name);
		}



