//used to check browser
function checkIt(string) {
	var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
			
function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser != "Microsoft Internet Explorer" || (checkIt('opera')) ) {
		ro = new XMLHttpRequest();
	} else {
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return ro;
}

var http = createRequestObject();

function sndReq(string,cookie) {
	showWait();
	http.open('get', '/apollo-ltv1/mpm/rpc.php?string='+escape(string)+'&cookie='+escape(cookie));
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
		setTimeout("showComplete()",1000);
    }
}
			
function showWait() {
	//document.getElementById('progress').style.display = 'block';
}
			
function showComplete() {
	//document.getElementById('progress').innerHTML = http.responseText;
	//alert(http.responseText);
	if(http.responseText=='OK'){
		document.getElementById('buy').value='true';
	}else{
		//document.getElementById('progress').innerHTML = http.responseText;
		document.getElementById('buy').value='false';
	}
	playVideo();
}
			
function mpm(string){
	//document.getElementById(string).style.display = 'none';
	var today = new Date();
	var expire = new Date();
	
	cookieValue = today.getTime();
	cookieValue = cookieValue.toString();
	cookieValue = hex_md5(cookieValue);
	cookieValue = cookieValue.substring(0,20);

	expire.setTime(today.getTime() + 39000);//9000 deriigs 9sekundes
	document.cookie = "cookijs="+escape(cookieValue)+ ";domain=www.apollo.lv;path=/;expires="+expire.toGMTString();
	myRef = window.open('/apollo-ltv1/mpm/popup.php?p='+string,'mpm','left=20,top=20,width=361,height=366, resizable=1, titlebar=1, scrollbars=0');
	myRef.focus(); 
	//alert('cookie value='+cookieValue+' string'+string);
	sndReq(string,cookieValue);
}
