/***********************************************
* Local Time script- &#65533; Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var weekdaystxt=["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"]

function showLocalTime(container, servermode, offsetMinutes, displayversion){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.displayversion=displayversion
//var servertimestring=(servermode=="server-php")? 'April 04, 2008 07:19:22' : (servermode=="server-ssi")? '<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="DATE_LOCAL" -->' : '<%= Now() %>'
//alert(servertimestring);
this.localtime=this.serverdate=new Date(servertimestring)
this.localtime.setTime(this.serverdate.getTime()+offsetMinutes*60*1000) //add user offset to server time
this.updateTime()
this.updateContainer()
}

showLocalTime.prototype.updateTime=function(){
var thisobj=this
this.localtime.setSeconds(this.localtime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

showLocalTime.prototype.updateContainer=function(){
var thisobj=this
if (this.displayversion=="long")
this.container.innerHTML=this.localtime.toLocaleString()
else{
var hour=this.localtime.getHours()
var minutes=this.localtime.getMinutes()
var seconds=this.localtime.getSeconds()
var ampm=(hour>=24)? "pm" : "am"
var dayofweek=weekdaystxt[this.localtime.getDay()]
this.container.innerHTML=formatField(hour, 1)+":"+formatField(minutes)+":"+formatField(seconds)+""
}
setTimeout(function(){thisobj.updateContainer()}, 1000) //update container every second
}

function formatField(num, isHour){
if (typeof isHour!="undefined"){ //if this is the hour field
var hour=(num>24)? num-24 : num
return (hour==0)? 24 : hour
}
return (num<=9)? "0"+num : num//if this is minute or sec field
}


var blurTextboxes = function(element, defValue) {
	//textfield.value = '';
	if (element.value.match(/^ *$/)) {
		element.value=defValue;
		$(element).addClassName('blank');
	};
}

var focusTextboxes = function(element, defValue) {
	if (element.value == defValue) {
		element.value='';
		$(element).removeClassName('blank');
	};
}


var removeBlankClass = function(form, hashInputValues) {
	
	subscription_form = $(form);
	aFormInputsform = subscription_form.getElements();
	aFormInputsform.each(function(field) {
		var sFieldValue = field.value;
		var sFieldName = field.name;
		//alert(sFieldValue + ': ' + eval('hashInputValues.get(\'' + sFieldName + '\')'));
		if (sFieldValue != eval('hashInputValues.get(\'' + sFieldName + '\')')) {
			$(sFieldName).removeClassName('blank');
		}
		
		if (sFieldValue == '') {
			$(sFieldName).value = eval('hashInputValues.get(\'' + sFieldName + '\')');
			$(sFieldName).addClassName('blank');
		}
		//alert(eval('hashInputValues.' + sFieldName));
	});
}


/*var usernameVerification = function(element) {
	new Ajax.Updater('username_verification_container', 'ajaxsrv.php', {
		method: 'post',
		parameters: {
			action: 'verify_user',
			module: 'fe_user_subscription',
			username: $F('username')
		}
	});
}*/


var hInputValues = $H({
		email : 'EMAIL'
});


var hInputValuesToValidate = hInputValues.clone();
	

var myrules = {
	'#email' : function(el){
		el.onblur = function(){ blurTextboxes(this, hInputValues.get('email')); },
		el.onfocus = function(){ focusTextboxes(this, hInputValues.get('email')); }
	}
};

Behaviour.register(myrules);

Validation.addAllThese([
	['blank', 'Please insert a value.', {
		notOneOf : hInputValuesToValidate.values(), // value does not equal anything
		isNot : ''
	}]
]);