/* Author: Chris Gaudreau - Chris@klickflow.com */

$(document).ready(function(){
  $("#disclaimerlink, .disclaimerlink").tooltip({
	  track: true, 
  	delay: 0, 
  	showURL: false, 
	  extraClass: "pretty", 
   	fixPNG: true, 
		opacity: 0.95, 
    left: -120, 
    bodyHandler: function() {return $('#Disclaimer').html();}
	});
});

function loadMap(LocationName)
{
	var mapMarkerPos = '';
	var mapCenterPos = '';
	var mapMarkerPositions=new Array(); 
	var mapCenterPositions=new Array(); 
	var mapContent=new Array();
	var mapTitles=new Array();
	mapMarkerPositions['TorontoOffice'] = new google.maps.LatLng(43.647316, -79.386234);
	mapCenterPositions['TorontoOffice']= new google.maps.LatLng(43.651873, -79.385377);
	mapContent['TorontoOffice'] = '<div id="mapcontent"><div id="mapicon"><img src="http://media.stanchierifamilylaw.com/sflweb/icon.gif" width="38px" height="38px"/></div><div id="bodyContent"><p class="mapTitle">Stanchieri Family Law</p><p><strong>Toronto Office</strong></p><br /><p>214 King Street West #216<br />Toronto ON<br />M5H 3S6</p></div><br class="brClear" /></div>';
	mapTitles['TorontoOffice'] = "Stanchieri Family Law - Toronto Office";
	mapMarkerPositions['RichmondHillOffice'] =new google.maps.LatLng(43.862896, -79.384468);
	mapCenterPositions['RichmondHillOffice']=  new google.maps.LatLng(43.867339, -79.384520);	
	mapContent['RichmondHillOffice'] = '<div id="mapcontent"><div id="mapicon"><img src="http://media.stanchierifamilylaw.com/sflweb/icon.gif" width="38px" height="38px"/></div><div id="bodyContent"><p class="mapTitle">Stanchieri Family Law</p><p><strong>Richmond Hill Office</strong></p><br /><p>1595-16th Avenue #301<br />Richmond Hill ON<br />ON L4B 3N9</p></div><br class="brClear" /></div>';
	mapTitles['RichmondHillOffice'] = "Stanchieri Family Law - Richmond Hill Office";	
	mapMarkerPositions['50EagleStreet'] = new google.maps.LatLng(44.044692, -79.482007);
	mapCenterPositions['50EagleStreet']=  new google.maps.LatLng(44.049249, -79.48115);	
	mapContent['50EagleStreet'] = '<div id="mapcontent"></div><div id="bodyContent"><p class="mapTitle">Superior Court of Justice</p><p>&nbsp;</p><br /><p>50 Eagle Street West<br />Newmarket, ON L3Y 6B1<br />905-853-4809</p></div><br class="brClear" /></div>';
	mapTitles['50EagleStreet'] = "Superior Court of Justice - 50 Eagle Street West";
	mapMarkerPositions['393UniversityAve'] = new google.maps.LatLng(43.653705, -79.387524);
	mapCenterPositions['393UniversityAve']=  new google.maps.LatLng(43.658262, -79.386667);		
	mapContent['393UniversityAve'] = '<div id="mapcontent"></div><div id="bodyContent"><p class="mapTitle">Superior Court of Justice</p><p>&nbsp;</p><br /><p>393 University Avenue<br />Toronto, ON M5G 1E6<br />416-327-2064</p></div><br class="brClear" /></div>';	
	mapTitles['393UniversityAve'] = "Superior Court of Justice - 393 University Avenue";
	mapMarkerPositions['311Jarvis'] = new google.maps.LatLng(43.659504, -79.375494);
	mapCenterPositions['311Jarvis']=  new google.maps.LatLng(43.664061, -79.374637);			
	mapContent['311Jarvis'] = '<div id="mapcontent"></div><div id="bodyContent"><p class="mapTitle">Ontario Court of Justice</p><p>&nbsp;</p><br /><p>311 Jarvis Street<br />Toronto, ON M5B 2C4<br />416-327-6874</p></div><br class="brClear" /></div>';	
	mapTitles['311Jarvis'] = "Ontario Court of Justice - 311 Jarvis Street";
	mapMarkerPositions['47Sheppard'] = new google.maps.LatLng(43.761824, -79.409204);
	mapCenterPositions['47Sheppard']=  new google.maps.LatLng(43.766381, -79.408347);			
	mapContent['47Sheppard'] = '<div id="mapcontent"></div><div id="bodyContent"><p class="mapTitle">Ontario Court of Justice</p><p>&nbsp;</p><br /><p>47 Sheppard Avenue East<br />Toronto, ON M2N 5X5<br />416-326-3592</p></div><br class="brClear" /></div>';	
	mapTitles['47Sheppard'] = "Ontario Court of Justice - 47 Sheppard Avenue East";	
	mapMarkerPositions['150Bond'] = new google.maps.LatLng(43.899643, -78.858815);
	mapCenterPositions['150Bond']=  new google.maps.LatLng(43.904200, -78.857958);			
	mapContent['150Bond'] = '<div id="mapcontent"></div><div id="bodyContent"><p class="mapTitle">Superior Court of Justice</p><p>&nbsp;</p><br /><p>150 Bond Street East<br />Oshawa, ON L1H 1A1<br />905-743-2800</p></div><br class="brClear" /></div>';	
	mapTitles['150Bond'] = "Superior Court of Justice - 150 Bond Street East";	
	mapMarkerPositions['7755Hurontario'] = new google.maps.LatLng(43.661115, -79.726425);
	mapCenterPositions['7755Hurontario']=  new google.maps.LatLng(43.665672, -79.725568);			
	mapContent['7755Hurontario'] = '<div id="mapcontent"></div><div id="bodyContent"><p class="mapTitle">Superior &amp; Ontario Court of Justice</p><p>&nbsp;</p><br /><p>7755 Hurontario Street<br />Brampton, ON L6W 4T<br />905-456-4700</p></div><br class="brClear" /></div>';	
	mapTitles['7755Hurontario'] = "Superior &amp; Ontario Court of Justice - 7755 Hurontario Street";	
	var MarkerPosition = mapMarkerPositions[LocationName];
	var CenterPosition = 	mapCenterPositions[LocationName];
	var MarkerContent = mapContent[LocationName];
	var MapTitle = mapTitles[LocationName];
	var myOptions = {
		zoom: 15,
		center: CenterPosition,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var infowindow = new google.maps.InfoWindow({
		content: MarkerContent
	});
	var marker = new google.maps.Marker({
		position: MarkerPosition,
		map: map,
		title:MapTitle
	});
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
	infowindow.open(map,marker);
}





function validateContactFormAjax()
{
	var Errors = '';
	
	$('#contactForm .requiredInput.email').each(function(){
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
				Errors += "Please Provide Your <strong>Email Address</strong><br />";
		} else {
			if (!validateEmail($(this).val())) { Errors += "Please Enter a Proper <strong>Email Address</strong><br />";}
		}
	});
	$('#contactForm .requiredInput.textArea,#contactForm .requiredInput.name, #contactForm .requiredInput.text:not(.email)').each(function(){
			if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
					Errors += "Please Provide Your <strong>" +  w_DefaultValues[$(this).attr('id')].substr(0,w_DefaultValues[$(this).attr('id')].indexOf('*')) + "</strong><br />";
			}
	});
	$('#contactForm .requiredInput.select').each(function(){
		
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
			MyValue = $(this).children(':first').text();
			MyValue = MyValue.substr(0,MyValue.indexOf('*'));
			Errors += "Please <strong>"+MyValue + "</strong><br />";
		}
	});	
	if (Errors != '')
	{ 
		showErrors(Errors);
	} else {
		// Do ajaxy stuff here
		var DataSet = {};
		$('#contactForm input,#contactForm select,#contactForm textarea').each(function(){
			DataSet[$(this).attr('id')] = $(this).val();
		})
		DataSet['ajax'] = 'true';
		var URL = document.location.href;
		$.post(URL, DataSet, function (data){
			if (data.indexOf('TRUE') != -1) 
			{
				window.location = "/legal-consultation-thank-you.html";
			} else {
				showErrors(data);
			}
		});
	}
	return false;
}

