

var http = createRequestObject(); //make the AJAX thingy
var timeoutholder=null; //this variable holds the timeouts which wait between keypresses



 function updateTellAfriend() {

	 	try{
    if((http.readyState == 4)&& (http.status == 200)){
        var response = http.responseText;

	 		//alert(response); //DEBUG   

	var resp_arr = response.split("||");
	//alert(resp_arr[1]);
	
          var theDIV = document.getElementById('prijatelj'); // the DIV
			if (resp_arr[0] == 'ERR') {
				 if (theDIV) { theDIV.innerHTML = resp_arr[1]; }
			}

			if (resp_arr[0] == 'OK') {
				

          if (theDIV) { 
        	  theDIV.innerHTML = resp_arr[1];
        	  
      timeoutholder=window.setTimeout("slideup(\'prijatelj\');", 2000);
          
          }
			}


	}
    }

catch(e){
}
finally{}
			// alert(request.responseText);  // DEBUGGING 
		
}



function createRequestObject() {  //Get the right xmlHTTP, including IE, FF and Opera, try and catch for errors error catching
	var xmlhttp;
try
    {
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(f)
        {
             xmlhttp=null;
        }
    }
    if(! xmlhttp&&typeof XMLHttpRequest!="undefined")
    {
         xmlhttp=new XMLHttpRequest();
				 if (xmlhttp.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            xmlhttp.overrideMimeType('text/html');
         }

    }
	return  xmlhttp;
}

function sndReqTellAfriend(name, email, femail1, femail2, femail3, firmid) { //this function asks for the functions

	name=encodeURI(name);  //escape for URLs
	email=encodeURI(email);  //escape for URLs
	femail1=encodeURI(femail1);  //escape for URLs
	femail2=encodeURI(femail2);  //escape for URLs
	femail3=encodeURI(femail3);  //escape for URLs
	firmid=encodeURI(firmid);  //escape for URLs
try{
	var url = "tellafriend/tellafriend.php";
var params = "name="+name+"&email="+email+"&friendmail1="+femail1+"&friendmail2="+femail2+"&friendmail3="+femail3+"&firmid="+firmid;
   
	 
http.onreadystatechange = updateTellAfriend; //ensures the response is handled by the correct function
http.open('POST', url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
}
	catch(e){}
	finally{}

}



function tellAfriend(name, email, femail1, femail2, femail3, firmid){ //Sets a timeout waiting to look up but cancels it if another key is pressed within 0.4 secs
if(name=="" || email==""  || femail1=="" ){
alert("Molimo Vas unesite Vase ime, Vas email i minimum email jednog prijatelja");
return false;
}
 var theDIV = document.getElementById('prijatelj'); // the DIV
           if (theDIV) { theDIV.innerHTML = '<div class="loading"></div>'; }
								if(timeoutholder!=null)window.clearTimeout(timeoutholder);
	timeoutholder=window.setTimeout("sndReqTellAfriend(\'"+name+"\',\'"+email+"\',\'"+femail1+"\',\'"+femail2+"\',\'"+femail3+"\',\'"+firmid+"\');", 0);
}


