profileHeader = "profile_setup_header";
profileHeadline = "profile_headline";

function selectTheme(_this) {
	value = _this.value;
   document.getElementById('color_headline').value = value;
   document.getElementById('color_header').value = value;

   updateProfileHeader(value);
   updateProfileHeadline(value);
}

function updateProfileTheme() {
	updateProfileHeader(document.getElementById('color_header').value);
	updateProfileHeadline(document.getElementById('color_headline').value);
}


function updateProfileHeader(_color) {
   document.getElementById(profileHeader).style.backgroundImage = "url('"+layout+"profile_header_"+_color+".jpg')";
}

function updateProfileHeadline(_color) {
   document.getElementById(profileHeadline).className = "headline_" + _color;
   document.getElementById('profile_header_custom').className = "button_"+_color+"_active";
}


swapElements = new Array('custom_start','custom_profile','custom_rss');
swapExtra = new Array();
swapExtra['custom_start'] = '';
swapExtra['custom_profile'] = '';
swapExtra['custom_rss'] = '';

function swapContent(_active) {
   for(i = 0; i < swapElements.length;i++) {
      if(swapElements[i] == _active) {
         document.getElementById(swapElements[i]).className = "button_red_active"+swapExtra[swapElements[i]];
         document.getElementById(swapElements[i] + "_content").style.display = "";
      } else {
         document.getElementById(swapElements[i]).className = "";
         document.getElementById(swapElements[i]).className = "button_orange_item"+swapExtra[swapElements[i]];
         document.getElementById(swapElements[i] + "_content").style.display = "none";
      }
   }
   return;
}



var hardwareType;
var currentType = null;

var hardwareTypes = {"os":"Betriebssystem","cpu":"Prozessor","mainboard":"Mainboard","ram":"Arbeitsspeicher",
                     "gfxcard":"Grafikkarte","sound":"Soundkarte","speaker":"Lautsprecher","headset":"Headset",
                     "keyboard":"Tastatur","mouse":"Maus","internet":"Internet","handy":"Handy",

                     "os_producer":"Hersteller","cpu_producer":"Hersteller","mainboard_producer":"Hersteller","ram_producer":"Hersteller",
                     "gfxcard_producer":"Hersteller","sound_producer":"Hersteller","speaker_producer":"Hersteller","headset_producer":"Hersteller",
                     "keyboard_producer":"Hersteller","mouse_producer":"Hersteller","internet_producer":"Anbieter","handy_producer":"Marke"};

function parseTournaments(html,xml) {
	document.getElementById('select_' + currentType).innerHTML = html;
}

function parseHardwareProducer(html,xml) {
	document.getElementsByName(hardwareType + '_producer')[0].parentNode.innerHTML = html;
   loadSubelements(document.getElementsByName(hardwareType + '_producer')[0],hardwareType,0);
}

function hardwareNew(value,type) {
	if(value == '-1' || value == '-4') {
		$('input_' + type).show();
		$('input_' + type).innerHTML = '<table class="multicheckbox_table" cellspacing="0" cellpadding="0"><tr><td colspan="2">'+hardwareTypes[type]+' erfassen:</td></tr><tr><td style="border:0px"><input id="new_'+type+'" class="default"></td><td style="border:0px"><input onClick="hardwareNewDo(\''+type+'\');return false;" type="Image" src="'+dir+'dynamic/button/red/16/?text=hinzufügen"></td></tr></table>';
   } else {
		$('input_' + type).hide();
   }
}

function hardwareNewDo(type,producer) {
	var name = $('new_' + type).value;
   hardwareType = type;
   if(producer != undefined) {
		AjaxRequest(parseHardwareProducerDone,dir + "profile_setup/gamer/"+type+"/?new=producer&name="+name,"GET",false,'xml');
   } else {
     	var producer = document.getElementsByName(type + '_producer')[0].value;
		AjaxRequest(parseHardwareDone,dir + "profile_setup/gamer/"+type+"/?new=1&producer="+producer+"&name="+name,"GET",false,'xml');
   }
}

function parseHardwareProducerDone(html,xml) {
	if(html == "ERROR") {
   	alert("Gib bitte einen Namen ein.");
   } else if(html == "ERROR2") {
   	alert("Dieser Eintrag existiert bereits.");
   } else  {
   	$('input_' + hardwareType).hide();
   	loadElements(hardwareType,html);
   }
}

function parseHardwareDone(html,xml) {
	if(html == "ERROR") {
   	alert("Gib bitte einen Namen ein.");
   } else if(html == "ERROR2") {
   	alert("Dieser Eintrag existiert bereits.");
   } else  {
   	$('input_' + hardwareType).hide();
   	loadSubelements(document.getElementsByName(hardwareType + '_producer')[0],hardwareType,html);
   }
}

function loadElements(type,selected) {
	hardwareType = type;
	AjaxRequest(parseHardwareProducer,dir + "profile_setup/gamer/"+type+"/?producer=1&selected="+selected,"GET",false,'xml');
}

function loadSubelements(field,type,selected) {
   hardwareType = type;
	$('input_' + type).hide();
	if(field.value > 0) {
		document.getElementById('select_' + type).firstChild.innerHTML = '<option value="0">Lade Auswahl</option>';
      currentType = type;
		AjaxRequest(parseTournaments,dir + "profile_setup/gamer/"+type+"/"+field.value+"/?selected="+selected,"GET",false,'xml');
   } else if(field.value == '-1' || field.value == '-4') {
		$('input_' + type).show();
		$('input_' + type).innerHTML = '<table class="multicheckbox_table" cellspacing="0" cellpadding="0"><tr><td colspan="2">'+hardwareTypes[type+'_producer']+' erfassen:</td></tr><tr><td style="border:0px"><input id="new_'+type+'" class="default"></td><td style="border:0px"><input onClick="hardwareNewDo(\''+type+'\',true);return false;" type="Image" src="'+dir+'dynamic/button/red/16/?text=hinzufügen"></td></tr></table>';
		document.getElementById('select_' + type).innerHTML = '<select name="'+type+'"><option value="0">---</option></select>';
   } else {
		document.getElementById('select_' + type).innerHTML = '<select name="'+type+'"><option value="0">---</option></select>';
   }
}