function validateSFLCareersForm()
{
	var Errors = '';
	$('#contactForm .requiredInput.email').each(function(){
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
				Errors += "Please Provide Your <strong>Email Address</strong><br />";
		} else {
			if (!validateEmail($(this).val())) { Errors += "Please Enter a Proper <strong>Email Address</strong><br />";}
		}
	});

	$('#contactForm .requiredInput.textArea,#contactForm .requiredInput.name, #contactForm .requiredInput.text:not(.email)').each(function(){
			if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
					Errors += "Please Provide Your <strong>" +  w_DefaultValues[$(this).attr('id')].substr(0,w_DefaultValues[$(this).attr('id')].indexOf('*')) + "</strong><br />";
			}
	});

	$("#contactForm .phone").each(function() 
	{
			if ($(this).val() != w_DefaultValues[ $(this).attr('id')])
			{
				var PhoneDgits = $(this).val().replace("-","");
				PhoneDgits = stripAlphaChars(PhoneDgits);
				if ((isNaN(PhoneDgits)) ||  (PhoneDgits == "")) 
				{ 
					Errors += "Please provide your <strong>Phone Number</strong> in (###) ###-#### format<br />";
				}
			}
	});
	
	$('#contactForm .requiredInput.select').each(function(){
		
		if ($(this).val() == w_DefaultValues[$(this).attr('id')]) {
			MyValue = $(this).children(':first').text();
			MyValue = MyValue.substr(0,MyValue.indexOf('*'));
			Errors += "Please  <strong>"+MyValue + "</strong><br />";
		}
	});	
		$('#contactForm .requiredInput.file').each(function(){
		if ($(this).val() == '') {
				Errors += "Please Provide <strong>"+  w_DefaultValues[$(this).attr('id')].substr(0,w_DefaultValues[$(this).attr('id')].indexOf('*')) + "</strong><br />";
		} 
	});		
	if (Errors != '')
	{ 
		showErrors(Errors);
	} else {
		// Do ajaxy stuff here
		return true;
	}
	return false;
}


















