function hair_change(project_id,hair_change,color_id){
	var myReq = new XhttpRequest();

	if(myReq.bInitialized == false) {
		alert("Can't get request object.");
		return;
	}

	var func = function (response) {
		var final_image = document.getElementById("final_image");
		if(response.indexOf(".jpg")>-1) {
			final_image.innerHTML= "<img src=\"" +  response + "\" />\r\n";	
		}
		else {
			alert(response);	
		}
		display_processing_complete();
		myReq = null;	// THIS IS CRITICAL to stop IE memory leaks
	}
	
	
	//form url with get parameters for ajax request
	var gparam="project_id="+project_id;
	gparam=gparam+"&hair_change="+hair_change;
	
	//if color change, convert hex to rgb and add to GET request string
	if(hair_change == 7 && color_id > 0) {
		gparam=gparam+"&base_color_id="+color_id;
	}
	if(hair_change == 8 && color_id > 0) {
		gparam=gparam+"&highlight_color_id="+color_id;
	}
	display_processing();
	myReq.connect("/_includes/hair_change.php", "GET", gparam, func);
}

function hair_change2(hair_change,hair_id){
	var myReq = new XhttpRequest();

	if(myReq.bInitialized == false) {
		alert("Can't get request object.");
		return;
	}

	var func = function (response) {
		document.getElementById("status_processing").style.display = 'none';
		document.getElementById("console").style.display = 'block';
		if (response == "1") {
			window.location.href = "hairstyle_detail.php?id="+hair_id;
		}
		myReq = null;	// THIS IS CRITICAL to stop IE memory leaks
	}
	
	//form url with get parameters for ajax request
	var gparam="hair_id="+hair_id+"&hair_change="+hair_change;
	
	document.getElementById("console").style.display = 'none';
	document.getElementById("status_processing").style.display = 'block';
	myReq.connect("hair_change.php", "GET", gparam, func);
	//myReq.connect("hairstyle_detail.php", "GET", "id="+hair_id, func);
}

function acc_change(acc_change,acc_id){
	var myReq = new XhttpRequest();

	if(myReq.bInitialized == false) {
		alert("Can't get request object.");
		return;
	}

	var func = function (response) {
		document.getElementById("status_processing").style.display = 'none';
		document.getElementById("console").style.display = 'block';
		if (response == "1") {
			window.location.href = "accessory_detail.php?id="+acc_id;
		}
		myReq = null;	// THIS IS CRITICAL to stop IE memory leaks
	}
	
	//form url with get parameters for ajax request
	var gparam="acc_id="+acc_id+"&acc_change="+acc_change;
	
	document.getElementById("console").style.display = 'none';
	document.getElementById("status_processing").style.display = 'block';
	myReq.connect("accessory_change.php", "GET", gparam, func);
	//myReq.connect("hairstyle_detail.php", "GET", "id="+hair_id, func);
}

function display_processing() {
	document.getElementById("console").style.display = 'none';
	document.getElementById("hair_length_console").style.display = 'none';
	document.getElementById("final_image").style.display = 'none';
	document.getElementById("status_processing").style.display = 'block';
	document.getElementById("process_image_cover").style.display = 'block';
}

function display_processing_complete() {
	document.getElementById("status_processing").style.display = 'none';
	document.getElementById("process_image_cover").style.display = 'none';
	document.getElementById("console").style.display = 'block';
	document.getElementById("hair_length_console").style.display = 'block';
	document.getElementById("final_image").style.display = 'block';
}
