//-------------------------------------------------------//
// Author:Rodolfo Machon
// Nombre del archivo: leyes_upld.js
// Created: 2016-01-18
// Updates: 2016-01-18
//-------------------------------------------------------//
//-------------------------------------------------------//
var isIE = document.all?true:false;
var isNS = document.layers?true:false;
var client = new XMLHttpRequest();
//-------------------------------------------------------//
window.onload = function(){
	window.resizeTo(600,200);
};
//------------------------------------------------------//
function upload() {

	var url   	= "../pl/inmueble_fichas_upldp.pl";
	var file  	= document.getElementById("uploadfile");
	var splt 	= file.value.split(".");
	var len 	= splt.length;
	var formData= new FormData();
	var e 	    = document.getElementById("i2_pagina");
	var pagina  = e.options[e.selectedIndex].value;
	document.getElementById("doc_id").value= document.getElementById("id").value+"_F"+pagina;
	if (splt[len-1] == "jpg" || splt[len-1] == "JPG" || splt[len-1] == "pdf" || splt[len-1] == "PDF"){		
		formData.append("upload", file.files[0]);
		formData.append("lan", document.getElementById("lan").value);
		formData.append("appid", document.getElementById("appid").value);		
		formData.append("clase", document.getElementById("clase").value);
		formData.append("id", document.getElementById("id").value);
		formData.append("doc_id", document.getElementById("doc_id").value);
		formData.append("file_type", splt[len-1]);
		client.open("post", url, true);
		client.setRequestHeader("Content-Type", "multipart/form-data");
		client.send(formData);  // send formData to the server using XHR
	}else{
		alert("Archivo debe tener extesion JPG o PDF");
		return;		
	}
}
client.onreadystatechange = function () {
	if (client.readyState == 4 && client.status == 200) {
		alert(client.responseText);
		alert(client.statusText);
		close();
	}
};