

function getintidval(strname)
{
	if (document.getElementById(strname).value == null)
	{
		return 0;
	}
	else
	{
		if (isNumeric(document.getElementById(strname).value))
			return document.getElementById(strname).value;
		else
			return 0;
	}
}

function getidval(strname)
{
	if (!document.getElementById(strname).value)
		return ""
	if (document.getElementById(strname).value == null)
		return "";
	var res = document.getElementById(strname).value;
	return res;
}


function isNumeric(x) {
	var RegExp = /^[-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?$/;
	var result = x.match(RegExp);
	return result;
}

function pingupdate(strArtID)
{
	var params = new Array(1);
	params[0]="artid="+strArtID;
	joomlaPerformAjaxUpdate(ajax_callback_updatesearchresult,params,"ajax_updatesearchresult");
}

function pop(ar,val)
{
	var l = ar.length;
	for (i=0;i<l;i++)
	{
		var entity = ar.pop();		
		if (entity == val)
			return true;
		else
			ar.unshift(entity);
	}
	return false;
}

function ajax_callback_updatesearchresult()
{	
	var strResults = CleanHTMLComments(xmlHttp.responseText);
}
/*
Author Ben Horner
Copyright Alltraders, not to be used in anything but search
*/

function GetXMLHttpRequest()
{
	var xmlHttp;
	try
	{  // Firefox, Opera 8.0+, Safari  
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{  // Internet Explorer  
		try
		{  
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{    
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{   
				alert("Your browser does not support AJAX!");      
				return false;      
			}  
		}  
	}
	return xmlHttp;
}
var xmlHttp;

/*
Sends the ajax response to the correct function
*/
function AjaxResponse(funCallback) 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.status  == 200)
			funCallback();
	} 
}

/*
funCallback should be the callback of the function to perform the action
Format of parameters should be "paramname=parameter"
This joomla version will attempt to access the function through 
the controller
*/
function joomlaPerformAjaxUpdate(funCallback, ar_strParameters, funAjaxControllerFunction)
{
	xmlHttp = GetXMLHttpRequest();
	var i;

	var strUrl = "index.php";
	
	if (xmlHttp == null)
	{
		//error let user know
		alert("Browser does not support HTTP requests");
		return;
	}

	//assign the function
	xmlHttp.onreadystatechange = function()
	{
		AjaxResponse(funCallback);
	}
	
	ar_strParameters[ar_strParameters.length]="option=com_search";
	ar_strParameters[ar_strParameters.length]="format=raw";
	ar_strParameters[ar_strParameters.length]="task=" + funAjaxControllerFunction;
		
	if (ar_strParameters.length > 0)
		strUrl=strUrl+"?";
	
	//Add variables
	var i;
	for (i=0;i<ar_strParameters.length;i++)
	{
		if (i > 0)
			strUrl=strUrl+"&";			
		strUrl=strUrl+ar_strParameters[i];
	}
	
	//Add random number to stop cache being used
	if (ar_strParameters.length > 0)
		strUrl=strUrl+"&sid="+Math.random();
	else
		strUrl=strUrl+"?sid="+Math.random();
	
	//send php file to server and get response
	xmlHttp.open("GET", strUrl, true); 
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlHttp.send(null);
}

function CleanHTMLComments(str)
{
	str = str.replace(/<!--\/?[^>]+(-->|$)/g, "");
	str = str.replace(/^\s+|\s+$/g,"");
	return str;
}

