// JavaScript Document
$(document).ready(function() {
	function echeck(str) { //Check email address
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid E-mail ID");
			return false;
		}
		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid E-mail ID");
			return false;
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid E-mail ID");
			return false;
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid E-mail ID");
			return false;
		 }
		 if (str.indexOf(" ")!=-1){
			alert("Invalid E-mail ID");
			return false;
		 }
		return true;
	}
	
	$('.defaultText').defaultText();
	$("ul#main-menu > li").bind("mouseover", navigation_open);
    $("ul#main-menu > li").bind("mouseout",  navigation_timer);
	
	$('.defaultText').defaultText();
		
	$('ul#slide_photo').cycle({
        fx:     'fade',
        speed:  2000,
		timeout: 6000
    });
	
	/*$(".tab_content").hide(); //Hide all content
	$("div.tabs div.head a:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	$("div.tabs div.head a").click(function() {
		$("div.tabs div.head a").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});*/
	
	if($('div.related-tabs').length > 0 || $('div.related-topics').length > 0){
		var maxHeight = 0;
		$('div.related-tabs, div.related-topics').each(function() { maxHeight = Math.max(maxHeight, $(this).height()); })
		  .height(maxHeight);
	}
	
	$(".request-button a").click(function() {
		if($("div.info-form").is(':hidden')) {
			$("div.info-form").show();
			window.scrollTo(0,99999);
		} else {
			$("div.info-form").hide();
		}
	});
	
	$("form#formContact").submit(function(){
		var first_name = $("form#formContact input[name=first_name]");
		var last_name = $("form#formContact input[name=last_name]");
		var email = $("form#formContact input[name=email]");
		if(jQuery.trim(first_name.val()) == "") {
			alert("Please enter your first name!");
			first_name.focus();
			return false;
		} else if(jQuery.trim(last_name.val()) == "") {
			alert("Please enter your last name!");
			last_name.focus();
			return false;
		} else if(echeck(email.val())==false) {
			email.focus();
			return false;
		}		
		return true;
	});
	
	$("form#formInfo").submit(function(){
		var first_name = $("form#formInfo input[name=first_name]");
		var last_name = $("form#formInfo input[name=last_name]");
		var email = $("form#formInfo input[name=email]");
		if(jQuery.trim(first_name.val()) == "" || first_name.val() == "First Name") {
			alert("Please enter your first name!");
			first_name.focus();
			return false;
		} else if(jQuery.trim(last_name.val()) == "" || lastt_name.val() == "Last Name") {
			alert("Please enter your last name!");
			last_name.focus();
			return false;
		} else if(echeck(email.val())==false) {
			email.focus();
			return false;
		}		
		return true;
	});
});
