//this is the javascript for the Yellow Pages
//by Liz Delgado

j=jQuery.noConflict();


j(document).ready(function(){

//set items to their onLoad state

	j(".srchPop,.tip,.Can").hide();
	
	var sel = j('input[name="srchSelect_us"]:checked').val();
	setSelPopup(sel);
	
	var wwsel = j('input[name="wwSrch"]:checked').val();
	setSelPopup(wwsel);
	
	var wwSel = j('#selCountry option:selected').val();
		setCanada(wwSel);
	
	
//functions		
	function setSelPopup(sel){
		if(sel=="national"|| sel=="region" || sel=="state"){
			j('.srchPopUS').hide();
			
		}else if (sel=="Worldwide"|| sel=="Continent"|| sel=="Country"|| sel=="Province"){
			j('.srchPopWW').hide();
		}
		switch (sel) {
			case "national":
				break;
			
			case "region":
			j('#USregions').show()
			break;
			
			case "state":
			j('#USstates').show();
			break;
			
			case "Continent":
			j('#wwProvince').hide();
			j('#selContinent').show();
			break;
			
			case "Country":
			if(j('#selCountry option:selected').val()=="Canada"){
				j('#wwProvince').show();
			}else{
				j('#wwProvince').hide();
			}
			j('#selCountry').show();
			break;
			
			case "Province":
			j('#selProvince').show();
			break;
			};			
		};
		
	function setCanada(sel){
		if(sel=="Canada"){
				j('#wwProvince').show();
			}else{
				j(".Can").hide();
			}
		};

	function setUrl(sel){
		switch (sel){
			case "national":
			j('#USgo').attr("href","index.a4d?action=cyp.list;state=national");
			break;
			
			case "region":
			var selRegion = j('#USregions option:selected').val();
				var acURL = 'index.a4d?action=cyp.list;region=';
				acURL+=selRegion
				j('#USgo').attr("href",acURL);
			break;
			
			case "state":
			var selState = j('#USstates option:selected').val();
			var acURL = 'index.a4d?action=cyp.list;state=';
				acURL+=selState
				j('#USgo').attr("href",acURL)
			break;
			
			case "Worldwide":
			j('#wwgo').attr("href","index.a4d?action=cyp.list;Continent=worldwide");
			break;
			
			case "Continent":
			var wwContinent = j('#selContinent option:selected').val();
				var acURL = 'index.a4d?action=cyp.list;Continent=';
				acURL+=wwContinent;
				j('#wwgo').attr("href",acURL);
			break;
			
			case "Country":
			var wwCountry = j('#selCountry option:selected').val();
			if(wwCountry=="Canada"){
				j('#wwProvince').show();
			}else{
				j(".Can").hide();
			}
			var acURL = 'index.a4d?action=cyp.list;country=';
				acURL+=wwCountry;
				j('#wwgo').attr("href",acURL);
			break;
			
			case "Province":
			var wwProvince = j('#selProvince option:selected').val();
			var acURL = 'index.a4d?action=cyp.list;province=';
				acURL+=wwProvince;
				j('#wwgo').attr("href",acURL);
			break;
			
			}
		};	
		
		

//Display the correct popup and URL when the page loads	and when user changes an option


	j('input[name="srchSelect_us"],input[name="wwSrch"]').click(function(){
		var sel = j(this).val();
		setSelPopup(sel);
		//setUrl(sel);
		});
		
	  	
	  j('#selCountry').change(function(){
			var wwSel = j('#selCountry option:selected').val();
			setCanada(wwSel);
			
		});


  /* j("#USregions, #USstates").change(function(){ 
		var sel =j('input[name="srchSelect_us"]:checked').val();
		//setSurl(sel);
		});
		
		
   j("#selContinent, #selCountry, #selProvince").change(function(){
	 	 var sel =j('input[name="wwSrch"]:checked').val();
		 setUrl(sel);
	  	});*/
	
	  



//These functions handle the rollover tips
	j('#usNational').bt({
		closeWhenOthersOpen: true,
		padding: '10px',
		fill: '#FFFF33',
		width: '100px',
		cornerRadius: '20px',
		shadow: true,
		contentSelector: "j('#nationalTip')",
		position: [,'top','left','top','left'],
		cssStyles:{color:'#000'},
		});
		
	j('#usRegions').bt({
		width: '100px',
		closeWhenOthersOpen: true,
		padding: '10px',
		fill: '#FFFF33',
		cornerRadius: '40px',
		shadow: true,
		contentSelector: "j('#regionTip')",
		position: ['bottom','left','top','right'],
		cssStyles:{color:'#000'},
		});
		
	j('#usStates').bt({
		closeWhenOthersOpen: true,
		padding: '10px',
		fill: '#FFFF33',
		width: '80px',
		cornerRadius: '20px',
		shadow: true,
		contentSelector: "j('#stateTip')",
		position: ['bottom','left','top','right'],
		cssStyles:{color:'#000'},
		});
		
	j('#ww').bt({
		closeWhenOthersOpen: true,
		padding: '10px',
		fill: '#FFFF33',
		width: '80px',
		cornerRadius: '20px',
		shadow: true,
		contentSelector: "j('#wwTip')",
		position: ['bottom','left','top','right'],
		cssStyles:{color:'#000'},
		});
		
	j('#wwContinent').bt({
		closeWhenOthersOpen: true,
		padding: '10px',
		fill: '#FFFF33',
		width: '80px',
		cornerRadius: '20px',
		shadow: true,
		contentSelector: "j('#continentTip')",
		position: ['bottom','left','top','right'],
		cssStyles:{color:'#000'},
		});
		
	j('#wwCountry').bt({
		closeWhenOthersOpen: true,
		padding: '10px',
		fill: '#FFFF33',
		width: '80px',
		cornerRadius: '20px',
		shadow: true,
		contentSelector: "j('#countryTip')",
		position: ['bottom','left','top','right'],
		cssStyles:{color:'#000'},
		});
		
	j('#wwProvince').bt({
		closeWhenOthersOpen: true,
		padding: '10px',
		fill: '#FFFF33',
		width: '80px',
		cornerRadius: '20px',
		shadow: true,
		contentSelector: "j('#provinceTip')",
		position: ['bottom','left','top','right'],
		cssStyles:{color:'#000'},
		});
			
 
	    	
	  	
	 /* function setwwURL(sel){   		
		
		switch (sel){
			case "Worldwide":
			j('#wwgo').attr("href","index.a4d?action=cyp.list;Continent=worldwide");
			break;
			
			case "Continent":
			var wwContinent = j('#selContinent option:selected').val();
				var acURL = 'index.a4d?action=cyp.list;Continent=';
				acURL+=wwContinent;
				j('#wwgo').attr("href",acURL);
			break;
			
			case "Country":
			var wwSel = j('#selCountry option:selected').val();
			if(wwSel=="Canada"){
				j('#wwProvince').show();
			}else{
				j(".Can").hide();
			}
			var acURL = 'index.a4d?action=cyp.list;country=';
				acURL+=wwCountry;
				j('#wwgo').attr("href",acURL);
			break;
			
			case "Province":
			var wwProvince = j('#selProvince option:selected').val();
			var acURL = 'index.a4d?action=cyp.list;province=';
				acURL+=wwProvince;
				j('#wwgo').attr("href",acURL);
			break;
			
			default:
			j('#wwgo').attr("href","index.a4d?action=cyp.list;Continent=worldwide");
			};
		};*/
			
	

})

