/* contact form submission */

document.write('<script id="__init_script" defer="true" src="//[]"><\/script>');

function registerInit(callback) {
    if (document.addEventListener) {
        document.addEventListener("DOMContentLoaded", callback, false);
    }

    if (document.getElementById) {
        var deferScript = document.getElementById('__init_script');
        if (deferScript) {
            deferScript.onreadystatechange = function() {
                if (this.readyState == 'complete') {
                    callback();
                }
            };
            deferScript.onreadystatechange();
            deferScript = null;
        }
    }

    window.onload = callback;
}


function init() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    // do initialization here
	var tForm = document.getElementById('contact');
	//alert(tForm);
	tForm.onsubmit = function() {
		var tName = document.getElementById('name').value;
		var tEmail = document.getElementById('email').value;
		var tMessage = document.getElementById('message').value;
		var oXml = getXmlObject();
		oXml = loadXmlString(oXml,'<consulta><name>' + tName + '</name><email>' + tEmail + '</email><message>' + tMessage + '</message></consulta>');
		var oHttp = getHTTPObject();
		var sLoc = 'send_messgae.aspx?d=' + getUnique();
		http.open("POST", sLoc, true);		
		http.send(oXml);
		return false;
	}	
};

registerInit(init);

/* Ajax Cross Browser! - handles http requests and xml document creation */
function getHTTPObject() {
	var xmlhttp;
	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') {
		try {
			xmlhttp = new XMLHttpRequest();
			xmlhttp.overrideMimeType("text/xml"); 
		} 
		catch (e) {
			xmlhttp = false;
		}
  	}
  	return xmlhttp;
}

function getXmlObject() {
	var xmldoc;
	xmldoc = false;
	
	try {
		xmldoc = new ActiveXObject("Msxml2.DomDocument.4.0");
	}
	catch(e) {
		try {
			xmldoc = new ActiveXObject("Msxml2.DomDocument");
		}
		catch(E) {
			try {
				xmldoc = new ActiveXObject("Microsoft.DomDocument");
			}
			catch(ee) {
				xmldoc = false;
			}
		}
	}
	
	if (!xmldoc && typeof document.implementation.createDocument != 'undefined') {
		try {
			xmldoc = document.implementation.createDocument('','',null);		
		}
		catch(e) {
			xmldoc = false;
		}
	}	
	return xmldoc;
}

function getXmlString(xmlObject) {
	var xmlout;
	xmlout = false;
	
	try {
		xmlout = xmlObject.xml;
	}
	catch (e) {
		xmlout = false;
	}
	
	if(!xmlout && typeof XMLSerializer != 'undefined') {
		try {
			stringMaker = new XMLSerializer();
			xmlout = stringMaker.serializeToString(xmlObject);		
		}
		catch (e) {
			xmlout = false;
		}	
	}
	return xmlout;
}

function loadXmlString(xmlObject, xmlString) {
	if(typeof xmlObject.loadXML != 'undefined') {
		xmlObject.loadXML(xmlString);
	}
	else {
    		var objDOMParser = new DOMParser();	
    		xmlObject = objDOMParser.parseFromString(xmlString, "text/xml");    		
	}
    return xmlObject;
}

function getNodeValue(xmlNode) {
	if(typeof xmlNode.text != 'undefined') {
		return xmlNode.text;
	}
	if(typeof xmlNode.nodeValue == 'object') {
		return xmlNode.firstChild.nodeValue;
	}
	return '';
}

function is_all_ws(nod) {
	return !(/[^\t\n\r ]/.test(nod.data));
}

function is_ignorable(nod) {
	return ( nod.nodeType == 8) || ( (nod.nodeType == 3) && is_all_ws(nod) );
}

function node_before(sib) {
	while ((sib = sib.previousSibling)) {
		if (!is_ignorable(sib)) return sib;
	}
	return null;
}

function node_after(sib) {
	while ((sib = sib.nextSibling)) {
		if (!is_ignorable(sib)) return sib;
	}
	return null;
}

function last_child(par) {
	var res=par.lastChild;
	while (res) {
		if (!is_ignorable(res)) return res;
		res = res.previousSibling;
	}
	return null;
}

function first_child(par) {
	var res=par.firstChild;
	while (res) {
		if (!is_ignorable(res)) return res;
		res = res.nextSibling;
	}
	return null;
}

function data_of( txt ) {
	var data = txt.data;
	data = data.replace(/[\t\n\r ]+/g, " ");
	if (data.charAt(0) == " ") data = data.substring(1, data.length);
	if (data.charAt(data.length - 1) == " ") data = data.substring(0, data.length - 1);
	return data;
}