function contactForm()
{
	document.getElementById('contactForm').style.visibility = 'visible'
	document.getElementById('contactForm').visibility = 'show'
}

function closecontactForm()
{
	document.getElementById('contactForm').style.visibility = 'hidden'
	document.getElementById('contactForm').visibility = 'hidden'
}

function getFormByFieldName(fieldName)
{
   	var intForms = document.forms.length;
    var myForm;
    for (var i=0; i < intForms ; i++)
    {
        if (document.forms[i].elements[fieldName] != null )
        {
            myForm = document.forms[i];
        	continue;
        }
    }
    return myForm;
}

var xmlhttp

function sendContactForm()
{
	myForm = getFormByFieldName('fullname0')
	
	url = "dbcontact.php"

	vars = "formA=" + myForm.fullname0.value
	vars= vars+ "&formB=" + myForm.Country0.value
	vars= vars+ "&formC=" + myForm.TelNo0.value
	vars= vars+ "&formD=" + myForm.EmailAddr0.value
	vars= vars+ "&formE=" + myForm.Subject0.value
	vars= vars+ "&formF=" + myForm.YourEnq0.value

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=contstate_Change
		xmlhttp.open("POST",url,true)
		xmlhttp.setRequestHeader("Method", "POST "+ url +" HTTP/1.1");
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(vars)
		}
	// code for IE
	else if (window.ActiveXObject)
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
	    {
	    	xmlhttp.onreadystatechange=contstate_Change
	    	xmlhttp.open("POST",url,true)
	    	xmlhttp.setRequestHeader("Method", "POST "+ url +" HTTP/1.1");
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    	xmlhttp.send(vars)
	    }
	 }
}

function contstate_Change()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			//alert("Thanks for booking your IDC with Fineglobe")
			txt = xmlhttp.responseText

			//alert(txt)

			if (txt.indexOf("FGDBINSERTSUCCESS") != -1)
			{
				st = (txt.indexOf("<ID>"))+4
				end = txt.indexOf("</ID>")
				id = txt.substring(st, end)
				alert("Thanks for contacting Fineglobe.\n\nWe have received your email and will reply as soon as possible.\n\nYour contact reference is FG" + id +".\n\n\Click X to close the window if it doesn't close automatically.")
				closecontactForm()
			}
			if (txt.indexOf("FGDBINSERTFAIL") != -1)
			{
				alert("WARNING: Your contact was not received due to techncial problems.\n\nPlease try submitting the form again or email directly.")
			}
			
		}
		else
		{
			alert("WARNING: Your contact was not received due to techncial problems.\n\nPlease try submitting the form again or email directly.\n\nContact Script not found - 404")
		}
	}
}



