function ajax(id,url,form,method,exec) {
var xmlhttp=newXMLHttpRequest();
var xmlid=id
var handlerFunction
var query_string="";
if (typeof method == 'undefined' ) {
	var method = "GET";
}

if (typeof form !== 'undefined'  ) {
	var query_string=formData2QueryString(form);
	
}
if (url.indexOf("?")<=0) {
		var amperson="?";
	} else {
		var amperson="&";
	}
if (method=="GET") {

	url=url+amperson+"sid="+Math.random()+"&tag="+id+"&"+query_string
}
if (xmlhttp!=null)
  {
handlerFunction=state_Change(xmlhttp,xmlid,exec)
 xmlhttp.onreadystatechange=handlerFunction
  xmlhttp.open(method,url,true)
	if (method=="POST") {  
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", query_string.length);
		xmlhttp.setRequestHeader("Connection", "close");
  		xmlhttp.send(query_string)
  	} else {
  		 xmlhttp.send(null)
  	}

  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}
function newXMLHttpRequest() {
 
    var xmlreq = false;
    if (window.XMLHttpRequest) {
        // Create XMLHttpRequest object in non-Microsoft browsers
        xmlreq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // Create XMLHttpRequest via MS ActiveX
        try {
            // Try to create XMLHttpRequest in later versions
            // of Internet Explorer
            xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e1) {
            try {
                // Try version supported by older versions
                // of Internet Explorer
                xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e2) {
                doError(e2);
        }
    }
  }
  return xmlreq;
}
function state_Change(xmlhttp,xmlid,exec) {
return function () {
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4) {

  // if "OK"
  if (xmlhttp.status==200) {
 	if (xmlid!=null) {  		 
  		var element=document.getElementById(xmlid);
  		try {
  			element.innerHTML=xmlhttp.responseText;	
  		}
  		catch (e) {
 			 // IE fails unless we wrap the string in another element.
 			 var wrappingDiv = document.createElement('div');
 			 wrappingDiv.innerHTML = request.responseText;
  			 element.appendChild(wrappingDiv);
		}
  		parseJavaScript(xmlhttp.responseText); 	
  		
  		/*debug
  		var debug=window=window.open ("","Debug","scrollbars,resizable,status");
  		debug.document.open();
  		debug.document.write(xmlhttp.responseText);
  		debug.document.close();
  		*/
  		
  	}
  	if (typeof exec !== 'undefined' ) {
		eval(exec);
	}	
	xmlhttp=null //garbage collection
  }
  else if (typeof xmlhttp.status !== 'undefined'  ) {
    //alert("Problem retrieving XML data. status="+xmlhttp.status)
    }
  }
}
}

/*parseJavaScript*/
String.prototype.trim=function(){
		return this.replace(/^\s*|\s*$/g,'');
	}
	function findnextJS(string){
		if (string.indexOf("script")!=-1&&string.indexOf("/script")!=-1){
			var posInicial = string.search('<script') ;
			var posFinal = string.search('</script')+9;
			var subTagOpen = posInicial+30;
			var subTagClose = posFinal-9;
			var codigo = string.slice(subTagOpen,subTagClose);
			var codigo = codigo.trim();
			return new Array(posFinal,codigo);
		}else{
			return new Array(0,'');
		}
	}
	function findJS(text){
		
		var result = findnextJS(text);
		var codigo = result[1];
		var posicion = result[0];
			
		if(posicion==0){
			return ""
		}
		else{
			text = text.substr(posicion);
			codigo =  codigo+findJS(text);
			return codigo;
		}
	}//
	function parseJavaScript(text){
			var codigo = findJS(text);
			eval (codigo);
	}

/*
 * Copyright 2005 Matthew Eernisse (mde@fleegix.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Original code by Matthew Eernisse (mde@fleegix.org), March 2005
 * Additional bugfixes by Mark Pruett (mark.pruett@comcast.net), 12th July 2005
 * Multi-select added by Craig Anderson (craig@sitepoint.com), 24th August 2006
 *
 * Version 1.3
*/

/**
 * Serializes the data from all the inputs in a Web form
 * into a query-string style string.
 * @param docForm -- Reference to a DOM node of the form element
 * @param formatOpts -- JS object of options for how to format
 * the return string. Supported options:
 *    collapseMulti: (Boolean) take values from elements that
 *    can return multiple values (multi-select, checkbox groups)
 *    and collapse into a single, comman-delimited value
 *    (e.g., thisVar=asdf,qwer,zxcv)
 * @returns query-string style String of variable-value pairs
 */
function formData2QueryString(docForm, formatOpts) {

  var opts = formatOpts || {};
  var str = '';
  var formElem;
  var lastElemName = '';
  
  for (i = 0; i < docForm.elements.length; i++) {
    formElem = docForm.elements[i];
    
    switch (formElem.type) {
      // Text fields, hidden form elements
      case 'text':
      case 'hidden':
      case 'password':
      case 'textarea':
      case 'select-one':
        str += formElem.name + '=' + encodeURI(encodeURIComponent(formElem.value)) + '&'
        break;
        
      // Multi-option select
      case 'select-multiple':
        var isSet = false;
        for(var j = 0; j < formElem.options.length; j++) {
          var currOpt = formElem.options[j];
          if(currOpt.selected) {
            if (opts.collapseMulti) {
              if (isSet) {
                str += ',' + encodeURI(encodeURIComponent(currOpt.value));
              }
              else {
                str += formElem.name + '=' + encodeURI(encodeURIComponent(currOpt.value));
                isSet = true;
              }
            }
            else {
              str += formElem.name + '=' + encodeURI(encodeURIComponent(currOpt.value)) + '&';
            }
          }
        }
        if (opts.collapseMulti) {
          str += '&';
        }
        break;
      
      // Radio buttons
      case 'radio':
        if (formElem.checked) {
          str += formElem.name + '=' + encodeURI(encodeURIComponent(formElem.value)) + '&'
        }
        break;
        
      // Checkboxes
      case 'checkbox':
        if (formElem.checked) {
          // Collapse multi-select into comma-separated list
          if (opts.collapseMulti && (formElem.name == lastElemName)) {
            // Strip of end ampersand if there is one
            if (str.lastIndexOf('&') == str.length-1) {
              str = str.substr(0, str.length - 1);
            }
            // Append value as comma-delimited string
            str += ',' + encodeURI(encodeURIComponent(formElem.value));
          }
          else {
            str += formElem.name + '=' + encodeURI(encodeURIComponent(formElem.value));
          }
          str += '&';
          lastElemName = formElem.name;
        }
        break;
        
    }
  }
  // Remove trailing separator
  str = str.substr(0, str.length - 1);
  return str;
  //encodeURIComponent: added By Quito on jan 28, 2008. encodes: , / ? : @ & = + $ #.
}