var Ajax = false;

function AjaxRequest() {
	Ajax = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		Ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
	    	Ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
	        	Ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}		
}


function monteSeuPlano() {
	var plano = document.getElementById('plano');
	var gigabyte = document.getElementById('gigabyte');
	var pagamento = document.getElementById('pagamento');
	if(plano.selectedIndex == 0) {
		return;
	} 
	if(gigabyte.selectedIndex == 0) {
		return;
	}
	if(pagamento.selectedIndex ==0) {
		return;
	}
	
	//faz a requisição do ajax e verifica se é um objeto válido
	AjaxRequest();
	if(!Ajax) {
		alert('erro na requisição');
		return;
	}	
	Ajax.onreadystatechange = showResult;
	Ajax.open('GET', 'jscript/monteseuplano.php?name='+plano.value+'&diskSpace='+gigabyte.value+'&paymentForm='+pagamento.value, true);
	
	Ajax.send(null);
}


function showResult() {
	if (Ajax.readyState == 4) {
    	if (Ajax.status == 200) {
			document.getElementById('resultValue').innerHTML = Ajax.responseText;
			document.getElementById('formValue').value = Ajax.responseText;
			
		} else {
			alert('Erro no Retorno do Servidor' + Ajax.statusText);
		}
	} else {
		
	}
}

function verifyGigabyte() {
	var plano = document.getElementById('plano');
	if(plano.value == 'MEGA') {
		document.getElementById('gigabyte').options[document.getElementById("gigabyte").options.length] = new Option ('1GB','1', true, true);
	}
	if(plano.value == 'VIP') {
		document.getElementById('gigabyte').remove(31);
	}
}