/*Menu Lev 01*/
var menu = new Class({
	
	Implements: Options,
	
	options: {		
		overClass: 'current',
		lastOverClass: 'lastCurrent'
	},
	
	initialize: function(options) {		
		this.setOptions(options);
		this.initMenu();
	},
	
	initMenu: function() {		
		var _self = this;		
		$$("a.menuBtn").each(function(btn, i){											
			btn.addEvent("mouseover", function(evt){
				new Event(evt).stop();
				this.isMouseOver = true;						
				if (!this.subMenu) {
					this.subMenu = this.getNext();					
				}							
				clearInterval(this.menuInterval);	
				this.subMenu.setStyle('visibility', 'visible');	
				
				this.subMenu.addEvents({
					"mouseover": function(evt){
						clearInterval(btn.menuInterval);
						btn.isMouseOver = true;
					},						
					"mouseout": function(evt){
						new Event(evt).stop();						
						try {
							clearInterval(btn.menuInterval);
							btn.menuInterval = setInterval(function() {
								btn.isMouseOver = false;
								_self.hideMenu(btn);
							}, 10);
						} catch(e) {}
					}
				});
				
				this.subMenu.getElements("li").addEvents({
					"mouseover": function(evt){
						new Event(evt).stop();					
						btn.isMouseOver = true;
						if(this.subMenu.hasClass('last')){
							btn.addClass(_self.options.lastOverClass);
						}
						else{
							btn.addClass(_self.options.overClass);	
						}
						try { 
							clearInterval(btn.menuInterval);
						} catch(e) {}						
					}.bind(this),
					
					"mouseout": function(evt){
						new Event(evt).stop();						
						try {
							clearInterval(btn.menuInterval);
							btn.menuInterval = setInterval(function() {
								btn.isMouseOver = false;
								_self.hideMenu(btn);
							}, 10);
						} catch(e) {}
					}
				});			
			});
			
			btn.addEvent("mouseout", function(evt){
				new Event(evt).stop();								
				clearInterval(this.menuInterval);
				this.menuInterval = setInterval(function() {				
					btn.isMouseOver = false;
					_self.hideMenu(btn);					
				}, 10);					
			});		
		});
	},
	
	hideMenu: function(menu) {
		if (!menu.isMouseOver && menu.subMenu) {			
			menu.removeClass(this.options.overClass);
			menu.removeClass(this.options.lastOverClass);
			clearInterval(menu.menuInterval);
			menu.subMenu.setStyle('visibility', 'hidden');			
		}
	}
});	

window.addEvent("domready", function(){
	/*Menu Lev 01*/
	new menu();
});



function CheckContactForm(){
		re = /([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)/;
		var username, email, question, vercode, dataRight = true;
		message = "";
		
		username = document.frmContact.user_name.value;	
		email = document.frmContact.email.value;
		question = document.frmContact.message.value;
		vercode = document.frmContact.vercode.value;
		
		if (username.length==0){
			message += "\n -  Enter Name";
			dataRight=false;
		}
		if (email.length==0){
		   message += "\n -  Enter Email";
		   dataRight=false;
		}
		if (email.length!=0 && email.match(re)==null){
		   dataRight=false;
		   message += "\n -  Email is incorrect";
		}
		if (question.length==0){
			message += "\n -  Enter Question";
			dataRight=false;
		}
		if (vercode.length==0){
			message += "\n -  Verification code";
			dataRight=false;
		}
	
		if (!dataRight){
			if (message != ""){
			   message ="\n" +
			   "You failed to correctly fill in the form:\n" +
			   message + "\n" +
			   "\nPlease re-enter and click the Send button again!";
		   }
		   alert(message);
		}
		return dataRight;
}


function CheckBlogForm(){
		re = /([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)/;
		var username, email, question, vercode, dataRight = true;
		message = "";
		
		username = document.frmBlog.user_name.value;	
		email = document.frmBlog.email.value;
		question = document.frmBlog.message.value;
		vercode = document.frmBlog.vercode.value;
		
		if (username.length==0){
			message += "\n -  Enter Name";
			dataRight=false;
		}
		if (email.length==0){
		   message += "\n -  Enter Email";
		   dataRight=false;
		}
		if (email.length!=0 && email.match(re)==null){
		   dataRight=false;
		   message += "\n -  Email is incorrect";
		}
		if (question.length==0){
			message += "\n -  Enter Question";
			dataRight=false;
		}
		if (vercode.length==0){
			message += "\n -  Verification code";
			dataRight=false;
		}
	
		if (!dataRight){
			if (message != ""){
			   message ="\n" +
			   "You failed to correctly fill in the form:\n" +
			   message + "\n" +
			   "\nPlease re-enter and click the Send button again!";
		   }
		   alert(message);
		}
		return dataRight;
}

