// http://www.w3schools.com/PHP/php_ajax_database.asp
var xmlHttp
function doprocessimg(dowhat,withwhat){ 
	xmlHttp=GetXmlHttpObject4()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="../___imgprocessing.php"
	url=url+"?d="+dowhat+"&nfn="+withwhat
	xmlHttp.onreadystatechange=stateChanged4 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
function stateChanged4(){ 
	if (xmlHttp.readyState==4){ 

		var mySplitResult = xmlHttp.responseText.split("_");
		var myserial = mySplitResult[0];
		var myinput = mySplitResult[1];
		var mymode = mySplitResult[2];
		var myDBresult = mySplitResult[3];
		var error_txt = '<span class="bold">An error occurred while processing your image. Likely reasons are:<br><ul><li>The file is not a genuine jpg image</li><li>Some kind of technical glitch</li></ul>If the file is a genuine jpg image, then either try to upload again, or E-mail it to us, and we will get back to you as soon as possible.</span><br>[For larger files you may want to use <a href="http://www.yousendit.com/">YouSendIt</a>, a free and easy to use service that requires no registration.]';
		//document.getElementById('savedImg').innerHTML = xmlHttp.responseText;
		if (xmlHttp.responseText=="tn_ok"){
			document.getElementById('img-processing1b').innerHTML = '<img src="../images/tick_transparent.gif" width="49" height="46" alt="Done">';
			document.getElementById('img-processing1a').style.color = "#C0C0C0";
			document.getElementById('img-processing2a').style.color = "#000000";
			document.getElementById('img-processing2b').innerHTML = '<img src="../images/waiting.gif" width="32" height="32" alt="Processing" style="margin: 7px 0;">';
			doprocessimg('rot1', newfancyname);
		}
		else if (xmlHttp.responseText=="tn_error"){
			document.getElementById('img-processing1b').innerHTML = '<img src="../images/error-icon.png" width="40" height="40" alt="Error" style="margin: 3px 0;">';
			document.getElementById('img-processing4').style.display = "block";
			document.getElementById('img-processing4').innerHTML = error_txt;
			//up.remove(); // clear old file
			document.getElementById('progr_bar').style.display = 'none';
		}
		else if (xmlHttp.responseText=="rot1_ok"){
			document.getElementById('img-processing2b').innerHTML = '<img src="../images/tick_transparent.gif" width="49" height="46" alt="Done">';
			document.getElementById('img-processing2a').style.color = "#C0C0C0";
			document.getElementById('img-processing3a').style.color = "#000000";
			document.getElementById('img-processing3b').innerHTML = '<img src="../images/waiting.gif" width="32" height="32" alt="Processing" style="margin: 7px 0;">';
			doprocessimg('rot2', newfancyname);
		}
		else if (xmlHttp.responseText=="rot1_error"){
			document.getElementById('img-processing2b').innerHTML = '<img src="../images/error-icon.png" width="40" height="40" alt="Error" style="margin: 3px 0;">';
			document.getElementById('img-processing4').style.display = "block";
			document.getElementById('img-processing4').innerHTML = error_txt;
			//up.remove(); // clear old file
			document.getElementById('progr_bar').style.display = 'none';
		}
		else if (xmlHttp.responseText=="rot2_ok"){
			document.getElementById('img-processing3b').innerHTML = '<img src="../images/tick_transparent.gif" width="49" height="46" alt="Done">';
			document.getElementById('img-processing3a').style.color = "#C0C0C0";
			// goto uploaded.php
			//var fancyw = document.getElementById('imgwidth').innerHTML;
			//var fancyh = document.getElementById('imgheight').innerHTML;
			document.go2uploaded.h.value = newfancyheight;
			document.go2uploaded.w.value = newfancywidth;
			document.go2uploaded.img.value = newfancyname;
			document.go2uploaded.email.value = newfancyemail;
			document.go2uploaded.submit();
		}
		else if (xmlHttp.responseText=="rot2_error"){
			document.getElementById('img-processing3b').innerHTML = '<img src="../images/error-icon.png" width="40" height="40" alt="Error" style="margin: 3px 0;">';
			document.getElementById('img-processing4').style.display = "block";
			document.getElementById('img-processing4').innerHTML = error_txt;
			//up.remove(); // clear old file
			document.getElementById('progr_bar').style.display = 'none';
		}
		else {
			document.getElementById('img-processing4').style.display = "block";
			document.getElementById('img-processing4').innerHTML = error_txt;
			//up.remove(); // clear old file
			document.getElementById('progr_bar').style.display = 'none';
		}
	} 
}

function GetXmlHttpObject4(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
		//Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function modifyOnclick(clientId){
	var recipient = window.document.getElementById(clientId);  
	recipient.onclick=function(){  
		alert('Image has been deleted'); 
		return false;  
	}  
	return false;  
}