$(document).ready(function() {
	
	// Preload Rollover Images for IE6
	var preload = ['/fileadmin/templates/images/icons/large_virtual_tour_over_ie.png', 
	               '/fileadmin/templates/images/icons/virtualtour_over_ie.png'];
	$.preloadImages(preload);
	
	$("#quicklinks ul li:not(:last)").addClass('sep');
	$("ul#legallinks li:not(:last)").addClass('sep');
	$("ul.csc-menu li:not(:last)").addClass('sep');
	
	$(".frontEndEditIcons").parent().addClass("editIconLink");
	
	// Accordion Menu
	$("#accordion").accordion();
	$("#finder").animate({opacity: 1}, 2000, 'linear', function() {
		if ($.browser.msie && ($.browser.version == "6.0")) {
			$("#finder").css({filter: 'none;'});
		}
	});
	
	if( $('#searchResults').length){
		$("#searchResults").filterSearch({searchMenu:'#searchMenu',res:'.pl_products_wrapper',paging:true,priceFinder:'#price'});
		$('.priceFrom, .priceTo, .radius', "#searchMenu").numeric();
		
		$('.radius, .location, .location_fr', "#searchMenu").keydown(function(e){
			if (e.keyCode == 13) {
				$(this).parents("form").submit();
				return false;
			}
		});	
		$('.priceFrom, .priceTo', "#searchMenu").keydown(function(e){
			if (e.keyCode == 13) {
				$("#searchMenu a.priceUpdate").trigger("click");
				return false;
			}
		});	
	}
	if( $('#specialsFormNew').length){
		$('.radius', '#specialsFormNew').val(50);
		$('.priceFrom, .priceTo, .radius', '#specialsFormNew').numeric();
		if ($.browser.msie && ($.browser.version < "8.0")) {
			$('ul.sorter li:eq(0)', '#specialsFormNew').css("z-index",15);
		}

		$('.priceFrom, .priceTo, .radius, .location, .location_fr', '#specialsFormNew').keydown(function(e){
			if (e.keyCode == 13) {
				$(this).parents("form").submit();
				return false;
			}
		});													 
	}
	
	// Country Selector
	$(".country_box").mouseenter(function() {
		$(this).addClass('over');
		$("#otherlang").addClass('over');
	}).mouseleave(function() {
		$(this).removeClass('over');
		$("#otherlang").removeClass('over');
	});
	
	// Branches Selector
	$(".see_branches").mouseenter(function() {
		$(this).addClass('over');
	}).mouseleave(function() {
		$(this).removeClass('over');
	});
	
	// Rollover of the ShareIt icon
	$(".addthis_button_compact").mouseenter(function() {
		$(this).children('img').attr('src','fileadmin/templates/images/icons/shareit_icon_over.gif');
	}).mouseleave(function() {
		$(this).children('img').attr('src','fileadmin/templates/images/icons/shareit_icon.gif');
	});
	
	$(".promoWrapper").singleElementViewSlideshowHome(); // Latest Promotions in Home Page -- singleElementViewSlideshowHome
	$(".slideshowItems").singleElementViewSlideshow();	 // Slideshow
	
	$("a[rel|=external]").attr('target', '_blank');
	
	$("input.submit").replaceWith('<a href="#" class="sendit">' + $(this).attr('value') + '</a>');
	$("input.submit_location").replaceWith('<a href="#" class="send_location">' + $(this).attr('value') + '</a>');
	$("input.update_location").replaceWith('<a href="#" class="sendit">Update</a>');
	$("input.update_location_fr").replaceWith('<a href="#" class="sendit">' + $("input.update_location_fr").attr('value') + '</a>');
	
	$(".send_location").click(function(event) {
		event.preventDefault();
		searchLocations();
		return false;
	});
	$('input#addressInput').keydown(function(e){
		if (e.keyCode == 13) {
			searchLocations();
			return false;
		}
	});
	$(".sendit").click(function(event) {
		event.preventDefault();
		$(this).parents('form').submit();
	});

	
	// Mobile Offices Selector redirect on change
	$(".mobile_offices_selector").change(function () {
		$("select option:selected").each(function () {
			$("#mobileOfficesForm").attr("action", $(this).attr("href"));
			$("#mobileOfficesForm").submit();
		});
	});
	
	// Specials State Selector redirect on change
	$(".state.styled").change(function () {
		$("select option:selected").each(function () {
			$("#specialsForm").attr("action", $(this).attr("href"));
			$("#specialsForm").submit();
		});
	});
	
	// Form validation [START]
	

	
	$(".validate").each(function() {
		$(this).validate({
			focusInvalid: false,
			/*rules: {
				emailAddress: {
					email: true
				}
			},
			messages: {
				emailAddress: "Please enter a valid email address."
			},*/
			errorLabelContainer: $(this).find('.errorLog')
		});
	});
	
	$.validator.addMethod("required_fr", function(value, element) {
		if ($(element).val().length > 0) {
			return true;
		}
		else return false;
	}, "Ce champs est obligatoire");
	
	$.validator.addMethod("required_location", function(value, element) {
		if ($(element).val().length > 0) {
			if ($(element).val() == 'Your Address/Postal Code') return false;
			return true;
		}
		else return false;
	}, "This field is required");
	
	$.validator.addMethod("required_location_fr", function(value, element) {
		if ($(element).val().length > 0) {
			if ($(element).val() == 'Votre adresse/Code Postal') return false;
			return true;
		}
		else return false;
	}, "Ce champs est obligatoire");
	
	$.validator.addMethod("email_fr", function(value, element) {
		return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
	}, "SVP entrer une adresse courriel valide");
	
	$.validator.addMethod("zipcode", function(value, element) {
		if (($("#00N30000000kHZh").val() != "" && $("#00N30000000kHZk").val() != "") || $("#00N30000000hRkX").val() != "") {
			return true;
		} else {
			return false;
		}
	}, "Please enter City/State OR Zip Code");
	$.validator.addMethod("zipcode_fr", function(value, element) {
		if (($("#00N30000000kHZh").val() != "" && $("#00N30000000kHZk").val() != "") || $("#00N30000000hRkX").val() != "") {
			return true;
		} else {
			return false;
		}
	}, "Veuillez entrer Ville/Province ou Code Postal");
	$.validator.addMethod("zipcodevalid", function(value, element) {
		if ($(element).val().length > 0) {
			var strValue = $(element).val();
			var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4})$/
				if(!objRegExp.test(strValue)) {
					return false;
				} else {
					return true;
				}
		} else {
			return true;
		}
	}, "Please enter a valid Zip Code");
	$.validator.addMethod("zipcodevalidcanada", function(value, element) {
		if ($(element).val().length > 0) {
			var strValue = $(element).val();
			var objRegExp = /^([a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d)$/
				if(!objRegExp.test(strValue)) {
					return false;
				} else {
					return true;
				}
		} else {
			return true;
		}
	}, "Please enter a valid Zip Code");
	$.validator.addMethod("zipcodevalidcanada_fr", function(value, element) {
		if ($(element).val().length > 0) {
			var strValue = $(element).val();
			var objRegExp = /^([a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d)$/
				if(!objRegExp.test(strValue)) {
					return false;
				} else {
					return true;
				}
		} else {
			return true;
		}
	}, "Veuillez entrer un code Postal valide");
	$.validator.addMethod("phonenumbervalid", function(value, element) {
		if ($(element).val() >= 1000000000 && $(element).val() <= 9999999999) {
			return true;
		} else {
			return false;
		}
	}, "Please enter a valid 10 digit Phone");
	$.validator.addMethod("phonenumbervalid_fr", function(value, element) {
		if ($(element).val() >= 1000000000 && $(element).val() <= 9999999999) {
			return true;
		} else {
			return false;
		}
	}, "Veuillez entrer un num&eacute;ro de t&eacute;l&eacute;phone valide de 10");
	$.validator.addMethod("datevalid", function(value, element) {
		if ($(element).val().length > 0) {
			var strValue = $(element).val();
			var objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/
			  if(!objRegExp.test(strValue))
			    return false;
			  else{
			    var strSeparator = strValue.substring(2,3) 
			    var arrayDate = strValue.split(strSeparator); 
			    var arrayLookup = { '01' : 31,'03' : 31, 
			                        '04' : 30,'05' : 31,
			                        '06' : 30,'07' : 31,
			                        '08' : 31,'09' : 30,
			                        '10' : 31,'11' : 30,'12' : 31}
			    var intDay = parseInt(arrayDate[1],10); 
			    if(arrayLookup[arrayDate[0]] != null) {
			      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
			        return true;
			    }
			    var intMonth = parseInt(arrayDate[0],10);
			    if (intMonth == 2) { 
			       var intYear = parseInt(arrayDate[2]);
			       if (intDay > 0 && intDay < 29) {
			           return true;
			       }
			       else if (intDay == 29) {
			         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
			             (intYear % 400 == 0)) {
			             return true;
			         }   
			       }
			    }
			  }  
			  return false;
		} else {
			return true;
		}
	}, "Please enter a valid Expected Delivery Date");
	$.validator.addMethod("servicetype", function(value, element) {
		var serviceTypes = document.getElementsByName("servicetype");
		var i;
		var pass = false;
		for(i=0; i < serviceTypes.length; i++){
			if(serviceTypes[i].checked){
				pass = true;
				return true;
			}	
		}
		return false;
	}, "Please select at least one service type to proceed");
	$.validator.addMethod("recaptcha_response_field", function(value, element) {
		if (validateCaptcha() == "Invalid"){
			Recaptcha.reload();
			return false;
		}
		else return true;
	}, "The visual confirmation code you submitted was incorrect");
	$.validator.addClassRules("zipcode", {
		zipcode: true,
		zipcodevalid: true
	});
	$.validator.addClassRules("zipcodevalid", {
		zipcodevalid: true
	});
	$.validator.addClassRules("zipcodecanada", {
		zipcode: true,
		zipcodevalidcanada: true
	});
	$.validator.addClassRules("zipcodecanada_fr", {
		zipcode_fr: true,
		zipcodevalidcanada_fr: true
	});
	$.validator.addClassRules("zipcodevalidcanada", {
		zipcodevalidcanada: true
	});
	$.validator.addClassRules("phonenumbervalid", {
		phonenumbervalid: true
	});
	$.validator.addClassRules("phonenumbervalid_fr", {
		phonenumbervalid_fr: true
	});
	$.validator.addClassRules("datevalid", {
		datevalid: true
	});
	$.validator.addClassRules("required_fr", {
		required_fr: true
	});
	$.validator.addClassRules("email_fr", {
		required_fr: true,
		email_fr: true
	});
	$.validator.addClassRules("location", {
		required: true,
		required_location: true
	});
	$.validator.addClassRules("location_fr", {
		required_fr: true,
		required_location_fr: true
	});
	$.validator.addClassRules("servicetype", {
		servicetype: true
	});
	$.validator.addClassRules("recaptcha_response_field", {
		recaptcha_response_field: true
	});
	$(".tovalidate").validate({
		   onfocusout: false,
		   onkeyup: false,
		   onclick: false
	});
	$(".request_service_validate").validate({
		   onfocusout: false,
		   onkeyup: false,
		   onclick: false,
		   submitHandler: function(form) {
				if ($(form).attr('name')=='serviceRequestForm') {
					if ($(form).attr('action')) {
						(form).submit();
					}
					else {
						buildJson();
						(form).submit();
					}
				}
				
			}
	});
	$(".request_status_validate").validate({
		   onfocusout: false,
		   onkeyup: false,
		   onclick: false,
		   submitHandler: function(form) {
				if ($(form).attr('name')=='requeststatus') {
					getStatus();
				}
			}
	});
	// Form validation [END]

	// Rollover PNG Images for IE6
	if ($.browser.msie && ($.browser.version == "6.0")) {
		$('.virtual_tour_pod .linkto a').toggleOverClassToParent();
		$('.video_pod .linkto a').toggleOverClassToParent();
		$('a.virtualTourLink').toggleOverClassToParent();
		$('a.videoLink').toggleOverClassToParent();
	}
	
	// Guide text into input fields, remove onfocus
	$(".guide").each(function() {
		$(this).attr("value", $(this).attr("alt"));
		$(this).focusin(function() {
			if ($(this).attr("value") == $(this).attr("alt")) {
				$(this).attr("value", "");
			}
			$(this).parents('.inputWrapper').addClass("focused");
		}).focusout(function(eventObject) {
			if ($(this).attr("value") == "") {
				$(this).attr("value", $(this).attr("alt"));
			}
			$(this).parents('.inputWrapper').removeClass("focused");
		});
	});
	
	
	$(".cmlTabs").each(function(){
		$(this).cmlTabs();
	});// Tabs
	$(".carousel ul").jcarousel();	// Carousel
	
	// Local Offers / Featured Products
	$('#localOffersContainer').append($('#localOffers'));
	
	$(".horizontalCarousel ul","#mainContentArea").jcarousel({
		vertical: true,
		start: 1,
		height:142,
		offset: 1,
		scroll: 2												 
	});
	
	// Accordion for FAQ section
	jQuery('#faqAccordion').accordion({
		autoHeight: false,
	    active: ".open"
	});
		
	if( $('select.styled').length )
		$('select.styled').selectbox();	// Style select lists
		
	if( $('input:text.styled').length )
		$('input:text.styled').textfield();	// Style textfields
	
	$('.specialsHeader .rollover').each(function(){
					$(this).rollover("right"); //rollovers!
	});
	
	if( $('#searchResults .rollover').length )
		$('#searchResults .rollover').rollover("bottom");
	
	$('.pod_large .item:even').addClass('odd');			// Adds odd class for styling
	$('.pod_large').find('.item h6 a').append('<span></span>');		// Fix for IE6
	
	// Adds border class on ULs with at least one LI
	$('.pod ul.normal_xlinks').each(function() {
		if ($(this).children('li').size() > 0) {
			$(this).addClass('border');
		}
	});
	
	if( $("#showMoreBranches").length )
	{
		var tar = $('#searchMenu .contents');
		var capturedh = tar.find(".category.c1").outerHeight()+126;
		
		$("#showMoreBranches").click(function(e){
				e.preventDefault();
				var i = $(this);
				if(i.hasClass("active")==true){
					if ($.browser.msie && ($.browser.version == "6.0"))
						tar.animate({'height':'255px'},400);
					else
						tar.animate({'height':'261px'},400);
					i.removeClass("active").text("more options");
				}
				else{
					tar.animate({'height':capturedh},400);
					i.addClass("active").text("less options");
				}
					
		});
	}
	
	// Styled Scroll Bar addition to Styled Select List
	$("#_container").css({"display": "block", "overflow": "hidden"}).children("ul").wrap("<div/>");
	
	if( $('dd:not(.dropdown) #_container').length)
		$('dd:not(.dropdown) #_container').children("div").css({"overflow": "auto", "height": "127px"}).jScrollPane({showArrows:true});
	$('#_container').css({"display": "none"});
	
	$('.lpInviteChatTbl').parent().addClass("livechatwrapper");
	
	$('a.live_chat').replaceWith("<a id=\"_lpChatBtn\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='chat4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat4527793','width=475,height=400,resizable=yes');return false;\" class=\"live_chat\">Live Chat</a>");
	$('a.live_chat_modsafe').replaceWith("<a id=\"_lpChatBtn\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='chat4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat4527793','width=475,height=400,resizable=yes');return false;\" class=\"live_chat\">Click to Chat</a>");
	$('li.live_chat').replaceWith("<li class=\"live_chat\"><a id=\"_lpChatBtn\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='chat4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat4527793','width=475,height=400,resizable=yes');return false;\" class=\"live_chat\">Live Chat</a></li>");
	$('ul.support_fr a.live_chat').replaceWith("<a id=\"_lpChatBtn\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=Canada - French&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='chat4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=Canada - French&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat4527793','width=475,height=400,resizable=yes');return false;\" class=\"live_chat\">Clavardage en direct</a>");
	$('li.live_chat_text').replaceWith("<li class=\"live_chat_text\"><a id=\"_lpChatBtn\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='chat4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat4527793','width=475,height=400,resizable=yes');return false;\" class=\"live_chat_text\">Live Chat</a></li>");
	$('li.live_chat_fr_text').replaceWith("<li class=\"live_chat_fr_text\"><a id=\"_lpChatBtn\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=Canada - French&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='chat4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=Canada - French&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat4527793','width=475,height=400,resizable=yes');return false;\" class=\"live_chat_fr_text\">Clavardage en direct</a></li>");
	$('a.live_chat_btn').replaceWith("<a id=\"_lpChatBtn\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='chat4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToChat&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat4527793','width=475,height=400,resizable=yes');return false;\" class=\"live_chat_btn\">Live Chat</a>");
	
	$('a.click_to_call').replaceWith("<a id=\"_lpChatBtn1\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='call4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'call4527793','width=472,height=320,resizable=yes');return false;\" class=\"click_to_call\" >Click to Call</a>");
	$('li.click_to_call').replaceWith("<li class=\"click_to_call\"><a id=\"_lpChatBtn1\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='call4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'call4527793','width=472,height=320,resizable=yes');return false;\" class=\"click_to_call\" >Click to Call</a></li>");
	$('ul.support_fr a.click_to_call').replaceWith("<a id=\"_lpChatBtn1\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=Canada - French&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='call4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=Canada - French&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'call4527793','width=472,height=320,resizable=yes');return false;\" class=\"click_to_call\" >Cliquez pour Discuter</a>");
	$('li.click_to_call_text').replaceWith("<li class=\"click_to_call_text\"><a id=\"_lpChatBtn1\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=English&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='call4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=English&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'call4527793','width=472,height=320,resizable=yes');return false;\" class=\"click_to_call_text\" >Click to Call</a></li>");
	$('li.click_to_call_fr_text').replaceWith("<li class=\"click_to_call_fr_text\"><a id=\"_lpChatBtn1\" href='https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=Canada - French&byhref=1&imageUrl=http://www.modspace.com/images/liveperson' target='call4527793'  onClick=\"lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/4527793/?cmd=file&file=visitorWantsToTalk&site=4527793&SESSIONVAR!skill=Canada - French&imageUrl=http://www.modspace.com/images/liveperson&referrer='+escape(document.location); lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'call4527793','width=472,height=320,resizable=yes');return false;\" class=\"click_to_call_fr_text\" >Cliquez pour Discuter</a></li>");

/*	$('p.print a').popupWindow({ 
		height:700, 
			width:900,
		//centerScreen:1,
		centerBrowser:1,
		scrollbars:1,
		menubar:1
	});*/


	$('.bulletOpts').each(function(){
		$(this).bulletize();
	});
	
	$(".carousel").css("visibility", "visible");
	$(".cmlTabs").css("visibility", "visible");
	
	if ( typeof( window[ 'printThis' ] ) != "undefined" ) {
		setTimeout('printMe()', 1000);
	}
	
	// Get referring site
	var referrerCookie = $.cookie('referrer');
	if(referrerCookie==null) {
		if (document.referrer) var referrer = document.referrer.match(/\w+:\/\/[^\/]+/)[0];
		else var referrer = location.href.match(/\w+:\/\/[^\/]+/);
		$.cookie('referrer', referrer);
		referrerCookie = referrer;
	}
	$("input.lead_source").attr('value', referrerCookie);
	
	// PNG Fix
	$("body").children().each(function() {
		if ($(this).attr("id").indexOf("Menu") >= 0) {
			$(this).supersleight({apply_positioning: false});
		} else {
			$(this).supersleight();
		}
	});
	
	// Request Service Form
	if ( $('#showCalendar').length ) {
		checkQueryString();
		checkRequest();
		$("#showCalendar").html($("#moveTable").html());
		$("#moveTable").html('');
		prepcalendar('',ccm,ccy);
	}
		if( $('#modsafe_form').length )
		{
			var form = $('#modsafe_form');
			
			$('span.textField').children('input').wrap('<span></span>');
			
			$('.popupWindowLink').bind('click',function(e){
				e.stopPropagation();
				e.preventDefault();
				window.open ( $(this).attr("href"), "","location=1,status=1,scrollbars=1, width=800,height=550");
			});
			
			if($.browser.msie && $.browser.version<=6)
			{
					var mIndex = $('#order_progress').children('.active').index();
					$('#order_progress').children('.active').addClass('active'+(mIndex+1));
					
					$('#Step3,#Step2,#Step1,#placeOrder').mouseover(function(){$(this).addClass('ie6hover_'+$(this).attr('id'));}).mouseout(function(){$(this).removeClass('ie6hover_'+$(this).attr('id'));});
			}
			
			//selectBoxes with controls
		//	$('select.styled').parent().find('input').bind('focus',function(e){

		//	});
			
			//step 2 validation
			if( $('#Step1').length )
			{
				form.submit(function(){
					var va = true;
					if( $('#Commercial_Use:checked').val()==1 || $('#Commercial_Use:checked').val()=="on" )
					{
						$('#Commercial_UseLabel').hide();
					}
					else
					{	
						$('#Commercial_UseLabel').show();
						va = false;
					}
					
					if($('#zip').val().length<=1 )
					{
						if( $('#zipLabel').length ){
								
						}
						$('#zipLabel').html('Field is Required').show();
						$('#networkErrorLabel').hide();
						$('#zip').parent().parent().addClass('error');
						va = false;
					}
					else
					{
						$('#zipLabel').hide();
						$('#networkErrorLabel').hide();
						$('#zip').parent().parent().removeClass('error');
					}
					
					
					if(va) return true;
					else return false;
					
				});
			}
			else if( $('#placeOrder').length )
			{
				$('.selectbox-wrapper').css({"overflow": "hidden","height":"127","display":"block"}).find('div:eq(0)').wrap('<div></div>').css({"height":"127px","overflow":"auto"}).parent().parent().hide();
				form.submit(function()
				{
					var va = true;
					//submit for the final step? Is this going to be cut and placed in a different webpage?
					var deAld = $('.radio[name="CardType"]:checked','#modsafe_form').val();
					if(!deAld)
					{
						$('#CreditCardTypeLabel').show();	
						va=false;
					}
					else
					{
						$('#CreditCardTypeLabel').hide();
					}
					
					var deAld=true;
					
					function textFieldVal( el, len )
					{
						if( el.val().length<len )
						{
							el.parent().parent().addClass('error');
							return 1;
						}
						else
						{
							el.parent().parent().removeClass('error');
							return 0;
						}
					}
					
					var deAld=true;
					deAld = textFieldVal( $('#cardHolder'),3 ) ? false : deAld;
					deAld = textFieldVal( $('#cardNumber'),4 ) ? false : deAld;
					deAld = textFieldVal( $('#ccv_number'),2 ) ? false : deAld;
					
					deAld = textFieldVal( $('.selectbox:eq(1)'),3 ) ? false : deAld;
					
					$('.selectbox').each(function(){
						deAld = textFieldVal( $(this),2 ) ? false : deAld;
						
						if( $(this).val()!= $(this).parent().parent().find('option:eq(0)').text() && $(this).val().length>1 )
						{
							$(this).parent().parent().removeClass('error');
						}
						else
						{
							va=false;
							$(this).parent().parent().addClass('error');
						}
					});
					
					if(deAld==false)
					{
						$('#creditInfoValidation').show();	
						va=false;
					}
					else
					{
						$('#creditInfoValidation').hide();
					}
					
					if( $('#agreeToTerms:checked').val()=="on" || $('#agreeToTerms:checked').val()==1 )
					{
						$('#agreeToTermsLabel').hide();
					}
					else
					{
						$('#agreeToTermsLabel').show();
						va=false;
					}
					
					$('#creditcarderrorLabel').hide();
					
					if(va)
						return true;	
					else
						return false;
						
				});
				
			}
			else if( $('#Step3').length )
			{
				$('.viewDetails a').bind('click',function(e){
					e.preventDefault();
					e.stopPropagation();
					$(this).toggleClass('active');
					
					$(this).parent().next('.details').stop(true,true).slideToggle();
				});
			}
			else if( $('#Step2').length )
			{
				var currentTime = new Date();
				var startDate = (currentTime.getMonth()+1)+'/'+(currentTime.getDate())+'/'+currentTime.getFullYear();
				
				
				$('#requesteddate').simpleDatepicker({ startdate: startDate, enddate: ('12/31/'+(currentTime.getFullYear()+1)), overHead: 3 });
				$('.selectbox-wrapper').css({"overflow": "hidden","height":"127","display":"block"}).find('div:eq(0)').wrap('<div></div>').css({"height":"127px","overflow":"auto"}).parent().parent().hide();
				
				var ownIns = $('#own_insurance:checked');
				
				var txtDiv = $('#textareaDiv');
				txtDiv.wrap("<div style='position:relative;' class='textareaWrapper'></div>");
				var cvr = document.createElement("div");
				$(cvr).css('opacity',0);
				cvr.className="cover";
				cvr.id="cvr";
				txtDiv.parent().append(cvr);
				
				if ($.browser.msie && ($.browser.version <= "7.0")) {
					var areaCover = function( $this, action, chkbx )
					{
						if(action){
							$this.show();
							$this.fadeTo(600,0.4, function(){
								$this.prev().css({'overflow':'hidden'});
							});
							chkbx.attr('disabled', true);
						}
						else
						{
							$this.fadeOut(600, function(){
								$this.prev().css({'overflow':'auto'});
							});
							chkbx.attr('checked', false).removeAttr('disabled');
							
						}
					}
				}
				else
				{
					var areaCover = function( $this, action, chkbx )
					{
						if(action){
							$this.css('opacity',0).show();
							$this.fadeTo(800,0.4);
							chkbx.attr('checked', false).attr('disabled', true);
						}
						else
						{
							$this.fadeOut(500);
							chkbx.removeAttr('disabled');
						}
					}
				}
				
				if( ownIns.length===0 )
				{
					areaCover( $("#cvr"), true, $('#acceptTerms') );
				}
				
				
				
				$('#own_insurance').bind('click',function(){
					areaCover( $("#cvr"), false, $('#acceptTerms') );
				});
				$('#damageWaiver').bind('click',function(){
					areaCover( $("#cvr"), true, $('#acceptTerms') );
				});
				
				
				var cont = $( '.contact_information' ),
				    main = $(cont[0]).find('.main'),
				    target = $(cont[1]).find('.main'),
					mainVal = {},
					targetVal = {};
					
				//binds Value Change
				(function(){
					var checkBox = document.getElementById('sameAddress');
					if( checkBox )
					{
						var active = checkBox.checked,
							siteContact = $('#siteContact'),
							siteContactPhone = $('#siteContactPhone'),
							deliveryAddress = $('#deliveryAddress'),
							deliveryAddress2 = $('#deliveryAddress2'),
							stateCityZip = $('#state_city_zip_input');
							
						var firstName = $('#firstName'),
							lastName = $('#lastName'),
							Address = $('#Address'),
							Address2 = $('#Address2'),
							City = document.getElementById('City'),
							State_input = $('#State_input'),
							State = $('#State'),
							ZipCode = $('#ZipCode'),
							Phone = $('#Phone');
							
						var tmp,
							tmp2,
							mainVal = {},
							targetVal = {};
							
						var setValues = function( tmp, bool ) {
							if( active == bool )
							{
								firstName.get(0).value = tmp.substr( 0, tmp.indexOf(' ') );
								lastName.get(0).value = tmp.substr( tmp.indexOf(' ') + 1 );
									
								Address.get(0).value = deliveryAddress.val();
								Address2.get(0).value = deliveryAddress2.val();
								Phone.get(0).value = siteContactPhone.val();
									
								tmp2 = stateCityZip.val();
								tmp  = tmp2.substr( 0, tmp2.indexOf(',') );
								tmp2 = tmp2.replace( tmp, '').substr( 2 );
								
								mainVal['siteContact'] = siteContact.val();
								mainVal['siteContactPhone'] = siteContactPhone.val();
								mainVal['siteContactPhone'] = siteContactPhone.val();
								mainVal['deliveryAddress'] = deliveryAddress.val();
								mainVal['deliveryAddress2'] = deliveryAddress2.val();
								mainVal['stateCityZip'] = stateCityZip.val();
								mainVal['siteContactPhone'] = siteContactPhone.val();
								
								targetVal['firstName'] = firstName.val();
								targetVal['lastName'] = lastName.val();
								targetVal['Address'] = Address.val();
								targetVal['Address2'] = Address2.val();

								if( $('#state_city_zip option:selected').val() != $('#state_city_zip').find('option')[0].value )
								{
									City.value = tmp;
									State_input.get(0).value = tmp2.substr( 0, tmp2.indexOf(',') );
									State.get(0).value = tmp2.substr( 0, tmp2.indexOf(',') );
									ZipCode.get(0).value = tmp2.substr( tmp2.indexOf(',') + 2 );
								
									targetVal['City'] = City.value;
									targetVal['State_input'] = State_input.val();
									targetVal['State'] = State_input.val();
									targetVal['ZipCode'] = ZipCode.val();
								}
								targetVal['Phone'] = Phone.val();
								
							}
						}
							
						mainVal['siteContact'] = siteContact.val();
						mainVal['siteContactPhone'] = siteContactPhone.val();
						mainVal['siteContactPhone'] = siteContactPhone.val();
						mainVal['deliveryAddress'] = deliveryAddress.val();
						mainVal['deliveryAddress2'] = deliveryAddress2.val();
						mainVal['stateCityZip'] = stateCityZip.val();
						mainVal['siteContactPhone'] = siteContactPhone.val();
						
						targetVal['firstName'] = firstName.val();
						targetVal['lastName'] = lastName.val();
						targetVal['Address'] = Address.val();
						targetVal['Address2'] = Address2.val();

						if( $('#state_city_zip option:selected').val() != $('#state_city_zip').find('option')[0].value )
						{
							targetVal['City'] = City.value;
							targetVal['State_input'] = State_input.val();
							targetVal['State'] = State_input.val();
							targetVal['ZipCode'] = ZipCode.val();
						}
						targetVal['Phone'] = Phone.val();

						$(checkBox).bind('click', function(e){
							if( !active ) //if the checkbox is just checked
							{
								tmp = siteContact.val().replace(/^ +/gm, '');
								setValues( tmp, false );
							}
							active = checkBox.checked;
						});
						
						$('#siteContact, #siteContactPhone, #deliveryAddress, #deliveryAddress2').bind('blur', function(e) {
								if( mainVal[ this.id ] !== this.value && document.getElementById('sameAddress').checked ) {
									var tmp = siteContact.val().replace(/^ +/gm, '');
									setTimeout( function(){
										setValues( tmp, true );
									}, 128 );
								}
								mainVal[ this.id ] = this.value;
						});
						$('#state_city_zip').change( function() {
							if( mainVal[ 'state_city_zip_input' ] !== this.value && document.getElementById('sameAddress').checked ) {
								$('#state_city_zip_input').get(0).value = this.value;
								setTimeout( function(){
									setValues( tmp, true );
								}, 40 );
							}
							mainVal[ 'state_city_zip_input' ] = this.value;
						});
						
						$('#firstName, #lastName, #Address, #Address2, #State_input, #City, #ZipCode').bind('blur', function() {
							if( targetVal[ this.id ] !== this.value && document.getElementById('sameAddress').checked ) {
								document.getElementById('sameAddress').checked = false;
								active = !active;
							}
							targetVal[ this.id ] = this.value;
						});
						
					$('#topLabel').bind('click', function( e ) {
							e.preventDefault();
							e.stopPropagation();
							
							if( !active )
							{
								tmp = siteContact.val().replace(/^ +/gm, '');
								setValues( tmp, false );
							}
							active = !active;
							document.getElementById('sameAddress').checked = active;
					});
						
					}
				})();
				form.submit(function()
				{
					var va=true;
					var quant=0;
					
					$('.product_information2 input.quantity','#modsafe_form').each(function(){
						var mVal = parseInt($(this).val());
						if( !isNaN( mVal) )
						{
							quant=quant+parseInt(mVal);
							if(mVal>=5)
								$(this).parent().parent().addClass('error');	
							else
								$(this).parent().parent().removeClass('error');
						}
						else if( $(this).val().length==0)
						{
							$(this).val(0);
							$(this).parent().parent().removeClass('error');
						}
						else
						{
							$(this).parent().parent().addClass('error');
							quant=-9999;
						}
					});
					
					if(quant>5)
					{
						
						$('html, body').animate({scrollTop: ($('#requesteddate').offset().top-240) }, 'normal');
						//YscrollTop('requesteddate' );
						va=false;
						$('#quantityLabel').show();
					}
					else
						$('#quantityLabel').hide();
						
					if(quant<=0)
					{
						
						$('html, body').animate({scrollTop: ($('#requesteddate').offset().top-240) }, 'normal');
						//YscrollTop('requesteddate' );
						va=false;
						$('#quantityLabelInvalid').show();
					}
					else
						$('#quantityLabelInvalid').hide();

					mVal = $('#requesteddate').val();
					var mValpart =  parseInt( mVal.replace( /\d.*\// ,'') );
					
					if(mValpart < (new Date().getFullYear()) || isNaN(mValpart) )
					{
						if(va==true) $('html, body').animate({scrollTop: ($('#requesteddate').offset().top-120) }, 'normal');
						va=false;
						$('#requesteddate').parent().parent().addClass('error');
						$('#requestDate').show();
					}
					else
					{
						mVal = mVal.split('/');
						mVal[0]=parseInt(mVal[0]);
						mVal[1]=parseInt(mVal[1]);
						
						if( mVal[0] > (new Date().getMonth()+1) )
						{
							$('#requesteddate').parent().parent().removeClass('error');
							$('#requestDate').hide();
						}
						else if( (mVal[1] <= (new Date().getDate()) && mVal[0] == (new Date().getMonth()+1)) || ( mVal[0] < (new Date().getMonth()+1 ) ))
						{
							if(va==true) $('html, body').animate({scrollTop: ($('#requesteddate').offset().top-120) }, 'normal');
							va=false;
							$('#requesteddate').parent().parent().addClass('error');
							$('#requestDate').show();
						}
						else if( mVal[1] > (new Date().getDate()) && mVal[0] == (new Date().getMonth()+1) )
						{
							$('#requesteddate').parent().parent().removeClass('error');
							$('#requestDate').hide();
						}
					}
					
					mVal = parseInt( $('#length_of_use').val() );
					
					if( (mVal>=3 && mVal<=36)  )
					{
						$('#length_of_use').parent().parent().removeClass('error');
						$('#lengthOfUseLabel').hide();
					}
					else
					{
						$('#length_of_use').parent().parent().addClass('error');
						$('#lengthOfUseLabel').show();
						if(va==true) $('html, body').animate({scrollTop: ($('#length_of_use').offset().top-120) }, 'normal');
						va=false;
					}
					
					if( $('#acceptTerms:checked').val() && $('#own_insurance:checked').val() )
					{
						$('#InsuranceAccept').hide();
					}
					else if( $('#own_insurance:checked').val() )
					{
						if(va==true) $('html, body').animate({scrollTop: ($('#acceptTerms').offset().top-230) }, 'normal');
						va=false;
						$('#InsuranceAccept').show();
					}
					else if( $('#damageWaiver:checked').val() )
					{
						$('#InsuranceAccept').hide();
					}
					
					
					var deAld=true;
					
					function textFieldVal( el, len )
					{
						if( el.val().length<len )
						{
							el.parent().parent().addClass('error');
							return 1;
						}
						else
						{
							el.parent().parent().removeClass('error');
							return 0;
						}
					}
					
					deAld = textFieldVal( $('#siteContact'),3 ) ? false : deAld;
					deAld = textFieldVal( $('#siteContactPhone'),4 ) ? false : deAld;
					deAld = textFieldVal( $('#deliveryAddress'),3 ) ? false : deAld;
					//deAld = textFieldVal( $('#deliveryAddress2'),3 ) ? false : deAld;
					//deAld = textFieldVal( $('#_input'),3 ) ? false : deAld;
					
					if(deAld==false)
					{
						if(va==true) $('html, body').animate({scrollTop: ($('.delivery_information').offset().top-180) }, 'normal');
						$('#requiredFieldsLabel2').show();	
						va=false;
					}
					else
					{
						$('#requiredFieldsLabel2').hide();
					}
					
					deAld = $('.radio[name="tx_mdspmodsafe_pi1[deliveryInstructions]"]:checked','#modsafe_form').val();
					if(!deAld)
					{
						if(va==true) $('html, body').animate({scrollTop: ($('#DeliveryOptionLabel').offset().top-520) }, 'normal');
						$('#DeliveryOptionLabel').show();	
						va=false;
					}
					else
					{
						$('#DeliveryOptionLabel').hide();
					}
					
					deAld=true;
					deAld = textFieldVal( $('#firstName'),1 ) ? false : deAld;
					deAld = textFieldVal( $('#lastName'),1 ) ? false : deAld;
					deAld = textFieldVal( $('#Company'),2 ) ? false : deAld;
					//deAld = textFieldVal( $('#Title'),2 ) ? false : deAld;
					deAld = textFieldVal( $('#Phone'),2 ) ? false : deAld;
					//deAld = textFieldVal( $('#Fax'),2 ) ? false : deAld;
					deAld = textFieldVal( $('#Address'),2 ) ? false : deAld;
					//deAld = textFieldVal( $('#Address2'),3 ) ? false : deAld;
					deAld = textFieldVal( $('#City'),2 ) ? false : deAld;
					//deAld = textFieldVal( $('#State'),1 ) ? false : deAld;
					deAld = textFieldVal( $('#ZipCode'),2 ) ? false : deAld;
					
					
					
					if(deAld==false)
					{
						if(va==true) $('html, body').animate({scrollTop: ($('#requiredFieldsLabel').offset().top-20) }, 'normal');
						$('#requiredFieldsLabel').show();	
						va=false;
					}
					else
					{
						$('#requiredFieldsLabel').hide();
					}
					
					//State_input
					if( $('#State_input').val()!= $('#State').children('option:eq(0)').text() && $('#State_input').val().length>=2 )
					{
						$('#State_input').parent().parent().removeClass('error');
					}
					else
					{
						va=false;
						$('#State_input').parent().parent().addClass('error');
					}
					
					if( $('#state_city_zip_input').val()!= $('#state_city_zip').children('option:eq(0)').text() && $('#state_city_zip_input').val().length>2 )
					{
						$('#state_city_zip_input').parent().parent().removeClass('error');
						$('#CityStateZipLabel').hide();
					}
					else
					{
						if(va==true) $('html, body').animate({scrollTop: ($('#State').offset().top-170) }, 'normal');
						va=false;
						$('#state_city_zip_input').parent().parent().addClass('error');
						$('#CityStateZipLabel').show();
					}
					
					deAld = $('#Email').val();
					if( deAld.match(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i) )
					{
						$('#emailLabel').hide();
						$('#Email').parent().parent().removeClass('error');
					}
					else
					{
						$('#Email').parent().parent().addClass('error');
						if(va==true) $('html, body').animate({scrollTop: ($('#Email').offset().top + 140) }, 'normal');
						$('#emailLabel').show();
						va=false;
					}
					
					if(!va)	return false;
					else return true;
				});
			}
			
			if( $('#requesteddate').length )
			{	
				$('#calendarIcon').bind('click',function(e){e.stopPropagation();e.preventDefault();$('#requesteddate').trigger('click'); });
				$('#_container').css("width","294px");
				//$('#_container').css({"overflow": "hidden","height":"127","display":"block"}).find('div').css({"overflow": "auto","height":127,"display":"block"}).jScrollPane({showArrows:true});
				setTimeout(function(){ $('#_container').hide();},64);
			}
		}

	$("#finder dd a").css("position", "static");
	
	// Edit ModSafe Form
	$('#orderForm .change').bind('click',function(e){
		e.preventDefault();
		var frm = $('#orderForm');
		frm.attr('action', ($(this).attr('href') + '#' + $(this).attr('id') ) );
		
		document.forms["orderForm"].submit();
	});

});

function printMe() {
	window.print()
}

/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

function buildJson() {
	document.getElementById("jsonstring").value = getJsonString();
	$("#serviceRequestForm").attr('action', '/cs/serviceRequest');
	
}

function getJsonString(){
	var date = new Date();  
	var month = date.getMonth();
	month = month + 1;
	var jsonstring = "\"dateCreated\":" + "\"" + month + "/" + date.getDate() +"/" + date.getFullYear() + "\"," 
	+ "\"unitNumber\":" + "\"" + document.getElementById("unitnumber").value + "\","
	+ "\"requestStatusSynchCode\":\"Open\",";
	if (document.getElementById("leasenumber").value.length > 0)
		jsonstring = jsonstring + "\"leaseNumber\":" + "\"" + document.getElementById("leasenumber").value + "\",";
	if (document.getElementById("requesteddate").value.length > 0)
		jsonstring = jsonstring + "\"dateRequested\":" + "\"" + document.getElementById("requesteddate").value + "\",";
	if (document.getElementById("siteaddress").value.length > 0)
		jsonstring = jsonstring + "\"siteAddress\":" + "\"" + document.getElementById("siteaddress").value + "\"," ;
	if (document.getElementById("comments").value.length > 0)
		jsonstring = jsonstring + "\"comments\":" + "\"" + document.getElementById("comments").value + "\","; 
	
	jsonstring = "{" + jsonstring + getCustomer() + getServiceTypes() + "}";
	return jsonstring;
}

function getCustomer(){
	var customer;
	customer = "\"customer\":{\"customerFlag\":\"1\",\"phoneNumber\":" + "\"" + document.getElementById("phone").value + "\","
		+ "\"email\":" + "\"" + document.getElementById("email").value + "\","
		+ "\"lastName\":" + "\"" + document.getElementById("lastname").value + "\","
		+ "\"firstName\":" + "\"" + document.getElementById("firstname").value + "\",";
	if (document.getElementById("customernumber").value.length > 0)
		customer = customer + "\"customerNumber\":" + "\"" + document.getElementById("customernumber").value + "\",";
	if (document.getElementById("companyname").value.length > 0)
		customer = customer + "\"customerName\":" + "\"" + document.getElementById("companyname").value + "\",";
	if (location.host.toUpperCase().indexOf("MODSPACE.COM",0) != -1) customer = customer + "\"country\":" + "\"US\",";
	else if (location.host.toUpperCase().indexOf("MODSPACE.CA",0) != -1) customer = customer + "\"country\":" + "\"CA\",";
	var language = document.getElementById("language");
	if (language != null && language.value.length > 0)
		customer = customer + "\"language\":\""  + language.value + "\","; 
	else 
		customer = customer + "\"language\":" + "\"EN\",";
	var position = customer.lastIndexOf(",");
	customer = customer.substring(0, position) + "},"; 
	return customer;
}

function getServiceTypes(){
	var serviceTypes = document.getElementsByName("servicetype");
	var i;
	var service = "\"serviceTypes\":\"";
	for(i=0; i < serviceTypes.length; i++){
		if(serviceTypes[i].checked){
			service = service + serviceTypes[i].value + ",";
		}	
	}
	var position = service.lastIndexOf(",");
	service = service.substring(0, position);
	service = service + "\"";
	return service;  
}

function updateRequestField(fieldid){
	var requestfields = document.getElementsByName("requestfield");
	var i;
	var count = 0;
	var notempty = false;
	for (i = 0; i < requestfields.length; i++){
		if (requestfields[i].id == fieldid && requestfields[i].value.length > 0){
			notempty = true;
			break;
		}
	}
 
	if (notempty == true){
		for (i = 0; i < requestfields.length; i++){
			if (requestfields[i].id != fieldid && requestfields[i].value.length > 0){
				requestfields[i].value = "";
			}
		}
	}
}

function setStatus(results) {
	var div = document.getElementById("feedback");
	if (results.length > 0){
		div.style.display = "block";
	dwr.util.removeAllRows('requestStatusTable');

 	dwr.util.addRows("requestStatusTable", results, cellFunctions);
}
	else
		div.style.display = "none";
}

function getStatus() {
	var requestId = document.getElementById('request_id');
	var unitNumber = document.getElementById('unit_number');
	RequestStatus.getStatus(requestId.value,unitNumber.value, setStatus);
}

function getQueryParameter ( parameterName ) {
	  var queryString = window.top.location.search.substring(1);
	  var parameterName = parameterName + "=";
	  if ( queryString.length > 0 ) {
	    begin = queryString.indexOf ( parameterName );
	    if ( begin != -1 ) {
	      begin += parameterName.length;
	      end = queryString.indexOf ( "&" , begin );
	        if ( end == -1 ) {
	        end = queryString.length
	      }
	      return unescape ( queryString.substring ( begin, end ) );
	    }
	  }
	  return "null";
	}

function checkRequest() {
   var requestId = getQueryParameter("requestId");
   var unitNumber = getQueryParameter("unitNumber");
   if(requestId != null && requestId !="" && requestId !="null" && unitNumber != null && unitNumber !="" && unitNumber !="null") {
	   document.getElementById('request_id').value = requestId;
	   document.getElementById('unit_number').value = unitNumber;
	   getStatus();
   }
	    

}

function checkQueryString(){
	var querystring;
	var qstrings;
	var requestid = getQueryParameter("requestid");
	var thankyounote = getQueryParameter("thankyou");
	if(requestid != null && requestid !="" && requestid !="null" && thankyounote != null && thankyounote !="" && thankyounote !="null") {
		var failure = false;
		querystring = window.location.search.substring(1);
		if (querystring.length > 0){
			qstrings = querystring.split("&");
			if (qstrings.length > 1) {
				for (var i = 0; i < qstrings.length; i++){
					var keyvalues = qstrings[i].split("="); 
					if (keyvalues[0] == "thankyou"){	 
			 	             if(window.location.pathname.indexOf('fr') > 0 ) {
						thankyounote = "Merci d'avoir contacté ModSpace concernant votre demande de service. Nous vous contacterons bientôt pour confirmer les détails spécifiques à votre demande.";
					   } else {
						thankyounote = "Thank you for contacting ModSpace regarding your service request. We will be contacting you shortly to confirm the details specific to your request.";
					   }
					}
					if (keyvalues[0] == "requestid"){
						requestid = keyvalues[1];
					}
					if (keyvalues[0] == "notavailable"){
   					       if(window.location.pathname.indexOf('fr') > 0 ) {
						    thankyounote = "Merci d'avoir contacté ModSpace concernant votre demande de service. Malheureusement, nous ne pouvons pas traiter votre demande en ce moment.";
       					        } else {
						    thankyounote = "Thank you for contacting ModSpace regarding your service request. Unfortunately, we are unable to process your request at this time.";
					        }

						failure = true;
					}
				}
				if (failure == true)
					document.getElementById("thankyou").innerHTML = thankyounot;
				else {
					if(window.location.pathname.indexOf('fr') > 0 ) {
						thankyounote = thankyounote + " L'identification de votre demande est le: " + requestid;
					} else {
						thankyounote = thankyounote + " Your request id is: " + requestid;
					}
					document.getElementById("thankyou").innerHTML = thankyounote;
				}
			}
		}
	}
}

function validateCaptcha() {
	var returnstatus = "";
	recatchaValidator.validateReCaptchaData(Recaptcha.get_challenge(), Recaptcha.get_response(),"",
		  {  async: false, callback:function(status) { returnstatus = status; } });
	return returnstatus;
}
