﻿$().ready(function() {		  
	
	$(".ajax_btn").live("click",function(event) {
		event.preventDefault();

		$.ajax({
			url: $(this).attr("href"),
			cache: false,
			dataType: "json",
			success: function(data) {
				if(data.success == 1) {
					notice("#update", data.notice, data.message);
//					GetList(); 
				} else {
					notice("#update", data.notice, data.message);					
				}
			},
			error: function() {
				notice("#update", "error", "Error connecting to server");				
			}
		});
	});
	
	$(".js_btn").live("click",function(event) {
		event.preventDefault();
		var func = $(this).attr("href");
		if(func.substr(0,1) == "#") func = func.substr(1,func.length-1);
		
		eval(func);
	});					   
				   
	$('input.inputSwap').each(function() {
									   
		if($(this).attr("type").toLowerCase() == "password") {
			
			$(this).before("<div id=\"" + $(this).attr("id") + "_div1\"><input type=\"text\" id=\"" + $(this).attr("id") + "_temp\" value=\"" + $(this).attr("title") + "\" size=\"20\" maxlength=\"20\" class=\"text\" /></div>");
			$(this).wrap("<div id=\"" + $(this).attr("id") + "_div2\" style=\"display:none\"></div>");

			$("#" + $(this).attr("id") + "_temp").focus(function() {
				var baseId = $(this).attr("id").replace("_temp","");
				$("#" + baseId + "_div1").hide();
				$("#" + baseId + "_div2").show();
				$("#" + baseId).focus();	
			});
			
			$(this).blur(function() {
				if($(this).val() == '') {
					$("#" + $(this).attr("id") + "_div1").show();
					$("#" + $(this).attr("id") + "_div2").hide();
				}	
			});

		} else {
			if($(this).attr("title")) $(this).val($(this).attr("title"));
			$(this).focus(function() { checkField(this,true,false)});
			$(this).blur(function() { checkField($(this),false,false)});			
		}
	});
	
	
});

function checkField(target,onFocus,password) {
	if(onFocus) {	
		if($(target).val()==$(target).attr("title")) $(target).val("");
		if(password) $(target).attr("type","password");
	} else {
		if($(target).val()=="") $(target).val($(target).attr("title"));
		if(password) $(target).attr("type","text");				

	}
}

function submitRegistration() {
	$("form:first").submit();
}

