/**
 * @author Uber Helper
 * REQUIRES JQUERY, div, pop classes
 * 
 */

var ok = '<input type="button" value="OK" onclick="hidePopup();" />';

function toggle_my(cat){
	$.post("/include/my_toggle.php",{
			checked:$("input#only_mine").attr('checked'),
			cat:cat
	},function(result){
		if(result.substr(0,5) == 'NOTOK')alert(result.substr(5));
		else self.location=result;
	});
}

function change_order(order,cat){
	if(order == 0 || order == 1 || order == 2 || order == 3 || order == 4 || order == 5){
		$.get("/comments_change_order.php",{
			order:order,
			cat:cat
		},function(result){
			if(result.substr(0,5) == 'NOTOK')alert(result.substr(5));
			else self.location=result;
		});
		
	}
}

var vote_id;
var x;
function vote(id,score){
	if(score == 0 || score == 1 || score == 2 || score == 3 || score == 4 || score == 5){
		$.get("/vote_comments.php",{
			id:id,
			score:score
		},function(result){
			$("#vote_"+vote_id).html(result);
		});
	}
}


function clear_load(a){
	document.getElementById("load_"+a).innerHTML='';
}
function show_error(a){
	document.getElementById("load_"+a).innerHTML='Error Loading Image<br>Please Try Again Later';
}


var xx;
var div;
function fill_report(num){
	$("#popupcontent0").show();
	var temp = '<form name="report_form">';
	temp = temp+'<p align="center" style="color:#000000;font-size:10px;"><b>Reason for reporting image</b><br />';
	temp = temp+'<textarea name="comment" cols="25" rows="3"></textarea>';
	temp = temp+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	temp = temp+' <input type="button" onClick = "report_image(xx,document.report_form.comment.value);" value="Report" />';
	temp = temp+'<input type="button" onClick="hidePopup();" value="Cancel"/></p></form>';
	div = num;
	document.getElementById("popupcontent"+num).innerHTML=temp;
}

function report_image(id,reason){
	if(reason.length <= 0)alert("You must supply a reason");
	else{
		$("#popupcontent"+div).html('<br /><br /><b style="color:#000000;">Processing</b>');
		$.get("/report_comment.php",{
			id:id,
			reason:reason
		},function(result){
			if(result.substr(0,5) == 'NOTOK')alert(result.substr(5));
			else $("#popupcontent"+div).html('<br />'+result+'<br /><br />'+ok);
		});	
	}
}



var xxx;
var div_fav;
var fav;
function fill_fav(num){
	$("#popupcontent0").show();
	var temp = '<form name="fav_form">';
	temp = temp+'<br /><p align="center" style="color:#000000;font-size:10px;"><b>';
	if (fav=='NO')temp = temp+'Add to favorites?';
	else temp = temp+'Remove from favorites?';

	temp = temp+'</b><br /><br />';
	temp = temp+'<input type="button" onClick = "favorite(xxx);" value="Yes" />';
	temp = temp+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	temp = temp+'<input type="button" onClick="hidePopup();" value="No"/></p></form>';
	div_fav = num;
	$("#popupcontent"+num).html(temp);
}

function favorite(id){
	$("#popupcontent"+div_fav).html('<br /><br /><b style="color:#000000;">Processing</b>');
	$.get("/include/favorite_comment_add.php",{
		id:id
	},function(result){
		if(result.substr(0,5) == 'NOTOK')alert(result.substr(5));
		else $("#popupcontent"+div_fav).html('<br />'+result+'<br /><br />'+ok);	
	});		
}



function fill_own(id){
	var temp = '<form name="own_form">';
	temp = temp+'<br /><p align="center" style="color:#000000;font-size:10px;"><b>';
	temp = temp+'Request ownership of this image?';

	temp = temp+'</b><br /><br />';
	temp = temp+'<input type="button" onClick = "ownership('+id+');" value="Yes" />';
	temp = temp+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	temp = temp+'<input type="button" onClick="hidePopup();" value="No"/></p></form>';
	$("div#popupcontent0").html(temp);
	showPopup('popupcontent0',250,130,(tempX-100),(tempY - 110));
}

function ownership(id){
	$("div#popupcontent0").html('<br /><br /><b style="color:#000000;">Processing</b>');
	$.get("/include/ownership_request.php",{
		id:id
	},function(result){
		if(result.substr(0,5) == 'NOTOK')var temp = result.substr(5);
		else var temp = result;
		$("div#popupcontent0").html('<br />'+temp+'<br /><br />'+ok);
	});		
}

function fillCommentForm(image){
	var temp = '<textarea id="image_comment_text"></textarea><br />';
	temp += '<span id="image_comment_buttons"><input type="button" value="Cancel" onclick="hidePopup();" />';
	temp += ' <input type="button" value="Post Comment" onclick="submitImageComment('+image+');" /></span>';
	pop.popup(temp,200,80,50,100);
}

function submitImageComment(image){
	$("#image_comment_buttons").fadeOut("normal",function(){
		$.post("/include/image_comment_submit.php",{image:image,text:$("#image_comment_text").val()},function(result){
			if(result != 'OK'){
				$("#image_comment_buttons").fadeIn("normal");
				alert(result);
			}
			else {
				var temp = 'Succesfully posted<br /><br /><input type="button" value="OK" onclick="hidePopup();" />';
				$("#popupcontent0").html(temp);
			}
		});
	});
}

function reportImageComment(id){
	$("#popupcontent0").html("<h3>Processing</h3>");
	$.post("/include/image_comment_report.php",{id:id},function(result){
		$("#popupcontent0").html(result+'<br /><br /><input type="button" value="OK" onclick="hidePopup();" />');
	});
}

function deleteImageComment(id){
	$("#popupcontent0").html("<h3>Processing</h3>");
	$.post("/include/image_comment_delete.php",{id:id},function(result){
		if(result != 'OK')
			$("#popupcontent0").html(result+'<br /><br /><input type="button" value="OK" onclick="hidePopup();" />');
		else{
			$("#div_image_comment_"+id).fadeOut("normal");
			$("#popupcontent0").hide();
	
			
		}
	});
}





