var input = document.createElement('input');

$j(document).ready(function() {
    $j('.form-text').click(function() {
          $j('.form-note').css('visibility', 'hidden');

          $j(this).parent().children('.form-note').css('visibility', 'visible');
    });
});

function toggleLogin() {
	if ($j('#login-form').css('display') == 'none') {
		$j('.side-header').css('display', 'none');
		$j('#login-form').fadeIn(function() {
			$j('#side-username').focus();
		});
	} else {
		$j('#login-form').fadeOut(function() {
			$j('.side-header').css('display', 'block');
		});
	}
	return false;
}

function tileBury(id, bucket, is_file) {
	if (confirm('Are you sure you want to '+(section=='shared'?'remove':'delete')+' the '+(is_file?'folder':'file')+'?') === false) {
		return false;
	}
	$j.ajax({
		'type' : 'POST',
		'url' : 'ajax.php?bury'+(section=='shared'?'Share':'')+(is_file?'Bucket':'File'),
		'dataType' : 'json',
		'data' : {
			'id' : id,
			'bucket' : bucket
		},
		'success' : function(json) {
			if (json.success) {
				$j('#tile'+(is_file?'B':'F')+id).hide();
			} else {
				alert(json.error);
			}
		},
		'error' : function(xml) {
			alert('Error in "tileBury()":' + xml.responseText);
		}
	});

	return false;
}
function combineBury(id, bucket, is_file) {	if (confirm('Are you sure you want to '+(section=='shared'?'remove':'delete')+' the '+(is_file?'folder':'file')+'?') === false) {		return false;	}	$j.ajax({		'type' : 'POST',		'url' : 'ajax.php?combineBury'+(section=='shared'?'Share':''),		'dataType' : 'json',		'data' : {			'id' : id,			'bucket' : bucket		},		'success' : function(json) {			if (json.success) {				$j('#tile'+(is_file?'B':'F')+id).hide();			} else {				alert(json.error);			}		},		'error' : function(xml) {			alert('Error in "tileBury()":' + xml.responseText);		}	});	return false;}
function tileShare(id, bucket) {
	var objOverlay = $j('#overlay');
	var objActionLayer = $j('#lightbox');

	$j('#share_id').attr('value', id);
	$j('#share_bucket').attr('value', bucket);

	objActionLayer.show();
	objOverlay.show();

	return false;
}

function closeLightbox() {
	$j('#process-form').html('');
	$j('#process-form').hide();
	$j('#lightbox').hide();
	$j('#overlay').hide();
}

function doShare(form) {
	var error = '';

	$j('#btnsave').attr('disabled', true);
	$j('#btncancel').attr('disabled', true);

	id = form.id.value;
	bucket = form.bucket.value;
	mobile = form.mobile.value;
	carrier = form.carrier.value;

	if (mobile == '') { 
		error = 'Error: Please enter a mobile number or an email address.'; 
	} else { 
		regExEmail = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/i; 
		regExMobile = /^(([0-9]{1})*[- .(]*([0-9a-zA-Z]{3})*[- .)]*[0-9a-zA-Z]{3}[- .]*[0-9a-zA-Z]{4})+$/; 

		if (regExEmail.test(mobile) == false && regExMobile.test(mobile) == false) { 
			error = 'Error: Please enter a valid mobile number or email address.'; 
		} 
	} 

	if (error != '') {
		$j('#process-form').html(error);
		$j('#btnsave').attr('disabled', false);
		$j('#btncancel').attr('disabled', false);
		return false;
	}

	$j('#process-form').show();
	$j('#process-form').html('<img src="img/loadcirc_blue.gif" width="16" height="16" border="0" alt="Processing..." /> Processing...');

	$j.ajax({
		'type' : 'POST',
		'url' : 'ajax.php?share',
		'dataType' : 'json',
		'data' : {
			'id' : id,
			'bucket' : bucket,
			'mobile' : mobile,
			'carrier' : carrier
		},
		'success' : function(json) {
			$j('#btnsave').attr('disabled', false);
			$j('#btncancel').attr('disabled', false);

			if (json.success) {
				$j('#process-form').html('A notification has been sent to your friend.<br /><b>It\'s safe to close the window now.</b><br /><button onclick="closeLightbox()" id="btncancel">Done</button>');
			} else {
				$j('#process-form').html(json.error);
			}
		},
		'error' : function(xml) {
			$j('#process-form').html('Error: ' + xml.responseText);
		}
	});

	return false;
}

if ($j.browser.msie && parseInt($j.browser.version) < 7) {
	$j(document).ready(function() {
		$j('.tile').hover(function() {
			$j(this).children().filter('h3').css('display', 'block').css('font-size', '100%').css('padding', '0').css('margin', '0');
		},
		function() {
			$j(this).children().filter('h3').css('display','none');
		});
	});
}

