var ini=0;
var global_cadena = '';
function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;

}


function inicio(){
	//donde se mostrarn los datos
	divFormulario = document.getElementById('formulario');
	cargando = document.getElementById('formulario');
	//instanciamos el objetoAjax
	ajax=objetoAjax();
	//uso del medotod GET
	ajax.open("POST", "calculo_corte.php");
	
	//cargando.innerHTML= '<img src="images/loader.gif">';

	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			divFormulario.innerHTML = ajax.responseText
			//mostrar el formulario
			divFormulario.style.display="block";
		}
	}
	//como hacemos uso del metodo GET
	//colocamos null
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("formulario=mostrar");

}

function enviar(){
	var mensaje='';
	var mens='';
	if(document.getElementById('alto1').value==''){mensaje=mensaje+'\n - Alto del Pliego.'}
	if(document.getElementById('ancho1').value==''){mensaje=mensaje+'\n - Ancho del Pliego.'}
	if(document.getElementById('alto2').value==''){mensaje=mensaje+'\n - Alto del Corte.'}
	if(document.getElementById('ancho2').value==''){mensaje=mensaje+'\n - Ancho del Corte.'}
	if (mensaje!='')
	{
		alert('Verificar los siguientes valores:' + mensaje);
	}
	else
	{
		document.getElementById('dibujo').src="";
		//donde se mostrarn los datos
		divFormulario = document.getElementById('resultado');
		cargando = document.getElementById('resultado');
		//instanciamos el objetoAjax
		ajax=objetoAjax();
		//uso del medotod GET
		ajax.open("POST", "calculo_corte.php");
		
		cargando.innerHTML= '<img src="images/loader.gif">';
	
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				//mostrar resultados en esta capa
				divFormulario.innerHTML = ajax.responseText;
				//mostrar el formulario
				divFormulario.style.display="block"; 
				dibu();
			}
		}
		//como hacemos uso del metodo GET
		//colocamos null
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("ox="+document.getElementById('ancho1').value+"&oy="+document.getElementById('alto1').value+"&cx="+document.getElementById('alto2').value+"&cy="+document.getElementById('ancho2').value)
	}
}


function limpiar(){
	document.getElementById('dibujo').src="";
	divFormulario = document.getElementById('resultado');
	divFormulario.innerHTML = '';
}

function dibu() 
{
	if(document.getElementById('resul').value!='0')
	{
		var pliego_x, pliego_y, corte_x, corte_y, c1a, c1l, c2a, c2l, c3a, c3l, orienta, cadena;
		pliego_x=parseFloat(document.getElementById('ancho1').value);
		pliego_y=parseFloat(document.getElementById('alto1').value);
		corte_x=parseFloat(document.getElementById('corte_x').value);
		corte_y=parseFloat(document.getElementById('corte_y').value);
		c1a=parseInt(document.getElementById('c1a').value);
		c1l=parseInt(document.getElementById('c1l').value);
		c2a=parseInt(document.getElementById('c2a').value);
		c2l=parseInt(document.getElementById('c2l').value);
		c3a=parseInt(document.getElementById('c3a').value);
		c3l=parseInt(document.getElementById('c3l').value);
		orienta=document.getElementById('orienta').value;
		//alert(orienta);
		if(orienta="h")
		{
			cadena='pliego_x='+pliego_x+'&pliego_y='+pliego_y+'&corte_x='+corte_x+'&corte_y='+corte_y+'&c1a='+c1a+'&c1l='+c1l+'&c2a='+c2a+'&c2l='+c2l+'&c3a='+c3a+'&c3l='+c3l;
		}
		else
		{
			cadena='pliego_x='+pliego_x+'&pliego_y='+pliego_y+'&corte_x='+corte_x+'&corte_y='+corte_y+'&c1a='+c1a+'&c1l='+c1l+'&c2a='+c2a+'&c2l='+c2l+'&c3a='+c3a+'&c3l='+c3l;
		}
		//donde se mostrarn los datos
		document.getElementById('dibujo').src="dibujar.php?"+cadena;
		//global_cadena = cadena;
		//window.open('dibujar.php?'+cadena,0,0,0,1,1,1,1,0,0,0,0,1);
		//abrir_ventana ('dibujar.php?'+cadena,pliego_x,pliego_y) 
	}
}


function abrir_ventana (pagina,pliego_x,pliego_y) 
{
	var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width="+screen.width+", height="+screen.height+", top=0, left=0";
	window.open(pagina,"",opciones);
}

function ver_result()
{
	abrir_ventana('dibujar.php?'+global_cadena,0,0);
}
