var submitMessageF = "Message Send Failed.";
var submitMessageS = "Your Message was Sent!"; 

/* ===============
	Modal Library
 	 Opening a Contact Bubble: contact("Business Name Inc.", 1231);
==================*/
function initModal() {		 	 
	$('#hideModal').click(function(){ $("#modal").fadeOut();});	
	$(window).scroll(function() {  $('#modal').css('top', $(window).scrollTop() + "px");	});
}
//Show Modal Command.
function openModal(){
	$("#modal").fadeIn();
}
//Close Modal Commmand.
function closeModal(){
	$("#modal").fadeOut( function(){
		$("#msgFlash").html(""); //erase message
		$("#msgFlash").hide();
		$("#modal").removeClass("fail"); //reset status
		$("#modal").removeClass("success");			
	});
}	
//Used heavily with validation script
function alertModal(alertMsg,msgType){
	//msgType is boolean, true for success, false for fail.
	var displayStatus = $("#modal").css("display");
	if (displayStatus == "none"){
		if (!(msgType))
			$("#modal").addClass("fail");	
		$("#modal").fadeIn();
	}

	//true for a success or false for error
	$("#msgFlash").hide();
	$("#msgFlash").html(alertMsg);

	if (msgType){
		$("#modal").addClass("success");			
		$("#msgFlash").fadeIn();	
		setTimeout("closeModalForm()",2000);	
	} else {
		$("#msgFlash").fadeIn();
	}					
}
//closing a modal with a contact form
function closeModalForm() {
	$("#modal").fadeOut(function(){
		$("#msgFlash").html("");
		$("#modal").removeClass("success");			
		$("#modal form").show();
		$("#msgFlash").hide();		
	});		
}

/*=== 
Validation on Yodle Local's claim business form. YLPROFILES
	Pre-requisite: business name and state.
	Validiates Phone.	
	Returns an error message.
===*/	
function validateClaimForm(thisform){

	var errorMsg = "";

	if ((thisform.phone1.value == null || thisform.phone1.value == "") || 
			(thisform.phone1.value == null || thisform.phone1.value == "") ||
			(thisform.phone1.value == null || thisform.phone1.value == "")) {
		thisform.phone.value = null;
		errorMsg = "I need your <strong>PHONE NUMBER</strong>, please.";
	} 
	else if (thisform.first_name.value == null || thisform.first_name.value == "") {
		thisform.first_name.value = null;
		errorMsg = "I need your <strong>NAME</strong>.";
	}
	else if (thisform.email.value == null || thisform.email.value == "") {
		thisform.email.value = null;
		errorMsg = "I need your <strong>EMAIL</strong>.";
	}
	else {

		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(thisform.email.value)))
			errorMsg = "Invalid <strong>EMAIL</strong> address.";
		else {
		thisform.phone.value = thisform.phone1.value + thisform.phone2.value + thisform.phone3.value;
		if (thisform.phone.value != null) {
			thisform.phone.value = thisform.phone.value.replace(/\D/g, "");
			if (thisform.phone.value.length < 10){
				errorMsg = "A <strong>PHONE NUMBER</strong> needs to be<br/> <strong>10 Digits</strong>. <br/> Example:(888)555 - 1234";
			}
		}
		}
	}

	if (errorMsg.length > 0) {
		alertModal(errorMsg,false);
		return false;
	}
	
	alertModal(submitMessageS,true);
//	return true;
	setTimeout(function() { $('#YodleSignUp').submit() }, 2000);
}

//Fade Toggler
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
}; 

jQuery.fn.toggleText = function(a, b) {
	return this.each(function() {
		jQuery(this).text(jQuery(this).text() == a ? b : a);
	});
};

/**
Vertigo Tip by www.vertigo-project.com
Requires jQuery
*/
this.vtip=function(){this.xOffset=-10;this.yOffset=10;$(".vtip").unbind().hover(function(a){this.t=this.title;this.title="";this.top=(a.pageY+yOffset);this.left=(a.pageX+xOffset);$("body").append('<p id="vtip"><img id="vtipArrow" />'+this.t+"</p>");$("p#vtip #vtipArrow").attr("src","images/vtip_arrow.png");$("p#vtip").css("top",this.top+"px").css("left",this.left+"px").fadeIn("slow")},function(){this.title=this.t;$("p#vtip").fadeOut("slow").remove()}).mousemove(function(a){this.top=(a.pageY+yOffset);this.left=(a.pageX+xOffset);$("p#vtip").css("top",this.top+"px").css("left",this.left+"px")})};jQuery(document).ready(function(a){vtip()});
