var xmlHttp;

function getFormNickName() {  
	xmlHttp=GetXmlHttpObject()
	var url = "util.asp"
	url = url + "?cod_function=1&var=" + window.top.location
	
	
	if (xmlHttp==null) {
		alert ("Seu browser não suporta o objeto HTTP Request.")
		return
	} 
        var xmlHttpValue = function() {
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				if (xmlHttp.responseText.indexOf("/pedido/FC.asp") > -1  || xmlHttp.responseText.indexOf("/pedido/FP.asp") > -1  ||  xmlHttp.responseText.indexOf("/pedido/FD.asp") > -1 ||  xmlHttp.responseText.indexOf("/pedido/FE.asp") > -1)
				window.location.href=xmlHttp.responseText
			else
				window.location.href = "indexForm.asp?error=1&rt="+xmlHttp.responseText
			} 
        }
	url = url + "&sid="+Math.random()
	xmlHttp.onreadystatechange = xmlHttpValue 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function verifyIfExistsFormNickName(form_nick_name) {
	
	var url = "../pedido/util.asp"
	var xmlHttpValue = null;
	xmlHttp=GetXmlHttpObject()
	url = url + "?cod_function=2&form_nick_name=" + form_nick_name
	if (xmlHttp==null) {
		alert ("Seu browser não suporta o objeto HTTP Request.")
		return
	} 
	xmlHttpValue = function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			document.getElementById('msg').innerHTML = xmlHttp.responseText; 
			if (xmlHttp.responseText.indexOf("Erro. ") > -1) {
				document.getElementById('btn').disabled = true;
				document.getElementById("btn").value = "Aguarde"
			} else {
				document.getElementById('btn').disabled = false;
				document.getElementById("btn").value = "Continuar"
			}
		}

	}
	url = url + "&sid="+Math.random()
	xmlHttp.onreadystatechange = xmlHttpValue 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)

}

function GetXmlHttpObject(){ 
   	var objXMLHttp=null
	try {
		objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP")
	}catch(e){
		try {
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		} catch(e){
			objXMLHttp==null;
		}
	} 

	if (objXMLHttp==null) {
		objXMLHttp=new XMLHttpRequest()
	}

	return objXMLHttp
}

function disabledButton() {
	if (document.getElementById("form_nick_name").value != null && document.getElementById("form_nick_name").value != "") {
		document.getElementById("btn").disabled = true	
		document.getElementById("btn").value = "Aguarde"
	}
}

//#####################################################################################
//################################Contador Regressivo##################################
//#####################################################################################
function iniciar(tempo,dif,url){
	window.setTimeout("mostra(tempo,dif,url)",tempo);
}
function mostra(tempo,dif,url){
	valor = document.getElementById("time").value;
	document.getElementById("time").value = (valor - dif); 
	message = "Redicionando para a url: <br/><br/><a href='" + url + "' class=menu10>" + url + "</a><br/><br/>" + (valor - dif) + " segundos.";
	showIntoLayer("showtime",message);
	if(valor == 1){
		TempoExpirou();
	}else{
		iniciar(tempo,dif,url);
	}
}

function showIntoLayer(div, string) {
	if(document.all){
		eval("document.all." + div + ".innerHTML = string");
	}else if(document.layers){
		eval("document.layers['" + div + "'].document.open()");
		eval("document.layers['" + div + "'].document.write(string)");
		eval("document.layers['" + div + "'].document.close()");
	}else{
		eval("document.getElementById('" + div + "').innerHTML = string ");
	}
}