// JavaScript Document
function openfile(){
	popup_window = window.open('temp/temp.txt','_blank','resizable=no, scrollbars=no, toolbar=no, location=no, directories=no');
	//popup_window.blur();
	
	popup_window.document.execCommand('SaveAs', false, 'file.txt');
	popup_window.close();
	return false;
	}
	
function writefile(){
	
//check whether there're empty fields
for(var loop=3;loop<=10;loop++){
	if (document.getElementById("T"+loop).value.length==0) {
	alert("fill all the fields and try again");
	return;
}
}
var content="type="+encodeURI(document.getElementById('typedrop').selectedIndex)+
"&T3="+encodeURI(document.getElementById('T3').value)+
"&T4="+encodeURI(document.getElementById('T4').value)+
"&T5="+encodeURI(document.getElementById('T5').value)+
"&T6="+encodeURI(document.getElementById('T6').value)+
"&T7="+encodeURI(document.getElementById('T7').value)+
"&T8="+encodeURI(document.getElementById('T8').value)+
"&T9="+encodeURI(document.getElementById('T9').value)+
"&T10="+encodeURI(document.getElementById('T10').value);
for(i=1;i<=14;i++){
content+=("&o"+i+"="+encodeURI(document.getElementById('o'+i).value));
}
if (document.getElementById('radiob1').checked) unit=1;
else unit=2;
content+=("&unit="+unit);
if(document.getElementById('Sradiob1').checked) gender = 1;
else gender = 2;
content+=("&gender="+gender);
makePOSTRequest("writefile1.php",content);

}

function showwritestatus(){
	if(http_request.readyState==4){
		if(http_request.status==200){
		var response=http_request.responseText;
		openfile();
		}
	}
	}