
var xmlhttpCity;
var xmlhttpCategory;

var tmp_abs_url;
var tmp_id;
var tmp_cat;

function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - innerHTML to add option(s) to select(s)
* Problem: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Creative Commons license
* Versão: 1.0 - 06/04/2006
* Author: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - elmicoxcodes.blogspot.com
* Parametros:
* objeto(tipo object): the select
* innerHTML(tipo string): the new innerHTML
*******/
    objeto.innerHTML = ""
    //creating phantom element to receive temp innerHTML
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.toLowerCase().indexOf("<option")<0){//if not option, convert do option
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
    //transfering childs of phantom element to options
    for(var i=0;i<selTemp.childNodes.length;i++){
        if(selTemp.childNodes[i].tagName){
            opt = document.createElement("OPTION")
            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
            }
            opt.value = selTemp.childNodes[i].getAttribute("value")
            opt.text = selTemp.childNodes[i].innerHTML
            if(document.all){ //IEca
                objeto.add(opt)
            }else{
                objeto.appendChild(opt)
            }
        }
    }
    //clear phantom
    document.body.removeChild(selTemp)
    selTemp = null
}

function GetXmlHttpObject(){
	var xmlhttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlhttp=new XMLHttpRequest();
	} catch (e)  {
		// Internet Explorer
		try {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	return xmlhttp;
}

function get_categories(value,target_id,url) {
	selected = '';
	xmlhttpCategory=GetXmlHttpObject()
	if (xmlhttpCategory==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlhttpCategory.onreadystatechange = function() {
		if (xmlhttpCategory.readyState==4 || xmlhttpCategory.readyState=="complete") {
			document.getElementById(target_id).innerHTML = '';
			//document.getElementById(target_id).innerHTML = xmlhttpCategory.responseText;
			select_innerHTML(document.getElementById(target_id),xmlhttpCategory.responseText);
		}
	}
	// Send the POST request
	xmlhttpCategory.open('POST',url+'ajax/categories.php', true);
	xmlhttpCategory.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttpCategory.send('value='+value+ '&selected=' + selected);
}

function get_cities(value,target_id,url) {
	selected = '';
	tmp_abs_url = url;
	tmp_id = value;
	xmlhttpCity=GetXmlHttpObject()
	if (xmlhttpCity==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlhttpCity.onreadystatechange = function() {

		if (xmlhttpCity.readyState==4 || xmlhttpCity.readyState=="complete") {
			document.getElementById(target_id).innerHTML = '';
			//document.getElementById(target_id).innerHTML = xmlhttpCity.responseText;
			select_innerHTML(document.getElementById(target_id),xmlhttpCity.responseText);
		}
	}

	// Send the POST request
	xmlhttpCity.open('POST',url+'ajax/state_cities.php', true);
	xmlhttpCity.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttpCity.send('value='+value + '&selected=' + selected);
}

function inc_banner(banner_id) {
	xmlhttpCounter=GetXmlHttpObject()
	if (xmlhttpCounter==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	xmlhttpCounter.onreadystatechange = function() {
		if (xmlhttpCounter.readyState==4 || xmlhttpCounter.readyState=="complete") {
		}
	}
	// Send the POST request
	xmlhttpCounter.open('POST','http://www.partnerspluscard.com/ajax/ajax_count.php', true);
	xmlhttpCounter.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttpCounter.send('banner_id='+banner_id);
}

