$(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;'});
		}
	});
	
	// 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").singleElementViewSlideshow();	// Latest Promotions in Home Page
	$(".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>');
	
	$(".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("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("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").cmlTabs();		// Tabs
	$(".carousel ul").jcarousel();	// Carousel
	
	// Accordion for FAQ section
	jQuery('#faqAccordion').accordion({
		autoHeight: false,
	    active: ".open"
	});
		
	$('select.styled').selectbox();	// Style select lists
	
	$('.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');
		}
	});
	
	// Styled Scroll Bar addition to Styled Select List
	$("#_container").css({"display": "block", "overflow": "hidden"}).children("ul").wrap("<div/>");
	$('#_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>");
	$('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.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
	});
	
	$(".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+:\/\/[^\/]+/)[0];
		$.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);
	}

	$("#finder dd a").css("position", "static");

});

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;
}