$(function() {
    $("#listphoto img").click(function() {
        var img = $(this).attr('src');
				img = img.replace("c.php?f=thumb_", "");
				var filetxt = $("#filetxt").val();			
				$("#listphoto").html('<img src="http://klimg.com/kapanlagi.com/v5/i/ajax-loading-image.gif" />');
				var url = 'view.php?p='+ img +'&t=this&filetxt='+ filetxt;
				$("#listphoto").load(url);
    });
		
		$("#otherupload").click(function() {
				$('#otherupload').hide();
				$('#filesUploaded').html('');
				$('#nav_upload').show('fade');
				$('#browseagain').show();
    });
		
		$(".reportthis").click(function(){
				var i = $(this).attr('rel');
				var filetxt = $("#filetxt").val();				
				var url = 'reportfile.php?f='+ i +'&filetxt='+ filetxt;
				var url2 = 'reportfile.php?';
				$("#listphoto").append('<form class="reasonreport"><b>Alasan Laporan Anda</b><br /><textarea id="reason" name="reason"></textarea><br /><input id="sendreport" type="button" value=" Laporkan Foto " /><input id="cancelButton" type="button" value=" Batal " /></form><script>$("#sendreport").click(function(){var r = $("#reason").val();$(".reasonreport").load(\''+url+'&r=\'+encodeURIComponent(r));$(".reasonreport").remove();});$("#cancelButton").click(function(){$(".reasonreport").remove();});</script>');
				
				var leftWidth = ((window.document.body.clientWidth)/2)-150;
				var topWidth = (window.document.body.clientHeight)/2;
				$(".reasonreport").css("top",topWidth+"px");
				$(".reasonreport").css("left",leftWidth+"px");		
				$(".reasonreport").focus();	
				//$(this).load(url);
		});
});

function checkEmail(idEmail) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(idEmail)) {
		return true;
	}
	return false;
}

function checkForms(email) {
	if(email == '') {
		alert('Alamat e-mail harus diisi!');
	}
	else if(checkEmail(email) == false) {
		alert('Alamat e-mail tidak valid');
	}
	else {
		var mf = '';
		var sf = '';
		
		if($('input[name=txtPublic]:checked').val() == '1'){ mf = 'public'; }else{ mf = 'private'; }
		if($('input[name=txtPorn]:checked').val() == '1'){ sf = 'porno'; }else{ sf = 'reguler'; }
		var f = mf+"/"+sf+"/";
		
		$('#uploadify').uploadifySettings('scriptData',{'e': email});
		$('#uploadify').uploadifySettings('folder',f);
		$('#uploadify').uploadifyUpload();
	}
}

function goForumURL(path, path_thumb, file) {
	return '[URL='+path+file+'][IMG]'+path_thumb+file+'[/IMG][/URL]';
}

function goWebURL(path, path_thumb, file) {
	return '<a href="'+path+file+'" target="_blank"><img src="'+path_thumb+file+'" alt="" /></a>';
}

function goEmailURL(path, file) {
	return path+file;
}

function goThumbURL(path_thumb, file) {
	return path_thumb+file;
}

function afterUpload(event, queueID, fileObj, response, data) {
	$('#'+queueID).fadeOut(250, function() { jQuery(this).remove()});
	$('#filesUploaded').append(response).animate({ opacity: 'show' }, "slow", "easein");	
}

function afterAllUpload() {
	//$('#upload_form').html('<h3>Upload Form &raquo;</h3><a href="index.php">Upload Foto Lain</a>');
	//$('#nav_upload').hide('fade').html('<a href="index.php">Upload Foto Lain</a>').show('fade');
	$('#otherupload').show('fade');
	$('#nav_upload').hide();
	$('#browseagain').hide();
	
}
