// Customizations & Styling
// Hybrid Forge (www.HybridForge.com)
// March 2010 

//---------------------------------------------------
// Customizations:
//---------------------------------------------------

jQuery(document).ready(function($) {

	//Main menu drop-downs
	$("#mainMenu .sf-menu").superfish({				
		delay:       250,								// delay on mouseout 
		animation:   {opacity:'show',height:'show'},	// fade-in and slide-down animation 
		speed:       200,								// animation speed 
		autoArrows:  false,								// generation of arrow mark-up 
		disableHI:	 false,								// true to disable hoverIntent detection 
		dropShadows: false								// false to disable drop shadows 
	});
	//Main menu fixes
	$("#mainMenu li.mmItem").mouseover( function() {
		$(this).find("a.mainlevel").addClass("hover");
	});
	$("#mainMenu li.mmItem").mouseout( function() {
		$(this).find("a.mainlevel").removeClass("hover");
	});
	
	//Home Page Appt Request text replacement
	var fnInit = "- First Name -";
	var lnInit = "- Last Name -";
	var emInit = "- Email Address -";	
	$('#aptReqFormMini-first').val(fnInit);
	$('#aptReqFormMini-last').val(lnInit);
	$('#aptReqFormMini-email').val(emInit);	
	$('#aptReqFormMini-submit').val('');	
	$('#aptReqFormMini-first').focus( function(){ if( $.trim($(this).val()) == fnInit ){ $(this).val(''); } });
	$('#aptReqFormMini-first').blur( function(){ if( $.trim($(this).val()) == '' ){ $(this).val(fnInit); } });	
	$('#aptReqFormMini-last').focus( function(){ if( $.trim($(this).val()) == lnInit ){ $(this).val(''); } });
	$('#aptReqFormMini-last').blur( function(){ if( $.trim($(this).val()) == '' ){ $(this).val(lnInit); } });	
	$('#aptReqFormMini-email').focus( function(){ if( $.trim($(this).val()) == emInit ){ $(this).val(''); } });
	$('#aptReqFormMini-email').blur( function(){ if( $.trim($(this).val()) == '' ){ $(this).val(emInit); } });
	
	//Pre-fill Appt Req Form, if applicable
	var fname = unescape(gup("firstname"));
	var lname = unescape(gup("lastname"));
	var emailAddy = unescape(gup("email"));	
	$("#fieldformBuilderFieldFirst_Name").val(fname);
	$("#fieldformBuilderFieldLast_Name").val(lname);
	$("#fieldformBuilderFieldEmail").val(emailAddy);
	
	//Add "example input" info beside certain fields
	$("#formBuilderAppointment_Request_Form #formBuilderFieldPreferred_Date_DD_MM_YYYY .formBuilderDateStamp").append("<span class='helperText'>&nbsp;Click the field to show a calendar</span>");
	$("#formBuilderAppointment_Request_Form #formBuilderFieldVehicle_Make .formBuilderInput").append("<span class='helperText'>&nbsp;(e.g., Volkswagen)</span>");
	$("#formBuilderAppointment_Request_Form #formBuilderFieldVehicle_Model .formBuilderInput").append("<span class='helperText'>&nbsp;(e.g., Jetta GLS)</span>");
	
	//add odd/even classes to tables 
	$('table:not(#commentform table)').each(function() {
		$(this).find('tr:odd').addClass('odd');
		$(this).find('tr:even').addClass('even');
	});	

});



//Grabs URL and parses the query string
// e.g., gup("email"); will retrun "info@hybridforge.com" in http://www.xyz.com/default.aspx?email=info@hybridforge.com
function gup( name ) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) return "";
	else return results[1];
}



//----- Validate Email Addresses -----------//
// checks for valid looking email addy
function checkemail(str){
	var filter=/^.+@.+\..{2,3}$/;	
	return (filter.test(str));
}



//----- Trim White Space -----------//
//trim whitespace for validation
function trim(s){
	if((s==null)||(typeof(s)!='string')||!s.length)return'';return s.replace(/^\s+/,'').replace(/\s+$/,'')
}


//----- Open New Window -----------//
//Open a new window with specific width/height/location 
function openWindow(location, width, height) {		
	newWidth = width + 20;
	newHeight = height + 20;
	widthHeight = "width=" + newWidth + ",height=" + newHeight;
	window.open(location,"",widthHeight);		
}

//----- Open New Window -----------//
//Open a new window with specific width/height/location & scroll bars
function openWindowScroll(location, width, height) {		
	newWidth = width + 20;
	newHeight = height + 20;
	windowParameters = "width=" + newWidth + ",height=" + newHeight + ",scrollbars=yes";
	window.open(location,"",windowParameters);		
}

