// GOOZMO 2.0 COMMENTS WIDGET (c) 2010

// MAIN COMMENTS FUNCTION
// site_id=Site ID, page_id=System Page ID, entry_id=Entry ID, flags=Flag list (login,view,approve,email), user_id=Site User ID, entry_url=Direct URL of entry
function goocomments(site_id,page_id,entry_id,flags,user_id,entry_url) {
	var dis;
	var flagar=flags.split(",");
	dis='<div id="goo_comments_box">';
	dis+='<form style="margin:0;padding:0;" id="goo_comments_form" name="goo_comments_form">';
	dis+='<span id="goo_comments_commdis"></span>';
	dis+='<h1>Leave a Comment</h1><p>';
	dis+='<span id="goo_comments_msg" name="goo_comments_msg" class="msg" style="display:none;"></span>';
	// CHECK FOR LOGIN
	if ((flagar[0]==1&&user_id!=0&&user_id!='')||flagar[0]==0) {
		if (user_id==0||user_id=='') {
			dis+='<h4>Name</h4>';
			dis+='<input type="text" id="goo_comments_name" name="goo_comments_name">';
			dis+='<h4>Email Address</h4>';
			dis+='<input type="text" id="goo_comments_email" name="goo_comments_email">';
		}
		dis+='<h4>Comment</h4>';
		dis+='<textarea rows="5" onkeypress="return goosubmitenter(this,event,goocomments_submit)" name="goo_comments_comment" id="goo_comments_comment" onfocus="goocomments_commentclear(this)">Please Type in a Comment!</textarea>';
		dis+='<span id="goo_comments_comment_err" name="goo_comments_comment_err" class="err" style="display:none;"></span>';
		if (flagar[1]==1) {
			dis+='<h4>Rating</h4>';
			dis+='<select onkeypress="return goosubmitenter(this,event,goocomments_submit)" id="goo_comments_rating" name="goo_comments_rating"><option value="0">Select One</option><option value="1">1 - Lowest</option><option>2</option><option>3</option><<option>4</option><option value="5">5 - Highest</option></select>';
			dis+='<span id="goo_comments_rating_err" name="goo_comments_rating_err" class="err" style="display:none;"></span>';
		}
		if (flagar[3]==1) {
			dis+='<h4>Email me about new comments, my comment status, etc?</h4>';
			dis+='<span class="radio"><input type="radio" name="goo_comments_emailnot" id="goo_comments_emailnot" value="1">Yes</span><span class="radio"><input type="radio" name="goo_comments_emailnot" id="goo_comments_emailnot" value="0" checked="checked">No</span><div class="spacer"></div>';
		} else {
			dis+='<input type="hidden" id="goo_comments_emailnot" name="goo_comments_emailnot" value="0">';	
		}
		dis+='<br><input type="button" value="Add Comment" onmouseover="this.className=\'over\'" onmouseout="this.className=\'\'" onclick="goocomments_submit()">';
	} else {
		dis+='<p>You need to login or register for a new account in order to leave a comment</p>';
		dis+='<br><input type="button" value="Login" onclick="linklogin();" onmouseover="this.className=\'over\'" onmouseout="this.className=\'\'">';
		dis+='<input type="button" value="Register" onclick="window.location =\'/?gooua=1&action=register&redirect='+goocomments_geturl()+'\';" onmouseover="this.className=\'over\'" onmouseout="this.className=\'\'">';
	}
	dis+='<input type="hidden" id="goo_comments_entryurl" name="goo_comments_entryurl" value="'+entry_url+'">';
	dis+='<input type="hidden" id="submitcomment" name="submitcomment" value="1">';
	dis+='<input type="hidden" id="goo_comments_data" name="goo_comments_data" value="'+site_id+','+page_id+','+entry_id+','+user_id+','+flagar[2]+'">';
	dis+='</p></form></div>';
	document.write(dis);
	// RUN AJAX
	goocomments_comments(site_id,page_id,entry_id);
}
function goocomments_comments(site_id,page_id,entry_id,approve) {
	goojax_load_data('/googlobal/goocomments/goocomments.php','type=comments&sid='+site_id+'&pid='+page_id+'&eid='+entry_id);
}
function goocomments_submit() {
	// DATA CHECK
	var err=0;
	goocomments_displayerr('','goo_comments_comment_err',2);
	if (document.getElementById('goo_comments_comment').value=="Please Type in a Comment!") document.getElementById('goo_comments_comment').value="";
	if (document.getElementById('goo_comments_comment').value=="") {
		err=1;	
		goocomments_displayerr('Please enter in a comment.','goo_comments_comment_err',1);
	}
	if (document.getElementById('goo_comments_rating')) {
		goocomments_displayerr('Please select a rating.','goo_comments_rating_err',2);
		if (document.getElementById('goo_comments_rating').value==0) {
			err=1;
			goocomments_displayerr('Please select a rating.','goo_comments_rating_err',1);
		}
	}
	if (!err) {
		document.getElementById('goo_comments_msg').style.display='block';
		document.getElementById('goo_comments_msg').innerHTML='Please Wait...';
		goojax_saveformdata('goo_comments_form','/googlobal/goocomments/goocomments.php',1);
	}
}
function goocomments_displayerr(msg,id,show) {
	if (!document.getElementById(id)) return;
	if (show==1) {
		document.getElementById(id).innerHTML=msg;
		document.getElementById(id).style.display="block";
	} else if (show==2) {
		document.getElementById(id).style.display="none";	
	}
}
function goocomments_commentclear(x) {
	if (x.value=="Please Type in a Comment!") x.value="";	
}
function goocomments_geturl() {
	var url=window.location.href.split("/");
	var urlstr="";
	for (i=3;i<url.length;i++) {
		urlstr+="/"+url[i];	
	}
	return urlstr;
}
