// treme treme '07

// share this pop-up functions
function fbs_click(u, t) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function delicious_click(u, t) {
	window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t), 'delicious', 'toolbar=no,width=700,height=400');
	return false;
}

// ajax send mail functions
function validateEmail(email) {
	var rule = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	return rule.test(email.value);
}

function validateContactForm() {
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var subject = document.getElementById('subject');
	var message = document.getElementById('message');
	
	if (name.value=='')
		return 'You forgot to fill-in your Name!';
		
	if (email.value=='')
		return 'You forgot to fill-in your Email Address!';
	else
	if (!validateEmail(email))
		return 'Your Email Address appears invalid. Please try another.';
		
	if (subject.value=='')
		return 'You forgot to fill-in the Subject!';
	if (message.value=='')
		return 'You forgot to fill-in your Message!';

	return '';
}

function sendContactForm() {
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var subject = document.getElementById('subject');
	var message = document.getElementById('message');

	var button_submit = document.getElementById('submit');
	var validateResult;
	var error = false;
	var error_text = '';
	
	Effect.Appear('ajax_contact_loading');
	button_submit.disabled = true;
	validateResult = validateContactForm();
	if (validateResult != '') {
		error = true;
		error_text = validateResult;	
	}
	
	if (!error) {	
		var url = document.getElementById('url').value;
		var parameters = '';
		parameters += 'name='+encodeURIComponent(name.value);
		parameters += '&email='+encodeURIComponent(email.value);
		parameters += '&subject='+encodeURIComponent(subject.value);
		parameters += '&message='+encodeURIComponent(message.value);

		new Ajax.Request(url, {
						 method: 'post',
						 parameters : '?' + parameters,
						 onFailure: function() {alert('Oops! ...maybe later!');},
						 onSuccess: function(transport) {
							 	if (transport.responseText=='-1' || transport.responseText=='-2')
									alert('Oops! ...maybe later!');
								else {
									name.value = '';
									email.value = '';
									subject.value = '';
									message.value = '';
									alert(transport.responseText);
								}
									
						 }
		});
	}else{
		alert(error_text);
	}

	button_submit.disabled = false;
	Effect.Fade('ajax_contact_loading');
	return false;
}

// ABBR

function styleAbbr() {
  var oldBodyText, newBodyText, reg
  if (isIE) {
    oldBodyText = document.body.innerHTML;
    reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
    newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class="abbr" $1>$2</SPAN></ABBR>');
    document.body.innerHTML = newBodyText;
  }
}

window.onload = function(){
  styleAbbr()
};

isIE = (document.all) ? true:false;