function evalScript(scripts)
{	
	try
	{	
		if(scripts != '')	
		{	
			var script = "";
			scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){if (scripts !== null) script+=arguments[1]+'\n';return '';});
			if(script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
		}
		return false;
	}
	catch(e)
	{	
		alert(e);
	}
}

function makeRequest(url,targetdiv) 
{
	var http_request = false;
	if (window.XMLHttpRequest)
	{ // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} 
	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('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function()
	{
		alertContents(http_request,targetdiv);
	};
	http_request.open('GET', url, true);
	http_request.send(null);

}

function alertContents(http_request,targetdiv) 
{

	if (http_request.readyState == 4)
	{
		if (http_request.status == 200) 
		{
			result=http_request.responseText;
			
			//document.getElementById(targetdiv).innerHTML="";
			document.getElementById(targetdiv).innerHTML=http_request.responseText;	
			evalScript(result);
		} 
		else
		{
			//alert('There was a problem with the request.');
		}
	}
}

//.............................................................
function check_rate_this_public(val,ident)
{
	for(i=1;i<=5;i++)
	{
		if(i<=val)
		{
			document.getElementById(ident+'star'+i).src='images/rating/star_over.png';
		}
		else
		{
			document.getElementById(ident+'star'+i).src='images/rating/star_off.png';
		}
	}	
}
function reset_rate_this_public(max,ident)
{
	for(i=1;i<=5;i++)
	{
		if(i<=max)
		{
			document.getElementById(ident+'star'+i).src='images/rating/star_on.png';
		}
		else
		{
			document.getElementById(ident+'star'+i).src='images/rating/star_off.png';
		}
	}	
}
function rate_this_public(val,id_entity,entity,ident)
{
	makeRequest('_rating_function.inc.php?star='+val+'&id_entity='+escape(id_entity)+'&entity='+escape(entity)+'&next='+Math.random(),ident+'_art_rating');
}	

//...............
function check_rate_this(val)
{
	for(i=1;i<=5;i++)
	{
		if(i<=val)
		{
			document.getElementById('star'+i).src='images/rating/star_over.png';
		}
		else
		{
			document.getElementById('star'+i).src='images/rating/star_off.png';
		}
	}	
}
function reset_rate_this(max)
{
	for(i=1;i<=5;i++)
	{
		if(i<=max)
		{
			document.getElementById('star'+i).src='images/rating/star_on.png';
		}
		else
		{
			document.getElementById('star'+i).src='images/rating/star_off.png';
		}
	}	
}
function rate_this(val)
{
	makeRequest('_rating.inc.php?star='+val+'&amp;next='+Math.random(),'art_rating');
}	
//...............

function currency_convert()
{
	makeRequest('_curs_valutar_convert.inc.php'
	+ '?currency_from_value='+ escape(document.getElementById('currency_from_value').value)
	+ '&currency_from_currency='+ escape(document.getElementById('currency_from_currency').value)
	+ '&currency_to_currency='+ escape(document.getElementById('currency_to_currency').value)
	,'curs_valutar_convert');
}

function make_hidden(elem)
{
	document.getElementById(elem).style.display='none';
}

function check_delete_selection(frm,elem)
{
	if(confirm('Delete selection?'))
	{
		document.getElementById(elem).value=1;
		document.getElementById(frm).submit();
	}
}



// end AJAX aSynchron request----------------------------------------------------------------------
function makeES(ar)//make elements as string
{
	var rez='';
	var string='';
	for(i=0;i<ar.length;i++)
	{
		rez += (rez=='')?'':'&';
		
		if(encodeURIComponent) 
		{
			string=encodeURIComponent(document.getElementById(ar[i]).value);
		} 
		else
		{
			string=escape(document.getElementById(ar[i]).value);
		}
		rez+=ar[i]+'='+string;
	}
	return(rez);
}
function makeES_strip(ar)//make elements as string
{
	var rez='';
	var string='';
	for(i=0;i<ar.length;i++)
	{
		rez+=(rez=='')?'':'&';

		if(encodeURIComponent) 
		{
			string=encodeURIComponent(stripHTML_string(document.getElementById(ar[i]).value));
		} 
		else
		{
			string=escape(stripHTML_string(document.getElementById(ar[i]).value));
		}
		rez+=ar[i]+'='+string;
	}
	return(rez);
}
//----------------------------------------------------------------------------------
function binaryLength_UTF8(str)
{	
	var bytes, charCode, a, len;
	bytes = 0;
	for (a = 0, len = str.length; a < len; a++)
	{
		charCode = str.charCodeAt(a);
		if (charCode < 128) //2^7
			bytes += 1;
		else if (charCode < 2048) // 2^11
			bytes += 2;
		else if (charCode < 65536) // 2^16
			bytes += 3;
		else
			bytes += 4;
	}
	
	return bytes;
}
//----------------------------------------------------------------------------------
function sendPost(url,content,targetdiv) 
{
	var http_request = false;
	if (window.XMLHttpRequest)
	{ // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml; charset=x-user-defined-binary');
			// See note below about this line
		}
	} 
	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)
	{
		return false; //alert('Giving up :( Cannot create an XMLHTTP instance');
	}
	http_request.onreadystatechange = function()
	{
		alertContents(http_request,targetdiv);
	};
	http_request.open("POST", url, true);		
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", binaryLength_UTF8(content));
	http_request.setRequestHeader("Connection", "close");
	http_request.send(content); 
}
function stripHTML_string(strtextv)
{
	var re= /<\S[^><]*>/g;
	strtextv=strtextv.replace(re, "");
	strtextv=replaceDiacritics(strtextv);
	return(strtextv);
}
//----------------------------------------------------------------------------------
