   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType(\'text/xml\');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('ajaxprocess').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
     var poststr = "p309_fullname=" + escape(encodeURI(document.getElementById("p309_fullname").value )) +"&p309_useremail=" + escape(encodeURI(document.getElementById("p309_useremail").value )) +"&p309_empresa=" + escape(encodeURI(document.getElementById("p309_empresa").value )) +"&p309_telefono=" + escape(encodeURI(document.getElementById("p309_telefono").value ));
    makePOSTRequest('plugins/p309_mailing/ajaxfunct.php?actiond=submituser', poststr);
   }

   function getAdmin(obj) {
     var poststr = "field1=" + escape(encodeURI(document.getElementById("field1").value )) +"&field2=" + escape(encodeURI(document.getElementById("field2").value ));
    makePOSTRequest('../plugins/p309_mailing/ajaxfunct.php?actiond=edittemplate', poststr);
   }


  function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				req = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }


   function showform(divid) {
		var strURL="plugins/p309_mailing/ajaxfunct.php?actiond=showform";
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById(divid).innerHTML=req.responseText;
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
   }
   function edittemplate() {
		var divid      = escape(encodeURI(document.getElementById("field2").value ));
	    var productid  = escape(encodeURI(document.getElementById("field1").value ));
		var strURL = "../plugins/p309_mailing/ajaxfunct.php?actiond=edittemplate&productid="+productid+"&type="+divid;
		var req = getXMLHTTP();
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById(divid).innerHTML=req.responseText;
					  	 if(navigator.appName != "Microsoft Internet Explorer")
                     	 {
					      document.getElementById('hiddencontent').innerHTML = document.getElementById('globalcontent').innerHTML;
						 }
						 else
						 {
					      document.getElementById('hiddencontent').value = document.getElementById('globalcontent').innerHTML;
						 }
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}
   }
   
