 //Common Functions
function logIn2Comment(){
	var pass = $F('password');	 
	var user = $F('username');
	if((pass=="")||(user=="")){
		$('error').innerHTML = '<div style="float:left; padding-right:6px;"><img src="http://rli.ie/images/pageElements/icons/error.png" /></div>Please fill in username and password fields';
		new Effect.Highlight('error');
	}else{
		new Ajax.Request( 
			'http://rli.ie/loginUser.php', {
				method:'post',   
				parameters:{username:user,pass:pass},
				onSuccess: function(t) {
					var reply = t.responseText.evalJSON();
					if(reply.userexists>0){	
						var id = reply.id;
						$('userInteract').innerHTML='<div id = "logHead"><h2>Post your views</h2></div>';
        		$('userInteract').innerHTML+='<div class = "logForm">';
        		$('userInteract').innerHTML+='<div id = "error"></div>';
          	$('userInteract').innerHTML+='<div id = "userInteract">';
        		$('userInteract').innerHTML+='<div class = "logRow">';
          	$('userInteract').innerHTML+='<div class = "logEle">';
          	$('userInteract').innerHTML+='<span><textarea name="comment" cols="40" rows="7" id = "comment"></textarea></span>';
          	$('userInteract').innerHTML+='</div>';
         		$('userInteract').innerHTML+='</div>';
         		$('userInteract').innerHTML+='<div class="logRow">';
         		$('userInteract').innerHTML+='<a href = "javascript:postUrViews()">submit</a>';
        		$('userInteract').innerHTML+='</div>';
         	 	$('userInteract').innerHTML+='</div>';
    				$('userInteract').innerHTML+='</div>';	
						$('userInteract').innerHTML+='<input id="user" name="user" type="hidden" value="'+id+'" />';	
						clearerror();
					}else{						
						$('error').innerHTML = '<div style="float:left; padding-right:6px;"><img src="http://rli.ie/images/pageElements/icons/error.png" /></div>This username/password combination could not be found in our database. - <a href = "javascript:sendPassword()" >Send password to my email</a>';
						new Effect.Highlight('error');
					}
				} 
			}
		);	 
	}
}
function postUrViews(){
	var comment= $F('comment');	
	var user= $F('user');	
	var article= $F('article');	
	if((comment=="")){
		$('error').innerHTML = '<div style="float:left; padding-right:6px;"><img src="http://rli.ie/images/pageElements/icons/error.png" /></div>You have neglected to add your comment on this article!!';
		new Effect.Highlight('error');
	}else{
		new Ajax.Request( 
			'http://rli.ie/comment.php', {
				method:'post',   
				parameters:{comment:comment,user:user,article:article},
				onSuccess: function(t) {
					var reply = t.responseText.evalJSON();
					if(reply.saved>0){					
						$('userInteract').innerHTML='Your comment has been submitted and will be reviewed shortly';	
						clearerror();
					}else{						
						$('error').innerHTML = '<div style="float:left; padding-right:6px;"><img src="http://rli.ie/images/pageElements/icons/error.png" /></div>An error occurred while trying to save your comment';
						new Effect.Highlight('error');
					}
				} 
			}
		);	 
	}
}
function postUrWcViews(){
	var comment= $F('comment');	
	var user= $F('user');	
	var article= $F('article');	
	if((comment=="")){
		$('error').innerHTML = '<div style="float:left; padding-right:6px;"><img src="http://rli.ie/images/pageElements/icons/error.png" /></div>You have neglected to add your comment on this article!!';
		new Effect.Highlight('error');
	}else{
		new Ajax.Request( 
			'http://rli.ie/wc_comment.php', {
				method:'post',   
				parameters:{comment:comment,user:user,article:article},
				onSuccess: function(t) {
					var reply = t.responseText.evalJSON();
					if(reply.saved>0){					
						$('userInteract').innerHTML='Your comment has been submitted and will be reviewed shortly';	
						clearerror();
					}else{						
						$('error').innerHTML = '<div style="float:left; padding-right:6px;"><img src="http://rli.ie/images/pageElements/icons/error.png" /></div>An error occurred while trying to save your comment';
						new Effect.Highlight('error');
					}
				} 
			}
		);	 
	}
}
function register2Comment(){
	document.location.href="http://rli.ie/guestBookRegister.php?news=1";
}
function clearerror(){
	$('error').innerHTML = '';
}