$(document).ready(function(){
						   
	
	var lmmoffset_2 = $('#link_mmitem_2').offset();	
	var lmmoffset_3 = $('#link_mmitem_3').offset();	
	
	
	$('#sub_link_3').css({'left': ( lmmoffset_2.left - 2 ) +'px'});
	$('#sub_link_4').css({'left': ( lmmoffset_3.left - 2 ) +'px'});
	
	$('#link_mmitem_2').hover(
		function(){			
			$('#sub_link_3').show();
		},
		function(){
			$('#sub_link_3').hide();
		});
	
	$('#sub_link_3').hover(
		function(){
			$(this).show();
		},
		function(){
			$(this).hide();
		})
	
	$('#link_mmitem_3').hover(
		function(){			
			$('#sub_link_4').show();
		},
		function(){
			$('#sub_link_4').hide();
		});
	
	$('#sub_link_4').hover(
		function(){
			$(this).show();
		},
		function(){
			$(this).hide();
		})
	
	

	$("form[name=contactus]").each(function(){		
		$(this).find("input").each(function(){
			$(this)
				.val( $(this).attr('alt') )
				.click(function(){
					if($(this).val() == $(this).attr('alt')) {
						$(this).val('');
					}
				})
				.blur(function(){
					if($(this).val() == '') {
						$(this).val($(this).attr('alt'));
					}
				});
		});
		$(this).find("textarea").each(function(){
			$(this)
				.val( $(this).attr('label') )
				.click(function(){
					if($(this).val() == $(this).attr('label')) {
						$(this).val('');
					}
				})
				.blur(function(){
					if($(this).val() == '') {
						$(this).val($(this).attr('label'));
					}
				});
		});		
		$(this).submit(function(){			
			var err = false;

			$(this).find("input[title=required]").each(function(){
				if(change_border($(this))) err = true;
			});

			$(this).find("textarea[title=required]").each(function(){								
				if(change_border($(this))) err = true;
			});
			
		
			if(err) {
				return false;
			}
			else {
				return true;
			}
		});	
	});/**/
	
});
/* --------------------------------------------------------------------------- */

function change_border(el) {
	if( ((el.val() == "") || (el.val() == el.attr('alt'))) && (el.attr('type') == 'text') ) {
		el.css("border-bottom", "1px dotted #B11C0F");
		return true;

	} else if( ((el.val() == "") || (el.val() == el.attr('label'))) && (el.attr('label') != '') ) {
		el.css("border-bottom", "1px dotted #B11C0F");
		return true;

	} else {
		if(el.attr('name') == 'email') {
			if(validateemail(el)) {
				el.css("border-bottom", "none");				
				return false;
			}
			else {
				el.css("border-bottom", "1px dotted #B11C0F");
				return true;
			}
		}
		else {
			el.css("border-bottom", "none");
			return false;
		}
	}
}

function validateemail(el) {
	var matchArray = el.val().match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
	
	if (matchArray == null) {
		return false;
	} else {
		return true;
	}
}
