var d1 = null;
var d2 = null;

function Goto(page, pos, func)
  {

  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }

    a = pos;
    loader = setTimeout("ShowLoader()", 1000);

    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
	if (pos.length > 0)
	{
		clearTimeout(loader);
		document.getElementById(pos).innerHTML=xmlHttp.responseText;
		if (func)
		{
			func();
		}
	}
        }
      }

    var found = false;
    for (var i = 0; i < page.length; i++)
    {
	if (page.charAt(i) == '?')
	{
		found = true;
		break;
	}
    }

    var date = new Date();
    var timestamp = date.getTime();

    if (found == true)
    {
    	xmlHttp.open("GET",page + "&time=" + timestamp,true); 
    }
    else
    {
    	xmlHttp.open("GET",page + "?time=" + timestamp,true); 
    }

    xmlHttp.send(null);
  }

function Query(page, func)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
        if(xmlHttp.readyState==4)
        {	
		var a;
		a = xmlHttp.responseText;
		if (func)
		{
			func(a);
		}
        }
      }

    var found = false;
    for (var i = 0; i < page.length; i++)
    {
	if (page.charAt(i) == '?')
	{
		found = true;
		break;
	}
    }

    var date = new Date();
    var timestamp = date.getTime();

    if (found == true)
    {
    	xmlHttp.open("GET",page + "&time=" + timestamp,true); 
    }
    else
    {
    	xmlHttp.open("GET",page + "?time=" + timestamp,true); 
    }

    xmlHttp.send(null);
  }

function QueryAndWait(page)
{
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }

    var found = false;
    for (var i = 0; i < page.length; i++)
    {
	if (page.charAt(i) == '?')
	{
		found = true;
		break;
	}
    }

    var date = new Date();
    var timestamp = date.getTime();

    if (found == true)
    {
    	xmlHttp.open("GET",page + "&time=" + timestamp,false); 
    }
    else
    {
    	xmlHttp.open("GET",page + "?time=" + timestamp,false); 
    }

    xmlHttp.send(null);
    return xmlHttp.responseText;
}

function launchContactUsForm()
{	
	URL="contactus.php"
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=430,height=480');");	
}

function SendContactUs()
{
	var valid = true;
		
	var topicCbo = document.getElementById("subject");
	var subject = topicCbo.options[topicCbo.selectedIndex].value;

	if (document.getElementById("name").value.length == 0)
	{
		alert("Your name is required.");
		document.getElementById("name").focus();
		valid = false;
	}
	else if (document.getElementById("email").value.length == 0)
	{
		alert("E-mail address is required.");
		document.getElementById("email").focus();
		valid = false;
	}
	else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email").value) == false)
	{
		alert("Invalid e-mail address specified.");
		document.getElementById("email").focus();
		valid = false;
	}
	else if (document.getElementById("msg").value.length == 0)
	{
		alert("Please enter a message.");
		document.getElementById("msg").focus();
		valid = false;
	}
	else if (subject == '')
	{
		alert("Please choose a subject.");
		valid = false;
	}
	
	if (valid == false)
	{
		return;
	}

	var page = "email.php?contact_name=" + document.getElementById("name").value + "&contact_email=" + document.getElementById("email").value  + "&topic=" + subject + "&msg=" + document.getElementById("msg").value.replace(/\n/g,"<br/>");
	Query(page, EmailResult);
}

function EmailResult(a)
{	
	if (a == "True")
	{
		document.getElementById("name").value = "";
		document.getElementById("email").value = "";
		document.getElementById("msg").value = "";
		document.getElementById("subject").options[0].selected=true;
		document.getElementById("err_success").innerHTML = "<p><font color='blue'>Message successfully sent! We will get back to you shortly. You can now close the window.</font></p>";
	}
}

function ClearContactUs()
{	
	document.getElementById("name").value = "";
	document.getElementById("email").value = "";
	document.getElementById("msg").value = "";
	document.getElementById("subject").options[0].selected=true;
	document.getElementById("err_success").innerHTML = "";
}