
var items = new Array();
function userSelect(state,articleid,starnumber) {
	if (state) {
		cookie = Get_Cookie('ArticleUserRating_' + articleid);
		if (!cookie) {
			for (i=1;i<=5;i++) {
				items[i] = document.getElementById('star_' + i).src;
			}
			for (i=1;i<=starnumber;i++) {
				document.getElementById('star_' + i).src = '/images/full.gif';
			}
			for (i=(starnumber+1);i<=5;i++) {
				document.getElementById('star_' + i).src = '/images/off.gif';
			}
		}
	} else {
		for (i=1;i<=5;i++) {
			document.getElementById('star_' + i).src = items[i];
		}
	}
}

function vote(articleid,starnumber) {
	var date = new Date();
	date.setTime(date.getTime()+(365*24*60*60*1000));
	Set_Cookie('ArticleUserRating_' + articleid,'1',date); 
	
	new Ajax.Request('/article.php?mode=userratingdb&articleid=' + articleid + '&rating=' + starnumber,
	{
	    method:'get',
	    onSuccess: function(transport) {
	      var response = transport.responseText;
	      var json = transport.responseText.evalJSON();
	      var values = json['average'].split('.');
	      
	      document.getElementById('numbervotes').innerHTML = json['total'];
	      
	      for (i=1;i<=5;i++) {
	    	  
	    	  document.getElementById('star_' + i).removeAttribute('onclick');
	    	  document.getElementById('star_' + i).removeAttribute('onmouseover');
	    	  document.getElementById('star_' + i).removeAttribute('onmouseout');
	    	  if (i < 5) {
	    		  document.getElementById('stardot_' + i).removeAttribute('onmouseover');
	    		  document.getElementById('stardot_' + i).removeAttribute('onmouseout');
	    	  }
	    	  document.getElementById('star_' + i).src = '/images/off.gif';
	      }
	      var starcounter = 1;
	      for (i=1;i<=values[0];i++) {
	    	  document.getElementById('star_' + i).src = '/images/full.gif';
	    	  starcounter++;
	      }
	      
	      if (values[1] <= 5 && values[1] > 0) {
	    	  document.getElementById('star_' + starcounter).src = '/images/half.gif';
	    	  starcounter++;
	      }

	      if (values[1] > 5) {
	    	  document.getElementById('star_' + starcounter).src = '/images/full.gif';
	      }
	      
	      
	    },
	    onFailure: function(){ alert('Something went wrong...') }
	});

	
}

function CheckEmail(form,field)  {
	url = document[form][field].value;
	var status = true;
	if (url != null && url != "") {
		a = url.lastIndexOf("@");
		b = url.lastIndexOf(".");
		c = url.indexOf(":");
		d = url.indexOf("/");
		e = url.substring(0,a);
		f = e.indexOf("@");
		g = url.substring(a+1,url.length);
		h = g.indexOf("[");
		i = g.indexOf("]");
		j = g.indexOf("<");
		k = g.indexOf(">");
		l = url.substring(a+1,b);
		m = url.substring(b+1,url.length);
		n = url.substring(0,a);
		o = 0;
		if (a > b) {o++};
		if (c != -1) {o++};
		if (d != -1) {o++};
		if (f != -1) {o++};
		if (h != -1) {o++};
		if (i != -1) {o++};
		if (j != -1) {o++};
		if (k != -1) {o++};
		if (l.length < 1) {o++};
		if (m.length < 2 || m.length > 4) {o++};
		if (n.length < 1) {o++};
		if (o == 0) {
			status = true;
		}
		else {
			status = false;
		}
	}
	else {
		status = false;
		url="";
	}
	return status;
}

function PrintFriendly() {
	newWindow=window.open(printfriendly_url,"mywindow","width=750,height=500,toolbar=1,menubar=0,scrollbars=1,resizeable=1");
	newWindow.focus();
}

function openBigMap() {
    newWindow=window.open("/categorymap.php?mode=big","mywindow","width=900,height=700,toolbar=0,menubar=0,scrollbars=0,resizeable=0");
    newWindow.focus();
}

function ChangeIssue(issueid) {
	if (issueid > 0) {
        location.href='/issue.' + issueid + '.html';
    }
}

function ArticleLogin(password,state) {
    new Ajax.Request('/articlelogin.php',
    {
        method:'get',
        parameters: {password:password,state:state},
        onSuccess: function(transport) {
            var response = transport.responseText;
            if (response == 1 && state == 'login') {
                $('loggedin').show();
                $('notloggedin').hide();
                $('loginerror').hide();
            } 
            
            if (response == 0 && state == 'login') {
                $('loginerror').show();
            }
            
            if (response == 1 && state == 'logout') {
                $('loggedin').hide();
                $('notloggedin').show();
            }
            
        },
        onFailure: function(){ alert('Something went wrong...') }
  });
}


