var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height, other) {
  if(popUpWin) {
	  if(!popUpWin.closed) popUpWin.close();
  }
  var winleft = (screen.width - width) / 2;
  var winUp = (screen.height - height) / 2;
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,'+other+',resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+winleft+', top='+winUp+',screenX='+winleft+',screenY='+winUp+'');
}

function showResponse(responseText, statusText)  { 
	if(statusText == "success") {
	 var tmp = jQuery.trim(responseText);
		if(tmp.length == 0) {
				location.href = 'member-home.php';
		} else {
			$("#result").html(tmp);  
			$("#authenticate").overlay().load();
		}
	}
} 
jQuery.fn.placeholder = function() 
{
	$('textarea', this).each(function()
	{
		var placeholder = $(this).attr("placeholder");
		
		$(this).html(placeholder);
		
		$(this).bind('focus', function()
		{
			if($(this).html()==placeholder)
			{
				$(this).html("");
			}
		}
		)
		
		$(this).bind('blur', function()
		{
			if($(this).html()=="")
			{
				$(this).html(placeholder);
			}
		}
		)
	}
	);
	
	var counter=0;
	
	$('input', this).each(function()
	{
		var id = $(this).attr("id");
		var placeholder = $(this).attr("placeholder");
		
		if($(this).attr("type")=="password")
		{
			var thisdummy = 'dummy' + counter;
			
			$(this).hide();
			$(this).after('<input type="text" class="text" id="' + thisdummy + '"/>');
			$('#' + thisdummy).val(placeholder);
			
			counter++;
			
			$('#' + thisdummy).bind('focus', function()
			{
				$("#" + id).show().val("");
				$("#" + id).show().focus();
				$(this).hide();
			}
			)
			
			$(this).bind('blur', function()
			{
				if($(this).val()=="")
				{
					$(this).hide();
					$("#" + thisdummy).show();
				};
			}
			)
		}
		
		if($(this).attr("type")=="text" && placeholder != "")
		{
			$(this).val(placeholder);
			
			$(this).bind('focus', function()
			{
				if($(this).val()==placeholder)
				{
					$(this).val("");
				}
			}
			)
			
			$(this).bind('blur', function()
			{
				if($(this).val()=="")
				{
					$(this).val(placeholder);
				}
			}
			)
		}
	}
	);
};

$(document).ready(function(){
						   
	$("#login-form").placeholder();
						   
	$(".submit").live("click", function(){
		$(this).fadeOut("fast").parents("form").submit();
		setTimeout('$(".submit").show();', 2000);
		return false;
	});
	$("#sendEmail").click(function(){
		var editordata = CKEDITOR.instances.body.getData();
		$("#bodyHTML").val(editordata);
		$(this).fadeOut("fast").parents("form").submit();
		setTimeout('$("#sendEmail").show();', 2000);
		return false;
	});
	$("#sendemail").validate({
	   submitHandler: function(form) {
		$(form).ajaxSubmit({ success:showResponse });
	   }
	});
	$("#signinform").validate({
	   submitHandler: function(form) {
		$(form).ajaxSubmit({ success:showResponse });
	   }
	});
	$("#signupform").validate({
		submitHandler: function(form) {
		$(form).ajaxSubmit({ success:showResponse });
	   }
	});
	$("#emailform").validate({
		submitHandler: function(form) {
		$(form).ajaxSubmit({ success:showResponse });
	   }
	});
	$("#passwordform").validate({
		rules: {
			password2: { equalTo: "#password" }
		}
	});
	$("#forgottenform").validate({
	   submitHandler: function(form) {
		$(form).ajaxSubmit({ success:showResponse });
	   }
	});
	$("form#accountform").validate();

});

