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 SendContactUs()
{
	var valid = true;
	var contactName = document.getElementById("contactname").value;
	var contactComp = document.getElementById("company").value;
	var contactEmail = document.getElementById("email").value;
	var message = document.getElementById("message").value;
	var subject = "Contact Us - From Website (JSA)";
	document.getElementById("err_contactname").innerHTML = "";
	document.getElementById("err_email").innerHTML = "";
	document.getElementById("err_message").innerHTML = "";
	
if (document.getElementById("contactname").value.length == 0)	
{
	document.getElementById("err_contactname").innerHTML = "<p STYLE='padding:0px; margin:0px; font-size:12px; font-weight: bold;'>* Required field</p>";
	document.getElementById("contactname").focus();
	valid = false;
}
else if (document.getElementById("email").value.length == 0)	
{
	document.getElementById("err_email").innerHTML = "<p STYLE='padding:0px;margin:0px;font-size:12px;font-weight: bold;'>* Required field</p>";
	document.getElementById("email").focus();
	valid = false;
}
else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email").value) == false)
{
	document.getElementById("err_email").innerHTML = "<p STYLE='padding:0px;margin:0px;font-size:12px;font-weight: bold;'>* Not a valid e-mail address</p>";
	document.getElementById("email").focus();
	valid = false;
}
else if (document.getElementById("message").value.length == 0)	
{
	document.getElementById("err_message").innerHTML = "<p STYLE='padding:0px;margin:0px;font-size:12px;font-weight: bold;'>* Required field</p>";
	document.getElementById("message").focus();
	valid = false;
}

if (valid == false)	
{
	return;
}	

if (valid == true)	
{
		var page = "email.php?contact_name=" + contactName + "&contact_email=" + contactEmail + "&contact_comp=" + contactComp + "&topic=" + subject + "&msg=" + message.replace(/\n/g,"<br/>");
	Query(page, ContactUsResult);
}
}

function SendContactUsOld()
{
	var valid = true;
	var contactName = document.getElementById("contactname").value;
	var contactComp = document.getElementById("company").value;
	var contactEmail = document.getElementById("email").value;
	var message = document.getElementById("message").value;
	var subject = "Contact Us - From Website (JSA)";
	if (document.getElementById("contactname").value.length == 0)	
	{
		alert("Contact Name is a required field");
		document.getElementById("contactname").focus();
		valid = false;
	}
	else if (document.getElementById("email").value.length == 0)	
	{
		alert("Contact E-mail is a required field");
		document.getElementById("email").focus();
		valid = false;
	}
	else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email").value) == false)
{
		alert("Contact E-mail Address is not valid");
		document.getElementById("email").focus();
		valid = false;
}	
else if (document.getElementById("message").value.length == 0)	
{		alert("Message is not valid");
		document.getElementById("message").focus();
		valid = false;
	}		if (valid == false)	
{		return;
	}	if (valid == true)	
{		var page = "email.php?contact_name=" + contactName + "&contact_email=" + contactEmail + "&contact_comp=" + contactComp + "&topic=" + subject + "&msg=" + message.replace(/\n/g,"<br/>");
	Query(page, ContactUsResultOld);
	}}

function ClearContactUs()
{
	document.getElementById("err_contactname").innerHTML = "";	document.getElementById("err_email").innerHTML = "";	document.getElementById("err_message").innerHTML = "";	document.getElementById("contactname").value = "";	document.getElementById("company").value = "";	document.getElementById("email").value = "";	document.getElementById("message").value = "";
}

function ClearContactUsOld()
{
	document.getElementById("contactname").value = "";
        document.getElementById("company").value = "";
        document.getElementById("email").value = "";
        document.getElementById("message").value = "";
}

function ContactUsResult(a)
{
	if(a == 'True')
        {
        document.getElementById("status").innerHTML = "<p STYLE='font-size: 11px; font-color: blue; font-weight: bold;'>Message successfully sent. We will contact you shortly.</p>";
        ClearContactUs();
        }
}

function ContactUsResultOld(a)
{
        if(a == 'True')
        {
        	document.getElementById("status").innerHTML = "<p STYLE='font-size: 12px; font-color: blue; font-weight: bold;'>Message successfully sent. We will contact you shortly.</p>";
                ClearContactUsOld();
        }
}

