var re=/^[\w+\.+@+_+-]+$/;
var timeout = 1;
var closetimer = 0;
var menuItem = 0;
//var auaral = azu;
var boolLogin = false;
var RecaptchaOptions = {theme : 'white'};

function CheckAndGo(form,acttype,formname){
	if(form.elements['login'].value.length == 0 || form.elements['password'].value.length == 0){
		if(form.elements['login'].value.length == 0)
			form.elements['login'].style.borderColor = "#FF0000";

		if(form.elements['password'].value.length == 0)
			form.elements['password'].style.borderColor = "#FF0000"

		return false;
	}else{
		form.method = "post";

		if(acttype == "1")
		form.action = "https://ondemand-1.agendize.com/agendize/dologin";

		form.submit();
		return true;
	}
}

function swapDiv(div1,div2,condition){
	if($(div1).css("display")=="block" && !condition){
		$(div1).css("display", "none");
		$(div2).css("display", "block");
	}else{
		$(div1).css("display", "block");
		$(div2).css("display", "none");	
	}

}
function cleanMenu(){
	$("a.smenu").each(function(){ $(this).css({"background-color":"transparent",'border':'1px solid #FFF','padding':'5px'}); });
	$("ul.submenu").each(function(){ $(this).css("visibility", "hidden"); });
}
$().ready(function(){
	/*
	var azscript = document.createElement('script');
	azscript.type = 'text/javascript';
	azscript.src = SERVER_ROOT + "/js/" + auaral + "js";
	document.getElementsByTagName('head')[0].appendChild(azscript);
	*/
	var bool = false;
	var intChecked = 0;
	$("a[rel^='prettyPhoto']").prettyPhoto({allow_resize:false,theme:"light_rounded",show_title:false});
	//$(".customFrmElm").helperkeeper();
	$("img.close").click(function(){ $(this).parent().hide();if(document.getElementById("az_close")!=null){closeBox();}});
	
	//Hover videos
	$.fn.HoverImageText.defaults.AnimShow = { marginTop: "116px"};
	$.fn.HoverImageText.defaults.AnimHide = { marginTop: "143px"};
	$.fn.HoverImageText.defaults.HoverCheck = 0;
	$.fn.HoverImageText.defaults.HoverIn = 200;
	$.fn.HoverImageText.defaults.HoverOut = 400;
	$('#video a').HoverImageText();

	$('#feedback-frm').jqm({overlay:85, overlayClass:'bgOverlay', trigger:'a#feedback-link'});
	$('#feedback-frm').jqmAddClose('span.close');
	
	//$('#az-screencast').HoverImageText();	
	// MENU
	$("ul.submenu li:first-child").css({"-moz-border-radius-topright":"7px", "-webkit-border-top-right-radius":"7px", "border-top-right-radius":"7px" });
	$("ul.submenu li:last-child").css({"-moz-border-radius-bottomright":"7px", "-moz-border-radius-bottomleft":"7px", "-webkit-border-bottom-right-radius":"7px", "-webkit-border-bottom-left-radius":"7px", "border-bottom-right-radius":"7px", "border-bottom-left-radius":"7px" })
	$("ul.submenu li a").hover(function(){ $(this).parent().css('background-color', '#E9E9E9'); }, function(){ $(this).parent().css('background-color', '#F5F5F5'); })
	$("ul.lightsubmenu li a").hover(function(){ $(this).parent().css('background-color', '#E9E9E9'); }, function(){ $(this).parent().css('background-color', '#F5F5F5'); })
	
	$("ul.lightsubmenu li:first-child").css({"-moz-border-radius-topright":"7px", "-webkit-border-top-right-radius":"7px", "border-top-right-radius":"7px" });
	$("ul.lightsubmenu li:last-child").css({"-moz-border-radius-bottomright":"7px", "-moz-border-radius-bottomleft":"7px", "-webkit-border-bottom-right-radius":"7px", "-webkit-border-bottom-left-radius":"7px", "border-bottom-right-radius":"7px", "border-bottom-left-radius":"7px" })
	if(!mobile){ $('ul#links').jmenu({animation:'fade',duration:200});}
	
	// HOMEPAGE MEDIAS
	$("input[name=feature]", ".medias").each(function(){var $this=$(this);if($this.is(":checked")){$this.parents("li").addClass("selected");return false;}else{intChecked++;}if(intChecked==$(".medias").children().length){$("ul.medias").children(":first").addClass("selected").find("input[name=feature]").attr("checked", true);return false;}});
	$(".title", ".media").hover(function(){
		var $this = $(this);
		if(!$this.parents("li").hasClass("selected")){
			$this.parents("li").addClass("hover");
			$this.click(function(){
				$(".medias").find(".selected").removeClass("selected");
				$this.parents("li").removeClass("hover").addClass("selected").find("input[name=feature]").attr("checked", true);
			});
		}
	}, function(){
		$(this).parents("li").removeClass("hover");
	});
	$("#moreMedias").click(function(e){
		e.preventDefault();
		if(!bool){
			$(".hide").slideDown();
			$(this).html("Display less button types").css({"background-position":"0 -15px"});
			bool = true;
		}else if(bool){
			$(".hide").slideUp();
			$(this).html("Display more button types").css({"background-position":"0 0"});
			bool = false;
		}
	})

	// PRODUCT BANNER POSITIONING 
	$("#product-rgt").css({"height":$("#product-lft").height() + "px"});
	$("#product-intro").css({"top":((288 - $("#product-intro").height())/2) + "px"});
	
	// PRODUCT OVERVIEW
	$("td.overview").hover(function(){$(this).css({"background-color":"#F9F9F9", "cursor":"pointer"});},function(){$(this).css({"background-color":"transparent", "cursor":"default"});})
	
	//DIV BOXES HEIGHT FIX
	$("#boxes").css({"height":$("#boxes").prev().height() + "px"})
	
	// PRICING EXPAND TABLE 
	$("table.pricing td.more a").click(function(e){
		e.preventDefault();
		$this = $(this);
		var media = ($this.attr("class")).substring($this.attr("class").indexOf("-")+1, $this.attr("class").length);
		if($("table.pricing", "#mid").find("tr."+media).css("display") == "none"){
			$this.css("background-position", "5px -17px");
			$this.parent().parent().children("td").addClass("selected");
			$("tr."+media).toggle();
		}else{
			$this.css("background-position", "5px 5px");
			$this.parent().parent().children("td").removeClass("selected");
			$("tr."+media).toggle();
		}
	});
	
$(".showpassword").click(function(){
	var element = document.getElementById('passwordsignup');
	if(element.type=='password'){
		element.type = 'text';
	}else{
		element.type = 'password';
	}
});	
	//SIGN UP FORM
	$("#signup").validate({
		rules:{
			
			email:{
				required: true,
				email: true
			},
			password:{
				required:true,
				minlength:5
			},
			password2:{
				equalTo:"#passwordsignup"
			},
			conditions:{
				required:true
			}
		},
		submitHandler: function(form){
			form.action=SERVER_ROOT_S+"/signup";
			form.submit();
		}
	});

	//SIGN UP FORM
	$("#sign-up").validate({
		rules:{
			email:{
				required:true,
				email:true
			},
			password:{
				required:true,
				minlength:5
			},
			conditions:{
				required:true
			}
		},
		errorPlacement:function(error, element){
			error.appendTo(element.parent());
		},
		submitHandler: function(form){
			$("input[name=password2]").val($("input[name=passwordsignup]").val());
			form.action=SERVER_ROOT_S+"/signup";
			form.submit();
		}
	});	
	
	//CASEFORM FORM
	$("#caseform").validate({
		rules:{
			firstname: "required",
			lastname: "required",
			company: "required",
			country: "required",
			email: {
				required: true,
				email: true
			}
			
		},
		submitHandler: function(form){
			form.action="";
			form.submit();
		}
	});
	$("#loginFrmFull").validate({
		rules: {
			login:"required",
			password:"required"
	

		},
	   submitHandler: function(form) {
		form.action=SERVER_ROOT_S+"/dologin";
		form.submit();
	   }
	});

	$(".swapDiv").click(function(e){ e.preventDefault(); swapDiv("#login", "#forgot-pass"); });
	$(".swapDiv2").click(function(e){ e.preventDefault(); swapDiv("#loginFull", "#forgot-passFull"); });
	$("#recoverBtn").click(function(e){ e.preventDefault(); if($("#password2email").val() != ""){ $("#forgotPass").submit(); toggleLogin(); }else{ $("td.error", "#forgot-pass").html("Please enter a valid email.") } });

	//Contact
	$("#newsletter-submit").click(function(e){
		e.preventDefault();
		var inputValue = $("input.newsletter").val();
		if(inputValue == "" || inputValue == " " || inputValue == "Your email address..." || inputValue.indexOf("@") == -1 || inputValue.indexOf(".") == -1){
			$("input.newsletter").css({"background-color":"#ffefef","border":"1px solid #F00"});
		}else{
			$("input.newsletter").css({"border":"1px solid #D0D0D0"});
			$("#newsletter").css("display","none");
			$("#thanksnewsletter").css("display","block");
			document.forms['newsletter'].action = "http://www.agendize.com/website/inscription";
			document.forms['newsletter'].submit();
		}
	});
	
	$("#send-message").click(function(e){
		e.preventDefault();
		document.forms['sendMessage'].elements['sender-name'].style.borderColor = "#D0D0D0";
		document.forms['sendMessage'].elements['email-from'].style.borderColor = "#D0D0D0";
		document.forms['sendMessage'].elements['topic'].style.borderColor = "#D0D0D0";
		document.forms['sendMessage'].elements['message'].style.borderColor = "#D0D0D0";
		
		if(document.forms['sendMessage'].elements['sender-name'].value == " " || document.forms['sendMessage'].elements['sender-name'].value == ""){
			document.forms['sendMessage'].elements['sender-name'].style.borderColor = "#FF0000";
		}
		
		if(document.forms['sendMessage'].elements['email-from'].value == " " || document.forms['sendMessage'].elements['email-from'].value == ""){
			document.forms['sendMessage'].elements['email-from'].style.borderColor = "#FF0000";
		}

		if(document.forms['sendMessage'].elements['topic'].value == ""){
			document.forms['sendMessage'].elements['topic'].style.borderColor = "#FF0000";
		}						
		
		if(document.forms['sendMessage'].elements['message'].value == " " || document.forms['sendMessage'].elements['message'].value == ""){
			document.forms['sendMessage'].elements['message'].style.borderColor = "#FF0000";
		}
		if(document.forms['sendMessage'].elements['message'].value != "" && document.forms['sendMessage'].elements['email-from'].value != "" && document.forms['sendMessage'].elements['topic'].value != "" && document.forms['sendMessage'].elements['sender-name'].value != ""){
			document.forms['sendMessage'].action = "http://o2.agendize.com/w1/inserter/mailto?m=416558906&profile=httpcalls&id="+document.forms['sendMessage'].elements['topic'].value+"&email-from="+escape(document.forms['sendMessage'].elements['email-from'].value)+"&sender-name="+document.forms['sendMessage'].elements['sender-name'].value+"&message="+document.forms['sendMessage'].elements['message'].value;
			document.forms['sendMessage'].submit();
			$("#request-form").html("<tr><td colspan='2'>Thank you. Your request has been sent and we will come back to you as soon as we can.</td></tr>");
			$("p.submit").hide();
		}
	});
	
	$("input.newsletter").focus(function(){
		var $this = $(this);
		if($this.val() == "Your email address..."){
			$this.val("");
			$this.css("color", "#333333");
		}
	})
	$("input.newsletter").blur(function(){
		var $this = $(this);
		if($this.val() == ""){
			$this.val("Your email address...");
			$this.css("color", "#999999");
		}
	})
});
function activatefrmlogin()
{
    if(window.location.href.substring(window.location.href.length - 5,window.location.href.length) == 'fr=hp')
        toggleLogin();
}

