/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 2/26/2009
DESCRIPTION: This document contains general javascript functionality used within the site.  Requires jQuery library
************************************************************************************************************************/
var map;
var mgrOptions = { borderPadding: 50, maxZoom: 15, trackMarkers: true };
var mgr;
var geocoder;
var errMsgBody;
var init;
function initialize() {
      if (GBrowserIsCompatible()) {	
	  	if(!init){
        map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(0,  0), 1);
		map.setUIToDefault();
		map.setMapType(G_HYBRID_MAP);
		}
		
	  }
 }
function entsub(e) {
	var unicode = e.keyCode? e.keyCode : e.charCode;
	if (unicode == 13){
   partsearch($('#partID').val());
}
}



	function validatePasswords(){
		var valid = false;
	 if($("#password").val() != ""){
		if($("#password").val() == $("#password2").val()){
			valid = true;
			}else{
				errMsgBody += '<li>Passwords do not match.</li>';
			}
	 }else{
		 errMsgBody += '<li>Passwords cannot be blank.</li>';		 
	 	}
	 return valid;
	}
	
	function validateFirstName(){
		//if it's NOT valid
		if($("#FirstName").val().length < 1){
			$("#FirstName").addClass("TextBoxError");
			errMsgBody = '<li>First name is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#FirstName").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateLastName(){
		//if it's NOT valid
		if($("#LastName").val().length < 1){
			$("#LastName").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>Last name is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#LastName").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateCompany(){
		//if it's NOT valid
		if($("#Company").val().length < 1){
			$("#Company").addClass("TextBoxError");
			errMsgBody = '<li>Company name is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#Company").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateEmail(){
		//testing regular expression
		var a = $("#EmailAddress").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		//if it's valid email
		if(filter.test(a)){
			$("#EmailAddress").removeClass("TextBoxError");
			return true;
		}
		//if it's NOT valid
		else{
			$("#EmailAddress").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>Email address is a requirement.</li>';
			return false;
		}
	}
	function validateLikeEmails(){
	var a =  $("#EmailAddress").val();
	var b =  $("#EmailAddress2").val();
	 if(a == b){
	     return true;
       }else{
            $("#EmailAddress").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>Email addresses do not match.</li>';
			return false;
			}
	}
	function validateAddr1(){
		//if it's NOT valid
		if($("#Address").val().length < 1){
			$("#Address").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>Address 1 is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#Address").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateCity(){
		//if it's NOT valid
		if($("#City").val().length < 1){
			$("#City").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>City is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#City").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateState(){
		//if it's NOT valid
		if($("#State").val() == -1){
			$("#State").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>State is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#State").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateZip(){
		//if it's NOT valid
		if($("#Zipcode").val().length < 1){
			$("#Zipcode").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>Zipcode is a requirement.</li>';
			return false;
		}
		else{
			$("#Zipcode").removeClass("TextBoxError");
			return true;
		}
	}
		
	function validateCompany(){
		//if it's NOT valid
		if($("#Company").val().length < 5){
			$("#Company").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>A company name is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#Company").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateSubject(){
		//if it's NOT valid
		if($("#Subject").val().length < 10){
			$("#Subject").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>A subject matter is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#Subject").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateBody(){
		//if it's NOT valid
		if($("#Body").val().length < 10){
			$("#Body").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>A body is a requirement.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#Body").removeClass("TextBoxError");
			return true;
		}
	}
	
	function validateDist(){
		//if it's NOT valid
		if($("#Dist:checked").val() == null){
			$("#Dist").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>You must agree that you are an authorized Lyn-Tron distributor.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#Dist").removeClass("TextBoxError");
			return true;
		}		
	}
	
	function validateTerms(){
		//if it's NOT valid
		if($('#Terms:checked').val() == null){
			$("#Terms").addClass("TextBoxError");
			errMsgBody = errMsgBody + '<li>You must agree to the Terms and Conditions.</li>';
			return false;
		}
		//if it's valid
		else{
			$("#Terms").removeClass("TextBoxError");
			return true;
		}		
	}
	//validateTerms
	
	
	
	






$(document).ready(function() {
	$(".thumb").click(function(){
			var strImg =   $(this).attr('src');
			$("#mainImage").attr({
				src: 'http://ajax.lyntron.com/watermark.php?src='+strImg,
				height: '375',
				align:'center'
				});
				$("#webready").attr({
				href:strImg
			});
			strImg = strImg.replace("LynTronImages/Professional","pressready");
			strImg = strImg.replace("jpg","tif");			
			$("#pressready").attr({
				href:strImg
			});
			});
	
	//Add alternating row colors to all tables in the Catalog portion
	$(".generatepart table tr:odd").addClass("CatOdd");
	$(".generatepart table tr:even").addClass("CatEven");
	
	$(".generatepart table tr").mouseover(function() {
		$(this).addClass("CatOver");
		})
		.mouseout(function() {
			$(this).removeClass("CatOver");
			});

	// This portion is used to keep the heading on the plating matrix at the top.
	if (window.pageYOffset > 0){
		window.scroll(0,window.pageYOffset - 60);
	}




	/********************************************************************************************************************
	Form validation
	********************************************************************************************************************/	
	//On key change
	$("#FirstName").blur(function(){validateFirstName()});
	$("#LastName").blur(function(){validateLastName()});
	$("#Address").blur(function(){validateAddr1()});
	$("#City").blur(function(){validateCity()});
	$("#State").click(function(){validateState()});
	$("#Zipcode").blur(function(){validateZip()});
	$("#EmailAddress").blur(function(){validateEmail()});

	$("#FormCatalog").ready(function() {
		$('#message').hide();							 
	});
	
	$("#FormEmail").ready(function() {
		$('#message').hide();							 
	});
		
	$("#FormUserReq").ready(function() {
		$('#message').hide();							 
	});
	
	
	$("#formPasswordReset").submit(function(){
											var valid = false;
											$("#div_pass").css('display','block');
													$("#div_pass_temp").css('display','none');
													$("#div_pass_temp2").css('display','none');
													$("#div_pass2").css('display','block');
											if($("#password").val() != ""){
												if($("#password").val() == $("#password2").val()){
													
													valid = true;
												}else{
													$("#message").html("<ul><li>Please check password</li><li>"+$("#password").val()+"</li><li>"+$("#password").val()+"</li></ul>");
													$("#message").show();
												}
											}
											return valid;
											});
	
	
	//On Submitting
	$("#btnSend").click(function(){
		//Hide any previous messages
		$("#message").hide();
		errMsgBody = '';
		
		
		
		//validate fields
		if(validateFirstName() & validateLastName())
		{
			var elements = document.FormCatalog.elements;
			var message = "";
			var emailAddress = elements['EmailAddress'].value;
			
			//loop through form elements and get field values to insert into mail template
			for(i=0;i<13;i++)
			{
				message = 	message + "<br/>"+elements[i].name + " " +elements[i].value;
			}
			
			//send the message
			$.post('lynMail/send',{message1: message,to: "info@lyntron.com",from: emailAddress,replyTo: emailAddress,files: "",cc: "",subject: "Catalog Request",mailTemplate: elements['mailTemplate'].value}); 
			
			//show message that request was sent	   				   
			$("#message").html("<strong>Message was sent</strong>");
			$("#message").addClass("Valid");
			$("#message").show();	
			for(i=0;i<13;i++)
			{
				elements[i].value = "";	  
			}
								   
			return true;
		}
		else{
			if(errMsgBody.length > 5)
			{
				$("#message").html("<strong>Errors were found</strong><ul>" + errMsgBody + "</ul>");
				$("#message").show();
			}
				return false;
			}
	});
	
	
	
	
	
	
	// Sending out a catalog -- need to check more values
	$("#SendCatalog").click(function()
	{
		//Hide any previous messages
		$("#message").hide();
		errMsgBody = '';

		//validate fields
		if(validateFirstName() & validateLastName() & validateEmail() & validateAddr1() & validateCity() & validateState() & validateZip())
		{
			//create vars
			var body = "";
			body = body + $('#FirstName').val() + ' ' + $('#LastName').val() + '<br/>' + $('#Company').val() + '<br/>' + $('#Address').val() + '<br/>' + $('#Address2').val() + '<br/>' + $('#Address3').val() + '<br/>' + $('#City').val() + '<br/>' + $('#State').val() + '<br/>' + $('#Zipcode').val() + '<br/>' + $('#Country').val() + '<br/>' + $('#EmailAddress').val() + '<br/>' + $('#PhoneNumber').val() + '<br/>' + $('#FaxNumber').val() + '<br/>' + $('#NumOfCatalogs').val() + '<br/>';
			//post message to be sent
			$.post('/lynMail/send',{'FirstName':$('#FirstName').val(),'to':'info@lyntron.com','from':$('#EmailAddress').val(),'message':body,'subject':'Catalog Request','cc':'','mailTemplate':$('#mailTemplate').val()});
			
			//show message that request was sent	   				   
			$("#message").html("<strong>Message was sent</strong>");
			$("#message").addClass("Valid");
			$("#message").show();
			
			
			return true;
		}
		else
		{
			if(errMsgBody.length > 5)
			{
				$("#message").html("<strong>Errors were found</strong><ul>" + errMsgBody + "</ul>");
				$("#message").show();
			}
				return false;
			}
	});
	
		
	// Sending email message to our account receivable department
	$("#SendAcctsRec").click(function()
	{
		//Hide any previous messages
		$("#message").hide();
		errMsgBody = '';

		//validate fields
		
			var body = "";
			body = body + $('#Company').val() + ' <br/> ' + $('#Telephone').val() + ' <br/>' + $('#InvoiceNums').val() + '<br/>' + $('#Body').val();
			//post message to be sent
			$.post('/lynMail/sendAR',{'to':'jsocci@lyntron.com','from':$('#EmailAddress').val(),'message':body,'subject':$('#Subject').val(),'mailTemplate':$('#mailTemplate').val()});
			
			//show message that request was sent	   				   
			$("#message").html("<strong>Message was sent</strong>");
			$("#message").addClass("Valid");
			$("#message").show();
			return false;
		
	});
	
	
		// Sending email message to our account payable department
	$("#SendAcctsPay").click(function()
	{
		//Hide any previous messages
		$("#message").hide();
		errMsgBody = '';

		//validate fields
		
			var body = "";
			body = body + $('#Company').val() + ' <br/> ' + $('#Telephone').val() + ' <br/>' + $('#invoicenums').val() + '<br/>' + $('#body').val();
			//post message to be sent
			$.post('/lynMail/sendAP',{'to':'ngoldsberry@lyntron.com','from':$('#from').val(),'message':body,'subject':$('#subject').val(),'mailTemplate':$('#mailTemplate').val()});
			
			//show message that request was sent	   				   
			$("#message").html("<strong>Message was sent</strong>");
			$("#message").addClass("Valid");
			$("#message").show();
			return false;
		
	});
	
	
		// Sending email message to our account receivable department
	$("#SendSample").click(function()
	{
		//Hide any previous messages
		$("#message").hide();
		errMsgBody = '';

		//validate fields
		if(validateFirstName() & validateLastName() & validateEmail() & validateAddr1() & validateCity() & validateState() & validateZip())
		{
			var msg = "";
			var items = $('#tblSampleAdded').html().replace(/<img/g,'<!--<img');
			items = items.replace(/height="17">/g,'>-->');
			items = items.replace('<td class="EmailTD">Remove</td>','');
			msg = msg + $('#FirstName').val() + ' ' + $('#LastName').val() + '<br/>' + $('#Company').val() + '<br/>' + $('#Address').val() + '<br/>' + $('#Address2').val() + '<br/>' + $('#Address3').val() + '<br/>' + $('#City').val() + '<br/>' + $('#State').val() + '<br/>' + $('#Zipcode').val() + '<br/>' + $('#Country').val() + '<br/>' + $('#EmailAddress').val() + '<br/>' + $('#PhoneNumber').val() + '<br/>' + $('#FaxNumber').val() + '<br/>' + '<table width="650" style=\'text-align:center;\'>' + items + '</table>' + '<br/>';


			//show message that request was sent	   				   
			$("#message").html("<strong>Message was sent</strong>");
			$("#message").addClass("Valid");
			$("#message").show();
			
			
			$.post('/lynMail/sendSample',{'fname':$('#FirstName').val(),'lname':$('#LastName').val(),'to':'info@lyntron.com','from':$('#EmailAddress').val(),'message':msg,'subject':'Sample Request','cc':'','mailTemplate':$('#mailTemplate').val()});
			
			$(".itemRow").each(function(){
									$(this).remove();});	
		}
		else{
			if(errMsgBody.length > 5) 
			{
				$("#message").html("<strong>Errors were found</strong><ul>" + errMsgBody + "</ul>");
				$("#message").show();
			}
				return false;
			}
	});
	

	$("#formUserReq").submit(function()
	{
		//Hide any previous messages
		$("#message").hide();
		errMsgBody = '';

		//validate fields
		if(validateLikeEmails() & validateFirstName() & validateLastName() & validateEmail() & validateCompany() & validateState() & validateDist() & validateTerms() & validatePasswords())
		{
			var body = "";
			var items = "";
			body = body + $('#FirstName').val() + ' ' + $('#LastName').val() + '<br/>' + 
				$('#Company').val() + '<br/>' + 
				$('#State').val() + '<br/>' + 
				$('#EmailAddress').val() + '<br/>' + 
				$('#Password').val();


			//show message that request was sent	   				   
			$("#message").html("<strong>Sending Request...</strong>");
			$("#message").addClass("Valid");
			$("#message").show();
			
		}
		else{
			if(errMsgBody.length > 5) 
			{
				$("#message").html("<strong>Errors were found</strong><ul>" + errMsgBody + "</ul>");
				$("#message").show();
			}
				return false;
			}
	});
	
	

	
	
	
	
	/********************************************************************************************************************
	HANDLE State select on rep and dist map
	********************************************************************************************************************/	
	$("#stateSelect").change(function(){
		$.post("ajax/getDists.php",{stateSelect : $("#stateSelect").val()},function(data){
								  $("#locations").html(data);
								  },"html");
									  });



	/********************************************************************************************************************
	HANDLE LOGIN BOX LABELS
	********************************************************************************************************************/	
	$("#formUser").focus(function () {
		$("#formUser").css('background-image', 'url()');
	});
	
	$("#formUser").blur(function () {
		var user = $("#formUser").attr('value');
		if(user == "") {
			$("#formUser").css('background-image', 'url(/images/username_background.jpg)');
		}
	});
	
	$("#formPass").focus(function () {
		$("#formPass").css('background-image', 'url()');
	});
	
	$("#formPass").blur(function () {
		var user = $("#formPass").attr('value');
		if(user == "") {
			$("#formPass").css('background-image', 'url(/images/password_background.jpg)');
		}
	});
	
	/********************************************************************************************************************
	HANDLE HOMEPAGE PRESENTATION
	********************************************************************************************************************/
	/* HANDLE THE CLICK EVENT AND SWAP OUT THE APPROPRIATE IMAGE AND CHANGE THE CONTENT OF THE LEFT DIV */
	$('#presentationButton1').click(function() {
		$('#presentationContent').fadeOut("slow",function() {
			$('#presentationContent').load('/includes/presentation/product-catalog.htm', function() {
				$('#presentationContent').fadeIn("slow");						
				$('#presentationButton1').attr('src','/images/presentation_productcatalog_on.jpg');
				$('#presentationButton2').attr('src','/images/presentation_customprojects.jpg');
				$('#presentationButton3').attr('src','/images/presentation_technical.jpg');
			});
		});
	});
	$('#presentationButton2').click(function() {
		$('#presentationContent').fadeOut("slow",function() {
			$('#presentationContent').load('/includes/presentation/custom-projects.htm', function() {
				$('#presentationContent').fadeIn("slow");						
				$('#presentationButton1').attr('src','/images/presentation_productcatalog.jpg');
				$('#presentationButton2').attr('src','/images/presentation_customprojects_on.jpg');
				$('#presentationButton3').attr('src','/images/presentation_technical.jpg');
			});
		});
	});
	$('#presentationButton3').click(function() {
		$('#presentationContent').fadeOut("slow",function() {
			$('#presentationContent').load('/includes/presentation/technical.htm', function() {
				$('#presentationContent').fadeIn("slow");						
				$('#presentationButton1').attr('src','/images/presentation_productcatalog.jpg');
				$('#presentationButton2').attr('src','/images/presentation_customprojects.jpg');
				$('#presentationButton3').attr('src','/images/presentation_technical_on.jpg');
			});
		});
	});
	
	/* MOUSEOVER EVENT TO CHECK THE TEXT COLOR */
	$('#presentationButton1').hover(function() {
		$('#presentationButton1').attr('src','/images/presentation_productcatalog_on.jpg');
	}, function() {
		$('#presentationButton1').attr('src','/images/presentation_productcatalog.jpg');
	});

	$('#presentationButton2').hover(function() {
		$('#presentationButton2').attr('src','/images/presentation_customprojects_on.jpg');
	}, function() {
		$('#presentationButton2').attr('src','/images/presentation_customprojects.jpg');
	});

	$('#presentationButton3').hover(function() {
		$('#presentationButton3').attr('src','/images/presentation_technical_on.jpg');
	}, function() {
		$('#presentationButton3').attr('src','/images/presentation_technical.jpg');
	});
	/********************************************************************************************************************
	TOGGLE THE LOOKUP BOXES ON THE INDEX PAGE OF THE TEMPLATE
	********************************************************************************************************************/	
	$('#lookup1').click(function() {
		$('#lookup1').attr('src','/images/loginbox_partreference_on.jpg');
		$('#lookup2').attr('src','/images/loginbox_partslookup.jpg');
		$('#lookup3').attr('src','/images/loginbox_finddistributor.jpg');
		$('#lookup4').attr('src','/images/loginbox_customerportal.jpg');
		$('#loginContent').load('/includes/search/part-number-cross-reference.htm');
	});
	$('#lookup2').click(function() {
		$('#lookup1').attr('src','/images/loginbox_partreference.jpg');
		$('#lookup2').attr('src','/images/loginbox_partslookup_on.jpg');
		$('#lookup3').attr('src','/images/loginbox_finddistributor.jpg');
		$('#lookup4').attr('src','/images/loginbox_customerportal.jpg');
		$('#loginContent').load('/includes/search/part-number-lookup.htm');
	});
	$('#lookup3').click(function() {
		$('#lookup1').attr('src','/images/loginbox_partreference.jpg');
		$('#lookup2').attr('src','/images/loginbox_partslookup.jpg');
		$('#lookup3').attr('src','/images/loginbox_finddistributor_on.jpg');
		$('#lookup4').attr('src','/images/loginbox_customerportal.jpg');
		$('#loginContent').load('/includes/search/find-a-rep-or-distributor.html');
	});
	$('#lookup4').click(function() {
		$('#lookup1').attr('src','/images/loginbox_partreference.jpg');
		$('#lookup2').attr('src','/images/loginbox_partslookup.jpg');
		$('#lookup3').attr('src','/images/loginbox_finddistributor.jpg');
		$('#lookup4').attr('src','/images/loginbox_customerportal_on.jpg');
		$.post('/home/loginContent/portal', function(data){
			   $('#loginContent').html(data);
													 });
	});
		
	/********************************************************************************************************************
	HANDLE SIDENAV MOUSEOVER
	********************************************************************************************************************/	
    $("div.sidenavOff").mouseover(function(){
    	$(this).removeClass("sidenavOff").addClass("sidenavOver");
    }).mouseout(function(){
    	$(this).removeClass("sidenavOver").addClass("sidenavOff");		
    });
	
    $("div.sidenav2Off").mouseover(function(){
    	$(this).removeClass().addClass("sidenav2Over");
    }).mouseout(function(){
    	$(this).removeClass().addClass("sidenav2Off");		
    });

	/********************************************************************************************************************
	SIMPLE ACCORDIAN STYLE MENU FOR THE CATALOG
	********************************************************************************************************************/	
	$('div.catalogItem').click(function() {
		if($(this).next().is(':visible')) {
			$('div.catalogDescription').slideUp('normal');
		} else {
			$('div.catalogDescription').slideUp('normal');	
			$(this).next().slideDown('normal');
		}
	});
	//PRICING SEARCH ACCORDIAN
	$(".searcharrow").click(function(){
									 
								if($(this).attr('src') == "/common/jqGrid-3.4.4/themes/steel/images/down.gif"){
									
									$(this).attr('src','/common/jqGrid-3.4.4/themes/steel/images/up.gif');
								}else{
									
									$(this).attr('src','/common/jqGrid-3.4.4/themes/steel/images/down.gif');
								}
								 if ($(this).next().is(':visible')){
									 $(this).next().slideUp('normal');
								 }else{
									 $(this).next().slideDown('normal');
								 }
									 });

	//CLOSES THE MENU
	$('img.closeButton').click(function() {
		$('div.catalogDescription').slideUp('normal');	
	});
	
	
	$('div.partBuilderName').click(function() {
		if($(this).next().is(':visible')) {
			$('div.partBuilder').slideUp('normal');
		} else {
			$(this).next().slideDown('normal');
		}
	});
	
		

	/********************************************************************************************************************
	INDEX / HOME SPECIFIC STYLES
	********************************************************************************************************************/	
	$("div.catalogDescription").hide();
	$("#lookup1").trigger('click');
	
	/********************************************************************************************************************
	MAP / SIDENAV
	********************************************************************************************************************/
	$("div.state").click(function(){
		centerMap($(this).attr("lat"),$(this).attr("lon"),$(this).attr("zoom"));
		});
	});

	/********************************************************************************************************************
	HOME PAGE ZIPCODE SEARCH FORM CODE BEHIND
	********************************************************************************************************************/
	$("#btnRepSearch").click(function(){
		document.location = 'rep.php?z=' + $("#txtRepSearch").text();
	});
	
	/********************************************************************************************************************
	Google Map API code to handle the Distributors and Reps
	********************************************************************************************************************/
	function showAddress(address) {
		//var map = new GMap2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
	  geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " not found");
		  } else {
			map.setCenter(point, 6);
		   // var marker = new GMarker(point);
		   // map.addOverlay(marker);
		   // marker.openInfoWindowHtml(address);
		  }
		}
	  );
	}

	function centerMap(lat, lon, zoom){
		var point = new GLatLng(lat,lon);
		var z = Number(zoom);
		map.setCenter(point, z);
		window.scroll(0,0);
	}
	
	function showAddress3(address) {
		if(!map){
		map = new GMap2(document.getElementById("map"));
		}
		var geocoder = new GClientGeocoder();
	  geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " not found");
		  } else {
			map.setCenter(point, 11);
		   // var marker = new GMarker(point);
		   // map.addOverlay(marker);
		   // marker.openInfoWindowHtml(address);
		  }
		}
	  );
	}
	
	function addMarker(lat, lon, html) {
		if(!map){
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(0,  0), 1);
			map.setUIToDefault();
			map.setMapType(G_HYBRID_MAP);
		}
		//var geocoder = new GClientGeocoder();
	 // geocoder.getLatLng(
	 //   address,
	  //  function(point) {
	  //    if (!point) {
	   //     alert(address + " not found");
	   //   } else {
		   var point = new GLatLng(lat,lon);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
		}
	  );
	}
	

 
	
	
	
	
	function addMarker2(lat, lon, html) {
		if(!map){
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(0,  0), 1);
			map.setUIToDefault();
			map.setMapType(G_HYBRID_MAP);
		}
		//var geocoder = new GClientGeocoder();
	 // geocoder.getLatLng(
	 //   address,
	  //  function(point) {
	  //    if (!point) {
	   //     alert(address + " not found");
	   //   } else {
		 var baseIcon = new GIcon();
			baseIcon.iconSize=new GSize(32,32);
			baseIcon.shadowSize=new GSize(56,32);
			baseIcon.iconAnchor=new GPoint(16,32);
			baseIcon.infoWindowAnchor=new GPoint(16,0);
			var lyn = new GIcon(baseIcon, "/images/lyntronIcon.gif", null, "");
			var point = new GLatLng(lat, lon);
			var lynIcon = new GMarker(point,{icon:lyn})
			map.addOverlay(lynIcon);
			GEvent.addListener(lynIcon, "click", function() {
			lynIcon.openInfoWindowHtml(html);
		}
	  );
	}

	function showAddress2(address, name, web, phone, fax) {
		//var map = new GMap2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
	  geocoder.getLatLng(
		address,
		function(point) {
		  if (!point) {
			alert(address + " not found");
		  } else {
			map.setCenter(point, 13);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			marker.openInfoWindowHtml("<div class='bubbleText'> <b>" + name + "</b><br/>" + address + "<br/>" + "Phone: " + phone + "<br/>" + "Fax: " + fax + "<br/>" + "<a href='"+web+"'>"+web+"</a></div>");
		  }
		}
	  );
	}
  
	function partSearch(p){		
		$.post("PartSearch.php",{'part_number':p});
	}























//	function validate_form(Form) 
//	{
//		var strErrorMsg;
//		
//		switch(Form)
//		{
//			case 'FormCatalog':
//				//if(!ValidEmailSyntax($("#Email").val())) {
////					
////				}
//				if($("#FirstName").val() == '')
//					strErrorMsg = 'Missing first name!';
//					
//			case 'foo':
//		}
//		
//		if(strErrorMsg != '') {
//			$("#ErrorsFound").html("test");
//			$("#ErrorsFound").show();
//			return false;
//		}
//	}
//	
//	function ValidEmailSyntax(strEmail)
//	{
//		emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
//		if(!emailpat.test(strEmail)){
//			return false; 
//		}
//		else{
//			return true;
//		}
//	}
	 
		



    

	
