

/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;

function setHit(hitType) {

	// Set te random number to add to URL request
	nocache = Math.random();

	var url = 'add_hits.php?target=entry&target_prms=' + encodeURIComponent(hitType);
//	makeCall(geturl);

	http.open('get', url);
	http.onreadystatechange = insertReply2;
	http.send(null);
}


function forwardURL(idprod, url) {

	var geturl = 'add_hits.php?target=fwdurl&target_prms=' + encodeURIComponent('id_prod=' + idprod) + '&fwdurl=' + encodeURIComponent(url);

	window.open(geturl,'adv_window');
}

function list(searchType) {

	// Set te random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	
	var fwdurl = 'search.php?nocache = ' + nocache + '&searchType=' + searchType ; 
	var geturl = 'add_hits.php?target=list&target_prms=' + encodeURIComponent(searchType) + '&fwdurl=' + encodeURIComponent(fwdurl);
	makeCall(geturl);
}

function next_prev(parms) {

	// Set te random number to add to URL request
	nocache = Math.random();

	var fwdurl = 'search.php?nocache = ' + nocache + parms  ;
	var geturl = 'add_hits.php?target=next_prev&target_prms=' + encodeURIComponent(parms) + '&fwdurl=' + encodeURIComponent(fwdurl);

	makeCall(geturl);
}

function search(parms,searchType) {
	// Set the random number to add to URL request
	nocache = Math.random();

	var fwdurl = 'search.php?nocache = ' + nocache + '&q=' + parms + '&searchType= ' + searchType ;
	var geturl = 'add_hits.php?target=search&target_prms=' + encodeURIComponent(parms) + '&fwdurl=' + encodeURIComponent(fwdurl);
	makeCall(geturl);
}

function makeCall(url) {

document.getElementById('insert_response').innerHTML = "<IMG SRC='images/ajax_loading.gif' BORDER='0'><br>Just a second..."
http.open('get', url);
http.onreadystatechange = insertReply;
http.send(null);

}

function makePostCall(url,params) {

	document.getElementById('insert_response').innerHTML = "<IMG SRC='images/ajax_loading.gif' BORDER='0'><br>Just a second..."
	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.onreadystatechange = insertReply;
	http.send(params);

}

function insertReply() {
	if(http.readyState == 4){
		var response = http.responseText;
		// else if login is ok show a message: "Site added+ site URL".
		document.getElementById('insert_response').innerHTML = response;
	}
}

function insertReply2() {
	if(http.readyState == 4){
		var response = http.responseText;
		// else if login is ok show a message: "Site added+ site URL".
	}
}


function showImage() {
	document.getElementById('img').src = document.getElementById('url').value ;
}



function getQueryStr(str,name)
{
	name = name.replace(/[[]/,"\[").replace(/[]]/,"\]");
	var regexS = "[\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( str );
	alert (str);
	if( results == null )
	return "";
	else
	return results[1];
}
