//MIKARE CMS
//Public side AJAX Javascript functions
//Kristo Vaher - kristo@waher.net

//AJAX declaration
var xmlHttp;
function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

//plain function, can be used as function template
function ajaxtest(){
	xmlHttp=GetXmlHttpObject();
	var url='libraries/ajax.php';
	if (xmlHttp){
		url=url+'?act=ajaxtest';
		url=url+'&random='+Math.random();
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4){
				document.getElementById('ajaxtest').innerHTML=xmlHttp.responseText;
			}
		};
		xmlHttp.open('GET',url,true);
		xmlHttp.send(null);
	}
}

//plain function, can be used as function template
function setScreenSize(){
	width=getScreenSize('w');
	height=getScreenSize('h');
	xmlHttp=GetXmlHttpObject();
	var url='libraries/ajax.php';
	if (xmlHttp){
		url=url+'?act=setScreenSize';
		url=url+'&width='+width;
		url=url+'&height='+height;
		url=url+'&random='+Math.random();
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4){
				var done=1;
			}
		};
		xmlHttp.open('GET',url,true);
		xmlHttp.send(null);
	}
}

function currencyChange(currency){
	xmlHttp=GetXmlHttpObject();
	var url='libraries/ajax.php';
	if (xmlHttp){
		url=url+'?act=currencyChange';
		url=url+'&currency='+currency;
		url=url+'&random='+Math.random();
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4){
				document.location.href=document.location.href;
			}
		};
		xmlHttp.open('GET',url,true);
		xmlHttp.send(null);
	}
}

function sendToFriend(messagesent,urlfrom){
	emailto=document.getElementById('sendtofriend_emailto').value;
	namefrom=document.getElementById('sendtofriend_namefrom').value;
	mailfrom=document.getElementById('sendtofriend_mailfrom').value;
	if(emailto && emailto!='' && namefrom && namefrom!='' && mailfrom && mailfrom!=''){
		xmlHttp=GetXmlHttpObject();
		var url='libraries/ajax.php';
		if (xmlHttp){
			url=url+'?act=sendtofriend';
			url=url+'&emailto='+emailto;
			url=url+'&namefrom='+namefrom;
			url=url+'&mailfrom='+mailfrom;
			url=url+'&urlfrom='+urlfrom;
			url=url+'&random='+Math.random();
			xmlHttp.onreadystatechange = function() {
				if(xmlHttp.readyState == 4){
					document.getElementById('sendtofriendbox').innerHTML=messagesent;
				}
			};
			xmlHttp.open('GET',url,true);
			xmlHttp.send(null);
		}
	}
}