
/****************************************************************************

  This file is part of the GamesCast.tv Website

	GamesCast.tv coded by Steve "GreasedScotsman" Huff, 
	Copyright 2010 Steve Huff
	
	It is distributed under the terms of the 
	GNU General Public License
		
***************************************************************************/

$(document).ready(function(){

	$("#pDialog").dialog({
		bgiframe: true,
		autoOpen: false,
		height: 'auto',
		width: 290,
		position: ['right','top'],
		modal: false,
		buttons: {
			'OK': function() {
				var bValid = true;
					
				if (bValid) {

					$.post("/data/updateprofile.php", { pUser: $("#pUser").val(), 
										pTimeFormat: $("input[name='pTimeFormat']:checked").val(), 
										pTwitterUpdates: $("input[name='pTwitterUpdates']:checked").val(), 
										pNavWarning: $("input[name='pNavWarning']:checked").val(),
										pLayout: $("input[name='pLayout']:checked").val(),
										pExplicit: $("#pExplicit").val() },
											//pAutoSurf: $("input[name='pAutoSurf']:checked").val() },
						function(data){
							//alert("Data returned was: "+data);
							var pData = data.split("||");
							$("#pDialogSuccessMsg").html('<p><b>Success</b>: Your profile was updated.</p>');
							$("#pDialogSuccessMsg").fadeIn(500);
							$("#pDialogSuccessMsg").fadeOut(5000);
							notoficationsUpdate(nowlocal);
						}
			 		);
					$(this).dialog('close');
				}
			},
			Cancel: function() {
				$("#pDialogSuccessMsg").html('<p>Profile update was <b>cancelled</b>.</p>');
				$("#pDialogSuccessMsg").fadeIn(500);
				$("#pDialogSuccessMsg").fadeOut(5000);
				$(this).dialog('close');
			}
		},
		close: function() {
			// nothing here
		}
	});
		
		
		
	$('#updateProfile').click(function() {

		$.post("/data/updateprofile.php", { pUser: $("#pUser").val() },
			function(data){
				//alert("profile read: "+data);
				var pData = data.split("||");
				if (pData[0] == "Error:") {
					alert("Error: "+pData[1]);
				} else {
					// Notification Time Format
					$("input[id='"+pData[1]+"']").attr('checked','checked');

					// NavWarning Preference
					if(pData[2] == 1) { pData[2] = "navwarnenabled"; } else { pData[2] = "navwarndisabled"; }
					$("input[id='"+pData[2]+"']").attr('checked','checked');
					
					// NavWarning Preference
					if(pData[3] == 1) { pData[3] = "tweetsenabled"; } else { pData[3] = "tweetsdisabled"; }
					$("input[id='"+pData[3]+"']").attr('checked','checked');
					
					// Explicit Content Pref
					$("#pExplicit").val(pData[4]);

					// Layout Preference
					if(pData[5] == "wide1200") { pData[5] = "gctvlayoutwide1200"; } 
					else if (pData[5] == "orig4x3") { pData[5] = "gctvlayoutorig4x3"; }
					else { pData[5] = "gctvlayoutwide1200"; }
					$("input[id='"+pData[5]+"']").attr('checked','checked');
					
					// AutoSurf Preference
					//if(pData[2] == 1) { pData[2] = "autoyes"; } else { pData[2] = "autono"; }
					//$("input[id='"+pData[2]+"']").attr('checked','checked');

					//$("#validateTips").html("User: "+pData[0]+"<br/>pTimeFormat: "+pData[1]+"<br/>pAutoSurf: "+pData[2]+"<br/>");
				}
			}
		 );
	
		$('#pDialog').dialog('open');
		ProfileDialogTheme(0);
		
	})
	
	.hover(
		function(){ 
			//$(this).addClass("ui-state-hover"); 
		},
		function(){ 
			//$(this).removeClass("ui-state-hover"); 
		}
	)
	.mousedown(function(){
		//$(this).addClass("ui-state-active"); 
	})
	.mouseup(function(){
			//$(this).removeClass("ui-state-active");
	});

var dwrap = [false, false];

// fix for dialogs not getting the class-scoped dialog UI theme
function ProfileDialogTheme(dialog){
	switch (dialog){
		case 0 :
			if( !dwrap[0] ){ 
				$("div[aria-labelledby*='ui-dialog-title-pDialog']").wrap("<div class='gctvtheme'></div>"); 
				dwrap[0] = true; 
			}

			//for overlay no good way but i dont see another
			$(".ui-widget-overlay").wrap("<div class='gctvtheme'></div>"); 
		break; 
		case 1 : 
			if( !dwrap[1] ){
				$("div[aria-labelledby*='ui-dialog-title-pDialog']").wrap("<div class='gctvtheme'></div>"); 
				dwrap[1] = true; 
			}
		break; 
		default : 
		break; 
	}
}

});
 
// EOF
