// JavaScript Document

function ajaxFunction()
  {
  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)
        {
		document.getElementById('nl_validate').style.visibility="visible";
		document.getElementById('nl_validate').style.color="blue";
         document.getElementById('nl_validate').innerHTML=xmlHttp.responseText;
		 document.newsletter.text2.value = "";
        }
      }
    xmlHttp.open("GET","newsletters.jsp?text2="+document.newsletter.text2.value,true);
    xmlHttp.send(null);
  }

/*newsletter Vallidation*/
function dummyFunction() {

	return false;
}
function emailValidation(){

if(document.newsletter.text2.value==""){
           //alert("pleae enter  email");
		   document.getElementById('nl_validate').style.visibility = "visible";
			document.getElementById('nl_validate').style.color="red";
           document.getElementById('nl_validate').innerHTML = "Please enter your e-mail Id";
           document.newsletter.text2.focus();
            return false;
            }
if (validateemail()==false){
           document.newsletter.text2.focus();
  			document.getElementById('nl_validate').style.color="red";
			document.getElementById('nl_validate').innerHTML = "Please enter a valid mail ID";
           return false
           }

      function validateemail(){
          apos=document.newsletter.text2.value.indexOf("@")
          dotpos=document.newsletter.text2.value.lastIndexOf(".")
         if (apos<1||dotpos-apos<2)
          {
		  document.getElementById('nl_validate').style.visibility = "visible";
			document.getElementById('nl_validate').style.color="red";
		  document.getElementById('nl_validate').innerHTML = "Please enter a valid mail ID";
         return false;
          }
         else
           {//alert("b4");

			   ajaxFunction('newsletters.jsp?text2='+document.newsletter.text2.value);
				
			   
//         return true;
           }
    }
}


//check for alphanumeric

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function alphanumeric(alphane)
{
	var numaric = trimAll(alphane);
if(numaric==""){
/*		  document.getElementById('search_val').style.visibility = "visible";*/
alert("Please enter a valid string");
return false;
}
else{
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh==32) || (hh==64) )
		  {

		  }
		else	{
/*             document.getElementById('search_val').style.visibility = "visible";*/
			alert("Please enter a valid string");
			 return false;
		  }
		}
}

}

  // scroller
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));


    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}