var EVisible = false;
function hideCalcError()
{
 if (EVisible)
 {
	 $('#CalcError').slideUp('normal');
	 EVisible = false;
 }
}

function calcSupport()
{
		var Errors = '';
		var Income = '';
		var Children = '';
		var Location = '';
		if ($('#Income').val() != '') { Income = $('#Income').val(); } else { Errors += "Please provide the <strong>Income of the paying parent</strong>.<br />";}
		if ($('#Children').val() != '') { Children = $('#Children').val(); } else { Errors += "Please provide the <strong>Number of children</strong>.<br />";}
		if ($('#Location').val() != '') { Location = $('#Location').val(); } else { Errors += "Please provide the <strong>Location of the paying parent</strong>.<br />";}
		if (Errors != '')
		{
			// do error stuff here
			if (EVisible == false)
			{
				$('#CalcError').slideDown('normal', function(){
					EVisible = true;
					setTimeout("$('#CalcError').slideUp('normal', function(){EVisible = false;});",70000);	
				});
			}
		} else {
			// do ajax stuff here
			EVisible = false;
			$('#CalcError').slideUp('normal');
			$.get("php/sfl.ajax.php", { 'childSupport': true, 'Income': Income, "Children": Children, "Location": Location},
				function(data){
					var Length = data.length;
					var SpacePos = data.indexOf(' ', 0);
					if (SpacePos == -1)
					{
						$('#csccalcright').fadeOut('normal', function(){
							$('#csccalcright .paymentValue').html("$"+data);
							$('#csccalcright .paymentExtra').html("");
							$('#csccalcright').fadeIn('normal');
						});
					} else {
						$('#csccalcright').fadeOut('normal', function(){
							$('#csccalcright .paymentValue').html("$"+data.slice(0,SpacePos));
							$('#csccalcright .paymentExtra').html(data.slice(SpacePos,Length));
							$('#csccalcright').fadeIn('normal');
						});
					}
				});
		}
}



function wSetInputHandlers(DefaultValues)
{
	
	$('#contactForm .name, #contactForm .text, #contactForm .textArea').focus(function(){
			MyValue = $(this).val();
			if (MyValue == w_DefaultValues[$(this).attr('id')]) {
					$(this).val('');
					$(this).css('font-weight','bold');
			}
		});
	$('#contactForm .name, #contactForm .text, #contactForm .textArea').blur(function(){
			MyValue = $(this).val();
			if (MyValue == '') {
					$(this).val(w_DefaultValues[$(this).attr('id')]);
					$(this).css('font-weight','normal');	
			}
		});		
}



function showThankYou()
{
	
	var Message = "Thank you for your submission.<br />We'll do our best to reply within one<br /> business day.";
	$('#contactForm').slideUp('normal',function(){
		$('#contactForm').html('<p class="thankYouBox">'+Message+'</p>');
		$('#contactForm').slideDown('normal');
	});

}


function returnDocument() {
        var file_name = document.location.href;
        var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
        return file_name.substring(file_name.lastIndexOf("/"), end);
    }


function showErrors(Errors)
{
	$('#contactForm .ErrorBox').slideUp('normal',function(){
		$('#contactForm .ErrorBox').html(Errors);
		$('#contactForm .ErrorBox').slideDown();
	});
}

function validateEmail(emailAddress) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(emailAddress) == false) {
      return false;
   } else {
		 return true;
	 }
}














function stripAlphaChars(pstrSource) 
{ 
	var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[^0-9]/g, ''); 

    return m_strOut; 
}




