var req;
var gid;
var procName;
function drugVote(id,vote,response)
{
  procName='drugVote';
  var l=document.getElementById('wait_div');
  if (response == 'voted')
  {
	l.innerHTML='<br><br><br>You have already voted<br>for this drug.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>To vote,<br><a href="/login.php?page='+page+'">login</a> or <a href="/register.php">join</a> for free.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>Sorry, an error occured.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response != '')
  {
	var e=document.getElementById('rating'+gid);
	if(e){e.innerHTML=response;}
	l.innerHTML='<br><br><br>Thanks for voting.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else
  {
  	showWaitDiv();
    url  = '/inc/drug_vote.php?id='+id+'&vote='+vote;
    loadXMLDoc(url,id);
  }
}
function shopVote(id,vote,response)
{
  procName='shopVote';
  var l=document.getElementById('wait_div');
  if (response == 'voted')
  {
	l.innerHTML='<br><br><br>You have already voted<br>for this pharmacy.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>To vote,<br><a href="/login.php?page='+page+'">login</a> or <a href="/register.php">join</a> for free.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>Sorry, an error occured.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response != '')
  {
	var e=document.getElementById('rating'+gid);
	if(e){e.innerHTML=response;}
	l.innerHTML='<br><br><br>Thanks for voting.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else
  {
  	showWaitDiv();
    url  = '/inc/shop_vote.php?id='+id+'&vote='+vote;
    loadXMLDoc(url,id);
  }
}
function tipVote(id,vote,response)
{
  procName='tipVote';
  var l=document.getElementById('wait_div');
  if (response == 'voted')
  {
	l.innerHTML='<br><br><br>You have already voted<br>for this advice.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>To vote,<br><a href="/login.php?page='+page+'">login</a> or <a href="/register.php">join</a> for free.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>Sorry, an error occured.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response != '')
  {
	var e=document.getElementById('rating'+gid);
	if(e){e.innerHTML=response;}
	l.innerHTML='<br><br><br>Thanks for voting.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else
  {
  	showWaitDiv();
    url  = '/inc/tip_vote.php?id='+id+'&vote='+vote;
    loadXMLDoc(url,id);
  }
}
function shopFavs(id,dummy,response)
{
  procName='shopFavs';
  var l=document.getElementById('wait_div');
  if (response == 'exists')
  {
	l.innerHTML='<br><br><br>This pharmacy is already<br>in <a href="/account.php">your favourites</a>.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>To add,<br><a href="/login.php?page='+page+'">login</a> or <a href="/register.php">join</a> for free.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>Sorry, an error occured.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response != '')
  {
	l.innerHTML='<br><br><br>The pharmacy has been added<br>to <a href="/account.php">your favourites</a>.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else
  {
  	showWaitDiv();
    url  = '/inc/shop_favs.php?id='+id;
    loadXMLDoc(url,id);
  }
}
function tipFavs(id,dummy,response)
{
  procName='tipFavs';
  var l=document.getElementById('wait_div');
  if (response == 'exists')
  {
	l.innerHTML='<br><br><br>This advice is already<br>in <a href="/account.php">your favourites</a>.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>To add,<br><a href="/login.php?page='+page+'">login</a> or <a href="/register.php">join</a> for free.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response == 'not_logged_in')
  {
	l.innerHTML='<br><br><br>Sorry, an error occured.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else if (response != '')
  {
	l.innerHTML='<br><br><br>The advice has been added<br>to <a href="/account.php">your favourites</a>.<br><br><a href=\'javascript:hideWaitDiv();\'>OK</a>';
  }
  else
  {
  	showWaitDiv();
    url  = '/inc/tip_favs.php?id='+id;
    loadXMLDoc(url,id);
  }
}
function loadXMLDoc(url,id) {
	gid=id;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange() 
{
    if (req.readyState == 4) {
        if (req.status == 200) {
      response = req.responseText;
	  eval(procName + '(\'\', \'\', response)');
        } else {
            alert("Îøèáêà:\n" + req.statusText);
        }
    }
}
function showWaitDiv()
{
	var l=document.getElementById('wait_div_ext');
  	if(l)
  	{
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
  		l.style.top=(arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 60) / 2) + 'px');;
//  		l.style.top='1000px');;
  		l.style.left=(((arrayPageSize[0] - 20 - 260) / 2) + 'px');
  		l.style.display='block';
  	}
}
function hideWaitDiv()
{
  	var l=document.getElementById('wait_div');
  	var l1=document.getElementById('wait_div_ext');
  	if(l && l1)
  	{
		l.innerHTML='<img src="/no" width="1" height="64" alt=""><br><img src="/img/wait.gif" width="32" height="32" alt="">';
  		l1.style.display='none';
  	}
}
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

