function CheckNewsletterForm()
{
     var isOk = true;
     var str = "";
     var champsToCheck = new Array("name","email");
     var champsName = new Array("Ime","E-mail adresa");
     for(i=0;i<champsToCheck.length;i++)
     {
	     if(eval('document.forms["formcheck"].'+champsToCheck[i]+'.value == ""') || eval('document.forms["formcheck"].'+champsToCheck[i]+'.value == " "'))
       {
       	str += ""+champsName[i]+" je obavezno/a .\n";
        isOk = false;
       }
     }
     if(isOk == true)
     {
       Send_Newsletter_Registration();
			 urchinTracker("/goal/newsletter");
     }
     else { alert(str); }
     return;
 }
 
 function CheckPamtiForm()
 {
   var Ok = true;
   var str = "";
   var ToCheck = new Array("pojam");
   var Name = new Array("Pojam");
   for(i=0;i<ToCheck.length;i++)
   {
     if( eval('document.forms["pamtiforma"].'+ToCheck[i]+'.value == ""') )
      {
             str += ""+Name[i]+" je obavezan .\n";
             Ok = false;
      }
   }
   if(Ok == true)
   {
   	Send_To_Pamtilicalog();
 		urchinTracker("/goal/pojam");
   }
   else { alert(str); }
   return;
 }

// stores the reference to the XMLHttpRequest object
var xmlHttp = create_XmlHttpRequest_Object();

// retrieves the XMLHttpRequest object
function create_XmlHttpRequest_Object()
{
   // will store the reference to the XMLHttpRequest object
   var xmlHttp;
   // if running Internet Explorer
   if(window.ActiveXObject)
   {
      try
      {
         // Initialize the Microsoft XMLHTTP object
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }
   // if running Mozilla or other browsers
   else
   {
      try
      {
         xmlHttp = new XMLHttpRequest();
      }
      catch (e)
      {
         xmlHttp = false;
      }
   }
   // return the created object or display an error message
   if (!xmlHttp)
      alert("Error creating the XMLHttpRequest object.");
   else
      return xmlHttp;
}



// make asynchronous HTTP request using the XMLHttpRequest object
function Send_Newsletter_Registration()
{
   // proceed only if the xmlHttp object isn't busy
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
   {
      // retrieve the name typed by the user on the form
      name = encodeURIComponent(document.getElementById("name").value);
          email=encodeURIComponent(document.getElementById("email").value);
      // execute the quickstart.php page from the server
      xmlHttp.open("GET", "http://www.pamtilica.com/signup.php?name=" + name+"&email="+email, true);
      // define the method to handle server responses
      xmlHttp.onreadystatechange = Server_Response;
      // make the server request
      xmlHttp.send(null);
   }
   else
      // if the connection is busy, try again after one second
      setTimeout('Send_Newsletter_Registration()', 1000);
}

function Send_To_Pamtilicalog()
{
   // proceed only if the xmlHttp object isn't busy
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
   {
      // retrieve the name typed by the user on the form
      pojam = encodeURIComponent(document.getElementById("pojam").value);
      // execute the quickstart.php page from the server
      xmlHttp.open("GET", "http://www.pamtilica.com/pamtilog.php?pojam=" + pojam, true);
      // define the method to handle server responses
      xmlHttp.onreadystatechange = Server_Response2;
      // make the server request
      xmlHttp.send(null);
   }
   else
      // if the connection is busy, try again after one second
      setTimeout('Send_To_Pamtilicalog()', 1000);
}

// executed automatically when a message is received from the server
function Server_Response()
{
   // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4)
   {
      // status of 200 indicates the transaction completed successfully
      if (xmlHttp.status == 200)
      {
         // extract the XML retrieved from the server
         xmlResponse = xmlHttp.responseXML;
         // Get the first element from the document which is <response> and read its content.
         helloMessage = xmlResponse.documentElement.firstChild.data;
         
         //create an object that represents the row in which the results are to be output
         var obj= document.getElementById('Status');
         obj.innerHTML=helloMessage;
         setTimeout("document.getElementById('Status').innerHTML='';", 2000);
      }
      else
      {
         alert("Problem pristupanja poslužitelju: " + xmlHttp.statusText);
      }
   }
}

function Server_Response2()
{
   // move forward only if the transaction has completed
   if (xmlHttp.readyState == 4)
   {
      // status of 200 indicates the transaction completed successfully
      if (xmlHttp.status == 200)
      {
         // extract the XML retrieved from the server
         xmlResponse = xmlHttp.responseXML;
         // Get the first element from the document which is <response> and read its content.
         helloMessage = xmlResponse.documentElement.firstChild.data;
         
         //create an object that represents the row in which the results are to be output
         var obj= document.getElementById('Status2');
         obj.innerHTML=helloMessage;
        setTimeout("document.getElementById('Status2').innerHTML='';", 2000);
      }
      else
      {
         alert("Problem pristupanja poslužitelju: " + xmlHttp.statusText);
      }
   }
}

